Browse Source

*: 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
Denis Vlasenko 16 years ago
parent
commit
1d42665b6b

+ 4 - 8
console-tools/deallocvt.c

@@ -16,19 +16,15 @@
 enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
 enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
 
 
 int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int deallocvt_main(int argc, char **argv)
+int deallocvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	/* num = 0 deallocate all unused consoles */
 	/* num = 0 deallocate all unused consoles */
 	int num = 0;
 	int num = 0;
 
 
-	switch (argc) {
-	case 2:
+	if (argv[1]) {
+		if (argv[2])
+			bb_show_usage();
 		num = xatou_range(argv[1], 1, 63);
 		num = xatou_range(argv[1], 1, 63);
-		/* Fallthrough */
-	case 1:
-		break;
-	default:
-		bb_show_usage();
 	}
 	}
 
 
 	/* double cast suppresses "cast to ptr from int of different size" */
 	/* double cast suppresses "cast to ptr from int of different size" */

+ 4 - 3
console-tools/openvt.c

@@ -27,9 +27,10 @@ int openvt_main(int argc, char **argv)
 	/* grab new one */
 	/* grab new one */
 	close(0);
 	close(0);
 	xopen(vtname, O_RDWR);
 	xopen(vtname, O_RDWR);
-	dup2(0, STDOUT_FILENO);
-	dup2(0, STDERR_FILENO);
+	xdup2(0, STDOUT_FILENO);
+	xdup2(0, STDERR_FILENO);
 
 
-	BB_EXECVP(argv[2], &argv[2]);
+	argv += 2;
+	BB_EXECVP(argv[0], argv);
 	_exit(1);
 	_exit(1);
 }
 }

+ 2 - 2
console-tools/setkeycodes.c

