aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--console-tools/deallocvt.c12
-rw-r--r--console-tools/openvt.c7
-rw-r--r--console-tools/setkeycodes.c4
-rw-r--r--console-tools/setlogcons.c6
-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
-rw-r--r--editors/diff.c9
-rw-r--r--editors/ed.c4
-rw-r--r--findutils/grep.c48
-rw-r--r--init/halt.c7
-rw-r--r--init/init.c8
-rw-r--r--ipsvd/tcpudp.c19
-rw-r--r--libbb/getopt32.c15
-rw-r--r--loginutils/addgroup.c8
-rw-r--r--loginutils/login.c7
-rw-r--r--loginutils/sulogin.c7
-rw-r--r--miscutils/mt.c10
-rw-r--r--networking/arping.c8
-rw-r--r--networking/nc_bloaty.c10
-rw-r--r--networking/tftp.c16
-rw-r--r--networking/udhcp/dhcpc.c17
-rw-r--r--runit/sv.c7
-rw-r--r--util-linux/fdformat.c6
-rw-r--r--util-linux/mkfs_minix.c6
-rw-r--r--util-linux/readprofile.c53
-rw-r--r--util-linux/setarch.c2
-rw-r--r--util-linux/swaponoff.c4
34 files changed, 172 insertions, 209 deletions
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c
index 117224560..1200cae1d 100644
--- a/console-tools/deallocvt.c
+++ b/console-tools/deallocvt.c
@@ -16,19 +16,15 @@
16enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */ 16enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
17 17
18int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 18int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
19int deallocvt_main(int argc, char **argv) 19int deallocvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
20{ 20{
21 /* num = 0 deallocate all unused consoles */ 21 /* num = 0 deallocate all unused consoles */
22 int num = 0; 22 int num = 0;
23 23
24 switch (argc) { 24 if (argv[1]) {
25 case 2: 25 if (argv[2])
26 bb_show_usage();
26 num = xatou_range(argv[1], 1, 63); 27 num = xatou_range(argv[1], 1, 63);
27 /* Fallthrough */
28 case 1:
29 break;
30 default:
31 bb_show_usage();
32 } 28 }
33 29
34 /* double cast suppresses "cast to ptr from int of different size" */ 30 /* double cast suppresses "cast to ptr from int of different size" */
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
index ff169530d..39b985995 100644
--- a/console-tools/openvt.c
+++ b/console-tools/openvt.c
@@ -27,9 +27,10 @@ int openvt_main(int argc, char **argv)
27 /* grab new one */ 27 /* grab new one */
28 close(0); 28 close(0);
29 xopen(vtname, O_RDWR); 29 xopen(vtname, O_RDWR);
30 dup2(0, STDOUT_FILENO); 30 xdup2(0, STDOUT_FILENO);
31 dup2(0, STDERR_FILENO); 31 xdup2(0, STDERR_FILENO);
32 32
33 BB_EXECVP(argv[2], &argv[2]); 33 argv += 2;
34 BB_EXECVP(argv[0], argv);
34 _exit(1); 35 _exit(1);
35} 36}
diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c
index ba3d2e44e..e9a050862 100644
--- a/console-tools/setkeycodes.c
+++ b/console-tools/setkeycodes.c
@@ -14,7 +14,7 @@
14 14
15/* From <linux/kd.h> */ 15/* From <linux/kd.h> */
16struct kbkeycode { 16struct kbkeycode {
17 unsigned int scancode, keycode; 17 unsigned scancode, keycode;
18}; 18};
19enum { 19enum {
20 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ 20 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
@@ -33,7 +33,7 @@ int setkeycodes_main(int argc, char **argv)
33 fd = get_console_fd(); 33 fd = get_console_fd();
34 34
35 while (argc > 2) { 35 while (argc > 2) {
36 a.keycode = xatoul_range(argv[2], 0, 127); 36 a.keycode = xatou_range(argv[2], 0, 127);
37 a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255); 37 a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
38 if (a.scancode > 127) { 38 if (a.scancode > 127) {
39 a.scancode -= 0xe000; 39 a.scancode -= 0xe000;
diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c
index 0f6491c72..b312fa76e 100644
--- a/console-tools/setlogcons.c
+++ b/console-tools/setlogcons.c
@@ -12,7 +12,7 @@
12#include "libbb.h" 12#include "libbb.h"
13 13
14int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15int setlogcons_main(int argc, char **argv) 15int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv)
16{ 16{
17 struct { 17 struct {
18 char fn; 18 char fn;
@@ -22,8 +22,8 @@ int setlogcons_main(int argc, char **argv)
22 arg.fn = 11; /* redirect kernel messages */ 22 arg.fn = 11; /* redirect kernel messages */
23 arg.subarg = 0; /* to specified console (current as default) */ 23 arg.subarg = 0; /* to specified console (current as default) */
24 24
25 if (argc == 2) 25 if (argv[1])
26 arg.subarg = xatoul_range(argv[1], 0, 63); 26 arg.subarg = xatou_range(argv[1], 0, 63);
27 27
28 xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg); 28 xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
29 29
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
diff --git a/editors/diff.c b/editors/diff.c
index f9e82ba02..486077847 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -1208,17 +1208,16 @@ int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1208int diff_main(int argc ATTRIBUTE_UNUSED, char **argv) 1208int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
1209{ 1209{
1210 bool gotstdin = 0; 1210 bool gotstdin = 0;
1211 char *U_opt;
1212 char *f1, *f2; 1211 char *f1, *f2;
1213 llist_t *L_arg = NULL; 1212 llist_t *L_arg = NULL;
1214 1213
1215 INIT_G(); 1214 INIT_G();
1216 1215
1217 /* exactly 2 params; collect multiple -L <label> */ 1216 /* exactly 2 params; collect multiple -L <label>; -U N */
1218 opt_complementary = "=2:L::"; 1217 opt_complementary = "=2:L::U+";
1219 getopt32(argv, "abdiL:NqrsS:tTU:wu" 1218 getopt32(argv, "abdiL:NqrsS:tTU:wu"
1220 "p" /* ignored (for compatibility) */, 1219 "p" /* ignored (for compatibility) */,
1221 &L_arg, &start, &U_opt); 1220 &L_arg, &start, &context);
1222 /*argc -= optind;*/ 1221 /*argc -= optind;*/
1223 argv += optind; 1222 argv += optind;
1224 while (L_arg) { 1223 while (L_arg) {
@@ -1233,8 +1232,6 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
1233 /* we leak L_arg here... */ 1232 /* we leak L_arg here... */
1234 L_arg = L_arg->link; 1233 L_arg = L_arg->link;
1235 } 1234 }
1236 if (option_mask32 & FLAG_U)
1237 context = xatoi_u(U_opt);
1238 1235
1239 /* 1236 /*
1240 * Do sanity checks, fill in stb1 and stb2 and call the appropriate 1237 * Do sanity checks, fill in stb1 and stb2 and call the appropriate
diff --git a/editors/ed.c b/editors/ed.c
index 15f0147be..9606cfdde 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -89,7 +89,7 @@ static char *skip_blank(const char *cp)
89 89
90 90
91int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 91int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
92int ed_main(int argc, char **argv) 92int ed_main(int argc ATTRIBUTE_UNUSED, char **argv)
93{ 93{
94 INIT_G(); 94 INIT_G();
95 95
@@ -99,7 +99,7 @@ int ed_main(int argc, char **argv)
99 lines.next = &lines; 99 lines.next = &lines;
100 lines.prev = &lines; 100 lines.prev = &lines;
101 101
102 if (argc > 1) { 102 if (argv[1]) {
103 fileName = xstrdup(argv[1]); 103 fileName = xstrdup(argv[1]);
104 if (!readLines(fileName, 1)) { 104 if (!readLines(fileName, 1)) {
105 return EXIT_SUCCESS; 105 return EXIT_SUCCESS;
diff --git a/findutils/grep.c b/findutils/grep.c
index c4cfcb852..259026ee5 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 9 */
10/* BB_AUDIT SUSv3 defects - unsupported option -x. */ 10/* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */
11/* BB_AUDIT GNU defects - always acts as -a. */ 11/* BB_AUDIT GNU defects - always acts as -a. */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */ 12/* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */
13/* 13/*
@@ -299,7 +299,7 @@ static int grep_file(FILE *file)
299 free(before_buf[curpos]); 299 free(before_buf[curpos]);
300 before_buf[curpos] = line; 300 before_buf[curpos] = line;
301 curpos = (curpos + 1) % lines_before; 301 curpos = (curpos + 1) % lines_before;
302 /* avoid free(line) - we took line */ 302 /* avoid free(line) - we took the line */
303 line = NULL; 303 line = NULL;
304 } 304 }
305 } 305 }
@@ -371,7 +371,10 @@ static void load_regexes_from_file(llist_t *fopt)
371 } 371 }
372} 372}
373 373
374static int file_action_grep(const char *filename, struct stat *statbuf ATTRIBUTE_UNUSED, void* matched, int depth ATTRIBUTE_UNUSED) 374static int file_action_grep(const char *filename,
375 struct stat *statbuf ATTRIBUTE_UNUSED,
376 void* matched,
377 int depth ATTRIBUTE_UNUSED)
375{ 378{
376 FILE *file = fopen(filename, "r"); 379 FILE *file = fopen(filename, "r");
377 if (file == NULL) { 380 if (file == NULL) {
@@ -405,35 +408,28 @@ int grep_main(int argc, char **argv)
405{ 408{
406 FILE *file; 409 FILE *file;
407 int matched; 410 int matched;
408 char *mopt;
409 llist_t *fopt = NULL; 411 llist_t *fopt = NULL;
410 412
411 /* do normal option parsing */ 413 /* do normal option parsing */
412#if ENABLE_FEATURE_GREP_CONTEXT 414#if ENABLE_FEATURE_GREP_CONTEXT
413 char *slines_after; 415 int Copt;
414 char *slines_before;
415 char *Copt;
416 416
417 opt_complementary = "H-h:e::f::C-AB"; 417 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
418 * -m,-A,-B,-C have numeric param */
419 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
418 getopt32(argv, 420 getopt32(argv,
419 OPTSTR_GREP, 421 OPTSTR_GREP,
420 &pattern_head, &fopt, &mopt, 422 &pattern_head, &fopt, &max_matches,
421 &slines_after, &slines_before, &Copt); 423 &lines_after, &lines_before, &Copt);
422 424
423 if (option_mask32 & OPT_C) { 425 if (option_mask32 & OPT_C) {
424 /* -C unsets prev -A and -B, but following -A or -B 426 /* -C unsets prev -A and -B, but following -A or -B
425 may override it */ 427 may override it */
426 if (!(option_mask32 & OPT_A)) /* not overridden */ 428 if (!(option_mask32 & OPT_A)) /* not overridden */
427 slines_after = Copt; 429 lines_after = Copt;
428 if (!(option_mask32 & OPT_B)) /* not overridden */ 430 if (!(option_mask32 & OPT_B)) /* not overridden */
429 slines_before = Copt; 431 lines_before = Copt;
430 option_mask32 |= OPT_A|OPT_B; /* for parser */ 432 //option_mask32 |= OPT_A|OPT_B; /* for parser */
431 }
432 if (option_mask32 & OPT_A) {
433 lines_after = xatoi_u(slines_after);
434 }
435 if (option_mask32 & OPT_B) {
436 lines_before = xatoi_u(slines_before);
437 } 433 }
438 /* sanity checks */ 434 /* sanity checks */
439 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) { 435 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) {
@@ -444,13 +440,11 @@ int grep_main(int argc, char **argv)
444 before_buf = xzalloc(lines_before * sizeof(char *)); 440 before_buf = xzalloc(lines_before * sizeof(char *));
445#else 441#else
446 /* with auto sanity checks */ 442 /* with auto sanity checks */
447 opt_complementary = "H-h:e::f::c-n:q-n:l-n"; 443 /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
444 opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
448 getopt32(argv, OPTSTR_GREP, 445 getopt32(argv, OPTSTR_GREP,
449 &pattern_head, &fopt, &mopt); 446 &pattern_head, &fopt, &max_matches);
450#endif 447#endif
451 if (option_mask32 & OPT_m) {
452 max_matches = xatoi_u(mopt);
453 }
454 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ 448 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
455 449
456 if (pattern_head != NULL) { 450 if (pattern_head != NULL) {
@@ -481,8 +475,8 @@ int grep_main(int argc, char **argv)
481 argv += optind; 475 argv += optind;
482 argc -= optind; 476 argc -= optind;
483 477
484 /* if we didn't get a pattern from a -e and no command file was specified, 478 /* if we didn't get a pattern from -e and no command file was specified,
485 * argv[optind] should be the pattern. no pattern, no worky */ 479 * first parameter should be the pattern. no pattern, no worky */
486 if (pattern_head == NULL) { 480 if (pattern_head == NULL) {
487 char *pattern; 481 char *pattern;
488 if (*argv == NULL) 482 if (*argv == NULL)
@@ -508,7 +502,7 @@ int grep_main(int argc, char **argv)
508 do { 502 do {
509 cur_file = *argv++; 503 cur_file = *argv++;
510 file = stdin; 504 file = stdin;
511 if (!cur_file || (*cur_file == '-' && !cur_file[1])) { 505 if (!cur_file || LONE_DASH(cur_file)) {
512 cur_file = "(standard input)"; 506 cur_file = "(standard input)";
513 } else { 507 } else {
514 if (option_mask32 & OPT_r) { 508 if (option_mask32 & OPT_r) {
diff --git a/init/halt.c b/init/halt.c
index 1f0fae302..c14f0f221 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -33,7 +33,7 @@ RB_AUTOBOOT
33 }; 33 };
34 static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM }; 34 static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
35 35
36 char *delay; 36 int delay = 0;
37 int which, flags, rc = 1; 37 int which, flags, rc = 1;
38#if ENABLE_FEATURE_WTMP 38#if ENABLE_FEATURE_WTMP
39 struct utmp utmp; 39 struct utmp utmp;
@@ -46,9 +46,10 @@ RB_AUTOBOOT
46 continue; 46 continue;
47 47
48 /* Parse and handle arguments */ 48 /* Parse and handle arguments */
49 opt_complementary = "d+"; /* -d N */
49 flags = getopt32(argv, "d:nfw", &delay); 50 flags = getopt32(argv, "d:nfw", &delay);
50 if (flags & 1) 51
51 sleep(xatou(delay)); 52 sleep(delay);
52 53
53#if ENABLE_FEATURE_WTMP 54#if ENABLE_FEATURE_WTMP
54 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) { 55 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
diff --git a/init/init.c b/init/init.c
index 1145c0490..6d4969c4b 100644
--- a/init/init.c
+++ b/init/init.c
@@ -818,14 +818,14 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
818} 818}
819 819
820int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 820int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
821int init_main(int argc, char **argv) 821int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
822{ 822{
823 struct init_action *a; 823 struct init_action *a;
824 pid_t wpid; 824 pid_t wpid;
825 825
826 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */ 826 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
827 827
828 if (argc > 1 && !strcmp(argv[1], "-q")) { 828 if (argv[1] && !strcmp(argv[1], "-q")) {
829 return kill(1, SIGHUP); 829 return kill(1, SIGHUP);
830 } 830 }
831 831
@@ -868,7 +868,7 @@ int init_main(int argc, char **argv)
868 putenv((char *) *e); 868 putenv((char *) *e);
869 } 869 }
870 870
871 if (argc > 1) setenv("RUNLEVEL", argv[1], 1); 871 if (argv[1]) setenv("RUNLEVEL", argv[1], 1);
872 872
873 /* Hello world */ 873 /* Hello world */
874 message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); 874 message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
@@ -890,7 +890,7 @@ int init_main(int argc, char **argv)
890 } 890 }
891 891
892 /* Check if we are supposed to be in single user mode */ 892 /* Check if we are supposed to be in single user mode */
893 if (argc > 1 893 if (argv[1]
894 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1')) 894 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
895 ) { 895 ) {
896 /* Start a shell on console */ 896 /* Start a shell on console */
diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c
index 8f23ca640..8f6616fe0 100644
--- a/ipsvd/tcpudp.c
+++ b/ipsvd/tcpudp.c
@@ -163,7 +163,7 @@ static void sig_child_handler(int sig ATTRIBUTE_UNUSED)
163int tcpudpsvd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 163int tcpudpsvd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
164int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv) 164int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
165{ 165{
166 char *str_c, *str_C, *str_b, *str_t; 166 char *str_C, *str_t;
167 char *user; 167 char *user;
168 struct hcc *hccp; 168 struct hcc *hccp;
169 const char *instructs; 169 const char *instructs;
@@ -189,21 +189,20 @@ int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
189 189
190 tcp = (applet_name[0] == 't'); 190 tcp = (applet_name[0] == 't');
191 191
192 /* 3+ args, -i at most once, -p implies -h, -v is counter */ 192 /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
193 opt_complementary = "-3:i--i:ph:vv"; 193 opt_complementary = "-3:i--i:ph:vv:b+:c+";
194#ifdef SSLSVD 194#ifdef SSLSVD
195 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:", 195 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
196 &str_c, &str_C, &instructs, &instructs, &user, &preset_local_hostname, 196 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
197 &str_b, &str_t, &ssluser, &root, &cert, &key, &verbose 197 &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
198 ); 198 );
199#else 199#else
200 /* "+": stop on first non-option */
200 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v", 201 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v",
201 &str_c, &str_C, &instructs, &instructs, &user, &preset_local_hostname, 202 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
202 &str_b, &str_t, &verbose 203 &backlog, &str_t, &verbose
203 ); 204 );
204#endif 205#endif
205 if (option_mask32 & OPT_c)
206 cmax = xatou_range(str_c, 1, INT_MAX);
207 if (option_mask32 & OPT_C) { /* -C n[:message] */ 206 if (option_mask32 & OPT_C) { /* -C n[:message] */
208 max_per_host = bb_strtou(str_C, &str_C, 10); 207 max_per_host = bb_strtou(str_C, &str_C, 10);
209 if (str_C[0]) { 208 if (str_C[0]) {
@@ -219,8 +218,6 @@ int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
219 if (!get_uidgid(&ugid, user, 1)) 218 if (!get_uidgid(&ugid, user, 1))
220 bb_error_msg_and_die("unknown user/group: %s", user); 219 bb_error_msg_and_die("unknown user/group: %s", user);
221 } 220 }
222 if (option_mask32 & OPT_b)
223 backlog = xatou(str_b);
224#ifdef SSLSVD 221#ifdef SSLSVD
225 if (option_mask32 & OPT_U) ssluser = optarg; 222 if (option_mask32 & OPT_U) ssluser = optarg;
226 if (option_mask32 & OPT_slash) root = optarg; 223 if (option_mask32 & OPT_slash) root = optarg;
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 9e53dfd08..51e030653 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -117,7 +117,7 @@ const char *opt_complementary
117 if w is given once, GNU ps sets the width to 132, 117 if w is given once, GNU ps sets the width to 132,
118 if w is given more than once, it is "unlimited" 118 if w is given more than once, it is "unlimited"
119 119
120 int w_counter = 0; 120 int w_counter = 0; // must be initialized!
121 opt_complementary = "ww"; 121 opt_complementary = "ww";
122 getopt32(argv, "w", &w_counter); 122 getopt32(argv, "w", &w_counter);
123 if (w_counter) 123 if (w_counter)
@@ -220,7 +220,7 @@ Special characters:
220 "x--x" Variation of the above, it means that -x option should occur 220 "x--x" Variation of the above, it means that -x option should occur
221 at most once. 221 at most once.
222 222
223 "a+:" A plus after a char in opt_complementary means that the parameter 223 "a+" A plus after a char in opt_complementary means that the parameter
224 for this option is a nonnegative integer. It will be processed 224 for this option is a nonnegative integer. It will be processed
225 with xatoi_u() - allowed range is 0..INT_MAX. 225 with xatoi_u() - allowed range is 0..INT_MAX.
226 226
@@ -255,7 +255,7 @@ Special characters:
255 For example from "id" applet: 255 For example from "id" applet:
256 256
257 // Don't allow -n -r -rn -ug -rug -nug -rnug 257 // Don't allow -n -r -rn -ug -rug -nug -rnug
258 opt_complementary = "r?ug:n?ug:?u--g:g--u"; 258 opt_complementary = "r?ug:n?ug:u--g:g--u";
259 flags = getopt32(argv, "rnug"); 259 flags = getopt32(argv, "rnug");
260 260
261 This example allowed only: 261 This example allowed only:
@@ -545,11 +545,14 @@ getopt32(char **argv, const char *applet_opts, ...)
545 if (on_off->counter) 545 if (on_off->counter)
546 (*(on_off->counter))++; 546 (*(on_off->counter))++;
547 if (on_off->param_type == PARAM_LIST) { 547 if (on_off->param_type == PARAM_LIST) {
548 llist_add_to_end((llist_t **)(on_off->optarg), optarg); 548 if (optarg)
549 llist_add_to_end((llist_t **)(on_off->optarg), optarg);
549 } else if (on_off->param_type == PARAM_INT) { 550 } else if (on_off->param_type == PARAM_INT) {
550 *(unsigned*)(on_off->optarg) = xatoi_u(optarg); 551 if (optarg)
552 *(unsigned*)(on_off->optarg) = xatoi_u(optarg);
551 } else if (on_off->optarg) { 553 } else if (on_off->optarg) {
552 *(char **)(on_off->optarg) = optarg; 554 if (optarg)
555 *(char **)(on_off->optarg) = optarg;
553 } 556 }
554 if (pargv != NULL) 557 if (pargv != NULL)
555 break; 558 break;
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index 31e507045..b25f8171d 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -123,7 +123,7 @@ static void add_user_to_group(char **args,
123 * will add an existing user to an existing group. 123 * will add an existing user to an existing group.
124 */ 124 */
125int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 125int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
126int addgroup_main(int argc, char **argv) 126int addgroup_main(int argc ATTRIBUTE_UNUSED, char **argv)
127{ 127{
128 char *group; 128 char *group;
129 gid_t gid = 0; 129 gid_t gid = 0;
@@ -144,10 +144,10 @@ int addgroup_main(int argc, char **argv)
144 } 144 }
145 /* move past the commandline options */ 145 /* move past the commandline options */
146 argv += optind; 146 argv += optind;
147 argc -= optind; 147 //argc -= optind;
148 148
149#if ENABLE_FEATURE_ADDUSER_TO_GROUP 149#if ENABLE_FEATURE_ADDUSER_TO_GROUP
150 if (argc == 2) { 150 if (argv[1]) {
151 struct group *gr; 151 struct group *gr;
152 152
153 if (option_mask32) { 153 if (option_mask32) {
@@ -170,7 +170,7 @@ int addgroup_main(int argc, char **argv)
170 add_user_to_group(argv, bb_path_group_file, xfopen); 170 add_user_to_group(argv, bb_path_group_file, xfopen);
171#if ENABLE_FEATURE_SHADOWPASSWDS 171#if ENABLE_FEATURE_SHADOWPASSWDS
172 add_user_to_group(argv, bb_path_gshadow_file, fopen_or_warn); 172 add_user_to_group(argv, bb_path_gshadow_file, fopen_or_warn);
173#endif /* ENABLE_FEATURE_SHADOWPASSWDS */ 173#endif
174 } else 174 } else
175#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ 175#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
176 new_group(argv[0], gid); 176 new_group(argv[0], gid);
diff --git a/loginutils/login.c b/loginutils/login.c
index d7eb8d35b..e8fe74e16 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -221,7 +221,7 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED)
221} 221}
222 222
223int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 223int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
224int login_main(int argc, char **argv) 224int login_main(int argc ATTRIBUTE_UNUSED, char **argv)
225{ 225{
226 enum { 226 enum {
227 LOGIN_OPT_f = (1<<0), 227 LOGIN_OPT_f = (1<<0),
@@ -269,8 +269,9 @@ int login_main(int argc, char **argv)
269 bb_error_msg_and_die("-f is for root only"); 269 bb_error_msg_and_die("-f is for root only");
270 safe_strncpy(username, opt_user, sizeof(username)); 270 safe_strncpy(username, opt_user, sizeof(username));
271 } 271 }
272 if (optind < argc) /* user from command line (getty) */ 272 argv += optind;
273 safe_strncpy(username, argv[optind], sizeof(username)); 273 if (argv[0]) /* user from command line (getty) */
274 safe_strncpy(username, argv[0], sizeof(username));
274 275
275 /* Let's find out and memorize our tty */ 276 /* Let's find out and memorize our tty */
276 if (!isatty(0) || !isatty(1) || !isatty(2)) 277 if (!isatty(0) || !isatty(1) || !isatty(2))
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index caa1a8335..17bb15efa 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -19,7 +19,6 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
19{ 19{
20 char *cp; 20 char *cp;
21 int timeout = 0; 21 int timeout = 0;
22 char *timeout_arg;
23 struct passwd *pwd; 22 struct passwd *pwd;
24 const char *shell; 23 const char *shell;
25#if ENABLE_FEATURE_SHADOWPASSWDS 24#if ENABLE_FEATURE_SHADOWPASSWDS
@@ -31,9 +30,8 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
31 logmode = LOGMODE_BOTH; 30 logmode = LOGMODE_BOTH;
32 openlog(applet_name, 0, LOG_AUTH); 31 openlog(applet_name, 0, LOG_AUTH);
33 32
34 if (getopt32(argv, "t:", &timeout_arg)) { 33 opt_complementary = "t+"; /* -t N */
35 timeout = xatoi_u(timeout_arg); 34 getopt32(argv, "t:", &timeout);
36 }
37 35
38 if (argv[optind]) { 36 if (argv[optind]) {
39 close(0); 37 close(0);
@@ -43,6 +41,7 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
43 dup(0); 41 dup(0);
44 } 42 }
45 43
44 /* Malicious use like "sulogin /dev/sda"? */
46 if (!isatty(0) || !isatty(1) || !isatty(2)) { 45 if (!isatty(0) || !isatty(1) || !isatty(2)) {
47 logmode = LOGMODE_SYSLOG; 46 logmode = LOGMODE_SYSLOG;
48 bb_error_msg_and_die("not a tty"); 47 bb_error_msg_and_die("not a tty");
diff --git a/miscutils/mt.c b/miscutils/mt.c
index c16073c61..c56a8e0ca 100644
--- a/miscutils/mt.c
+++ b/miscutils/mt.c
@@ -81,24 +81,22 @@ static const char opcode_name[] ALIGN1 =
81 "weof" "\0"; 81 "weof" "\0";
82 82
83int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 83int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
84int mt_main(int argc, char **argv) 84int mt_main(int argc ATTRIBUTE_UNUSED, char **argv)
85{ 85{
86 const char *file = "/dev/tape"; 86 const char *file = "/dev/tape";
87 struct mtop op; 87 struct mtop op;
88 struct mtpos position; 88 struct mtpos position;
89 int fd, mode, idx; 89 int fd, mode, idx;
90 90
91 if (argc < 2) { 91 if (!argv[1]) {
92 bb_show_usage(); 92 bb_show_usage();
93 } 93 }
94 94
95 if (strcmp(argv[1], "-f") == 0) { 95 if (strcmp(argv[1], "-f") == 0) {
96 if (argc < 4) { 96 if (!argv[2] || !argv[3])
97 bb_show_usage(); 97 bb_show_usage();
98 }
99 file = argv[2]; 98 file = argv[2];
100 argv += 2; 99 argv += 2;
101 argc -= 2;
102 } 100 }
103 101
104 idx = index_in_strings(opcode_name, argv[1]); 102 idx = index_in_strings(opcode_name, argv[1]);
@@ -107,7 +105,7 @@ int mt_main(int argc, char **argv)
107 bb_error_msg_and_die("unrecognized opcode %s", argv[1]); 105 bb_error_msg_and_die("unrecognized opcode %s", argv[1]);
108 106
109 op.mt_op = opcode_value[idx]; 107 op.mt_op = opcode_value[idx];
110 if (argc >= 3) 108 if (argv[2])
111 op.mt_count = xatoi_u(argv[2]); 109 op.mt_count = xatoi_u(argv[2]);
112 else 110 else
113 op.mt_count = 1; /* One, not zero, right? */ 111 op.mt_count = 1; /* One, not zero, right? */
diff --git a/networking/arping.c b/networking/arping.c
index 6a17b18ee..39dcb7cc2 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -264,16 +264,14 @@ int arping_main(int argc ATTRIBUTE_UNUSED, char **argv)
264 err_str = xasprintf("interface %s %%s", device); 264 err_str = xasprintf("interface %s %%s", device);
265 { 265 {
266 unsigned opt; 266 unsigned opt;
267 char *str_count, *str_timeout; 267 char *str_timeout;
268 268
269 /* Dad also sets quit_on_reply. 269 /* Dad also sets quit_on_reply.
270 * Advert also sets unsolicited. 270 * Advert also sets unsolicited.
271 */ 271 */
272 opt_complementary = "=1:Df:AU"; 272 opt_complementary = "=1:Df:AU:c+";
273 opt = getopt32(argv, "DUAqfbc:w:I:s:", 273 opt = getopt32(argv, "DUAqfbc:w:I:s:",
274 &str_count, &str_timeout, &device, &source); 274 &count, &str_timeout, &device, &source);
275 if (opt & 0x40) /* -c: count */
276 count = xatoi_u(str_count);
277 if (opt & 0x80) /* -w: timeout */ 275 if (opt & 0x80) /* -w: timeout */
278 timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000; 276 timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
279 //if (opt & 0x200) /* -s: source */ 277 //if (opt & 0x200) /* -s: source */
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 34f715fc5..dd94a1460 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -674,7 +674,7 @@ Debug("wrote %d to net, errno %d", rr, errno);
674int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 674int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
675int nc_main(int argc, char **argv) 675int nc_main(int argc, char **argv)
676{ 676{
677 char *str_p, *str_s, *str_w; 677 char *str_p, *str_s;
678 USE_NC_EXTRA(char *str_i, *str_o;) 678 USE_NC_EXTRA(char *str_i, *str_o;)
679 char *themdotted = themdotted; /* gcc */ 679 char *themdotted = themdotted; /* gcc */
680 char **proggie; 680 char **proggie;
@@ -710,10 +710,10 @@ int nc_main(int argc, char **argv)
710 e_found: 710 e_found:
711 711
712 // -g -G -t -r deleted, unimplemented -a deleted too 712 // -g -G -t -r deleted, unimplemented -a deleted too
713 opt_complementary = "?2:vv"; /* max 2 params, -v is a counter */ 713 opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */
714 getopt32(argv, "hnp:s:uvw:" USE_NC_SERVER("l") 714 getopt32(argv, "hnp:s:uvw:" USE_NC_SERVER("l")
715 USE_NC_EXTRA("i:o:z"), 715 USE_NC_EXTRA("i:o:z"),
716 &str_p, &str_s, &str_w 716 &str_p, &str_s, &o_wait
717 USE_NC_EXTRA(, &str_i, &str_o, &o_verbose)); 717 USE_NC_EXTRA(, &str_i, &str_o, &o_verbose));
718 argv += optind; 718 argv += optind;
719#if ENABLE_NC_EXTRA 719#if ENABLE_NC_EXTRA
@@ -731,9 +731,7 @@ int nc_main(int argc, char **argv)
731 //if (option_mask32 & OPT_r) /* randomize various things */ 731 //if (option_mask32 & OPT_r) /* randomize various things */
732 //if (option_mask32 & OPT_u) /* use UDP */ 732 //if (option_mask32 & OPT_u) /* use UDP */
733 //if (option_mask32 & OPT_v) /* verbose */ 733 //if (option_mask32 & OPT_v) /* verbose */
734 if (option_mask32 & OPT_w) { /* wait time */ 734 //if (option_mask32 & OPT_w) /* wait time */
735 o_wait = xatoi_u(str_w);
736 }
737 //if (option_mask32 & OPT_z) /* little or no data xfer */ 735 //if (option_mask32 & OPT_z) /* little or no data xfer */
738 736
739 /* We manage our fd's so that they are never 0,1,2 */ 737 /* We manage our fd's so that they are never 0,1,2 */
diff --git a/networking/tftp.c b/networking/tftp.c
index 14c340b22..187261568 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -397,9 +397,6 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
397 len_and_sockaddr *peer_lsa; 397 len_and_sockaddr *peer_lsa;
398 const char *localfile = NULL; 398 const char *localfile = NULL;
399 const char *remotefile = NULL; 399 const char *remotefile = NULL;
400#if ENABLE_FEATURE_TFTP_BLOCKSIZE
401 const char *sblocksize = NULL;
402#endif
403 int port; 400 int port;
404 USE_GETPUT(int cmd;) 401 USE_GETPUT(int cmd;)
405 int fd = -1; 402 int fd = -1;
@@ -409,13 +406,14 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
409 406
410 /* -p or -g is mandatory, and they are mutually exclusive */ 407 /* -p or -g is mandatory, and they are mutually exclusive */
411 opt_complementary = "" USE_FEATURE_TFTP_GET("g:") USE_FEATURE_TFTP_PUT("p:") 408 opt_complementary = "" USE_FEATURE_TFTP_GET("g:") USE_FEATURE_TFTP_PUT("p:")
412 USE_GETPUT("?g--p:p--g"); 409 USE_GETPUT("g--p:p--g:")
410 USE_FEATURE_TFTP_BLOCKSIZE("b+");
413 411
414 USE_GETPUT(cmd =) getopt32(argv, 412 USE_GETPUT(cmd =) getopt32(argv,
415 USE_FEATURE_TFTP_GET("g") USE_FEATURE_TFTP_PUT("p") 413 USE_FEATURE_TFTP_GET("g") USE_FEATURE_TFTP_PUT("p")
416 "l:r:" USE_FEATURE_TFTP_BLOCKSIZE("b:"), 414 "l:r:" USE_FEATURE_TFTP_BLOCKSIZE("b:"),
417 &localfile, &remotefile 415 &localfile, &remotefile
418 USE_FEATURE_TFTP_BLOCKSIZE(, &sblocksize)); 416 USE_FEATURE_TFTP_BLOCKSIZE(, &blocksize));
419 argv += optind; 417 argv += optind;
420 418
421 flags = O_RDONLY; 419 flags = O_RDONLY;
@@ -423,12 +421,8 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
423 flags = O_WRONLY | O_CREAT | O_TRUNC; 421 flags = O_WRONLY | O_CREAT | O_TRUNC;
424 422
425#if ENABLE_FEATURE_TFTP_BLOCKSIZE 423#if ENABLE_FEATURE_TFTP_BLOCKSIZE
426 if (sblocksize) { 424 if (!tftp_blocksize_check(blocksize, 0))
427 blocksize = xatoi_u(sblocksize); 425 return EXIT_FAILURE;
428 if (!tftp_blocksize_check(blocksize, 0)) {
429 return EXIT_FAILURE;
430 }
431 }
432#endif 426#endif
433 427
434 if (!localfile) 428 if (!localfile)
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 576b1cbb8..fe8f4c8fa 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -132,7 +132,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
132int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) 132int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
133{ 133{
134 uint8_t *temp, *message; 134 uint8_t *temp, *message;
135 char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t; 135 char *str_c, *str_V, *str_h, *str_F, *str_r;
136 USE_FEATURE_UDHCP_PORT(char *str_P;) 136 USE_FEATURE_UDHCP_PORT(char *str_P;)
137 llist_t *list_O = NULL; 137 llist_t *list_O = NULL;
138#if ENABLE_FEATURE_UDHCPC_ARPING 138#if ENABLE_FEATURE_UDHCPC_ARPING
@@ -223,7 +223,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
223 client_config.script = DEFAULT_SCRIPT; 223 client_config.script = DEFAULT_SCRIPT;
224 224
225 /* Parse command line */ 225 /* Parse command line */
226 opt_complementary = "c--C:C--c:O::"; // Cc: mutually exclusive; O: list 226 /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */
227 opt_complementary = "c--C:C--c:O::T+:t+:A+";
227#if ENABLE_GETOPT_LONG 228#if ENABLE_GETOPT_LONG
228 applet_long_options = udhcpc_longopts; 229 applet_long_options = udhcpc_longopts;
229#endif 230#endif
@@ -233,7 +234,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
233 "O:" 234 "O:"
234 , &str_c, &str_V, &str_h, &str_h, &str_F 235 , &str_c, &str_V, &str_h, &str_h, &str_F
235 , &client_config.interface, &client_config.pidfile, &str_r 236 , &client_config.interface, &client_config.pidfile, &str_r
236 , &client_config.script, &str_T, &str_t, &str_A 237 , &client_config.script
238 , &discover_timeout, &discover_retries, &tryagain_timeout
237 USE_FEATURE_UDHCPC_ARPING(, &str_W) 239 USE_FEATURE_UDHCPC_ARPING(, &str_W)
238 USE_FEATURE_UDHCP_PORT(, &str_P) 240 USE_FEATURE_UDHCP_PORT(, &str_P)
239 , &list_O 241 , &list_O
@@ -273,12 +275,9 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
273 if (opt & OPT_r) 275 if (opt & OPT_r)
274 requested_ip = inet_addr(str_r); 276 requested_ip = inet_addr(str_r);
275 // if (opt & OPT_s) client_config.script = ... 277 // if (opt & OPT_s) client_config.script = ...
276 if (opt & OPT_T) 278 // if (opt & OPT_T) discover_timeout = xatoi_u(str_T);
277 discover_timeout = xatoi_u(str_T); 279 // if (opt & OPT_t) discover_retries = xatoi_u(str_t);
278 if (opt & OPT_t) 280 // if (opt & OPT_A) tryagain_timeout = xatoi_u(str_A);
279 discover_retries = xatoi_u(str_t);
280 if (opt & OPT_A)
281 tryagain_timeout = xatoi_u(str_A);
282 if (opt & OPT_v) { 281 if (opt & OPT_v) {
283 puts("version "BB_VER); 282 puts("version "BB_VER);
284 return 0; 283 return 0;
diff --git a/runit/sv.c b/runit/sv.c
index 45d5572f8..d5a9bd9cf 100644
--- a/runit/sv.c
+++ b/runit/sv.c
@@ -422,7 +422,7 @@ int sv_main(int argc, char **argv)
422 char **servicex; 422 char **servicex;
423 unsigned waitsec = 7; 423 unsigned waitsec = 7;
424 smallint kll = 0; 424 smallint kll = 0;
425 smallint verbose = 0; 425 int verbose = 0;
426 int (*act)(const char*); 426 int (*act)(const char*);
427 int (*cbk)(const char*); 427 int (*cbk)(const char*);
428 int curdir; 428 int curdir;
@@ -436,9 +436,8 @@ int sv_main(int argc, char **argv)
436 x = getenv("SVWAIT"); 436 x = getenv("SVWAIT");
437 if (x) waitsec = xatou(x); 437 if (x) waitsec = xatou(x);
438 438
439 opt = getopt32(argv, "w:v", &x); 439 opt_complementary = "w+:vv"; /* -w N, -v is a counter */
440 if (opt & 1) waitsec = xatou(x); // -w 440 opt = getopt32(argv, "w:v", &waitsec, &verbose);
441 if (opt & 2) verbose = 1; // -v
442 argc -= optind; 441 argc -= optind;
443 argv += optind; 442 argv += optind;
444 action = *argv++; 443 action = *argv++;
diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c
index c4f97ae34..eac7b15e9 100644
--- a/util-linux/fdformat.c
+++ b/util-linux/fdformat.c
@@ -41,7 +41,7 @@ struct format_descr {
41#define FD_FILL_BYTE 0xF6 /* format fill byte. */ 41#define FD_FILL_BYTE 0xF6 /* format fill byte. */
42 42
43int fdformat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 43int fdformat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44int fdformat_main(int argc, char **argv) 44int fdformat_main(int argc ATTRIBUTE_UNUSED, char **argv)
45{ 45{
46 int fd, n, cyl, read_bytes, verify; 46 int fd, n, cyl, read_bytes, verify;
47 unsigned char *data; 47 unsigned char *data;
@@ -49,9 +49,7 @@ int fdformat_main(int argc, char **argv)
49 struct floppy_struct param; 49 struct floppy_struct param;
50 struct format_descr descr; 50 struct format_descr descr;
51 51
52 if (argc < 2) { 52 opt_complementary = "=1"; /* must have 1 param */
53 bb_show_usage();
54 }
55 verify = !getopt32(argv, "n"); 53 verify = !getopt32(argv, "n");
56 argv += optind; 54 argv += optind;
57 55
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 3fbdc2020..60031a5c3 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -627,7 +627,7 @@ int mkfs_minix_main(int argc ATTRIBUTE_UNUSED, char **argv)
627 unsigned opt; 627 unsigned opt;
628 char *tmp; 628 char *tmp;
629 struct stat statbuf; 629 struct stat statbuf;
630 char *str_i, *str_n; 630 char *str_i;
631 char *listfile = NULL; 631 char *listfile = NULL;
632 632
633 INIT_G(); 633 INIT_G();
@@ -643,13 +643,13 @@ int mkfs_minix_main(int argc ATTRIBUTE_UNUSED, char **argv)
643 bb_error_msg_and_die("bad inode size"); 643 bb_error_msg_and_die("bad inode size");
644#endif 644#endif
645 645
646 opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &str_n); 646 opt_complementary = "n+"; /* -n N */
647 opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &G.namelen);
647 argv += optind; 648 argv += optind;
648 //if (opt & 1) -c 649 //if (opt & 1) -c
649 if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i 650 if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i
650 //if (opt & 4) -l 651 //if (opt & 4) -l
651 if (opt & 8) { // -n 652 if (opt & 8) { // -n
652 G.namelen = xatoi_u(str_n);
653 if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC; 653 if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC;
654 else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2; 654 else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2;
655 else bb_show_usage(); 655 else bb_show_usage();
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c
index ef7865951..e25d07d2b 100644
--- a/util-linux/readprofile.c
+++ b/util-linux/readprofile.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10/* 10/*
11 * 1999-02-22 Arkadiusz Mikiewicz <misiek@pld.ORG.PL> 11 * 1999-02-22 Arkadiusz Mickiewicz <misiek@pld.ORG.PL>
12 * - added Native Language Support 12 * - added Native Language Support
13 * 1999-09-01 Stephane Eranian <eranian@cello.hpl.hp.com> 13 * 1999-09-01 Stephane Eranian <eranian@cello.hpl.hp.com>
14 * - 64bit clean patch 14 * - 64bit clean patch
@@ -45,7 +45,7 @@ int readprofile_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
45int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv) 45int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
46{ 46{
47 FILE *map; 47 FILE *map;
48 const char *mapFile, *proFile, *mult = 0; 48 const char *mapFile, *proFile;
49 unsigned long indx = 1; 49 unsigned long indx = 1;
50 size_t len; 50 size_t len;
51 uint64_t add0 = 0; 51 uint64_t add0 = 0;
@@ -55,37 +55,49 @@ int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
55 char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ 55 char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */
56 char mapline[S_LEN]; 56 char mapline[S_LEN];
57 char mode[8]; 57 char mode[8];
58 int optAll = 0, optInfo = 0, optReset = 0;
59 int optVerbose = 0, optNative = 0;
60 int optBins = 0, optSub = 0;
61 int maplineno = 1; 58 int maplineno = 1;
62 int header_printed; 59 int header_printed;
60 int multiplier = 0;
61 unsigned opt;
62 enum {
63 OPT_M = (1 << 0),
64 OPT_m = (1 << 1),
65 OPT_p = (1 << 2),
66 OPT_n = (1 << 3),
67 OPT_a = (1 << 4),
68 OPT_b = (1 << 5),
69 OPT_s = (1 << 6),
70 OPT_i = (1 << 7),
71 OPT_r = (1 << 8),
72 OPT_v = (1 << 9),
73 };
74#define optMult (opt & OPT_M)
75#define optNative (opt & OPT_n)
76#define optAll (opt & OPT_a)
77#define optBins (opt & OPT_b)
78#define optSub (opt & OPT_s)
79#define optInfo (opt & OPT_i)
80#define optReset (opt & OPT_r)
81#define optVerbose (opt & OPT_v)
63 82
64#define next (current^1) 83#define next (current^1)
65 84
66 proFile = defaultpro; 85 proFile = defaultpro;
67 mapFile = defaultmap; 86 mapFile = defaultmap;
68 87
69 opt_complementary = "nn:aa:bb:ss:ii:rr:vv"; 88 opt_complementary = "M+"; /* -M N */
70 getopt32(argv, "M:m:p:nabsirv", 89 opt = getopt32(argv, "M:m:p:nabsirv", &multiplier, &mapFile, &proFile);
71 &mult, &mapFile, &proFile,
72 &optNative, &optAll, &optBins, &optSub,
73 &optInfo, &optReset, &optVerbose);
74 90
75 if (optReset || mult) { 91 if (opt & (OPT_M|OPT_r)) { /* mult or reset, or both */
76 int multiplier, fd, to_write; 92 int fd, to_write;
77 93
78 /* 94 /*
79 * When writing the multiplier, if the length of the write is 95 * When writing the multiplier, if the length of the write is
80 * not sizeof(int), the multiplier is not changed 96 * not sizeof(int), the multiplier is not changed
81 */ 97 */
82 if (mult) { 98 to_write = sizeof(int);
83 multiplier = xatoi_u(mult); 99 if (!optMult)
84 to_write = sizeof(int);
85 } else {
86 multiplier = 0;
87 to_write = 1; /* sth different from sizeof(int) */ 100 to_write = 1; /* sth different from sizeof(int) */
88 }
89 101
90 fd = xopen(defaultpro, O_WRONLY); 102 fd = xopen(defaultpro, O_WRONLY);
91 xwrite(fd, &multiplier, to_write); 103 xwrite(fd, &multiplier, to_write);
@@ -187,8 +199,9 @@ int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
187 if (optBins) { 199 if (optBins) {
188 if (optVerbose || this > 0) 200 if (optVerbose || this > 0)
189 printf(" total\t\t\t\t%u\n", this); 201 printf(" total\t\t\t\t%u\n", this);
190 } else if ((this || optAll) && 202 } else if ((this || optAll)
191 (fn_len = next_add-fn_add) != 0) { 203 && (fn_len = next_add-fn_add) != 0
204 ) {
192 if (optVerbose) 205 if (optVerbose)
193 printf("%016llx %-40s %6i %8.4f\n", fn_add, 206 printf("%016llx %-40s %6i %8.4f\n", fn_add,
194 fn_name, this, this/(double)fn_len); 207 fn_name, this, this/(double)fn_len);
diff --git a/util-linux/setarch.c b/util-linux/setarch.c
index dbc02de5e..1f979a73c 100644
--- a/util-linux/setarch.c
+++ b/util-linux/setarch.c
@@ -12,7 +12,7 @@
12#include "libbb.h" 12#include "libbb.h"
13 13
14int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv) 15int setarch_main(int argc ATTRIBUTE_UNUSED, char **argv)
16{ 16{
17 int pers = -1; 17 int pers = -1;
18 18
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 48f6f4e0b..beefac030 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -59,11 +59,11 @@ static int do_em_all(void)
59} 59}
60 60
61int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 61int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
62int swap_on_off_main(int argc, char **argv) 62int swap_on_off_main(int argc ATTRIBUTE_UNUSED, char **argv)
63{ 63{
64 int ret; 64 int ret;
65 65
66 if (argc == 1) 66 if (!argv[1])
67 bb_show_usage(); 67 bb_show_usage();
68 68
69 ret = getopt32(argv, "a"); 69 ret = getopt32(argv, "a");