aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:09:09 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:09:09 +0000
commit1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2 (patch)
tree7ec8969fc2b07a2b7dc37f96435e5eddf7daf7fd /coreutils
parent62a90cdd7435f09f4bb8673e8b7b213067f9d5cc (diff)
downloadbusybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.tar.gz
busybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.tar.bz2
busybox-w32-1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2.zip
*: shrink: use Vladimir's "o+" specifier instead of xatou(opt_param)
function old new delta getopt32 1370 1385 +15 sulogin_main 490 494 +4 realpath_main 84 86 +2 sleep_main 76 77 +1 mt_main 256 257 +1 printenv_main 75 74 -1 fdformat_main 546 545 -1 usleep_main 44 42 -2 setlogcons_main 77 75 -2 ed_main 2654 2649 -5 deallocvt_main 69 64 -5 addgroup_main 373 368 -5 mkfs_minix_main 2989 2982 -7 tail_main 1221 1213 -8 sv_main 1254 1241 -13 du_main 348 328 -20 tftp_main 325 302 -23 split_main 581 558 -23 nc_main 1000 977 -23 diff_main 891 868 -23 arping_main 1797 1770 -27 ls_main 893 847 -46 od_main 2797 2750 -47 readprofile_main 1944 1895 -49 tcpudpsvd_main 1973 1922 -51 udhcpc_main 2590 2513 -77 grep_main 824 722 -102 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/22 up/down: 23/-560) Total: -537 bytes text data bss dec hex filename 796973 658 7428 805059 c48c3 busybox_old 796479 662 7420 804561 c46d1 busybox_unstripped
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/du.c13
-rw-r--r--coreutils/ls.c9
-rw-r--r--coreutils/od_bloaty.c10
-rw-r--r--coreutils/printenv.c4
-rw-r--r--coreutils/realpath.c7
-rw-r--r--coreutils/sleep.c17
-rw-r--r--coreutils/split.c12
-rw-r--r--coreutils/tail.c5
-rw-r--r--coreutils/usleep.c4
9 files changed, 29 insertions, 52 deletions
diff --git a/coreutils/du.c b/coreutils/du.c
index 7495f7a7b..b469824ea 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -146,7 +146,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
146 unsigned long total; 146 unsigned long total;
147 int slink_depth_save; 147 int slink_depth_save;
148 bool print_final_total; 148 bool print_final_total;
149 char *smax_print_depth;
150 unsigned opt; 149 unsigned opt;
151 150
152#if ENABLE_FEATURE_HUMAN_READABLE 151#if ENABLE_FEATURE_HUMAN_READABLE
@@ -168,8 +167,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
168 * ignore -a. This is consistent with -s being equivalent to -d 0. 167 * ignore -a. This is consistent with -s being equivalent to -d 0.
169 */ 168 */
170#if ENABLE_FEATURE_HUMAN_READABLE 169#if ENABLE_FEATURE_HUMAN_READABLE
171 opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; 170 opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+";
172 opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); 171 opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
173 argv += optind; 172 argv += optind;
174 if (opt & (1 << 9)) { 173 if (opt & (1 << 9)) {
175 /* -h opt */ 174 /* -h opt */
@@ -184,8 +183,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
184 G.disp_hr = 1024; 183 G.disp_hr = 1024;
185 } 184 }
186#else 185#else
187 opt_complementary = "H-L:L-H:s-d:d-s"; 186 opt_complementary = "H-L:L-H:s-d:d-s:d+";
188 opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth); 187 opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
189 argv += optind; 188 argv += optind;
190#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K 189#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
191 if (opt & (1 << 2)) { 190 if (opt & (1 << 2)) {
@@ -211,10 +210,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
211 G.max_print_depth = 0; 210 G.max_print_depth = 0;
212 } 211 }
213 G.one_file_system = opt & (1 << 5); /* -x opt */ 212 G.one_file_system = opt & (1 << 5); /* -x opt */
214 if (opt & (1 << 6)) {
215 /* -d opt */
216 G.max_print_depth = xatoi_u(smax_print_depth);
217 }
218 if (opt & (1 << 7)) { 213 if (opt & (1 << 7)) {
219 /* -l opt */ 214 /* -l opt */
220 G.count_hardlinks = MAXINT(nlink_t); 215 G.count_hardlinks = MAXINT(nlink_t);
diff --git a/coreutils/ls.c b/coreutils/ls.c
index dbf1c5ba6..9e5c6dee9 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -799,8 +799,6 @@ int ls_main(int argc, char **argv)
799 int ac; 799 int ac;
800 int i; 800 int i;
801 char **av; 801 char **av;
802 USE_FEATURE_AUTOWIDTH(char *tabstops_str = NULL;)
803 USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
804 USE_FEATURE_LS_COLOR(char *color_opt;) 802 USE_FEATURE_LS_COLOR(char *color_opt;)
805 803
806#if ENABLE_FEATURE_LS_TIMESTAMPS 804#if ENABLE_FEATURE_LS_TIMESTAMPS
@@ -820,12 +818,9 @@ int ls_main(int argc, char **argv)
820 /* process options */ 818 /* process options */
821 USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;) 819 USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
822#if ENABLE_FEATURE_AUTOWIDTH 820#if ENABLE_FEATURE_AUTOWIDTH
823 opt = getopt32(argv, ls_options, &tabstops_str, &terminal_width_str 821 opt_complementary = "T+:w+"; /* -T N, -w N */
822 opt = getopt32(argv, ls_options, &tabstops, &terminal_width
824 USE_FEATURE_LS_COLOR(, &color_opt)); 823 USE_FEATURE_LS_COLOR(, &color_opt));
825 if (tabstops_str)
826 tabstops = xatou(tabstops_str);
827 if (terminal_width_str)
828 terminal_width = xatou(terminal_width_str);
829#else 824#else
830 opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt)); 825 opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
831#endif 826#endif
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index a083114c9..4526f0ede 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -188,7 +188,7 @@ static off_t pseudo_offset;
188 a multiple of the least common multiple of the sizes associated with 188 a multiple of the least common multiple of the sizes associated with
189 the specified output types. It should be as large as possible, but 189 the specified output types. It should be as large as possible, but
190 no larger than 16 -- unless specified with the -w option. */ 190 no larger than 16 -- unless specified with the -w option. */
191static size_t bytes_per_block; 191static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */
192 192
193/* A NULL-terminated list of the file-arguments from the command line. */ 193/* A NULL-terminated list of the file-arguments from the command line. */
194static const char *const *file_list; 194static const char *const *file_list;
@@ -1218,7 +1218,6 @@ int od_main(int argc, char **argv)
1218 ; 1218 ;
1219#endif 1219#endif
1220 char *str_A, *str_N, *str_j, *str_S; 1220 char *str_A, *str_N, *str_j, *str_S;
1221 char *str_w = NULL;
1222 llist_t *lst_t = NULL; 1221 llist_t *lst_t = NULL;
1223 unsigned opt; 1222 unsigned opt;
1224 int l_c_m; 1223 int l_c_m;
@@ -1239,7 +1238,7 @@ int od_main(int argc, char **argv)
1239 /* flag_dump_strings = 0; - already is */ 1238 /* flag_dump_strings = 0; - already is */
1240 1239
1241 /* Parse command line */ 1240 /* Parse command line */
1242 opt_complementary = "t::"; // list 1241 opt_complementary = "w+:t::"; /* -w N, -t is a list */
1243#if ENABLE_GETOPT_LONG 1242#if ENABLE_GETOPT_LONG
1244 applet_long_options = od_longopts; 1243 applet_long_options = od_longopts;
1245#endif 1244#endif
@@ -1248,7 +1247,7 @@ int od_main(int argc, char **argv)
1248 // -S was -s and also had optional parameter 1247 // -S was -s and also had optional parameter
1249 // but in coreutils 6.3 it was renamed and now has 1248 // but in coreutils 6.3 it was renamed and now has
1250 // _mandatory_ parameter 1249 // _mandatory_ parameter
1251 &str_A, &str_N, &str_j, &lst_t, &str_S, &str_w); 1250 &str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block);
1252 argc -= optind; 1251 argc -= optind;
1253 argv += optind; 1252 argv += optind;
1254 if (opt & OPT_A) { 1253 if (opt & OPT_A) {
@@ -1404,9 +1403,6 @@ int od_main(int argc, char **argv)
1404 l_c_m = get_lcm(); 1403 l_c_m = get_lcm();
1405 1404
1406 if (opt & OPT_w) { /* -w: width */ 1405 if (opt & OPT_w) { /* -w: width */
1407 bytes_per_block = 32;
1408 if (str_w)
1409 bytes_per_block = xatou(str_w);
1410 if (!bytes_per_block || bytes_per_block % l_c_m != 0) { 1406 if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
1411 bb_error_msg("warning: invalid width %u; using %d instead", 1407 bb_error_msg("warning: invalid width %u; using %d instead",
1412 (unsigned)bytes_per_block, l_c_m); 1408 (unsigned)bytes_per_block, l_c_m);
diff --git a/coreutils/printenv.c b/coreutils/printenv.c
index 06d68d0ef..31d76d712 100644
--- a/coreutils/printenv.c
+++ b/coreutils/printenv.c
@@ -11,10 +11,10 @@
11#include "libbb.h" 11#include "libbb.h"
12 12
13int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 13int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
14int printenv_main(int argc, char **argv) 14int printenv_main(int argc ATTRIBUTE_UNUSED, char **argv)
15{ 15{
16 /* no variables specified, show whole env */ 16 /* no variables specified, show whole env */
17 if (argc == 1) { 17 if (!argv[1]) {
18 int e = 0; 18 int e = 0;
19 while (environ[e]) 19 while (environ[e])
20 puts(environ[e++]); 20 puts(environ[e++]);
diff --git a/coreutils/realpath.c b/coreutils/realpath.c
index bcb73a8dc..6766524a7 100644
--- a/coreutils/realpath.c
+++ b/coreutils/realpath.c
@@ -13,7 +13,7 @@
13#include "libbb.h" 13#include "libbb.h"
14 14
15int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 15int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16int realpath_main(int argc, char **argv) 16int realpath_main(int argc ATTRIBUTE_UNUSED, char **argv)
17{ 17{
18 int retval = EXIT_SUCCESS; 18 int retval = EXIT_SUCCESS;
19 19
@@ -25,19 +25,18 @@ int realpath_main(int argc, char **argv)
25# define resolved_path_MUST_FREE 0 25# define resolved_path_MUST_FREE 0
26#endif 26#endif
27 27
28 if (--argc == 0) { 28 if (!*++argv) {
29 bb_show_usage(); 29 bb_show_usage();
30 } 30 }
31 31
32 do { 32 do {
33 argv++;
34 if (realpath(*argv, resolved_path) != NULL) { 33 if (realpath(*argv, resolved_path) != NULL) {
35 puts(resolved_path); 34 puts(resolved_path);
36 } else { 35 } else {
37 retval = EXIT_FAILURE; 36 retval = EXIT_FAILURE;
38 bb_simple_perror_msg(*argv); 37 bb_simple_perror_msg(*argv);
39 } 38 }
40 } while (--argc); 39 } while (*++argv);
41 40
42#if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE 41#if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
43 RELEASE_CONFIG_BUFFER(resolved_path); 42 RELEASE_CONFIG_BUFFER(resolved_path);
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index 6890e35c1..78f9a8ebf 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -34,17 +34,16 @@ static const struct suffix_mult sfx[] = {
34#endif 34#endif
35 35
36int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 36int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int sleep_main(int argc, char **argv) 37int sleep_main(int argc ATTRIBUTE_UNUSED, char **argv)
38{ 38{
39 unsigned duration; 39 unsigned duration;
40 40
41#if ENABLE_FEATURE_FANCY_SLEEP 41 ++argv;
42 42 if (!*argv)
43 if (argc < 2) {
44 bb_show_usage(); 43 bb_show_usage();
45 }
46 44
47 ++argv; 45#if ENABLE_FEATURE_FANCY_SLEEP
46
48 duration = 0; 47 duration = 0;
49 do { 48 do {
50 duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx); 49 duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
@@ -52,11 +51,7 @@ int sleep_main(int argc, char **argv)
52 51
53#else /* FEATURE_FANCY_SLEEP */ 52#else /* FEATURE_FANCY_SLEEP */
54 53
55 if (argc != 2) { 54 duration = xatou(*argv);
56 bb_show_usage();
57 }
58
59 duration = xatou(argv[1]);
60 55
61#endif /* FEATURE_FANCY_SLEEP */ 56#endif /* FEATURE_FANCY_SLEEP */
62 57
diff --git a/coreutils/split.c b/coreutils/split.c
index cf26a9322..2306789f0 100644
--- a/coreutils/split.c
+++ b/coreutils/split.c
@@ -68,15 +68,13 @@ int split_main(int argc ATTRIBUTE_UNUSED, char **argv)
68 ssize_t bytes_read, to_write; 68 ssize_t bytes_read, to_write;
69 char *src; 69 char *src;
70 70
71 opt_complementary = "?2"; 71 opt_complementary = "?2:a+"; /* max 2 args; -a N */
72 opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &sfx); 72 opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
73 73
74 if (opt & SPLIT_OPT_l) 74 if (opt & SPLIT_OPT_l)
75 cnt = xatoul(count_p); 75 cnt = XATOOFF(count_p);
76 if (opt & SPLIT_OPT_b) 76 if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF
77 cnt = xatoul_sfx(count_p, split_suffices); 77 cnt = xatoull_sfx(count_p, split_suffices);
78 if (opt & SPLIT_OPT_a)
79 suffix_len = xatou(sfx);
80 sfx = "x"; 78 sfx = "x";
81 79
82 argv += optind; 80 argv += optind;
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 52aa8f69e..35b25a416 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -87,7 +87,6 @@ int tail_main(int argc, char **argv)
87 bool from_top; 87 bool from_top;
88 int header_threshhold = 1; 88 int header_threshhold = 1;
89 const char *str_c, *str_n; 89 const char *str_c, *str_n;
90 USE_FEATURE_FANCY_TAIL(const char *str_s;)
91 90
92 char *tailbuf; 91 char *tailbuf;
93 size_t tailbufsize; 92 size_t tailbufsize;
@@ -110,8 +109,9 @@ int tail_main(int argc, char **argv)
110 } 109 }
111#endif 110#endif
112 111
112 USE_FEATURE_FANCY_TAIL(opt_complementary = "s+";) /* -s N */
113 opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), 113 opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
114 &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s)); 114 &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&sleep_period));
115#define FOLLOW (opt & 0x1) 115#define FOLLOW (opt & 0x1)
116#define COUNT_BYTES (opt & 0x2) 116#define COUNT_BYTES (opt & 0x2)
117 //if (opt & 0x1) // -f 117 //if (opt & 0x1) // -f
@@ -119,7 +119,6 @@ int tail_main(int argc, char **argv)
119 if (opt & 0x4) count = eat_num(str_n); // -n 119 if (opt & 0x4) count = eat_num(str_n); // -n
120#if ENABLE_FEATURE_FANCY_TAIL 120#if ENABLE_FEATURE_FANCY_TAIL
121 if (opt & 0x8) header_threshhold = INT_MAX; // -q 121 if (opt & 0x8) header_threshhold = INT_MAX; // -q
122 if (opt & 0x10) sleep_period = xatou(str_s); // -s
123 if (opt & 0x20) header_threshhold = 0; // -v 122 if (opt & 0x20) header_threshhold = 0; // -v
124#endif 123#endif
125 argc -= optind; 124 argc -= optind;
diff --git a/coreutils/usleep.c b/coreutils/usleep.c
index 1c9022325..d34880d3a 100644
--- a/coreutils/usleep.c
+++ b/coreutils/usleep.c
@@ -14,9 +14,9 @@
14/* This is a NOFORK applet. Be very careful! */ 14/* This is a NOFORK applet. Be very careful! */
15 15
16int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 16int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
17int usleep_main(int argc, char **argv) 17int usleep_main(int argc ATTRIBUTE_UNUSED, char **argv)
18{ 18{
19 if (argc != 2) { 19 if (!argv[1]) {
20 bb_show_usage(); 20 bb_show_usage();
21 } 21 }
22 22