@@ -14,7 +14,7 @@
 
 
 /* From <linux/kd.h> */
 /* From <linux/kd.h> */
 struct kbkeycode {
 struct kbkeycode {
-	unsigned int scancode, keycode;
+	unsigned scancode, keycode;
 };
 };
 enum {
 enum {
 	KDSETKEYCODE = 0x4B4D  /* write kernel keycode table entry */
 	KDSETKEYCODE = 0x4B4D  /* write kernel keycode table entry */
@@ -33,7 +33,7 @@ int setkeycodes_main(int argc, char **argv)
 	fd = get_console_fd();
 	fd = get_console_fd();
 
 
 	while (argc > 2) {
 	while (argc > 2) {
-		a.keycode = xatoul_range(argv[2], 0, 127);
+		a.keycode = xatou_range(argv[2], 0, 127);
 		a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
 		a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
 		if (a.scancode > 127) {
 		if (a.scancode > 127) {
 			a.scancode -= 0xe000;
 			a.scancode -= 0xe000;

+ 3 - 3
console-tools/setlogcons.c

@@ -12,7 +12,7 @@
 #include "libbb.h"
 #include "libbb.h"
 
 
 int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int setlogcons_main(int argc, char **argv)
+int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	struct {
 	struct {
 		char fn;
 		char fn;
@@ -22,8 +22,8 @@ int setlogcons_main(int argc, char **argv)
 	arg.fn = 11;    /* redirect kernel messages */
 	arg.fn = 11;    /* redirect kernel messages */
 	arg.subarg = 0; /* to specified console (current as default) */
 	arg.subarg = 0; /* to specified console (current as default) */
 
 
-	if (argc == 2)
-		arg.subarg = xatoul_range(argv[1], 0, 63);
+	if (argv[1])
+		arg.subarg = xatou_range(argv[1], 0, 63);
 
 
 	xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
 	xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
 
 

+ 4 - 9
coreutils/du.c

@@ -146,7 +146,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	unsigned long total;
 	unsigned long total;
 	int slink_depth_save;
 	int slink_depth_save;
 	bool print_final_total;
 	bool print_final_total;
-	char *smax_print_depth;
 	unsigned opt;
 	unsigned opt;
 
 
 #if ENABLE_FEATURE_HUMAN_READABLE
 #if ENABLE_FEATURE_HUMAN_READABLE
@@ -168,8 +167,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	 * ignore -a.  This is consistent with -s being equivalent to -d 0.
 	 * ignore -a.  This is consistent with -s being equivalent to -d 0.
 	 */
 	 */
 #if ENABLE_FEATURE_HUMAN_READABLE
 #if ENABLE_FEATURE_HUMAN_READABLE
-	opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
-	opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
+	opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+";
+	opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
 	argv += optind;
 	argv += optind;
 	if (opt & (1 << 9)) {
 	if (opt & (1 << 9)) {
 		/* -h opt */
 		/* -h opt */
@@ -184,8 +183,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		G.disp_hr = 1024;
 		G.disp_hr = 1024;
 	}
 	}
 #else
 #else
-	opt_complementary = "H-L:L-H:s-d:d-s";
-	opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+	opt_complementary = "H-L:L-H:s-d:d-s:d+";
+	opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
 	argv += optind;
 	argv += optind;
 #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
 #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
 	if (opt & (1 << 2)) {
 	if (opt & (1 << 2)) {
@@ -211,10 +210,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		G.max_print_depth = 0;
 		G.max_print_depth = 0;
 	}
 	}
 	G.one_file_system = opt & (1 << 5); /* -x opt */
 	G.one_file_system = opt & (1 << 5); /* -x opt */
-	if (opt & (1 << 6)) {
-		/* -d opt */
-		G.max_print_depth = xatoi_u(smax_print_depth);
-	}
 	if (opt & (1 << 7)) {
 	if (opt & (1 << 7)) {
 		/* -l opt */
 		/* -l opt */
 		G.count_hardlinks = MAXINT(nlink_t);
 		G.count_hardlinks = MAXINT(nlink_t);

+ 2 - 7
coreutils/ls.c

@@ -799,8 +799,6 @@ int ls_main(int argc, char **argv)
 	int ac;
 	int ac;
 	int i;
 	int i;
 	char **av;
 	char **av;
-	USE_FEATURE_AUTOWIDTH(char *tabstops_str = NULL;)
-	USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
 	USE_FEATURE_LS_COLOR(char *color_opt;)
 	USE_FEATURE_LS_COLOR(char *color_opt;)
 
 
 #if ENABLE_FEATURE_LS_TIMESTAMPS
 #if ENABLE_FEATURE_LS_TIMESTAMPS
@@ -820,12 +818,9 @@ int ls_main(int argc, char **argv)
 	/* process options */
 	/* process options */
 	USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
 	USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
 #if ENABLE_FEATURE_AUTOWIDTH
 #if ENABLE_FEATURE_AUTOWIDTH
-	opt = getopt32(argv, ls_options, &tabstops_str, &terminal_width_str
+	opt_complementary = "T+:w+"; /* -T N, -w N */
+	opt = getopt32(argv, ls_options, &tabstops, &terminal_width
 				USE_FEATURE_LS_COLOR(, &color_opt));
 				USE_FEATURE_LS_COLOR(, &color_opt));
-	if (tabstops_str)
-		tabstops = xatou(tabstops_str);
-	if (terminal_width_str)
-		terminal_width = xatou(terminal_width_str);
 #else
 #else
 	opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
 	opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
 #endif
 #endif

+ 3 - 7
coreutils/od_bloaty.c

@@ -188,7 +188,7 @@ static off_t pseudo_offset;
    a multiple of the least common multiple of the sizes associated with
    a multiple of the least common multiple of the sizes associated with
    the specified output types.  It should be as large as possible, but
    the specified output types.  It should be as large as possible, but
    no larger than 16 -- unless specified with the -w option.  */
    no larger than 16 -- unless specified with the -w option.  */
-static size_t bytes_per_block;
+static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */
 
 
 /* A NULL-terminated list of the file-arguments from the command line.  */
 /* A NULL-terminated list of the file-arguments from the command line.  */
 static const char *const *file_list;
 static const char *const *file_list;
@@ -1218,7 +1218,6 @@ int od_main(int argc, char **argv)
 		;
 		;
 #endif
 #endif
 	char *str_A, *str_N, *str_j, *str_S;
 	char *str_A, *str_N, *str_j, *str_S;
-	char *str_w = NULL;
 	llist_t *lst_t = NULL;
 	llist_t *lst_t = NULL;
 	unsigned opt;
 	unsigned opt;
 	int l_c_m;
 	int l_c_m;
@@ -1239,7 +1238,7 @@ int od_main(int argc, char **argv)
 	/* flag_dump_strings = 0; - already is */
 	/* flag_dump_strings = 0; - already is */
 
 
 	/* Parse command line */
 	/* Parse command line */
-	opt_complementary = "t::"; // list
+	opt_complementary = "w+:t::"; /* -w N, -t is a list */
 #if ENABLE_GETOPT_LONG
 #if ENABLE_GETOPT_LONG
 	applet_long_options = od_longopts;
 	applet_long_options = od_longopts;
 #endif
 #endif
@@ -1248,7 +1247,7 @@ int od_main(int argc, char **argv)
 		// -S was -s and also had optional parameter
 		// -S was -s and also had optional parameter
 		// but in coreutils 6.3 it was renamed and now has
 		// but in coreutils 6.3 it was renamed and now has
 		// _mandatory_ parameter
 		// _mandatory_ parameter
-		&str_A, &str_N, &str_j, &lst_t, &str_S, &str_w);
+		&str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block);
 	argc -= optind;
 	argc -= optind;
 	argv += optind;
 	argv += optind;
 	if (opt & OPT_A) {
 	if (opt & OPT_A) {
@@ -1404,9 +1403,6 @@ int od_main(int argc, char **argv)
 	l_c_m = get_lcm();
 	l_c_m = get_lcm();
 
 
 	if (opt & OPT_w) { /* -w: width */
 	if (opt & OPT_w) { /* -w: width */
-		bytes_per_block = 32;
-		if (str_w)
-			bytes_per_block = xatou(str_w);
 		if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
 		if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
 			bb_error_msg("warning: invalid width %u; using %d instead",
 			bb_error_msg("warning: invalid width %u; using %d instead",
 					(unsigned)bytes_per_block, l_c_m);
 					(unsigned)bytes_per_block, l_c_m);

+ 2 - 2
coreutils/printenv.c

@@ -11,10 +11,10 @@
 #include "libbb.h"
 #include "libbb.h"
 
 
 int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int printenv_main(int argc, char **argv)
+int printenv_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	/* no variables specified, show whole env */
 	/* no variables specified, show whole env */
-	if (argc == 1) {
+	if (!argv[1]) {
 		int e = 0;
 		int e = 0;
 		while (environ[e])
 		while (environ[e])
 			puts(environ[e++]);
 			puts(environ[e++]);

+ 3 - 4
coreutils/realpath.c

@@ -13,7 +13,7 @@
 #include "libbb.h"
 #include "libbb.h"
 
 
 int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int realpath_main(int argc, char **argv)
+int realpath_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	int retval = EXIT_SUCCESS;
 	int retval = EXIT_SUCCESS;
 
 
@@ -25,19 +25,18 @@ int realpath_main(int argc, char **argv)
 # define resolved_path_MUST_FREE 0
 # define resolved_path_MUST_FREE 0
 #endif
 #endif
 
 
-	if (--argc == 0) {
+	if (!*++argv) {
 		bb_show_usage();
 		bb_show_usage();
 	}
 	}
 
 
 	do {
 	do {
-		argv++;
 		if (realpath(*argv, resolved_path) != NULL) {
 		if (realpath(*argv, resolved_path) != NULL) {
 			puts(resolved_path);
 			puts(resolved_path);
 		} else {
 		} else {
 			retval = EXIT_FAILURE;
 			retval = EXIT_FAILURE;
 			bb_simple_perror_msg(*argv);
 			bb_simple_perror_msg(*argv);
 		}
 		}
-	} while (--argc);
+	} while (*++argv);
 
 
 #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
 #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
 	RELEASE_CONFIG_BUFFER(resolved_path);
 	RELEASE_CONFIG_BUFFER(resolved_path);

+ 6 - 11
coreutils/sleep.c

@@ -34,17 +34,16 @@ static const struct suffix_mult sfx[] = {
 #endif
 #endif
 
 
 int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int sleep_main(int argc, char **argv)
+int sleep_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	unsigned duration;
 	unsigned duration;
 
 
-#if ENABLE_FEATURE_FANCY_SLEEP
-
-	if (argc < 2) {
+	++argv;
+	if (!*argv)
 		bb_show_usage();
 		bb_show_usage();
-	}
 
 
-	++argv;
+#if ENABLE_FEATURE_FANCY_SLEEP
+
 	duration = 0;
 	duration = 0;
 	do {
 	do {
 		duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
 		duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
@@ -52,11 +51,7 @@ int sleep_main(int argc, char **argv)
 
 
 #else  /* FEATURE_FANCY_SLEEP */
 #else  /* FEATURE_FANCY_SLEEP */
 
 
-	if (argc != 2) {
-		bb_show_usage();
-	}
-
-	duration = xatou(argv[1]);
+	duration = xatou(*argv);
 
 
 #endif /* FEATURE_FANCY_SLEEP */
 #endif /* FEATURE_FANCY_SLEEP */
 
 

+ 5 - 7
coreutils/split.c

@@ -68,15 +68,13 @@ int split_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	ssize_t bytes_read, to_write;
 	ssize_t bytes_read, to_write;
 	char *src;
 	char *src;
 
 
-	opt_complementary = "?2";
-	opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &sfx);
+	opt_complementary = "?2:a+"; /* max 2 args; -a N */
+	opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
 
 
 	if (opt & SPLIT_OPT_l)
 	if (opt & SPLIT_OPT_l)
-		cnt = xatoul(count_p);
-	if (opt & SPLIT_OPT_b)
-		cnt = xatoul_sfx(count_p, split_suffices);
-	if (opt & SPLIT_OPT_a)
-		suffix_len = xatou(sfx);
+		cnt = XATOOFF(count_p);
+	if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF
+		cnt = xatoull_sfx(count_p, split_suffices);
 	sfx = "x";
 	sfx = "x";
 
 
 	argv += optind;
 	argv += optind;

+ 2 - 3
coreutils/tail.c

@@ -87,7 +87,6 @@ int tail_main(int argc, char **argv)
 	bool from_top;
 	bool from_top;
 	int header_threshhold = 1;
 	int header_threshhold = 1;
 	const char *str_c, *str_n;
 	const char *str_c, *str_n;
-	USE_FEATURE_FANCY_TAIL(const char *str_s;)
 
 
 	char *tailbuf;
 	char *tailbuf;
 	size_t tailbufsize;
 	size_t tailbufsize;
@@ -110,8 +109,9 @@ int tail_main(int argc, char **argv)
 	}
 	}
 #endif
 #endif
 
 
+	USE_FEATURE_FANCY_TAIL(opt_complementary = "s+";) /* -s N */
 	opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
 	opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
-			&str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s));
+			&str_c, &str_n USE_FEATURE_FANCY_TAIL(,&sleep_period));
 #define FOLLOW (opt & 0x1)
 #define FOLLOW (opt & 0x1)
 #define COUNT_BYTES (opt & 0x2)
 #define COUNT_BYTES (opt & 0x2)
 	//if (opt & 0x1) // -f
 	//if (opt & 0x1) // -f
@@ -119,7 +119,6 @@ int tail_main(int argc, char **argv)
 	if (opt & 0x4) count = eat_num(str_n); // -n
 	if (opt & 0x4) count = eat_num(str_n); // -n
 #if ENABLE_FEATURE_FANCY_TAIL
 #if ENABLE_FEATURE_FANCY_TAIL
 	if (opt & 0x8) header_threshhold = INT_MAX; // -q
 	if (opt & 0x8) header_threshhold = INT_MAX; // -q
-	if (opt & 0x10) sleep_period = xatou(str_s); // -s
 	if (opt & 0x20) header_threshhold = 0; // -v
 	if (opt & 0x20) header_threshhold = 0; // -v
 #endif
 #endif
 	argc -= optind;
 	argc -= optind;

+ 2 - 2
coreutils/usleep.c

@@ -14,9 +14,9 @@
 /* This is a NOFORK applet. Be very careful! */
 /* This is a NOFORK applet. Be very careful! */
 
 
 int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int usleep_main(int argc, char **argv)
+int usleep_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
-	if (argc != 2) {
+	if (!argv[1]) {
 		bb_show_usage();
 		bb_show_usage();
 	}
 	}
 
 

+ 3 - 6
editors/diff.c

@@ -1208,17 +1208,16 @@ int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
 int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	bool gotstdin = 0;
 	bool gotstdin = 0;
-	char *U_opt;
 	char *f1, *f2;
 	char *f1, *f2;
 	llist_t *L_arg = NULL;
 	llist_t *L_arg = NULL;
 
 
 	INIT_G();
 	INIT_G();
 
 
-	/* exactly 2 params; collect multiple -L <label> */
-	opt_complementary = "=2:L::";
+	/* exactly 2 params; collect multiple -L <label>; -U N */
+	opt_complementary = "=2:L::U+";
 	getopt32(argv, "abdiL:NqrsS:tTU:wu"
 	getopt32(argv, "abdiL:NqrsS:tTU:wu"
 			"p" /* ignored (for compatibility) */,
 			"p" /* ignored (for compatibility) */,
-			&L_arg, &start, &U_opt);
+			&L_arg, &start, &context);
 	/*argc -= optind;*/
 	/*argc -= optind;*/
 	argv += optind;
 	argv += optind;
 	while (L_arg) {
 	while (L_arg) {
@@ -1233,8 +1232,6 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		/* we leak L_arg here... */
 		/* we leak L_arg here... */
 		L_arg = L_arg->link;
 		L_arg = L_arg->link;
 	}
 	}
-	if (option_mask32 & FLAG_U)
-		context = xatoi_u(U_opt);
 
 
 	/*
 	/*
 	 * Do sanity checks, fill in stb1 and stb2 and call the appropriate
 	 * Do sanity checks, fill in stb1 and stb2 and call the appropriate

+ 2 - 2
editors/ed.c

@@ -89,7 +89,7 @@ static char *skip_blank(const char *cp)
 
 
 
 
 int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ed_main(int argc, char **argv)
+int ed_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	INIT_G();
 	INIT_G();
 
 
@@ -99,7 +99,7 @@ int ed_main(int argc, char **argv)
 	lines.next = &lines;
 	lines.next = &lines;
 	lines.prev = &lines;
 	lines.prev = &lines;
 
 
-	if (argc > 1) {
+	if (argv[1]) {
 		fileName = xstrdup(argv[1]);
 		fileName = xstrdup(argv[1]);
 		if (!readLines(fileName, 1)) {
 		if (!readLines(fileName, 1)) {
 			return EXIT_SUCCESS;
 			return EXIT_SUCCESS;

+ 21 - 27
findutils/grep.c

@@ -7,7 +7,7 @@
  *
  *
  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  */
  */
-/* BB_AUDIT SUSv3 defects - unsupported option -x.  */
+/* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */
 /* BB_AUDIT GNU defects - always acts as -a.  */
 /* BB_AUDIT GNU defects - always acts as -a.  */
 /* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */
 /* http://www.opengroup.org/onlinepubs/007904975/utilities/grep.html */
 /*
 /*
@@ -299,7 +299,7 @@ static int grep_file(FILE *file)
 				free(before_buf[curpos]);
 				free(before_buf[curpos]);
 				before_buf[curpos] = line;
 				before_buf[curpos] = line;
 				curpos = (curpos + 1) % lines_before;
 				curpos = (curpos + 1) % lines_before;
-				/* avoid free(line) - we took line */
+				/* avoid free(line) - we took the line */
 				line = NULL;
 				line = NULL;
 			}
 			}
 		}
 		}
@@ -371,7 +371,10 @@ static void load_regexes_from_file(llist_t *fopt)
 	}
 	}
 }
 }
 
 
-static int file_action_grep(const char *filename, struct stat *statbuf ATTRIBUTE_UNUSED, void* matched, int depth ATTRIBUTE_UNUSED)
+static int file_action_grep(const char *filename,
+			struct stat *statbuf ATTRIBUTE_UNUSED,
+			void* matched,
+			int depth ATTRIBUTE_UNUSED)
 {
 {
 	FILE *file = fopen(filename, "r");
 	FILE *file = fopen(filename, "r");
 	if (file == NULL) {
 	if (file == NULL) {
@@ -405,35 +408,28 @@ int grep_main(int argc, char **argv)
 {
 {
 	FILE *file;
 	FILE *file;
 	int matched;
 	int matched;
-	char *mopt;
 	llist_t *fopt = NULL;
 	llist_t *fopt = NULL;
 
 
 	/* do normal option parsing */
 	/* do normal option parsing */
 #if ENABLE_FEATURE_GREP_CONTEXT
 #if ENABLE_FEATURE_GREP_CONTEXT
-	char *slines_after;
-	char *slines_before;
-	char *Copt;
+	int Copt;
 
 
-	opt_complementary = "H-h:e::f::C-AB";
+	/* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
+	 * -m,-A,-B,-C have numeric param */
+	opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
 	getopt32(argv,
 	getopt32(argv,
 		OPTSTR_GREP,
 		OPTSTR_GREP,
-		&pattern_head, &fopt, &mopt,
-		&slines_after, &slines_before, &Copt);
+		&pattern_head, &fopt, &max_matches,
+		&lines_after, &lines_before, &Copt);
 
 
 	if (option_mask32 & OPT_C) {
 	if (option_mask32 & OPT_C) {
 		/* -C unsets prev -A and -B, but following -A or -B
 		/* -C unsets prev -A and -B, but following -A or -B
 		   may override it */
 		   may override it */
 		if (!(option_mask32 & OPT_A)) /* not overridden */
 		if (!(option_mask32 & OPT_A)) /* not overridden */
-			slines_after = Copt;
+			lines_after = Copt;
 		if (!(option_mask32 & OPT_B)) /* not overridden */
 		if (!(option_mask32 & OPT_B)) /* not overridden */
-			slines_before = Copt;
-		option_mask32 |= OPT_A|OPT_B; /* for parser */
-	}
-	if (option_mask32 & OPT_A) {
-		lines_after = xatoi_u(slines_after);
-	}
-	if (option_mask32 & OPT_B) {
-		lines_before = xatoi_u(slines_before);
+			lines_before = Copt;
+		//option_mask32 |= OPT_A|OPT_B; /* for parser */
 	}
 	}
 	/* sanity checks */
 	/* sanity checks */
 	if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) {
 	if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) {
@@ -444,13 +440,11 @@ int grep_main(int argc, char **argv)
 		before_buf = xzalloc(lines_before * sizeof(char *));
 		before_buf = xzalloc(lines_before * sizeof(char *));
 #else
 #else
 	/* with auto sanity checks */
 	/* with auto sanity checks */
-	opt_complementary = "H-h:e::f::c-n:q-n:l-n";
+	/* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
+	opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
 	getopt32(argv, OPTSTR_GREP,
 	getopt32(argv, OPTSTR_GREP,
-		&pattern_head, &fopt, &mopt);
+		&pattern_head, &fopt, &max_matches);
 #endif
 #endif
-	if (option_mask32 & OPT_m) {
-		max_matches = xatoi_u(mopt);
-	}
 	invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
 	invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
 
 
 	if (pattern_head != NULL) {
 	if (pattern_head != NULL) {
@@ -481,8 +475,8 @@ int grep_main(int argc, char **argv)
 	argv += optind;
 	argv += optind;
 	argc -= optind;
 	argc -= optind;
 
 
-	/* if we didn't get a pattern from a -e and no command file was specified,
-	 * argv[optind] should be the pattern. no pattern, no worky */
+	/* if we didn't get a pattern from -e and no command file was specified,
+	 * first parameter should be the pattern. no pattern, no worky */
 	if (pattern_head == NULL) {
 	if (pattern_head == NULL) {
 		char *pattern;
 		char *pattern;
 		if (*argv == NULL)
 		if (*argv == NULL)
@@ -508,7 +502,7 @@ int grep_main(int argc, char **argv)
 	do {
 	do {
 		cur_file = *argv++;
 		cur_file = *argv++;
 		file = stdin;
 		file = stdin;
-		if (!cur_file || (*cur_file == '-' && !cur_file[1])) {
+		if (!cur_file || LONE_DASH(cur_file)) {
 			cur_file = "(standard input)";
 			cur_file = "(standard input)";
 		} else {
 		} else {
 			if (option_mask32 & OPT_r) {
 			if (option_mask32 & OPT_r) {

+ 4 - 3
init/halt.c

@@ -33,7 +33,7 @@ RB_AUTOBOOT
 	};
 	};
 	static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
 	static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
 
 
-	char *delay;
+	int delay = 0;
 	int which, flags, rc = 1;
 	int which, flags, rc = 1;
 #if ENABLE_FEATURE_WTMP
 #if ENABLE_FEATURE_WTMP
 	struct utmp utmp;
 	struct utmp utmp;
@@ -46,9 +46,10 @@ RB_AUTOBOOT
 		continue;
 		continue;
 
 
 	/* Parse and handle arguments */
 	/* Parse and handle arguments */
+	opt_complementary = "d+"; /* -d N */
 	flags = getopt32(argv, "d:nfw", &delay);
 	flags = getopt32(argv, "d:nfw", &delay);
-	if (flags & 1)
-		sleep(xatou(delay));
+
+	sleep(delay);
 
 
 #if ENABLE_FEATURE_WTMP
 #if ENABLE_FEATURE_WTMP
 	if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
 	if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {

+ 4 - 4
init/init.c

@@ -818,14 +818,14 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
 }
 }
 
 
 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int init_main(int argc, char **argv)
+int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	struct init_action *a;
 	struct init_action *a;
 	pid_t wpid;
 	pid_t wpid;
 
 
 	die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
 	die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
 
 
-	if (argc > 1 && !strcmp(argv[1], "-q")) {
+	if (argv[1] && !strcmp(argv[1], "-q")) {
 		return kill(1, SIGHUP);
 		return kill(1, SIGHUP);
 	}
 	}
 
 
@@ -868,7 +868,7 @@ int init_main(int argc, char **argv)
 			putenv((char *) *e);
 			putenv((char *) *e);
 	}
 	}
 
 
-	if (argc > 1) setenv("RUNLEVEL", argv[1], 1);
+	if (argv[1]) setenv("RUNLEVEL", argv[1], 1);
 
 
 	/* Hello world */
 	/* Hello world */
 	message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
 	message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
@@ -890,7 +890,7 @@ int init_main(int argc, char **argv)
 	}
 	}
 
 
 	/* Check if we are supposed to be in single user mode */
 	/* Check if we are supposed to be in single user mode */
-	if (argc > 1
+	if (argv[1]
 	 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
 	 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
 	) {
 	) {
 		/* Start a shell on console */
 		/* Start a shell on console */

+ 8 - 11
ipsvd/tcpudp.c

@@ -163,7 +163,7 @@ static void sig_child_handler(int sig ATTRIBUTE_UNUSED)
 int tcpudpsvd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int tcpudpsvd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
 int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
-	char *str_c, *str_C, *str_b, *str_t;
+	char *str_C, *str_t;
 	char *user;
 	char *user;
 	struct hcc *hccp;
 	struct hcc *hccp;
 	const char *instructs;
 	const char *instructs;
@@ -189,21 +189,20 @@ int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
 
 
 	tcp = (applet_name[0] == 't');
 	tcp = (applet_name[0] == 't');
 
 
-	/* 3+ args, -i at most once, -p implies -h, -v is counter */
-	opt_complementary = "-3:i--i:ph:vv";
+	/* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
+	opt_complementary = "-3:i--i:ph:vv:b+:c+";
 #ifdef SSLSVD
 #ifdef SSLSVD
 	getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
 	getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
-		&str_c, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
-		&str_b, &str_t, &ssluser, &root, &cert, &key, &verbose
+		&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
+		&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
 	);
 	);
 #else
 #else
+	/* "+": stop on first non-option */
 	getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v",
 	getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v",
-		&str_c, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
-		&str_b, &str_t, &verbose
+		&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
+		&backlog, &str_t, &verbose
 	);
 	);
 #endif
 #endif
-	if (option_mask32 & OPT_c)
-		cmax = xatou_range(str_c, 1, INT_MAX);
 	if (option_mask32 & OPT_C) { /* -C n[:message] */
 	if (option_mask32 & OPT_C) { /* -C n[:message] */
 		max_per_host = bb_strtou(str_C, &str_C, 10);
 		max_per_host = bb_strtou(str_C, &str_C, 10);
 		if (str_C[0]) {
 		if (str_C[0]) {
@@ -219,8 +218,6 @@ int tcpudpsvd_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		if (!get_uidgid(&ugid, user, 1))
 		if (!get_uidgid(&ugid, user, 1))
 			bb_error_msg_and_die("unknown user/group: %s", user);
 			bb_error_msg_and_die("unknown user/group: %s", user);
 	}
 	}
-	if (option_mask32 & OPT_b)
-		backlog = xatou(str_b);
 #ifdef SSLSVD
 #ifdef SSLSVD
 	if (option_mask32 & OPT_U) ssluser = optarg;
 	if (option_mask32 & OPT_U) ssluser = optarg;
 	if (option_mask32 & OPT_slash) root = optarg;
 	if (option_mask32 & OPT_slash) root = optarg;

+ 9 - 6
libbb/getopt32.c

@@ -117,7 +117,7 @@ const char *opt_complementary
         if w is given once, GNU ps sets the width to 132,
         if w is given once, GNU ps sets the width to 132,
         if w is given more than once, it is "unlimited"
         if w is given more than once, it is "unlimited"
 
 
-        int w_counter = 0;
+        int w_counter = 0; // must be initialized!
         opt_complementary = "ww";
         opt_complementary = "ww";
         getopt32(argv, "w", &w_counter);
         getopt32(argv, "w", &w_counter);
         if (w_counter)
         if (w_counter)
@@ -220,7 +220,7 @@ Special characters:
  "x--x" Variation of the above, it means that -x option should occur
  "x--x" Variation of the above, it means that -x option should occur
         at most once.
         at most once.
 
 
- "a+:"  A plus after a char in opt_complementary means that the parameter
+ "a+"   A plus after a char in opt_complementary means that the parameter
         for this option is a nonnegative integer. It will be processed
         for this option is a nonnegative integer. It will be processed
         with xatoi_u() - allowed range is 0..INT_MAX.
         with xatoi_u() - allowed range is 0..INT_MAX.
 
 
@@ -255,7 +255,7 @@ Special characters:
         For example from "id" applet:
         For example from "id" applet:
 
 
         // Don't allow -n -r -rn -ug -rug -nug -rnug
         // Don't allow -n -r -rn -ug -rug -nug -rnug
-        opt_complementary = "r?ug:n?ug:?u--g:g--u";
+        opt_complementary = "r?ug:n?ug:u--g:g--u";
         flags = getopt32(argv, "rnug");
         flags = getopt32(argv, "rnug");
 
 
         This example allowed only:
         This example allowed only:
@@ -545,11 +545,14 @@ getopt32(char **argv, const char *applet_opts, ...)
 		if (on_off->counter)
 		if (on_off->counter)
 			(*(on_off->counter))++;
 			(*(on_off->counter))++;
 		if (on_off->param_type == PARAM_LIST) {
 		if (on_off->param_type == PARAM_LIST) {
-			llist_add_to_end((llist_t **)(on_off->optarg), optarg);
+			if (optarg)
+				llist_add_to_end((llist_t **)(on_off->optarg), optarg);
 		} else if (on_off->param_type == PARAM_INT) {
 		} else if (on_off->param_type == PARAM_INT) {
-			*(unsigned*)(on_off->optarg) = xatoi_u(optarg);
+			if (optarg)
+				*(unsigned*)(on_off->optarg) = xatoi_u(optarg);
 		} else if (on_off->optarg) {
 		} else if (on_off->optarg) {
-			*(char **)(on_off->optarg) = optarg;
+			if (optarg)
+				*(char **)(on_off->optarg) = optarg;
 		}
 		}
 		if (pargv != NULL)
 		if (pargv != NULL)
 			break;
 			break;

+ 4 - 4
loginutils/addgroup.c

@@ -123,7 +123,7 @@ static void add_user_to_group(char **args,
  * will add an existing user to an existing group.
  * will add an existing user to an existing group.
  */
  */
 int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int addgroup_main(int argc, char **argv)
+int addgroup_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	char *group;
 	char *group;
 	gid_t gid = 0;
 	gid_t gid = 0;
@@ -144,10 +144,10 @@ int addgroup_main(int argc, char **argv)
 	}
 	}
 	/* move past the commandline options */
 	/* move past the commandline options */
 	argv += optind;
 	argv += optind;
-	argc -= optind;
+	//argc -= optind;
 
 
 #if ENABLE_FEATURE_ADDUSER_TO_GROUP
 #if ENABLE_FEATURE_ADDUSER_TO_GROUP
-	if (argc == 2) {
+	if (argv[1]) {
 		struct group *gr;
 		struct group *gr;
 
 
 		if (option_mask32) {
 		if (option_mask32) {
@@ -170,7 +170,7 @@ int addgroup_main(int argc, char **argv)
 		add_user_to_group(argv, bb_path_group_file, xfopen);
 		add_user_to_group(argv, bb_path_group_file, xfopen);
 #if ENABLE_FEATURE_SHADOWPASSWDS
 #if ENABLE_FEATURE_SHADOWPASSWDS
 		add_user_to_group(argv, bb_path_gshadow_file, fopen_or_warn);
 		add_user_to_group(argv, bb_path_gshadow_file, fopen_or_warn);
-#endif /* ENABLE_FEATURE_SHADOWPASSWDS */
+#endif
 	} else
 	} else
 #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
 #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
 		new_group(argv[0], gid);
 		new_group(argv[0], gid);

+ 4 - 3
loginutils/login.c

@@ -221,7 +221,7 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED)
 }
 }
 
 
 int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int login_main(int argc, char **argv)
+int login_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	enum {
 	enum {
 		LOGIN_OPT_f = (1<<0),
 		LOGIN_OPT_f = (1<<0),
@@ -269,8 +269,9 @@ int login_main(int argc, char **argv)
 			bb_error_msg_and_die("-f is for root only");
 			bb_error_msg_and_die("-f is for root only");
 		safe_strncpy(username, opt_user, sizeof(username));
 		safe_strncpy(username, opt_user, sizeof(username));
 	}
 	}
-	if (optind < argc) /* user from command line (getty) */
-		safe_strncpy(username, argv[optind], sizeof(username));
+	argv += optind;
+	if (argv[0]) /* user from command line (getty) */
+		safe_strncpy(username, argv[0], sizeof(username));
 
 
 	/* Let's find out and memorize our tty */
 	/* Let's find out and memorize our tty */
 	if (!isatty(0) || !isatty(1) || !isatty(2))
 	if (!isatty(0) || !isatty(1) || !isatty(2))

+ 3 - 4
loginutils/sulogin.c

@@ -19,7 +19,6 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	char *cp;
 	char *cp;
 	int timeout = 0;
 	int timeout = 0;
-	char *timeout_arg;
 	struct passwd *pwd;
 	struct passwd *pwd;
 	const char *shell;
 	const char *shell;
 #if ENABLE_FEATURE_SHADOWPASSWDS
 #if ENABLE_FEATURE_SHADOWPASSWDS
@@ -31,9 +30,8 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	logmode = LOGMODE_BOTH;
 	logmode = LOGMODE_BOTH;
 	openlog(applet_name, 0, LOG_AUTH);
 	openlog(applet_name, 0, LOG_AUTH);
 
 
-	if (getopt32(argv, "t:", &timeout_arg)) {
-		timeout = xatoi_u(timeout_arg);
-	}
+	opt_complementary = "t+"; /* -t N */
+	getopt32(argv, "t:", &timeout);
 
 
 	if (argv[optind]) {
 	if (argv[optind]) {
 		close(0);
 		close(0);
@@ -43,6 +41,7 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		dup(0);
 		dup(0);
 	}
 	}
 
 
+	/* Malicious use like "sulogin /dev/sda"? */
 	if (!isatty(0) || !isatty(1) || !isatty(2)) {
 	if (!isatty(0) || !isatty(1) || !isatty(2)) {
 		logmode = LOGMODE_SYSLOG;
 		logmode = LOGMODE_SYSLOG;
 		bb_error_msg_and_die("not a tty");
 		bb_error_msg_and_die("not a tty");

+ 4 - 6
miscutils/mt.c

@@ -81,24 +81,22 @@ static const char opcode_name[] ALIGN1 =
 	"weof"            "\0";
 	"weof"            "\0";
 
 
 int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int mt_main(int argc, char **argv)
+int mt_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	const char *file = "/dev/tape";
 	const char *file = "/dev/tape";
 	struct mtop op;
 	struct mtop op;
 	struct mtpos position;
 	struct mtpos position;
 	int fd, mode, idx;
 	int fd, mode, idx;
 
 
-	if (argc < 2) {
+	if (!argv[1]) {
 		bb_show_usage();
 		bb_show_usage();
 	}
 	}
 
 
 	if (strcmp(argv[1], "-f") == 0) {
 	if (strcmp(argv[1], "-f") == 0) {
-		if (argc < 4) {
+		if (!argv[2] || !argv[3])
 			bb_show_usage();
 			bb_show_usage();
-		}
 		file = argv[2];
 		file = argv[2];
 		argv += 2;
 		argv += 2;
-		argc -= 2;
 	}
 	}
 
 
 	idx = index_in_strings(opcode_name, argv[1]);
 	idx = index_in_strings(opcode_name, argv[1]);
@@ -107,7 +105,7 @@ int mt_main(int argc, char **argv)
 		bb_error_msg_and_die("unrecognized opcode %s", argv[1]);
 		bb_error_msg_and_die("unrecognized opcode %s", argv[1]);
 
 
 	op.mt_op = opcode_value[idx];
 	op.mt_op = opcode_value[idx];
-	if (argc >= 3)
+	if (argv[2])
 		op.mt_count = xatoi_u(argv[2]);
 		op.mt_count = xatoi_u(argv[2]);
 	else
 	else
 		op.mt_count = 1;		/* One, not zero, right? */
 		op.mt_count = 1;		/* One, not zero, right? */

+ 3 - 5
networking/arping.c

@@ -264,16 +264,14 @@ int arping_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	err_str = xasprintf("interface %s %%s", device);
 	err_str = xasprintf("interface %s %%s", device);
 	{
 	{
 		unsigned opt;
 		unsigned opt;
-		char *str_count, *str_timeout;
+		char *str_timeout;
 
 
 		/* Dad also sets quit_on_reply.
 		/* Dad also sets quit_on_reply.
 		 * Advert also sets unsolicited.
 		 * Advert also sets unsolicited.
 		 */
 		 */
-		opt_complementary = "=1:Df:AU";
+		opt_complementary = "=1:Df:AU:c+";
 		opt = getopt32(argv, "DUAqfbc:w:I:s:",
 		opt = getopt32(argv, "DUAqfbc:w:I:s:",
-				&str_count, &str_timeout, &device, &source);
-		if (opt & 0x40) /* -c: count */
-			count = xatoi_u(str_count);
+				&count, &str_timeout, &device, &source);
 		if (opt & 0x80) /* -w: timeout */
 		if (opt & 0x80) /* -w: timeout */
 			timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
 			timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
 		//if (opt & 0x200) /* -s: source */
 		//if (opt & 0x200) /* -s: source */

+ 4 - 6
networking/nc_bloaty.c

@@ -674,7 +674,7 @@ Debug("wrote %d to net, errno %d", rr, errno);
 int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int nc_main(int argc, char **argv)
 int nc_main(int argc, char **argv)
 {
 {
-	char *str_p, *str_s, *str_w;
+	char *str_p, *str_s;
 	USE_NC_EXTRA(char *str_i, *str_o;)
 	USE_NC_EXTRA(char *str_i, *str_o;)
 	char *themdotted = themdotted; /* gcc */
 	char *themdotted = themdotted; /* gcc */
 	char **proggie;
 	char **proggie;
@@ -710,10 +710,10 @@ int nc_main(int argc, char **argv)
  e_found:
  e_found:
 
 
 	// -g -G -t -r deleted, unimplemented -a deleted too
 	// -g -G -t -r deleted, unimplemented -a deleted too
-	opt_complementary = "?2:vv"; /* max 2 params, -v is a counter */
+	opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */
 	getopt32(argv, "hnp:s:uvw:" USE_NC_SERVER("l")
 	getopt32(argv, "hnp:s:uvw:" USE_NC_SERVER("l")
 			USE_NC_EXTRA("i:o:z"),
 			USE_NC_EXTRA("i:o:z"),
-			&str_p, &str_s, &str_w
+			&str_p, &str_s, &o_wait
 			USE_NC_EXTRA(, &str_i, &str_o, &o_verbose));
 			USE_NC_EXTRA(, &str_i, &str_o, &o_verbose));
 	argv += optind;
 	argv += optind;
 #if ENABLE_NC_EXTRA
 #if ENABLE_NC_EXTRA
@@ -731,9 +731,7 @@ int nc_main(int argc, char **argv)
 	//if (option_mask32 & OPT_r) /* randomize various things */
 	//if (option_mask32 & OPT_r) /* randomize various things */
 	//if (option_mask32 & OPT_u) /* use UDP */
 	//if (option_mask32 & OPT_u) /* use UDP */
 	//if (option_mask32 & OPT_v) /* verbose */
 	//if (option_mask32 & OPT_v) /* verbose */
-	if (option_mask32 & OPT_w) { /* wait time */
-		o_wait = xatoi_u(str_w);
-	}
+	//if (option_mask32 & OPT_w) /* wait time */
 	//if (option_mask32 & OPT_z) /* little or no data xfer */
 	//if (option_mask32 & OPT_z) /* little or no data xfer */
 
 
 	/* We manage our fd's so that they are never 0,1,2 */
 	/* We manage our fd's so that they are never 0,1,2 */

+ 5 - 11
networking/tftp.c

@@ -397,9 +397,6 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	len_and_sockaddr *peer_lsa;
 	len_and_sockaddr *peer_lsa;
 	const char *localfile = NULL;
 	const char *localfile = NULL;
 	const char *remotefile = NULL;
 	const char *remotefile = NULL;
-#if ENABLE_FEATURE_TFTP_BLOCKSIZE
-	const char *sblocksize = NULL;
-#endif
 	int port;
 	int port;
 	USE_GETPUT(int cmd;)
 	USE_GETPUT(int cmd;)
 	int fd = -1;
 	int fd = -1;
@@ -409,13 +406,14 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
 
 
 	/* -p or -g is mandatory, and they are mutually exclusive */
 	/* -p or -g is mandatory, and they are mutually exclusive */
 	opt_complementary = "" USE_FEATURE_TFTP_GET("g:") USE_FEATURE_TFTP_PUT("p:")
 	opt_complementary = "" USE_FEATURE_TFTP_GET("g:") USE_FEATURE_TFTP_PUT("p:")
-			USE_GETPUT("?g--p:p--g");
+			USE_GETPUT("g--p:p--g:")
+			USE_FEATURE_TFTP_BLOCKSIZE("b+");
 
 
 	USE_GETPUT(cmd =) getopt32(argv,
 	USE_GETPUT(cmd =) getopt32(argv,
 			USE_FEATURE_TFTP_GET("g") USE_FEATURE_TFTP_PUT("p")
 			USE_FEATURE_TFTP_GET("g") USE_FEATURE_TFTP_PUT("p")
 				"l:r:" USE_FEATURE_TFTP_BLOCKSIZE("b:"),
 				"l:r:" USE_FEATURE_TFTP_BLOCKSIZE("b:"),
 			&localfile, &remotefile
 			&localfile, &remotefile
-			USE_FEATURE_TFTP_BLOCKSIZE(, &sblocksize));
+			USE_FEATURE_TFTP_BLOCKSIZE(, &blocksize));
 	argv += optind;
 	argv += optind;
 
 
 	flags = O_RDONLY;
 	flags = O_RDONLY;
@@ -423,12 +421,8 @@ int tftp_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		flags = O_WRONLY | O_CREAT | O_TRUNC;
 		flags = O_WRONLY | O_CREAT | O_TRUNC;
 
 
 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
-	if (sblocksize) {
-		blocksize = xatoi_u(sblocksize);
-		if (!tftp_blocksize_check(blocksize, 0)) {
-			return EXIT_FAILURE;
-		}
-	}
+	if (!tftp_blocksize_check(blocksize, 0))
+		return EXIT_FAILURE;
 #endif
 #endif
 
 
 	if (!localfile)
 	if (!localfile)

+ 8 - 9
networking/udhcp/dhcpc.c

@@ -132,7 +132,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
 int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	uint8_t *temp, *message;
 	uint8_t *temp, *message;
-	char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t;
+	char *str_c, *str_V, *str_h, *str_F, *str_r;
 	USE_FEATURE_UDHCP_PORT(char *str_P;)
 	USE_FEATURE_UDHCP_PORT(char *str_P;)
 	llist_t *list_O = NULL;
 	llist_t *list_O = NULL;
 #if ENABLE_FEATURE_UDHCPC_ARPING
 #if ENABLE_FEATURE_UDHCPC_ARPING
@@ -223,7 +223,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	client_config.script = DEFAULT_SCRIPT;
 	client_config.script = DEFAULT_SCRIPT;
 
 
 	/* Parse command line */
 	/* Parse command line */
-	opt_complementary = "c--C:C--c:O::"; // Cc: mutually exclusive; O: list
+	/* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */
+	opt_complementary = "c--C:C--c:O::T+:t+:A+";
 #if ENABLE_GETOPT_LONG
 #if ENABLE_GETOPT_LONG
 	applet_long_options = udhcpc_longopts;
 	applet_long_options = udhcpc_longopts;
 #endif
 #endif
@@ -233,7 +234,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		"O:"
 		"O:"
 		, &str_c, &str_V, &str_h, &str_h, &str_F
 		, &str_c, &str_V, &str_h, &str_h, &str_F
 		, &client_config.interface, &client_config.pidfile, &str_r
 		, &client_config.interface, &client_config.pidfile, &str_r
-		, &client_config.script, &str_T, &str_t, &str_A
+		, &client_config.script
+		, &discover_timeout, &discover_retries, &tryagain_timeout
 		USE_FEATURE_UDHCPC_ARPING(, &str_W)
 		USE_FEATURE_UDHCPC_ARPING(, &str_W)
 		USE_FEATURE_UDHCP_PORT(, &str_P)
 		USE_FEATURE_UDHCP_PORT(, &str_P)
 		, &list_O
 		, &list_O
@@ -273,12 +275,9 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	if (opt & OPT_r)
 	if (opt & OPT_r)
 		requested_ip = inet_addr(str_r);
 		requested_ip = inet_addr(str_r);
 	// if (opt & OPT_s) client_config.script = ...
 	// if (opt & OPT_s) client_config.script = ...
-	if (opt & OPT_T)
-		discover_timeout = xatoi_u(str_T);
-	if (opt & OPT_t)
-		discover_retries = xatoi_u(str_t);
-	if (opt & OPT_A)
-		tryagain_timeout = xatoi_u(str_A);
+	// if (opt & OPT_T) discover_timeout = xatoi_u(str_T);
+	// if (opt & OPT_t) discover_retries = xatoi_u(str_t);
+	// if (opt & OPT_A) tryagain_timeout = xatoi_u(str_A);
 	if (opt & OPT_v) {
 	if (opt & OPT_v) {
 		puts("version "BB_VER);
 		puts("version "BB_VER);
 		return 0;
 		return 0;

+ 3 - 4
runit/sv.c

@@ -422,7 +422,7 @@ int sv_main(int argc, char **argv)
 	char **servicex;
 	char **servicex;
 	unsigned waitsec = 7;
 	unsigned waitsec = 7;
 	smallint kll = 0;
 	smallint kll = 0;
-	smallint verbose = 0;
+	int verbose = 0;
 	int (*act)(const char*);
 	int (*act)(const char*);
 	int (*cbk)(const char*);
 	int (*cbk)(const char*);
 	int curdir;
 	int curdir;
@@ -436,9 +436,8 @@ int sv_main(int argc, char **argv)
 	x = getenv("SVWAIT");
 	x = getenv("SVWAIT");
 	if (x) waitsec = xatou(x);
 	if (x) waitsec = xatou(x);
 
 
-	opt = getopt32(argv, "w:v", &x);
-	if (opt & 1) waitsec = xatou(x); // -w
-	if (opt & 2) verbose = 1; // -v
+	opt_complementary = "w+:vv"; /* -w N, -v is a counter */
+	opt = getopt32(argv, "w:v", &waitsec, &verbose);
 	argc -= optind;
 	argc -= optind;
 	argv += optind;
 	argv += optind;
 	action = *argv++;
 	action = *argv++;

+ 2 - 4
util-linux/fdformat.c

@@ -41,7 +41,7 @@ struct format_descr {
 #define FD_FILL_BYTE 0xF6 /* format fill byte. */
 #define FD_FILL_BYTE 0xF6 /* format fill byte. */
 
 
 int fdformat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int fdformat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int fdformat_main(int argc, char **argv)
+int fdformat_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	int fd, n, cyl, read_bytes, verify;
 	int fd, n, cyl, read_bytes, verify;
 	unsigned char *data;
 	unsigned char *data;
@@ -49,9 +49,7 @@ int fdformat_main(int argc, char **argv)
 	struct floppy_struct param;
 	struct floppy_struct param;
 	struct format_descr descr;
 	struct format_descr descr;
 
 
-	if (argc < 2) {
-		bb_show_usage();
-	}
+	opt_complementary = "=1"; /* must have 1 param */
 	verify = !getopt32(argv, "n");
 	verify = !getopt32(argv, "n");
 	argv += optind;
 	argv += optind;
 
 

+ 3 - 3
util-linux/mkfs_minix.c

@@ -627,7 +627,7 @@ int mkfs_minix_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	unsigned opt;
 	unsigned opt;
 	char *tmp;
 	char *tmp;
 	struct stat statbuf;
 	struct stat statbuf;
-	char *str_i, *str_n;
+	char *str_i;
 	char *listfile = NULL;
 	char *listfile = NULL;
 
 
 	INIT_G();
 	INIT_G();
@@ -643,13 +643,13 @@ int mkfs_minix_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		bb_error_msg_and_die("bad inode size");
 		bb_error_msg_and_die("bad inode size");
 #endif
 #endif
 
 
-	opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &str_n);
+	opt_complementary = "n+"; /* -n N */
+	opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &G.namelen);
 	argv += optind;
 	argv += optind;
 	//if (opt & 1) -c
 	//if (opt & 1) -c
 	if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i
 	if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i
 	//if (opt & 4) -l
 	//if (opt & 4) -l
 	if (opt & 8) { // -n
 	if (opt & 8) { // -n
-		G.namelen = xatoi_u(str_n);
 		if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC;
 		if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC;
 		else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2;
 		else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2;
 		else bb_show_usage();
 		else bb_show_usage();

+ 33 - 20
util-linux/readprofile.c

@@ -8,7 +8,7 @@
  */
  */
 
 
 /*
 /*
- * 1999-02-22 Arkadiusz Mikiewicz <misiek@pld.ORG.PL>
+ * 1999-02-22 Arkadiusz Mickiewicz <misiek@pld.ORG.PL>
  * - added Native Language Support
  * - added Native Language Support
  * 1999-09-01 Stephane Eranian <eranian@cello.hpl.hp.com>
  * 1999-09-01 Stephane Eranian <eranian@cello.hpl.hp.com>
  * - 64bit clean patch
  * - 64bit clean patch
@@ -45,7 +45,7 @@ int readprofile_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
 int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	FILE *map;
 	FILE *map;
-	const char *mapFile, *proFile, *mult = 0;
+	const char *mapFile, *proFile;
 	unsigned long indx = 1;
 	unsigned long indx = 1;
 	size_t len;
 	size_t len;
 	uint64_t add0 = 0;
 	uint64_t add0 = 0;
@@ -55,37 +55,49 @@ int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
 	char fn_name[S_LEN], next_name[S_LEN];   /* current and next name */
 	char fn_name[S_LEN], next_name[S_LEN];   /* current and next name */
 	char mapline[S_LEN];
 	char mapline[S_LEN];
 	char mode[8];
 	char mode[8];
-	int optAll = 0, optInfo = 0, optReset = 0;
-	int optVerbose = 0, optNative = 0;
-	int optBins = 0, optSub = 0;
 	int maplineno = 1;
 	int maplineno = 1;
 	int header_printed;
 	int header_printed;
+	int multiplier = 0;
+	unsigned opt;
+	enum {
+		OPT_M = (1 << 0),
+		OPT_m = (1 << 1),
+		OPT_p = (1 << 2),
+		OPT_n = (1 << 3),
+		OPT_a = (1 << 4),
+		OPT_b = (1 << 5),
+		OPT_s = (1 << 6),
+		OPT_i = (1 << 7),
+		OPT_r = (1 << 8),
+		OPT_v = (1 << 9),
+	};
+#define optMult    (opt & OPT_M)
+#define optNative  (opt & OPT_n)
+#define optAll     (opt & OPT_a)
+#define optBins    (opt & OPT_b)
+#define optSub     (opt & OPT_s)
+#define optInfo    (opt & OPT_i)
+#define optReset   (opt & OPT_r)
+#define optVerbose (opt & OPT_v)
 
 
 #define next (current^1)
 #define next (current^1)
 
 
 	proFile = defaultpro;
 	proFile = defaultpro;
 	mapFile = defaultmap;
 	mapFile = defaultmap;
 
 
-	opt_complementary = "nn:aa:bb:ss:ii:rr:vv";
-	getopt32(argv, "M:m:p:nabsirv",
-			&mult, &mapFile, &proFile,
-			&optNative, &optAll, &optBins, &optSub,
-			&optInfo, &optReset, &optVerbose);
+	opt_complementary = "M+"; /* -M N */
+	opt = getopt32(argv, "M:m:p:nabsirv", &multiplier, &mapFile, &proFile);
 
 
-	if (optReset || mult) {
-		int multiplier, fd, to_write;
+	if (opt & (OPT_M|OPT_r)) { /* mult or reset, or both */
+		int fd, to_write;
 
 
 		/*
 		/*
 		 * When writing the multiplier, if the length of the write is
 		 * When writing the multiplier, if the length of the write is
 		 * not sizeof(int), the multiplier is not changed
 		 * not sizeof(int), the multiplier is not changed
 		 */
 		 */
-		if (mult) {
-			multiplier = xatoi_u(mult);
-			to_write = sizeof(int);
-		} else {
-			multiplier = 0;
+		to_write = sizeof(int);
+		if (!optMult)
 			to_write = 1;	/* sth different from sizeof(int) */
 			to_write = 1;	/* sth different from sizeof(int) */
-		}
 
 
 		fd = xopen(defaultpro, O_WRONLY);
 		fd = xopen(defaultpro, O_WRONLY);
 		xwrite(fd, &multiplier, to_write);
 		xwrite(fd, &multiplier, to_write);
@@ -187,8 +199,9 @@ int readprofile_main(int argc ATTRIBUTE_UNUSED, char **argv)
 		if (optBins) {
 		if (optBins) {
 			if (optVerbose || this > 0)
 			if (optVerbose || this > 0)
 				printf("  total\t\t\t\t%u\n", this);
 				printf("  total\t\t\t\t%u\n", this);
-		} else if ((this || optAll) &&
-			   (fn_len = next_add-fn_add) != 0) {
+		} else if ((this || optAll)
+		        && (fn_len = next_add-fn_add) != 0
+		) {
 			if (optVerbose)
 			if (optVerbose)
 				printf("%016llx %-40s %6i %8.4f\n", fn_add,
 				printf("%016llx %-40s %6i %8.4f\n", fn_add,
 				       fn_name, this, this/(double)fn_len);
 				       fn_name, this, this/(double)fn_len);

+ 1 - 1
util-linux/setarch.c

@@ -12,7 +12,7 @@
 #include "libbb.h"
 #include "libbb.h"
 
 
 int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv)
+int setarch_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	int pers = -1;
 	int pers = -1;
 
 

+ 2 - 2
util-linux/swaponoff.c

@@ -59,11 +59,11 @@ static int do_em_all(void)
 }
 }
 
 
 int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int swap_on_off_main(int argc, char **argv)
+int swap_on_off_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 {
 	int ret;
 	int ret;
 
 
-	if (argc == 1)
+	if (!argv[1])
 		bb_show_usage();
 		bb_show_usage();
 
 
 	ret = getopt32(argv, "a");
 	ret = getopt32(argv, "a");