diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-15 05:40:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-15 05:40:56 +0000 |
commit | d50dda8c3501af9d593cd11272a15b480864a01c (patch) | |
tree | 652da97787e8e86f876b647ca9dab4b6b64fe291 | |
parent | 873b895d50d69a45b52bef85a8a4fb190f9c89ce (diff) | |
download | busybox-w32-d50dda8c3501af9d593cd11272a15b480864a01c.tar.gz busybox-w32-d50dda8c3501af9d593cd11272a15b480864a01c.tar.bz2 busybox-w32-d50dda8c3501af9d593cd11272a15b480864a01c.zip |
*: use llist_pop for traverse-and-free list operation
function old new delta
append_file_list_to_list 109 111 +2
udhcpc_main 2414 2413 -1
run_parts_main 325 324 -1
od_main 2324 2323 -1
getopt_main 709 707 -2
env_main 253 251 -2
sed_main 659 656 -3
ps_main 522 519 -3
traceroute_main 3960 3954 -6
sort_main 844 838 -6
diff_main 866 858 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/10 up/down: 2/-33) Total: -31 bytes
-rw-r--r-- | archival/tar.c | 9 | ||||
-rw-r--r-- | coreutils/env.c | 3 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 3 | ||||
-rw-r--r-- | coreutils/sort.c | 4 | ||||
-rw-r--r-- | debianutils/run_parts.c | 6 | ||||
-rw-r--r-- | editors/diff.c | 9 | ||||
-rw-r--r-- | editors/sed.c | 8 | ||||
-rw-r--r-- | findutils/xargs.c | 2 | ||||
-rw-r--r-- | libbb/getopt32.c | 2 | ||||
-rw-r--r-- | networking/traceroute.c | 10 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 3 | ||||
-rw-r--r-- | networking/wget.c | 3 | ||||
-rw-r--r-- | procps/ps.c | 3 | ||||
-rw-r--r-- | util-linux/getopt.c | 3 |
14 files changed, 19 insertions, 49 deletions
diff --git a/archival/tar.c b/archival/tar.c index 64a4e35be..0162e0623 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -659,16 +659,11 @@ int writeTarFile(int tar_fd, int verboseFlag, | |||
659 | static llist_t *append_file_list_to_list(llist_t *list) | 659 | static llist_t *append_file_list_to_list(llist_t *list) |
660 | { | 660 | { |
661 | FILE *src_stream; | 661 | FILE *src_stream; |
662 | llist_t *cur = list; | ||
663 | llist_t *tmp; | ||
664 | char *line; | 662 | char *line; |
665 | llist_t *newlist = NULL; | 663 | llist_t *newlist = NULL; |
666 | 664 | ||
667 | while (cur) { | 665 | while (list) { |
668 | src_stream = xfopen(cur->data, "r"); | 666 | src_stream = xfopen(llist_pop(&list), "r"); |
669 | tmp = cur; | ||
670 | cur = cur->link; | ||
671 | free(tmp); | ||
672 | while ((line = xmalloc_fgetline(src_stream)) != NULL) { | 667 | while ((line = xmalloc_fgetline(src_stream)) != NULL) { |
673 | /* kill trailing '/' unless the string is just "/" */ | 668 | /* kill trailing '/' unless the string is just "/" */ |
674 | char *cp = last_char_is(line, '/'); | 669 | char *cp = last_char_is(line, '/'); |
diff --git a/coreutils/env.c b/coreutils/env.c index e21740d98..8d8753e8b 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -62,8 +62,7 @@ int env_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
62 | environ = cleanenv; | 62 | environ = cleanenv; |
63 | } else { | 63 | } else { |
64 | while (unset_env) { | 64 | while (unset_env) { |
65 | unsetenv(unset_env->data); | 65 | unsetenv(llist_pop(&unset_env)); |
66 | unset_env = unset_env->link; | ||
67 | } | 66 | } |
68 | } | 67 | } |
69 | 68 | ||
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 5e2287534..ce963db8a 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -1281,8 +1281,7 @@ int od_main(int argc, char **argv) | |||
1281 | if (opt & OPT_o) decode_format_string("o2"); | 1281 | if (opt & OPT_o) decode_format_string("o2"); |
1282 | //if (opt & OPT_t)... | 1282 | //if (opt & OPT_t)... |
1283 | while (lst_t) { | 1283 | while (lst_t) { |
1284 | decode_format_string(lst_t->data); | 1284 | decode_format_string(llist_pop(&lst_t)); |
1285 | lst_t = lst_t->link; | ||
1286 | } | 1285 | } |
1287 | if (opt & OPT_v) verbose = 1; | 1286 | if (opt & OPT_v) verbose = 1; |
1288 | if (opt & OPT_x) decode_format_string("x2"); | 1287 | if (opt & OPT_x) decode_format_string("x2"); |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 12b463a6d..1f531fb76 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -314,7 +314,7 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
314 | 0 | 314 | 0 |
315 | }; | 315 | }; |
316 | struct sort_key *key = add_key(); | 316 | struct sort_key *key = add_key(); |
317 | char *str_k = lst_k->data; | 317 | char *str_k = llist_pop(&lst_k); |
318 | const char *temp2; | 318 | const char *temp2; |
319 | 319 | ||
320 | i = 0; /* i==0 before comma, 1 after (-k3,6) */ | 320 | i = 0; /* i==0 before comma, 1 after (-k3,6) */ |
@@ -344,8 +344,6 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
344 | str_k++; | 344 | str_k++; |
345 | } | 345 | } |
346 | } | 346 | } |
347 | /* leaking lst_k... */ | ||
348 | lst_k = lst_k->link; | ||
349 | } | 347 | } |
350 | #endif | 348 | #endif |
351 | /* global b strips leading and trailing spaces */ | 349 | /* global b strips leading and trailing spaces */ |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 47eda8cf6..c9b090717 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -42,7 +42,7 @@ struct globals { | |||
42 | #define cur (G.cur ) | 42 | #define cur (G.cur ) |
43 | #define cmd (G.cmd ) | 43 | #define cmd (G.cmd ) |
44 | 44 | ||
45 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(struct globals)) / sizeof(cmd[0]) }; | 45 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 }; |
46 | 46 | ||
47 | enum { | 47 | enum { |
48 | OPT_r = (1 << 0), | 48 | OPT_r = (1 << 0), |
@@ -130,9 +130,7 @@ int run_parts_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
130 | 130 | ||
131 | n = 1; | 131 | n = 1; |
132 | while (arg_list && n < NUM_CMD) { | 132 | while (arg_list && n < NUM_CMD) { |
133 | cmd[n] = arg_list->data; | 133 | cmd[n++] = llist_pop(&arg_list); |
134 | arg_list = arg_list->link; | ||
135 | n++; | ||
136 | } | 134 | } |
137 | /* cmd[n] = NULL; - is already zeroed out */ | 135 | /* cmd[n] = NULL; - is already zeroed out */ |
138 | 136 | ||
diff --git a/editors/diff.c b/editors/diff.c index 4e51f6f76..26f352780 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -1289,14 +1289,9 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
1289 | while (L_arg) { | 1289 | while (L_arg) { |
1290 | if (label1 && label2) | 1290 | if (label1 && label2) |
1291 | bb_show_usage(); | 1291 | bb_show_usage(); |
1292 | if (!label1) | 1292 | if (label1) /* then label2 is NULL */ |
1293 | label1 = L_arg->data; | ||
1294 | else { /* then label2 is NULL */ | ||
1295 | label2 = label1; | 1293 | label2 = label1; |
1296 | label1 = L_arg->data; | 1294 | label1 = llist_pop(&L_arg); |
1297 | } | ||
1298 | /* we leak L_arg here... */ | ||
1299 | L_arg = L_arg->link; | ||
1300 | } | 1295 | } |
1301 | 1296 | ||
1302 | /* | 1297 | /* |
diff --git a/editors/sed.c b/editors/sed.c index 817840dc0..bf01fc630 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1267,21 +1267,17 @@ int sed_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
1267 | if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r | 1267 | if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r |
1268 | //if (opt & 0x4) G.be_quiet++; // -n | 1268 | //if (opt & 0x4) G.be_quiet++; // -n |
1269 | while (opt_e) { // -e | 1269 | while (opt_e) { // -e |
1270 | add_cmd_block(opt_e->data); | 1270 | add_cmd_block(llist_pop(&opt_e)); |
1271 | opt_e = opt_e->link; | ||
1272 | /* we leak opt_e here... */ | ||
1273 | } | 1271 | } |
1274 | while (opt_f) { // -f | 1272 | while (opt_f) { // -f |
1275 | char *line; | 1273 | char *line; |
1276 | FILE *cmdfile; | 1274 | FILE *cmdfile; |
1277 | cmdfile = xfopen(opt_f->data, "r"); | 1275 | cmdfile = xfopen(llist_pop(&opt_f), "r"); |
1278 | while ((line = xmalloc_fgetline(cmdfile)) != NULL) { | 1276 | while ((line = xmalloc_fgetline(cmdfile)) != NULL) { |
1279 | add_cmd(line); | 1277 | add_cmd(line); |
1280 | free(line); | 1278 | free(line); |
1281 | } | 1279 | } |
1282 | fclose(cmdfile); | 1280 | fclose(cmdfile); |
1283 | opt_f = opt_f->link; | ||
1284 | /* we leak opt_f here... */ | ||
1285 | } | 1281 | } |
1286 | /* if we didn't get a pattern from -e or -f, use argv[0] */ | 1282 | /* if we didn't get a pattern from -e or -f, use argv[0] */ |
1287 | if (!(opt & 0x18)) { | 1283 | if (!(opt & 0x18)) { |
diff --git a/findutils/xargs.c b/findutils/xargs.c index 352f7e64c..3322e9ebd 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -502,7 +502,7 @@ int xargs_main(int argc, char **argv) | |||
502 | if (child_error > 0 && child_error != 123) { | 502 | if (child_error > 0 && child_error != 123) { |
503 | break; | 503 | break; |
504 | } | 504 | } |
505 | } | 505 | } /* while */ |
506 | if (ENABLE_FEATURE_CLEAN_UP) | 506 | if (ENABLE_FEATURE_CLEAN_UP) |
507 | free(max_chars); | 507 | free(max_chars); |
508 | return child_error; | 508 | return child_error; |
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 4b5a7d208..86c33483b 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -137,7 +137,7 @@ const char *opt_complementary | |||
137 | opt_complementary = "vv:b::b-c:c-b"; | 137 | opt_complementary = "vv:b::b-c:c-b"; |
138 | f = getopt32(argv, "vb:c", &my_b, &verbose_level); | 138 | f = getopt32(argv, "vb:c", &my_b, &verbose_level); |
139 | if (f & 2) // -c after -b unsets -b flag | 139 | if (f & 2) // -c after -b unsets -b flag |
140 | while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; } | 140 | while (my_b) dosomething_with(llist_pop(&my_b)); |
141 | if (my_b) // but llist is stored if -b is specified | 141 | if (my_b) // but llist is stored if -b is specified |
142 | free_llist(my_b); | 142 | free_llist(my_b); |
143 | if (verbose_level) printf("verbose level is %d\n", verbose_level); | 143 | if (verbose_level) printf("verbose level is %d\n", verbose_level); |
diff --git a/networking/traceroute.c b/networking/traceroute.c index e9df27559..6a5373469 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -1001,17 +1001,11 @@ int traceroute_main(int argc, char **argv) | |||
1001 | 1001 | ||
1002 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE | 1002 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE |
1003 | if (source_route_list) { | 1003 | if (source_route_list) { |
1004 | llist_t *l_sr; | 1004 | while (source_route_list) { |
1005 | |||
1006 | l_sr = source_route_list; | ||
1007 | while (l_sr) { | ||
1008 | if (lsrr >= NGATEWAYS) | 1005 | if (lsrr >= NGATEWAYS) |
1009 | bb_error_msg_and_die("no more than %d gateways", NGATEWAYS); | 1006 | bb_error_msg_and_die("no more than %d gateways", NGATEWAYS); |
1010 | getaddr(gwlist + lsrr, l_sr->data); | 1007 | getaddr(gwlist + lsrr, llist_pop(&source_route_list)); |
1011 | ++lsrr; | 1008 | ++lsrr; |
1012 | l_sr = l_sr->link; | ||
1013 | free(source_route_list); | ||
1014 | source_route_list = l_sr; | ||
1015 | } | 1009 | } |
1016 | optlen = (lsrr + 1) * sizeof(gwlist[0]); | 1010 | optlen = (lsrr + 1) * sizeof(gwlist[0]); |
1017 | } | 1011 | } |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 655d39fd2..5eb1ed5fd 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -259,12 +259,11 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
259 | if (opt & OPT_o) | 259 | if (opt & OPT_o) |
260 | client_config.no_default_options = 1; | 260 | client_config.no_default_options = 1; |
261 | while (list_O) { | 261 | while (list_O) { |
262 | int n = index_in_strings(dhcp_option_strings, list_O->data); | 262 | int n = index_in_strings(dhcp_option_strings, llist_pop(&list_O)); |
263 | if (n < 0) | 263 | if (n < 0) |
264 | bb_error_msg_and_die("unknown option '%s'", list_O->data); | 264 | bb_error_msg_and_die("unknown option '%s'", list_O->data); |
265 | n = dhcp_options[n].code; | 265 | n = dhcp_options[n].code; |
266 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 266 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); |
267 | list_O = list_O->link; | ||
268 | } | 267 | } |
269 | 268 | ||
270 | if (read_interface(client_config.interface, &client_config.ifindex, | 269 | if (read_interface(client_config.interface, &client_config.ifindex, |
diff --git a/networking/wget.c b/networking/wget.c index 84ee1ca3e..7198197dd 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -469,8 +469,7 @@ int wget_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
469 | } | 469 | } |
470 | extra_headers = cp = xmalloc(size); | 470 | extra_headers = cp = xmalloc(size); |
471 | while (headers_llist) { | 471 | while (headers_llist) { |
472 | cp += sprintf(cp, "%s\r\n", headers_llist->data); | 472 | cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist)); |
473 | headers_llist = headers_llist->link; | ||
474 | } | 473 | } |
475 | } | 474 | } |
476 | #endif | 475 | #endif |
diff --git a/procps/ps.c b/procps/ps.c index 1ab3973e7..cfca851cf 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -443,8 +443,7 @@ int ps_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
443 | USE_SELINUX(opt =) getopt32(argv, "Zo:aAdefl", &opt_o); | 443 | USE_SELINUX(opt =) getopt32(argv, "Zo:aAdefl", &opt_o); |
444 | if (opt_o) { | 444 | if (opt_o) { |
445 | do { | 445 | do { |
446 | parse_o(opt_o->data); | 446 | parse_o(llist_pop(&opt_o)); |
447 | opt_o = opt_o->link; | ||
448 | } while (opt_o); | 447 | } while (opt_o); |
449 | } else { | 448 | } else { |
450 | /* Below: parse_o() needs char*, NOT const char*... */ | 449 | /* Below: parse_o() needs char*, NOT const char*... */ |
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index 31790d2a7..e3b4ca625 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -329,8 +329,7 @@ int getopt_main(int argc, char **argv) | |||
329 | &optstr, &name, &s_arg, &l_arg); | 329 | &optstr, &name, &s_arg, &l_arg); |
330 | /* Effectuate the read options for the applet itself */ | 330 | /* Effectuate the read options for the applet itself */ |
331 | while (l_arg) { | 331 | while (l_arg) { |
332 | long_options = add_long_options(long_options, l_arg->data); | 332 | long_options = add_long_options(long_options, llist_pop(&l_arg)); |
333 | l_arg = l_arg->link; | ||
334 | } | 333 | } |
335 | #endif | 334 | #endif |
336 | 335 | ||