summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-08 15:08:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-08 15:08:42 +0000
commit8d9f495d68664017e0b87f2c0c2d0eae9f3c4836 (patch)
tree157087760d624a657c3ce11b142afb1c72bf225a
parentb04b4357ff5a5b5194a7ff3c875d8746fac9ff33 (diff)
getopt32: fix llist_t options ordering. llist_rev is not unused.
function old new delta tar_main 705 695 -10 sort_main 928 918 -10 decode_format_string 886 876 -10 run_parts_main 197 185 -12 ps_main 513 500 -13 wget_main 2764 2750 -14 awk_main 1014 1000 -14 od_main 2886 2866 -20 llist_rev 25 - -25 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/8 up/down: 0/-128) Total: -128 bytes
-rw-r--r--archival/tar.c3
-rw-r--r--coreutils/od_bloaty.c1
-rw-r--r--coreutils/sort.c1
-rw-r--r--debianutils/run_parts.c3
-rw-r--r--editors/awk.c1
-rw-r--r--include/libbb.h69
-rw-r--r--libbb/getopt32.c4
-rw-r--r--libbb/llist.c23
-rw-r--r--networking/wget.c2
-rw-r--r--procps/ps.c1
10 files changed, 53 insertions, 55 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 6552d6c57..f2f1ccd06 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -864,10 +864,9 @@ int tar_main(int argc, char **argv)
char *cp = last_char_is(argv[optind], '/');
if (cp > argv[optind])
*cp = '\0';
- llist_add_to(&tar_handle->accept, argv[optind]);
+ llist_add_to_end(&tar_handle->accept, argv[optind]);
optind++;
}
- tar_handle->accept = llist_rev(tar_handle->accept);
if (tar_handle->accept || tar_handle->reject)
tar_handle->filter = filter_accept_reject_list;
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 74765f842..efdbf354a 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -1312,7 +1312,6 @@ int od_main(int argc, char **argv)
if (opt & OPT_l) decode_format_string("d4");
if (opt & OPT_o) decode_format_string("o2");
//if (opt & OPT_t)...
- lst_t = llist_rev(lst_t);
while (lst_t) {
decode_format_string(lst_t->data);
lst_t = lst_t->link;
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 311d0cb9c..dad542964 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -296,7 +296,6 @@ int sort_main(int argc, char **argv)
key_separator = str_t[0];
}
/* parse sort key */
- lst_k = llist_rev(lst_k);
while (lst_k) {
enum {
FLAG_allowed_for_k =
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c
index 873263a22..eb2fb94b3 100644
--- a/debianutils/run_parts.c
+++ b/debianutils/run_parts.c
@@ -131,9 +131,6 @@ int run_parts_main(int argc, char **argv)
*/
umask(xstrtoul_range(umask_p, 8, 0, 07777));
}
-//XXX: FIXME: reverse the list before handing it over to the user.
-//XXX: FIXME: The common case seems to be to use the order given by the user
- arg_list = llist_rev(arg_list); /* XXX: getopt32 appends them */
for (tmp = 1; arg_list; arg_list = arg_list->link, tmp++)
G.cmd[tmp] = arg_list->data;
/* G.cmd[tmp] = NULL; - G is already zeroed out */
diff --git a/editors/awk.c b/editors/awk.c
index a18025ef0..f331a33fa 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2707,7 +2707,6 @@ int awk_main(int argc, char **argv)
argv += optind;
argc -= optind;
if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
- opt_v = llist_rev(opt_v);
while (opt_v) { /* -v */
if (!is_assignment(llist_pop(&opt_v)))
bb_show_usage();
diff --git a/include/libbb.h b/include/libbb.h
index 6956aaf7b..6731adfe3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -285,7 +285,7 @@ extern void sig_catch(int,void (*)(int));
//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
extern void sig_block(int);
extern void sig_unblock(int);
-/* UNUSED: extern void sig_blocknone(void);*/
+/* UNUSED: extern void sig_blocknone(void); */
extern void sig_pause(void);
#define wait_crashed(w) ((w) & 127)
@@ -294,7 +294,6 @@ extern void sig_pause(void);
#define wait_stopped(w) (((w) & 127) == 127)
-
void xsetgid(gid_t gid);
void xsetuid(uid_t uid);
void xchdir(const char *path);
@@ -343,7 +342,7 @@ int xsocket_stream(len_and_sockaddr **lsap);
/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
* numeric IP ("N.N.N.N") or numeric IPv6 address,
* and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
- * If there is no suffix, port argument is used */
+ * Only if there is no suffix, port argument is used */
int create_and_bind_stream_or_die(const char *bindaddr, int port);
int create_and_bind_dgram_or_die(const char *bindaddr, int port);
/* Create client TCP socket connected to peer:port. Peer cannot be NULL.
@@ -412,9 +411,9 @@ extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf,
//int LONE_DASH(const char *s) { return s[0] == '-' && !s[1]; }
//static ATTRIBUTE_ALWAYS_INLINE
//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; }
-#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1])
+#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1])
#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
-#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
+#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1])
/* dmalloc will redefine these to it's own implementation. It is safe
@@ -456,14 +455,17 @@ extern FILE *fopen_or_warn(const char *filename, const char *mode);
extern FILE *fopen_or_warn_stdin(const char *filename);
-extern char *utoa(unsigned n);
-extern char *itoa(int n);
+char *utoa(unsigned n);
+char *itoa(int n);
/* Returns a pointer past the formatted number, does NOT null-terminate */
-extern char *utoa_to_buf(unsigned n, char *buf, unsigned buflen);
-extern char *itoa_to_buf(int n, char *buf, unsigned buflen);
-extern void smart_ulltoa5(unsigned long long ul, char buf[5]);
-/* Put a string of hex bytes (ala "1b"), return advanced pointer */
-extern char *bin2hex(char *buf, const char *cp, int count);
+char *utoa_to_buf(unsigned n, char *buf, unsigned buflen);
+char *itoa_to_buf(int n, char *buf, unsigned buflen);
+void smart_ulltoa5(unsigned long long ul, char buf[5]);
+//TODO: provide pointer to buf (avoid statics)?
+const char *make_human_readable_str(unsigned long long size,
+ unsigned long block_size, unsigned long display_unit);
+/* Put a string of hex bytes ("1b2e66fe"...), return advanced pointer */
+char *bin2hex(char *buf, const char *cp, int count);
struct suffix_mult {
const char *suffix;
@@ -580,16 +582,20 @@ extern uint32_t option_mask32;
extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
-typedef struct llist_s {
+typedef struct llist_t {
char *data;
- struct llist_s *link;
+ struct llist_t *link;
} llist_t;
-extern void llist_add_to(llist_t **old_head, void *data);
-extern void llist_add_to_end(llist_t **list_head, void *data);
-extern void *llist_pop(llist_t **elm);
-extern void llist_unlink(llist_t **head, llist_t *elm);
-extern void llist_free(llist_t *elm, void (*freeit)(void *data));
-extern llist_t* llist_rev(llist_t *list);
+void llist_add_to(llist_t **old_head, void *data);
+void llist_add_to_end(llist_t **list_head, void *data);
+void *llist_pop(llist_t **elm);
+void llist_unlink(llist_t **head, llist_t *elm);
+void llist_free(llist_t *elm, void (*freeit)(void *data));
+llist_t *llist_rev(llist_t *list);
+/* BTW, surprisingly, changing API to
+ * llist_t *llist_add_to(llist_t *old_head, void *data)
+ * etc does not result in smaller code... */
+
#if ENABLE_FEATURE_PIDFILE
int write_pidfile(const char *path);
@@ -674,10 +680,6 @@ extern int del_loop(const char *device);
extern int set_loop(char **device, const char *file, unsigned long long offset);
-//TODO: provide pointer to buf (avoid statics)?
-const char *make_human_readable_str(unsigned long long size,
- unsigned long block_size, unsigned long display_unit);
-
//TODO: pass buf pointer or return allocated buf (avoid statics)?
char *bb_askpass(int timeout, const char * prompt);
int bb_ask_confirmation(void);
@@ -725,14 +727,14 @@ extern void print_login_issue(const char *issue_file, const char *tty);
extern void print_login_prompt(void);
-extern int get_terminal_width_height(const int fd, int *width, int *height);
+int get_terminal_width_height(const int fd, int *width, int *height);
char *is_in_ino_dev_hashtable(const struct stat *statbuf);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
#ifdef __GLIBC__
/* At least glibc has horrendously large inline for this, so wrap it */
-extern unsigned long long bb_makedev(unsigned int major, unsigned int minor);
+unsigned long long bb_makedev(unsigned int major, unsigned int minor);
#undef makedev
#define makedev(a,b) bb_makedev(a,b)
#endif
@@ -745,7 +747,7 @@ extern unsigned long long bb_makedev(unsigned int major, unsigned int minor);
#else
#define MAX_HISTORY 0
#endif
-struct line_input_t {
+typedef struct line_input_t {
int flags;
const char *path_lookup;
#if MAX_HISTORY
@@ -754,7 +756,7 @@ struct line_input_t {
USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;)
char *history[MAX_HISTORY + 1];
#endif
-};
+} line_input_t;
enum {
DO_HISTORY = 1 * (MAX_HISTORY > 0),
SAVE_HISTORY = 2 * (MAX_HISTORY > 0) * ENABLE_FEATURE_EDITING_SAVEHISTORY,
@@ -764,7 +766,6 @@ enum {
WITH_PATH_LOOKUP = 0x20,
FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
};
-typedef struct line_input_t line_input_t;
line_input_t *new_line_input_t(int flags);
int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state);
#else
@@ -798,7 +799,7 @@ typedef struct {
/* sizeof(task_struct.comm) in /usr/include/linux/sched.h */
char state[4];
char comm[COMM_LEN];
-// user/group? - use passwd/group parsing functions
+ /* user/group? - use passwd/group parsing functions */
} procps_status_t;
enum {
PSSCAN_PID = 1 << 0,
@@ -902,18 +903,22 @@ extern const char bb_dev_null[];
extern const int const_int_0;
extern const int const_int_1;
+
#ifndef BUFSIZ
#define BUFSIZ 4096
#endif
+// TODO: provide hard guarantees on minimum size of bb_common_bufsiz1
extern char bb_common_bufsiz1[BUFSIZ+1];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;
-/* Magic prevents this from going into rodata */
-/* If you want to assign a value, use PTR_TO_GLOBALS = xxx */
+/* '*const' ptr makes gcc optimize code much better.
+ * Magic prevents ptr_to_globals from going into rodata
+ * If you want to assign a value, use PTR_TO_GLOBALS = xxx */
extern struct globals *const ptr_to_globals;
#define PTR_TO_GLOBALS (*(struct globals**)&ptr_to_globals)
+
/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
* use bb_default_login_shell and following defines.
* If you change LIBBB_DEFAULT_LOGIN_SHELL,
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 6cdbfd35d..dec97d743 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -242,7 +242,7 @@ Special characters:
llist_t *patterns = NULL;
(this pointer must be initializated to NULL if the list is empty
- as required by *llist_add_to(llist_t *old_head, char *new_item).)
+ as required by llist_add_to_end(llist_t **old_head, char *new_item).)
opt_complementary = "e::";
@@ -487,7 +487,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
if (on_off->counter)
(*(on_off->counter))++;
if (on_off->list_flg) {
- llist_add_to((llist_t **)(on_off->optarg), optarg);
+ llist_add_to_end((llist_t **)(on_off->optarg), optarg);
} else if (on_off->optarg) {
*(char **)(on_off->optarg) = optarg;
}
diff --git a/libbb/llist.c b/libbb/llist.c
index 2b34f762c..706751447 100644
--- a/libbb/llist.c
+++ b/libbb/llist.c
@@ -14,7 +14,7 @@
#include "libbb.h"
/* Add data to the start of the linked list. */
-void llist_add_to(llist_t ** old_head, void *data)
+void llist_add_to(llist_t **old_head, void *data)
{
llist_t *new_head = xmalloc(sizeof(llist_t));
@@ -24,7 +24,7 @@ void llist_add_to(llist_t ** old_head, void *data)
}
/* Add data to the end of the linked list. */
-void llist_add_to_end(llist_t ** list_head, void *data)
+void llist_add_to_end(llist_t **list_head, void *data)
{
llist_t *new_item = xmalloc(sizeof(llist_t));
@@ -43,7 +43,7 @@ void llist_add_to_end(llist_t ** list_head, void *data)
}
/* Remove first element from the list and return it */
-void *llist_pop(llist_t ** head)
+void *llist_pop(llist_t **head)
{
void *data, *next;
@@ -81,7 +81,7 @@ void llist_unlink(llist_t **head, llist_t *elm)
/* Recursively free all elements in the linked list. If freeit != NULL
* call it on each datum in the list */
-void llist_free(llist_t * elm, void (*freeit) (void *data))
+void llist_free(llist_t *elm, void (*freeit) (void *data))
{
while (elm) {
void *data = llist_pop(&elm);
@@ -91,18 +91,19 @@ void llist_free(llist_t * elm, void (*freeit) (void *data))
}
}
-/* Reverse list order. Useful since getopt32 saves option params
- * in reverse order */
-llist_t *llist_rev(llist_t * list)
+#ifdef UNUSED
+/* Reverse list order. */
+llist_t *llist_rev(llist_t *list)
{
- llist_t *new = NULL;
+ llist_t *rev = NULL;
while (list) {
llist_t *next = list->link;
- list->link = new;
- new = list;
+ list->link = rev;
+ rev = list;
list = next;
}
- return new;
+ return rev;
}
+#endif
diff --git a/networking/wget.c b/networking/wget.c
index 94b9b6954..1da18ff77 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -159,7 +159,7 @@ int wget_main(int argc, char **argv)
if (headers_llist) {
int size = 1;
char *cp;
- llist_t *ll = headers_llist = llist_rev(headers_llist);
+ llist_t *ll = headers_llist;
while (ll) {
size += strlen(ll->data) + 2;
ll = ll->link;
diff --git a/procps/ps.c b/procps/ps.c
index 2be0b3605..f8f5c1aa9 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -253,7 +253,6 @@ int ps_main(int argc, char **argv)
opt_complementary = "o::";
getopt32(argc, argv, "o:aAdefl", &opt_o);
if (opt_o) {
- opt_o = llist_rev(opt_o);
do {
parse_o(opt_o->data);
opt_o = opt_o->link;