don't pass argc in getopt32, it's superfluous

(add/remove: 0/0 grow/shrink: 12/131 up/down: 91/-727) Total: -636 bytes
   text    data     bss     dec     hex filename
 773469    1058   11092  785619   bfcd3 busybox_old
 772644    1058   11092  784794   bf99a busybox_unstripped
This commit is contained in:
Denis Vlasenko 2007-08-18 15:32:12 +00:00
parent d6cd9d7fe9
commit fe7cd642b0
143 changed files with 174 additions and 169 deletions

View File

@ -52,7 +52,7 @@ int ar_main(int argc, char **argv)
/* Prepend '-' to the first argument if required */ /* Prepend '-' to the first argument if required */
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt"; opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
opt = getopt32(argc, argv, "ptxovcr"); opt = getopt32(argv, "ptxovcr");
if (opt & AR_CTX_PRINT) { if (opt & AR_CTX_PRINT) {
archive_handle->action_data = data_extract_to_stdout; archive_handle->action_data = data_extract_to_stdout;

View File

@ -161,7 +161,7 @@ USE_DESKTOP(long long) int unpack_bunzip2(void)
int bunzip2_main(int argc, char **argv); int bunzip2_main(int argc, char **argv);
int bunzip2_main(int argc, char **argv) int bunzip2_main(int argc, char **argv)
{ {
getopt32(argc, argv, "cf"); getopt32(argv, "cf");
argv += optind; argv += optind;
if (applet_name[2] == 'c') if (applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT; option_mask32 |= OPT_STDOUT;
@ -260,7 +260,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
int gunzip_main(int argc, char **argv); int gunzip_main(int argc, char **argv);
int gunzip_main(int argc, char **argv) int gunzip_main(int argc, char **argv)
{ {
getopt32(argc, argv, "cfvdt"); getopt32(argv, "cfvdt");
argv += optind; argv += optind;
/* if called as zcat */ /* if called as zcat */
if (applet_name[1] == 'c') if (applet_name[1] == 'c')
@ -298,7 +298,7 @@ USE_DESKTOP(long long) int unpack_unlzma(void)
int unlzma_main(int argc, char **argv); int unlzma_main(int argc, char **argv);
int unlzma_main(int argc, char **argv) int unlzma_main(int argc, char **argv)
{ {
getopt32(argc, argv, "c"); getopt32(argv, "c");
argv += optind; argv += optind;
/* lzmacat? */ /* lzmacat? */
if (applet_name[4] == 'c') if (applet_name[4] == 'c')
@ -340,7 +340,7 @@ USE_DESKTOP(long long) int unpack_uncompress(void)
int uncompress_main(int argc, char **argv); int uncompress_main(int argc, char **argv);
int uncompress_main(int argc, char **argv) int uncompress_main(int argc, char **argv)
{ {
getopt32(argc, argv, "cf"); getopt32(argv, "cf");
argv += optind; argv += optind;
return bbunpack(argv, make_new_name_uncompress, unpack_uncompress); return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);

View File

@ -35,7 +35,7 @@ int cpio_main(int argc, char **argv)
archive_handle->seek = seek_by_read; archive_handle->seek = seek_by_read;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename); opt = getopt32(argv, "ituvF:dm", &cpio_filename);
/* One of either extract or test options must be given */ /* One of either extract or test options must be given */
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) { if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {

View File

@ -1579,7 +1579,7 @@ int dpkg_main(int argc, char **argv)
OPT_unpack = 0x40, OPT_unpack = 0x40,
}; };
opt = getopt32(argc, argv, "CF:ilPru", &str_f); opt = getopt32(argv, "CF:ilPru", &str_f);
//if (opt & OPT_configure) ... // -C //if (opt & OPT_configure) ... // -C
if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg) if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
if (strcmp(str_f, "depends")) if (strcmp(str_f, "depends"))

View File

@ -42,7 +42,7 @@ int dpkg_deb_main(int argc, char **argv)
#endif #endif
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argc, argv, "cefXx"); opt = getopt32(argv, "cefXx");
if (opt & DPKG_DEB_OPT_CONTENTS) { if (opt & DPKG_DEB_OPT_CONTENTS) {
tar_archive->action_header = header_verbose_list; tar_archive->action_header = header_verbose_list;

View File

@ -2031,7 +2031,7 @@ int gzip_main(int argc, char **argv)
unsigned opt; unsigned opt;
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argc, argv, "cfv" USE_GUNZIP("d") "q123456789" ); opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" );
option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */ option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */
//if (opt & 0x1) // -c //if (opt & 0x1) // -c
//if (opt & 0x2) // -f //if (opt & 0x2) // -f

View File

@ -788,7 +788,7 @@ int tar_main(int argc, char **argv)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS #if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_longopts; applet_long_options = tar_longopts;
#endif #endif
opt = getopt32(argc, argv, opt = getopt32(argv,
"txC:f:Opvk" "txC:f:Opvk"
USE_FEATURE_TAR_CREATE( "ch" ) USE_FEATURE_TAR_CREATE( "ch" )
USE_FEATURE_TAR_BZIP2( "j" ) USE_FEATURE_TAR_BZIP2( "j" )

View File

@ -27,7 +27,7 @@ int setconsole_main(int argc, char **argv)
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
applet_long_options = setconsole_longopts; applet_long_options = setconsole_longopts;
#endif #endif
flags = getopt32(argc, argv, "r"); flags = getopt32(argv, "r");
if (argc - optind > 1) if (argc - optind > 1)
bb_show_usage(); bb_show_usage();

View File

@ -86,7 +86,7 @@ int cal_main(int argc, char **argv)
char day_headings[28]; /* 28 for julian, 21 for nonjulian */ char day_headings[28]; /* 28 for julian, 21 for nonjulian */
char buf[40]; char buf[40];
flags = getopt32(argc, argv, "jy"); flags = getopt32(argv, "jy");
julian = flags & 1; julian = flags & 1;
month = 0; month = 0;
argv += optind; argv += optind;

View File

@ -46,7 +46,7 @@ int bb_cat(char **argv)
int cat_main(int argc, char **argv); int cat_main(int argc, char **argv);
int cat_main(int argc, char **argv) int cat_main(int argc, char **argv)
{ {
getopt32(argc, argv, "u"); getopt32(argv, "u");
argv += optind; argv += optind;
return bb_cat(argv); return bb_cat(argv);
} }

View File

@ -19,7 +19,7 @@ int catv_main(int argc, char **argv)
int fd; int fd;
unsigned flags; unsigned flags;
flags = getopt32(argc, argv, "etv"); flags = getopt32(argv, "etv");
#define CATV_OPT_e (1<<0) #define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1) #define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2) #define CATV_OPT_v (1<<2)

View File

@ -93,7 +93,7 @@ int chmod_main(int argc, char **argv)
/* Parse options */ /* Parse options */
opt_complementary = "-2"; opt_complementary = "-2";
getopt32(argc, argv, ("-"OPT_STR) + 1); /* Reuse string */ getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
argv += optind; argv += optind;
/* Restore option-like mode if needed */ /* Restore option-like mode if needed */

View File

@ -69,7 +69,7 @@ int chown_main(int argc, char **argv)
chown_fptr chown_func; chown_fptr chown_func;
opt_complementary = "-2"; opt_complementary = "-2";
getopt32(argc, argv, OPT_STR); getopt32(argv, OPT_STR);
argv += optind; argv += optind;
/* This matches coreutils behavior (almost - see below) */ /* This matches coreutils behavior (almost - see below) */

View File

@ -47,7 +47,7 @@ int comm_main(int argc, char **argv)
unsigned flags; unsigned flags;
opt_complementary = "=2"; opt_complementary = "=2";
flags = getopt32(argc, argv, "123"); flags = getopt32(argv, "123");
argv += optind; argv += optind;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {

View File

@ -45,7 +45,7 @@ int cp_main(int argc, char **argv)
// -r and -R are the same // -r and -R are the same
// -a = -pdR // -a = -pdR
opt_complementary = "l--s:s--l:Pd:rR:apdR"; opt_complementary = "l--s:s--l:Pd:rR:apdR";
flags = getopt32(argc, argv, FILEUTILS_CP_OPTSTR "arPHL"); flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL");
/* Default behavior of cp is to dereference, so we don't have to do /* Default behavior of cp is to dereference, so we don't have to do
* anything special when we are given -L. * anything special when we are given -L.
* The behavior of -H is *almost* like -L, but not quite, so let's * The behavior of -H is *almost* like -L, but not quite, so let's

View File

@ -171,7 +171,7 @@ int cut_main(int argc, char **argv)
char *sopt, *ltok; char *sopt, *ltok;
opt_complementary = "b--bcf:c--bcf:f--bcf"; opt_complementary = "b--bcf:c--bcf:f--bcf";
getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, &ltok); getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok);
// argc -= optind; // argc -= optind;
argv += optind; argv += optind;
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))

View File

@ -53,7 +53,7 @@ int date_main(int argc, char **argv)
opt_complementary = "d--s:s--d" opt_complementary = "d--s:s--d"
USE_FEATURE_DATE_ISOFMT(":R--I:I--R"); USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
opt = getopt32(argc, argv, "Rs:ud:r:" opt = getopt32(argv, "Rs:ud:r:"
USE_FEATURE_DATE_ISOFMT("I::D:"), USE_FEATURE_DATE_ISOFMT("I::D:"),
&date_str, &date_str, &filename &date_str, &date_str, &filename
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg)); USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));

View File

@ -47,7 +47,7 @@ int df_main(int argc, char **argv)
#if ENABLE_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk"; opt_complementary = "h-km:k-hm:m-hk";
opt = getopt32(argc, argv, "hmk"); opt = getopt32(argv, "hmk");
if (opt & 1) { if (opt & 1) {
df_disp_hr = 0; df_disp_hr = 0;
disp_units_hdr = " Size"; disp_units_hdr = " Size";
@ -57,7 +57,7 @@ int df_main(int argc, char **argv)
disp_units_hdr = "1M-blocks"; disp_units_hdr = "1M-blocks";
} }
#else #else
opt = getopt32(argc, argv, "k"); opt = getopt32(argv, "k");
#endif #endif
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n", printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",

View File

@ -92,7 +92,7 @@ int dos2unix_main(int argc, char **argv)
/* -u convert to unix, -d convert to dos */ /* -u convert to unix, -d convert to dos */
opt_complementary = "u--d:d--u"; /* mutually exclusive */ opt_complementary = "u--d:d--u"; /* mutually exclusive */
o = getopt32(argc, argv, "du"); o = getopt32(argv, "du");
/* Do the conversion requested by an argument else do the default /* Do the conversion requested by an argument else do the default
* conversion depending on our name. */ * conversion depending on our name. */

View File

@ -170,7 +170,7 @@ int du_main(int argc, char **argv)
*/ */
#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_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
if (opt & (1 << 9)) { if (opt & (1 << 9)) {
/* -h opt */ /* -h opt */
disp_hr = 0; disp_hr = 0;
@ -185,7 +185,7 @@ int du_main(int argc, char **argv)
} }
#else #else
opt_complementary = "H-L:L-H:s-d:d-s"; opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & (1 << 2)) { if (opt & (1 << 2)) {
/* -k opt */ /* -k opt */

View File

@ -54,7 +54,7 @@ int env_main(int argc, char** argv)
#if ENABLE_FEATURE_ENV_LONG_OPTIONS #if ENABLE_FEATURE_ENV_LONG_OPTIONS
applet_long_options = env_longopts; applet_long_options = env_longopts;
#endif #endif
opt = getopt32(argc, argv, "+iu:", &unset_env); opt = getopt32(argv, "+iu:", &unset_env);
argv += optind; argv += optind;
if (*argv && LONE_DASH(argv[0])) { if (*argv && LONE_DASH(argv[0])) {
opt |= 1; opt |= 1;

View File

@ -153,12 +153,12 @@ int expand_main(int argc, char **argv)
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) { if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts); USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
opt = getopt32(argc, argv, "it:", &opt_t); opt = getopt32(argv, "it:", &opt_t);
} else if (ENABLE_UNEXPAND) { } else if (ENABLE_UNEXPAND) {
USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts); USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
/* -t NUM sets also -a */ /* -t NUM sets also -a */
opt_complementary = "ta"; opt_complementary = "ta";
opt = getopt32(argc, argv, "ft:a", &opt_t); opt = getopt32(argv, "ft:a", &opt_t);
/* -f --first-only is the default */ /* -f --first-only is the default */
if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; if (!(opt & OPT_ALL)) opt |= OPT_INITIAL;
} }

View File

@ -63,7 +63,7 @@ int fold_main(int argc, char **argv)
} }
} }
flags = getopt32(argc, argv, "bsw:", &w_opt); flags = getopt32(argv, "bsw:", &w_opt);
if (flags & FLAG_WIDTH) if (flags & FLAG_WIDTH)
width = xatoul_range(w_opt, 1, 10000); width = xatoul_range(w_opt, 1, 10000);

View File

@ -50,7 +50,7 @@ int id_main(int argc, char **argv)
/* Don't allow -n -r -nr -ug -rug -nug -rnug */ /* Don't allow -n -r -nr -ug -rug -nug -rnug */
/* Don't allow more than one username */ /* Don't allow more than one username */
opt_complementary = "?1:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g"); opt_complementary = "?1:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z")); flags = getopt32(argv, "rnug" USE_SELINUX("Z"));
/* This values could be overwritten later */ /* This values could be overwritten later */
uid = geteuid(); uid = geteuid();

View File

@ -101,7 +101,7 @@ int install_main(int argc, char **argv)
opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z"); opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
/* -c exists for backwards compatibility, it's needed */ /* -c exists for backwards compatibility, it's needed */
flags = getopt32(argc, argv, "cdpsg:m:o:" USE_SELINUX("Z:"), flags = getopt32(argv, "cdpsg:m:o:" USE_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext)); &gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
#if ENABLE_SELINUX #if ENABLE_SELINUX

View File

@ -31,7 +31,7 @@ mode_t getopt_mk_fifo_nod(int argc, char **argv)
security_context_t scontext; security_context_t scontext;
#endif #endif
int opt; int opt;
opt = getopt32(argc, argv, "m:" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext)); opt = getopt32(argv, "m:" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) { if (opt & 1) {
if (bb_parse_mode(smode, &mode)) if (bb_parse_mode(smode, &mode))
umask(0); umask(0);

View File

@ -34,7 +34,7 @@ int ln_main(int argc, char **argv)
struct stat statbuf; struct stat statbuf;
int (*link_func)(const char *, const char *); int (*link_func)(const char *, const char *);
flag = getopt32(argc, argv, "sfnbS:", &suffix); flag = getopt32(argv, "sfnbS:", &suffix);
if (argc == optind) { if (argc == optind) {
bb_show_usage(); bb_show_usage();

View File

@ -820,14 +820,14 @@ 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(argc, argv, ls_options, &tabstops_str, &terminal_width_str opt = getopt32(argv, ls_options, &tabstops_str, &terminal_width_str
USE_FEATURE_LS_COLOR(, &color_opt)); USE_FEATURE_LS_COLOR(, &color_opt));
if (tabstops_str) if (tabstops_str)
tabstops = xatou(tabstops_str); tabstops = xatou(tabstops_str);
if (terminal_width_str) if (terminal_width_str)
terminal_width = xatou(terminal_width_str); terminal_width = xatou(terminal_width_str);
#else #else
opt = getopt32(argc, argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt)); opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
#endif #endif
for (i = 0; opt_flags[i] != (1U<<31); i++) { for (i = 0; opt_flags[i] != (1U<<31); i++) {
if (opt & (1 << i)) { if (opt & (1 << i)) {

View File

@ -88,7 +88,7 @@ int md5_sha1_sum_main(int argc, char **argv)
: HASH_SHA1; : HASH_SHA1;
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
flags = getopt32(argc, argv, "scw"); flags = getopt32(argv, "scw");
else optind = 1; else optind = 1;
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) { if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) {

View File

@ -49,7 +49,7 @@ int mkdir_main(int argc, char **argv)
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts; applet_long_options = mkdir_longopts;
#endif #endif
opt = getopt32(argc, argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext)); opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) { if (opt & 1) {
mode = 0777; mode = 0777;
if (!bb_parse_mode(smode, &mode)) { if (!bb_parse_mode(smode, &mode)) {

View File

@ -48,7 +48,7 @@ int mv_main(int argc, char **argv)
applet_long_options = mv_longopts; applet_long_options = mv_longopts;
#endif #endif
opt_complementary = "f-i:i-f"; opt_complementary = "f-i:i-f";
flags = getopt32(argc, argv, "fi"); flags = getopt32(argv, "fi");
if (optind + 2 > argc) { if (optind + 2 > argc) {
bb_show_usage(); bb_show_usage();
} }

View File

@ -1259,7 +1259,7 @@ int od_main(int argc, char **argv)
#if ENABLE_GETOPT_LONG #if ENABLE_GETOPT_LONG
applet_long_options = od_longopts; applet_long_options = od_longopts;
#endif #endif
opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:" opt = getopt32(argv, "A:N:abcdfhij:lot:vxsS:"
"w::", // -w with optional param "w::", // -w with optional param
// -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

View File

@ -21,7 +21,7 @@ int readlink_main(int argc, char **argv)
unsigned opt; unsigned opt;
/* We need exactly one non-option argument. */ /* We need exactly one non-option argument. */
opt_complementary = "=1"; opt_complementary = "=1";
opt = getopt32(argc, argv, "f"); opt = getopt32(argv, "f");
fname = argv[optind]; fname = argv[optind];
) )
SKIP_FEATURE_READLINK_FOLLOW( SKIP_FEATURE_READLINK_FOLLOW(

View File

@ -27,7 +27,7 @@ int rm_main(int argc, char **argv)
unsigned opt; unsigned opt;
opt_complementary = "f-i:i-f"; opt_complementary = "f-i:i-f";
opt = getopt32(argc, argv, "fiRr"); opt = getopt32(argv, "fiRr");
argv += optind; argv += optind;
if (opt & 1) if (opt & 1)
flags |= FILEUTILS_FORCE; flags |= FILEUTILS_FORCE;

View File

@ -24,7 +24,7 @@ int rmdir_main(int argc, char **argv)
int do_dot; int do_dot;
char *path; char *path;
flags = getopt32(argc, argv, "p"); flags = getopt32(argv, "p");
argv += optind; argv += optind;
if (!*argv) { if (!*argv) {

View File

@ -290,7 +290,7 @@ int sort_main(int argc, char **argv)
/* -o and -t can be given at most once */ /* -o and -t can be given at most once */
opt_complementary = "o--o:t--t:" /* -t, -o: maximum one of each */ opt_complementary = "o--o:t--t:" /* -t, -o: maximum one of each */
"k::"; /* -k takes list */ "k::"; /* -k takes list */
getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
#if ENABLE_FEATURE_SORT_BIG #if ENABLE_FEATURE_SORT_BIG
if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w"); if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w");
if (option_mask32 & FLAG_t) { if (option_mask32 & FLAG_t) {

View File

@ -69,7 +69,7 @@ int split_main(int argc, char **argv)
char *src; char *src;
opt_complementary = "?2"; opt_complementary = "?2";
opt = getopt32(argc, argv, "l:b:a:", &count_p, &count_p, &sfx); opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &sfx);
if (opt & SPLIT_OPT_l) if (opt & SPLIT_OPT_l)
cnt = xatoul(count_p); cnt = xatoul(count_p);

View File

@ -614,7 +614,7 @@ int stat_main(int argc, char **argv)
int ok = 1; int ok = 1;
bool (*statfunc)(char const *, char const *) = do_stat; bool (*statfunc)(char const *, char const *) = do_stat;
getopt32(argc, argv, "ftL" getopt32(argv, "ftL"
USE_SELINUX("Z") USE_SELINUX("Z")
USE_FEATURE_STAT_FORMAT("c:", &format) USE_FEATURE_STAT_FORMAT("c:", &format)
); );

View File

@ -80,7 +80,7 @@ int sum_main(int argc, char **argv)
unsigned n; unsigned n;
unsigned type = SUM_BSD; unsigned type = SUM_BSD;
n = getopt32(argc, argv, "sr"); n = getopt32(argv, "sr");
if (n & 1) type = SUM_SYSV; if (n & 1) type = SUM_SYSV;
/* give the bsd priority over sysv func */ /* give the bsd priority over sysv func */
if (n & 2) type = SUM_BSD; if (n & 2) type = SUM_BSD;

View File

@ -107,7 +107,7 @@ int tail_main(int argc, char **argv)
} }
#endif #endif
opt = getopt32(argc, 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(,&str_s));
#define FOLLOW (opt & 0x1) #define FOLLOW (opt & 0x1)
#define COUNT_BYTES (opt & 0x2) #define COUNT_BYTES (opt & 0x2)

View File

@ -28,7 +28,7 @@ int tee_main(int argc, char **argv)
#else #else
int c; int c;
#endif #endif
retval = getopt32(argc, argv, "ia"); /* 'a' must be 2nd */ retval = getopt32(argv, "ia"); /* 'a' must be 2nd */
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -26,7 +26,7 @@ int touch_main(int argc, char **argv)
{ {
int fd; int fd;
int status = EXIT_SUCCESS; int status = EXIT_SUCCESS;
int flags = getopt32(argc, argv, "c"); int flags = getopt32(argv, "c");
argv += optind; argv += optind;

View File

@ -21,7 +21,7 @@ int tty_main(int argc, char **argv)
xfunc_error_retval = 2; /* SUSv3 requires > 1 for error. */ xfunc_error_retval = 2; /* SUSv3 requires > 1 for error. */
USE_INCLUDE_SUSv2(silent = getopt32(argc, argv, "s");) USE_INCLUDE_SUSv2(silent = getopt32(argv, "s");)
/* gnu tty outputs a warning that it is ignoring all args. */ /* gnu tty outputs a warning that it is ignoring all args. */
bb_warn_ignoring_args(argc - optind); bb_warn_ignoring_args(argc - optind);

View File

@ -58,7 +58,7 @@ int uname_main(int argc, char **argv)
const unsigned short int *delta; const unsigned short int *delta;
char toprint; char toprint;
toprint = getopt32(argc, argv, options); toprint = getopt32(argv, options);
if (argc != optind) { if (argc != optind) {
bb_show_usage(); bb_show_usage();

View File

@ -45,7 +45,7 @@ int uniq_main(int argc, char **argv)
skip_fields = skip_chars = 0; skip_fields = skip_chars = 0;
opt = getopt32(argc, argv, "cduf:s:", &s0, &s1); opt = getopt32(argv, "cduf:s:", &s0, &s1);
if (opt & OPT_f) if (opt & OPT_f)
skip_fields = xatoul(s0); skip_fields = xatoul(s0);
if (opt & OPT_s) if (opt & OPT_s)

View File

@ -134,7 +134,7 @@ int uudecode_main(int argc, char **argv)
char *line; char *line;
opt_complementary = "?1"; /* 1 argument max */ opt_complementary = "?1"; /* 1 argument max */
getopt32(argc, argv, "o:", &outname); getopt32(argv, "o:", &outname);
argv += optind; argv += optind;
if (argv[0]) if (argv[0])

View File

@ -28,7 +28,7 @@ int uuencode_main(int argc, char **argv)
tbl = bb_uuenc_tbl_std; tbl = bb_uuenc_tbl_std;
mode = 0666 & ~umask(0666); mode = 0666 & ~umask(0666);
opt_complementary = "-1:?2"; /* must have 1 or 2 args */ opt_complementary = "-1:?2"; /* must have 1 or 2 args */
if (getopt32(argc, argv, "m")) { if (getopt32(argv, "m")) {
tbl = bb_uuenc_tbl_base64; tbl = bb_uuenc_tbl_base64;
} }
argv += optind; argv += optind;

View File

@ -86,7 +86,7 @@ int wc_main(int argc, char **argv)
smallint in_word; smallint in_word;
unsigned print_type; unsigned print_type;
print_type = getopt32(argc, argv, "lwcL"); print_type = getopt32(argv, "lwcL");
if (print_type == 0) { if (print_type == 0) {
print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_CHARS); print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_CHARS);

View File

@ -14,7 +14,7 @@
int mktemp_main(int argc, char **argv); int mktemp_main(int argc, char **argv);
int mktemp_main(int argc, char **argv) int mktemp_main(int argc, char **argv)
{ {
unsigned long flags = getopt32(argc, argv, "dqt"); unsigned long flags = getopt32(argv, "dqt");
char *chp; char *chp;
if (optind + 1 != argc) if (optind + 1 != argc)

View File

@ -121,7 +121,7 @@ int run_parts_main(int argc, char **argv)
#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
applet_long_options = runparts_longopts; applet_long_options = runparts_longopts;
#endif #endif
tmp = getopt32(argc, argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p); tmp = getopt32(argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p);
G.mode = tmp &~ (RUN_PARTS_OPT_a|RUN_PARTS_OPT_u); G.mode = tmp &~ (RUN_PARTS_OPT_a|RUN_PARTS_OPT_u);
if (tmp & RUN_PARTS_OPT_u) { if (tmp & RUN_PARTS_OPT_u) {
/* Check and set the umask of the program executed. /* Check and set the umask of the program executed.

View File

@ -252,7 +252,7 @@ int start_stop_daemon_main(int argc, char **argv)
/* Check required one context option was given */ /* Check required one context option was given */
opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa"; opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa";
opt = getopt32(argc, argv, "KSbqma:n:s:u:c:x:p:" opt = getopt32(argv, "KSbqma:n:s:u:c:x:p:"
USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"), USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"),
// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), // USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"),
&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile

View File

@ -98,7 +98,7 @@ static void lsattr_args(const char *name)
int lsattr_main(int argc, char **argv); int lsattr_main(int argc, char **argv);
int lsattr_main(int argc, char **argv) int lsattr_main(int argc, char **argv)
{ {
getopt32(argc, argv, "Radlv"); getopt32(argv, "Radlv");
argv += optind; argv += optind;
if (!*argv) if (!*argv)

View File

@ -117,7 +117,7 @@ int lsattr_main(int argc, char **argv)
{ {
int i; int i;
flags = getopt32(argc, argv, "Radlv"); flags = getopt32(argv, "Radlv");
if (optind > argc - 1) if (optind > argc - 1)
lsattr_args("."); lsattr_args(".");

View File

@ -2817,7 +2817,7 @@ int awk_main(int argc, char **argv)
} }
} }
opt_complementary = "v::"; opt_complementary = "v::";
opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W); opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W);
argv += optind; argv += optind;
argc -= optind; argc -= optind;
if (opt & 0x1) if (opt & 0x1)

View File

@ -61,7 +61,7 @@ int cmp_main(int argc, char **argv)
USE_DESKTOP(":?4") USE_DESKTOP(":?4")
SKIP_DESKTOP(":?2") SKIP_DESKTOP(":?2")
":l--s:s--l"; ":l--s:s--l";
opt = getopt32(argc, argv, opt_chars); opt = getopt32(argv, opt_chars);
argv += optind; argv += optind;
filename1 = *argv; filename1 = *argv;

View File

@ -1219,7 +1219,7 @@ int diff_main(int argc, char **argv)
/* exactly 2 params; collect multiple -L <label> */ /* exactly 2 params; collect multiple -L <label> */
opt_complementary = "=2:L::"; opt_complementary = "=2:L::";
getopt32(argc, 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, &U_opt);
/*argc -= optind;*/ /*argc -= optind;*/

View File

@ -87,7 +87,7 @@ int patch_main(int argc, char **argv)
{ {
char *p, *i; char *p, *i;
ret = getopt32(argc, argv, "p:i:", &p, &i); ret = getopt32(argv, "p:i:", &p, &i);
if (ret & 1) if (ret & 1)
patch_level = xatol_range(p, -1, USHRT_MAX); patch_level = xatol_range(p, -1, USHRT_MAX);
if (ret & 2) { if (ret & 2) {

View File

@ -1248,7 +1248,7 @@ int sed_main(int argc, char **argv)
opt_e = opt_f = NULL; opt_e = opt_f = NULL;
opt_complementary = "e::f::" /* can occur multiple times */ opt_complementary = "e::f::" /* can occur multiple times */
"nn"; /* count -n */ "nn"; /* count -n */
opt = getopt32(argc, argv, "irne:f:", &opt_e, &opt_f, opt = getopt32(argv, "irne:f:", &opt_e, &opt_f,
&G.be_quiet); /* counter for -n */ &G.be_quiet); /* counter for -n */
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -389,7 +389,7 @@ int grep_main(int argc, char **argv)
char *Copt; char *Copt;
opt_complementary = "H-h:e::f::C-AB"; opt_complementary = "H-h:e::f::C-AB";
getopt32(argc, argv, getopt32(argv,
OPTSTR_GREP, OPTSTR_GREP,
&pattern_head, &fopt, &mopt, &pattern_head, &fopt, &mopt,
&slines_after, &slines_before, &Copt); &slines_after, &slines_before, &Copt);
@ -419,7 +419,7 @@ int grep_main(int argc, char **argv)
#else #else
/* with auto sanity checks */ /* with auto sanity checks */
opt_complementary = "H-h:e::f::c-n:q-n:l-n"; opt_complementary = "H-h:e::f::c-n:q-n:l-n";
getopt32(argc, argv, OPTSTR_GREP, getopt32(argv, OPTSTR_GREP,
&pattern_head, &fopt, &mopt); &pattern_head, &fopt, &mopt);
#endif #endif
if (option_mask32 & OPT_m) { if (option_mask32 & OPT_m) {

View File

@ -394,7 +394,7 @@ int xargs_main(int argc, char **argv)
#define read_args process_stdin #define read_args process_stdin
#endif #endif
opt = getopt32(argc, argv, OPTION_STR, &max_args, &max_chars, &eof_str); opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &eof_str);
if (opt & OPT_ZEROTERM) if (opt & OPT_ZEROTERM)
USE_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin); USE_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);

View File

@ -35,7 +35,7 @@ RB_AUTOBOOT
for (which = 0; "hpr"[which] != *applet_name; which++); for (which = 0; "hpr"[which] != *applet_name; which++);
/* Parse and handle arguments */ /* Parse and handle arguments */
flags = getopt32(argc, argv, "d:nf", &delay); flags = getopt32(argv, "d:nf", &delay);
if (flags & 1) sleep(xatou(delay)); if (flags & 1) sleep(xatou(delay));
if (!(flags & 2)) sync(); if (!(flags & 2)) sync();

View File

@ -152,12 +152,12 @@ int tcpudpsvd_main(int argc, char **argv)
/* 3+ args, -i at most once, -p implies -h, -v is counter */ /* 3+ args, -i at most once, -p implies -h, -v is counter */
opt_complementary = "-3:i--i:ph:vv"; opt_complementary = "-3:i--i:ph:vv";
#ifdef SSLSVD #ifdef SSLSVD
getopt32(argc, 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, &local_hostname, &str_c, &str_C, &instructs, &instructs, &user, &local_hostname,
&str_b, &str_t, &ssluser, &root, &cert, &key, &verbose &str_b, &str_t, &ssluser, &root, &cert, &key, &verbose
); );
#else #else
getopt32(argc, 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, &local_hostname, &str_c, &str_C, &instructs, &instructs, &user, &local_hostname,
&str_b, &str_t, &verbose &str_b, &str_t, &verbose
); );

View File

@ -13,12 +13,12 @@
/* Documentation /* Documentation
uint32_t uint32_t
getopt32(int argc, char **argv, const char *applet_opts, ...) getopt32(char **argv, const char *applet_opts, ...)
The command line options must be declared in const char The command line options must be declared in const char
*applet_opts as a string of chars, for example: *applet_opts as a string of chars, for example:
flags = getopt32(argc, argv, "rnug"); flags = getopt32(argv, "rnug");
If one of the given options is found, a flag value is added to If one of the given options is found, a flag value is added to
the return value (an unsigned long). the return value (an unsigned long).
@ -26,7 +26,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
The flag value is determined by the position of the char in The flag value is determined by the position of the char in
applet_opts string. For example, in the above case: applet_opts string. For example, in the above case:
flags = getopt32(argc, argv, "rnug"); flags = getopt32(argv, "rnug");
"r" will add 1 (bit 0) "r" will add 1 (bit 0)
"n" will add 2 (bit 1) "n" will add 2 (bit 1)
@ -52,7 +52,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
char *pointer_to_arg_for_c; char *pointer_to_arg_for_c;
char *pointer_to_arg_for_d; char *pointer_to_arg_for_d;
flags = getopt32(argc, argv, "a:b:c:d:", flags = getopt32(argv, "a:b:c:d:",
&pointer_to_arg_for_a, &pointer_to_arg_for_b, &pointer_to_arg_for_a, &pointer_to_arg_for_b,
&pointer_to_arg_for_c, &pointer_to_arg_for_d); &pointer_to_arg_for_c, &pointer_to_arg_for_d);
@ -105,7 +105,7 @@ const char *opt_complementary
if they are not specifed on the command line. For example: if they are not specifed on the command line. For example:
opt_complementary = "abc"; opt_complementary = "abc";
flags = getopt32(argc, argv, "abcd") flags = getopt32(argv, "abcd")
If getopt() finds "-a" on the command line, then If getopt() finds "-a" on the command line, then
getopt32's return value will be as if "-a -b -c" were getopt32's return value will be as if "-a -b -c" were
@ -119,7 +119,7 @@ const char *opt_complementary
int w_counter = 0; int w_counter = 0;
opt_complementary = "ww"; opt_complementary = "ww";
getopt32(argc, argv, "w", &w_counter); getopt32(argv, "w", &w_counter);
if (w_counter) if (w_counter)
width = (w_counter == 1) ? 132 : INT_MAX; width = (w_counter == 1) ? 132 : INT_MAX;
else else
@ -135,7 +135,7 @@ const char *opt_complementary
llist_t *my_b = NULL; llist_t *my_b = NULL;
int verbose_level = 0; int verbose_level = 0;
opt_complementary = "vv:b::b-c:c-b"; opt_complementary = "vv:b::b-c:c-b";
f = getopt32(argc, argv, "vb:c", &my_b, &verbose_level); f = getopt32(argv, "vb:c", &my_b, &verbose_level);
if (f & 2) // -c after -b unsets -b flag if (f & 2) // -c after -b unsets -b flag
while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; } while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
if (my_b) // but llist is stored if -b is specified if (my_b) // but llist is stored if -b is specified
@ -150,7 +150,7 @@ Special characters:
use ':' or end of line. For example: use ':' or end of line. For example:
opt_complementary = "-:w-x:x-w"; opt_complementary = "-:w-x:x-w";
getopt32(argc, argv, "wx"); getopt32(argv, "wx");
Allows any arguments to be given without a dash (./program w x) Allows any arguments to be given without a dash (./program w x)
as well as with a dash (./program -x). as well as with a dash (./program -x).
@ -197,7 +197,7 @@ Special characters:
char *smax_print_depth; char *smax_print_depth;
opt_complementary = "s-d:d-s:x-x"; opt_complementary = "s-d:d-s:x-x";
opt = getopt32(argc, argv, "sd:x", &smax_print_depth); opt = getopt32(argv, "sd:x", &smax_print_depth);
if (opt & 2) if (opt & 2)
max_print_depth = atoi(smax_print_depth); max_print_depth = atoi(smax_print_depth);
@ -235,7 +235,7 @@ Special characters:
opt_complementary = "e::"; opt_complementary = "e::";
getopt32(argc, argv, "e:", &patterns); getopt32(argv, "e:", &patterns);
$ grep -e user -e root /etc/passwd $ grep -e user -e root /etc/passwd
root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash
user:x:500:500::/home/user:/bin/bash user:x:500:500::/home/user:/bin/bash
@ -248,7 +248,7 @@ Special characters:
// 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(argc, argv, "rnug"); flags = getopt32(argv, "rnug");
This example allowed only: This example allowed only:
$ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
@ -260,7 +260,7 @@ Special characters:
// Don't allow -KS -SK, but -S or -K is required // Don't allow -KS -SK, but -S or -K is required
opt_complementary = "K:S:?K--S:S--K"; opt_complementary = "K:S:?K--S:S--K";
flags = getopt32(argc, argv, "KS...); flags = getopt32(argv, "KS...);
Don't forget to use ':'. For example, "?322-22-23X-x-a" Don't forget to use ':'. For example, "?322-22-23X-x-a"
@ -296,8 +296,9 @@ const char *applet_long_options;
uint32_t option_mask32; uint32_t option_mask32;
uint32_t uint32_t
getopt32(int argc, char **argv, const char *applet_opts, ...) getopt32(char **argv, const char *applet_opts, ...)
{ {
int argc;
unsigned flags = 0; unsigned flags = 0;
unsigned requires = 0; unsigned requires = 0;
t_complementary complementary[33]; t_complementary complementary[33];
@ -320,6 +321,10 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
#define FREE_FIRST_ARGV_IS_OPT 8 #define FREE_FIRST_ARGV_IS_OPT 8
int spec_flgs = 0; int spec_flgs = 0;
argc = 0;
while (argv[argc])
argc++;
va_start(p, applet_opts); va_start(p, applet_opts);
c = 0; c = 0;

View File

@ -139,7 +139,7 @@ int addgroup_main(int argc, char **argv)
* addgroup user group * addgroup user group
* Check for min, max and missing args */ * Check for min, max and missing args */
opt_complementary = "-1:?2"; opt_complementary = "-1:?2";
if (getopt32(argc, argv, "g:", &group)) { if (getopt32(argv, "g:", &group)) {
gid = xatoul_range(group, 0, ((unsigned long)(gid_t)ULONG_MAX) >> 1); gid = xatoul_range(group, 0, ((unsigned long)(gid_t)ULONG_MAX) >> 1);
} }
/* move past the commandline options */ /* move past the commandline options */

View File

@ -182,7 +182,7 @@ int adduser_main(int argc, char **argv)
/* exactly one non-option arg */ /* exactly one non-option arg */
opt_complementary = "=1"; opt_complementary = "=1";
getopt32(argc, argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup); getopt32(argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup);
argv += optind; argv += optind;
/* create a passwd struct */ /* create a passwd struct */

View File

@ -33,7 +33,7 @@ int chpasswd_main(int argc, char **argv)
opt_complementary = "m--e:e--m"; opt_complementary = "m--e:e--m";
USE_GETOPT_LONG(applet_long_options = chpasswd_longopts;) USE_GETOPT_LONG(applet_long_options = chpasswd_longopts;)
opt = getopt32(argc, argv, "em"); opt = getopt32(argv, "em");
while ((name = xmalloc_getline(stdin)) != NULL) { while ((name = xmalloc_getline(stdin)) != NULL) {
pass = strchr(name, ':'); pass = strchr(name, ':');

View File

@ -12,7 +12,7 @@ int cryptpw_main(int argc, char **argv)
{ {
char salt[sizeof("$N$XXXXXXXX")]; char salt[sizeof("$N$XXXXXXXX")];
if (!getopt32(argc, argv, "a:", NULL) || argv[optind - 1][0] != 'd') { if (!getopt32(argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
strcpy(salt, "$1$"); strcpy(salt, "$1$");
/* Too ugly, and needs even more magic to handle endianness: */ /* Too ugly, and needs even more magic to handle endianness: */
//((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000; //((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000;

View File

@ -180,7 +180,7 @@ static void parse_args(int argc, char **argv, struct options *op)
{ {
char *ts; char *ts;
op->flags = getopt32(argc, argv, opt_string, op->flags = getopt32(argv, opt_string,
&(op->initstring), &fakehost, &(op->issue), &(op->initstring), &fakehost, &(op->issue),
&(op->login), &ts); &(op->login), &ts);
if (op->flags & F_INITSTRING) { if (op->flags & F_INITSTRING) {

View File

@ -239,7 +239,7 @@ int login_main(int argc, char **argv)
* (The name of the function is misleading. Not daemonizing here.) */ * (The name of the function is misleading. Not daemonizing here.) */
bb_daemonize_or_rexec(DAEMON_ONLY_SANITIZE | DAEMON_CLOSE_EXTRA_FDS, NULL); bb_daemonize_or_rexec(DAEMON_ONLY_SANITIZE | DAEMON_CLOSE_EXTRA_FDS, NULL);
opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host); opt = getopt32(argv, "f:h:p", &opt_user, &opt_host);
if (opt & LOGIN_OPT_f) { if (opt & LOGIN_OPT_f) {
if (!amroot) if (!amroot)
bb_error_msg_and_die("-f is for root only"); bb_error_msg_and_die("-f is for root only");

View File

@ -103,7 +103,7 @@ int passwd_main(int argc, char **argv)
logmode = LOGMODE_BOTH; logmode = LOGMODE_BOTH;
openlog(applet_name, LOG_NOWAIT, LOG_AUTH); openlog(applet_name, LOG_NOWAIT, LOG_AUTH);
opt = getopt32(argc, argv, "a:lud", &opt_a); opt = getopt32(argv, "a:lud", &opt_a);
//argc -= optind; //argc -= optind;
argv += optind; argv += optind;

View File

@ -23,7 +23,7 @@ int su_main(int argc, char **argv)
const char *tty; const char *tty;
char *old_user; char *old_user;
flags = getopt32(argc, argv, "mplc:s:", &opt_command, &opt_shell); flags = getopt32(argv, "mplc:s:", &opt_command, &opt_shell);
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -53,7 +53,7 @@ int sulogin_main(int argc, char **argv)
logmode = LOGMODE_BOTH; logmode = LOGMODE_BOTH;
openlog(applet_name, 0, LOG_AUTH); openlog(applet_name, 0, LOG_AUTH);
if (getopt32(argc, argv, "t:", &timeout_arg)) { if (getopt32(argv, "t:", &timeout_arg)) {
timeout = xatoi_u(timeout_arg); timeout = xatoi_u(timeout_arg);
} }

View File

@ -58,7 +58,7 @@ int vlock_main(int argc, char **argv)
bb_show_usage(); bb_show_usage();
} }
o_lock_all = getopt32(argc, argv, "a"); o_lock_all = getopt32(argv, "a");
vfd = xopen(CURRENT_TTY, O_RDWR); vfd = xopen(CURRENT_TTY, O_RDWR);

View File

@ -56,7 +56,7 @@ int adjtimex_main(int argc, char **argv)
const char *descript; const char *descript;
txc.modes=0; txc.modes=0;
opt = getopt32(argc, argv, "qo:f:p:t:", opt = getopt32(argv, "qo:f:p:t:",
&opt_o, &opt_f, &opt_p, &opt_t); &opt_o, &opt_f, &opt_p, &opt_t);
//if (opt & 0x1) // -q //if (opt & 0x1) // -q
if (opt & 0x2) { // -o if (opt & 0x2) { // -o

View File

@ -52,7 +52,7 @@ int chrt_main(int argc, char** argv)
int prio = 0, policy = SCHED_RR; int prio = 0, policy = SCHED_RR;
opt_complementary = "r--fo:f--ro:r--fo"; /* only one policy accepted */ opt_complementary = "r--fo:f--ro:r--fo"; /* only one policy accepted */
opt = getopt32(argc, argv, "+mp:rfo", &p_opt); opt = getopt32(argv, "+mp:rfo", &p_opt);
if (opt & OPT_r) if (opt & OPT_r)
policy = SCHED_RR; policy = SCHED_RR;
if (opt & OPT_f) if (opt & OPT_f)

View File

@ -33,7 +33,7 @@ int eject_main(int argc, char **argv)
int dev, cmd; int dev, cmd;
opt_complementary = "?1:t--T:T--t"; opt_complementary = "?1:t--T:T--t";
flags = getopt32(argc, argv, "tT"); flags = getopt32(argv, "tT");
device = argv[optind] ? : "/dev/cdrom"; device = argv[optind] ? : "/dev/cdrom";
// We used to do "umount <device>" here, but it was buggy // We used to do "umount <device>" here, but it was buggy

View File

@ -1321,7 +1321,7 @@ int less_main(int argc, char **argv)
/* TODO: -x: do not interpret backspace, -xx: tab also */ /* TODO: -x: do not interpret backspace, -xx: tab also */
/* -xxx: newline also */ /* -xxx: newline also */
/* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */ /* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */
getopt32(argc, argv, "EMmN~"); getopt32(argv, "EMmN~");
argc -= optind; argc -= optind;
argv += optind; argv += optind;
num_files = argc; num_files = argc;

View File

@ -78,7 +78,7 @@ int makedevs_main(int argc, char **argv)
int linenum = 0; int linenum = 0;
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
getopt32(argc, argv, "d:", &line); getopt32(argv, "d:", &line);
if (line) if (line)
table = xfopen(line, "r"); table = xfopen(line, "r");

View File

@ -16,7 +16,7 @@ int mountpoint_main(int argc, char **argv)
{ {
struct stat st; struct stat st;
char *arg; char *arg;
int opt = getopt32(argc, argv, "qdx"); int opt = getopt32(argv, "qdx");
#define OPT_q (1) #define OPT_q (1)
#define OPT_d (2) #define OPT_d (2)
#define OPT_x (4) #define OPT_x (4)

View File

@ -28,7 +28,7 @@ int strings_main(int argc, char **argv)
const char *fmt = "%s: "; const char *fmt = "%s: ";
const char *n_arg = "4"; const char *n_arg = "4";
opt = getopt32(argc, argv, "afon:", &n_arg); opt = getopt32(argv, "afon:", &n_arg);
/* -a is our default behaviour */ /* -a is our default behaviour */
/*argc -= optind;*/ /*argc -= optind;*/
argv += optind; argv += optind;

View File

@ -50,7 +50,7 @@ int taskset_main(int argc, char** argv)
const char *state = "current\0new"; const char *state = "current\0new";
char *p_opt = NULL, *aff = NULL; char *p_opt = NULL, *aff = NULL;
opt = getopt32(argc, argv, "+p:", &p_opt); opt = getopt32(argv, "+p:", &p_opt);
if (opt & OPT_p) { if (opt & OPT_p) {
if (argc == optind+1) { /* -p <aff> <pid> */ if (argc == optind+1) { /* -p <aff> <pid> */

View File

@ -30,7 +30,7 @@ int watchdog_main(int argc, char **argv)
char *t_arg; char *t_arg;
opt_complementary = "=1"; /* must have 1 argument */ opt_complementary = "=1"; /* must have 1 argument */
opts = getopt32(argc, argv, "Ft:", &t_arg); opts = getopt32(argv, "Ft:", &t_arg);
if (opts & OPT_TIMER) if (opts & OPT_TIMER)
timer_duration = xatou(t_arg); timer_duration = xatou(t_arg);

View File

@ -3980,7 +3980,7 @@ int insmod_main( int argc, char **argv)
struct utsname myuname; struct utsname myuname;
/* Parse any options */ /* Parse any options */
getopt32(argc, argv, OPTION_STR, &opt_o); getopt32(argv, OPTION_STR, &opt_o);
arg1 = argv[optind]; arg1 = argv[optind];
if (option_mask32 & OPT_o) { // -o /* name the output module */ if (option_mask32 & OPT_o) { // -o /* name the output module */
free(m_name); free(m_name);

View File

@ -868,7 +868,7 @@ int modprobe_main(int argc, char** argv)
char *unused; char *unused;
opt_complementary = "?V-:q-v:v-q"; opt_complementary = "?V-:q-v:v-q";
main_opts = getopt32(argc, argv, "acdklnqrst:vVC:", main_opts = getopt32(argv, "acdklnqrst:vVC:",
&unused, &unused); &unused, &unused);
if (main_opts & (DUMP_CONF_EXIT | LIST_ALL)) if (main_opts & (DUMP_CONF_EXIT | LIST_ALL))
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -47,7 +47,7 @@ int rmmod_main(int argc, char **argv)
#define misc_buf bb_common_bufsiz1 #define misc_buf bb_common_bufsiz1
/* Parse command line. */ /* Parse command line. */
n = getopt32(argc, argv, "wfa"); n = getopt32(argv, "wfa");
if (n & 1) // --wait if (n & 1) // --wait
flags &= ~O_NONBLOCK; flags &= ~O_NONBLOCK;
if (n & 2) // --force if (n & 2) // --force

View File

@ -445,7 +445,7 @@ int arp_main(int argc, char **argv)
if (!ap) if (!ap)
bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
getopt32(argc, argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,
&hw_type, &hw_type, &device); &hw_type, &hw_type, &device);
argv += optind; argv += optind;
if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) {

View File

@ -249,7 +249,7 @@ int arping_main(int argc, char **argv)
* Advert also sets unsolicited. * Advert also sets unsolicited.
*/ */
opt_complementary = "=1:Df:AU"; opt_complementary = "=1:Df:AU";
opt = getopt32(argc, argv, "DUAqfbc:w:I:s:", opt = getopt32(argv, "DUAqfbc:w:I:s:",
&str_count, &str_timeout, &device, &source); &str_count, &str_timeout, &device, &source);
if (opt & 0x40) /* -c: count */ if (opt & 0x40) /* -c: count */
count = xatou(str_count); count = xatou(str_count);

View File

@ -338,7 +338,7 @@ int dnsd_main(int argc, char **argv)
uint16_t port = 53; uint16_t port = 53;
uint8_t buf[MAX_PACK_LEN]; uint8_t buf[MAX_PACK_LEN];
getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport); getopt32(argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
//if (option_mask32 & 0x1) // -i //if (option_mask32 & 0x1) // -i
//if (option_mask32 & 0x2) // -c //if (option_mask32 & 0x2) // -c
if (option_mask32 & 0x4) // -t if (option_mask32 & 0x4) // -t

View File

@ -195,7 +195,7 @@ int ether_wake_main(int argc, char **argv)
/* handle misc user options */ /* handle misc user options */
opt_complementary = "=1"; opt_complementary = "=1";
flags = getopt32(argc, argv, "bi:p:", &ifname, &pass); flags = getopt32(argv, "bi:p:", &ifname, &pass);
if (flags & 4) /* -p */ if (flags & 4) /* -p */
wol_passwd_sz = get_wol_pw(pass, wol_passwd); wol_passwd_sz = get_wol_pw(pass, wol_passwd);
flags &= 1; /* we further interested only in -b [bcast] flag */ flags &= 1; /* we further interested only in -b [bcast] flag */

View File

@ -331,7 +331,7 @@ int ftpgetput_main(int argc, char **argv)
applet_long_options = ftpgetput_longopts; applet_long_options = ftpgetput_longopts;
#endif #endif
opt_complementary = "=3"; /* must have 3 params */ opt_complementary = "=3"; /* must have 3 params */
opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port); opt = getopt32(argv, "cvu:p:P:", &server->user, &server->password, &port);
argv += optind; argv += optind;
/* Process the non-option command line arguments */ /* Process the non-option command line arguments */

View File

@ -60,7 +60,7 @@ int hostname_main(int argc, char **argv)
if (argc < 1) if (argc < 1)
bb_show_usage(); bb_show_usage();
getopt32(argc, argv, "dfisF:", &hostname_str); getopt32(argv, "dfisF:", &hostname_str);
/* Output in desired format */ /* Output in desired format */
if (option_mask32 & OPT_dfis) { if (option_mask32 & OPT_dfis) {

View File

@ -1975,7 +1975,7 @@ int httpd_main(int argc, char **argv)
/* We do not "absolutize" path given by -h (home) opt. /* We do not "absolutize" path given by -h (home) opt.
* If user gives relative path in -h, $SCRIPT_FILENAME can end up * If user gives relative path in -h, $SCRIPT_FILENAME can end up
* relative too. */ * relative too. */
opt = getopt32(argc, argv, "c:d:h:" opt = getopt32(argv, "c:d:h:"
USE_FEATURE_HTTPD_ENCODE_URL_STR("e:") USE_FEATURE_HTTPD_ENCODE_URL_STR("e:")
USE_FEATURE_HTTPD_BASIC_AUTH("r:") USE_FEATURE_HTTPD_BASIC_AUTH("r:")
USE_FEATURE_HTTPD_AUTH_MD5("m:") USE_FEATURE_HTTPD_AUTH_MD5("m:")

View File

@ -1148,7 +1148,7 @@ int ifupdown_main(int argc, char **argv)
cmds = iface_up; cmds = iface_up;
} }
getopt32(argc, argv, OPTION_STR, &interfaces); getopt32(argv, OPTION_STR, &interfaces);
if (argc - optind > 0) { if (argc - optind > 0) {
if (DO_ALL) bb_show_usage(); if (DO_ALL) bb_show_usage();
} else { } else {

View File

@ -1278,7 +1278,7 @@ int inetd_main(int argc, char **argv)
if (uid != 0) if (uid != 0)
config_filename = NULL; config_filename = NULL;
opt = getopt32(argc, argv, "R:f", &stoomany); opt = getopt32(argv, "R:f", &stoomany);
if (opt & 1) if (opt & 1)
toomany = xatoi_u(stoomany); toomany = xatoi_u(stoomany);
argv += optind; argv += optind;

View File

@ -87,7 +87,7 @@ int ipcalc_main(int argc, char **argv)
#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
applet_long_options = ipcalc_longopts; applet_long_options = ipcalc_longopts;
#endif #endif
opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); opt = getopt32(argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (opt & (BROADCAST | NETWORK | NETPREFIX)) { if (opt & (BROADCAST | NETWORK | NETPREFIX)) {

View File

@ -107,7 +107,7 @@ int fakeidentd_main(int argc, char **argv)
unsigned opt; unsigned opt;
int fd; int fd;
opt = getopt32(argc, argv, "fiwb:", &bind_address); opt = getopt32(argv, "fiwb:", &bind_address);
strcpy(bogouser, "nobody"); strcpy(bogouser, "nobody");
if (argv[optind]) if (argv[optind])
strncpy(bogouser, argv[optind], sizeof(bogouser)); strncpy(bogouser, argv[optind], sizeof(bogouser));

View File

@ -66,7 +66,7 @@ int nameif_main(int argc, char **argv)
int if_index = 1; int if_index = 1;
mactable_t *ch; mactable_t *ch;
if (1 & getopt32(argc, argv, "sc:", &fname)) { if (1 & getopt32(argv, "sc:", &fname)) {
openlog(applet_name, 0, LOG_LOCAL0); openlog(applet_name, 0, LOG_LOCAL0);
logmode = LOGMODE_SYSLOG; logmode = LOGMODE_SYSLOG;
} }

View File

@ -706,7 +706,7 @@ int nc_main(int argc, char **argv)
// -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"; /* max 2 params, -v is a counter */
getopt32(argc, 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, &str_w
USE_NC_EXTRA(, &str_i, &str_o, &o_verbose)); USE_NC_EXTRA(, &str_i, &str_o, &o_verbose));

View File

@ -497,7 +497,7 @@ int netstat_main(int argc, char **argv)
#endif #endif
/* Option string must match NETSTAT_xxx constants */ /* Option string must match NETSTAT_xxx constants */
opt = getopt32(argc, argv, NETSTAT_OPTS); opt = getopt32(argv, NETSTAT_OPTS);
if (opt & 0x1) { // -l if (opt & 0x1) { // -l
flags &= ~NETSTAT_CONNECTED; flags &= ~NETSTAT_CONNECTED;
flags |= NETSTAT_LISTENING; flags |= NETSTAT_LISTENING;

View File

@ -689,7 +689,7 @@ int ping_main(int argc, char **argv)
/* exactly one argument needed, -v and -q don't mix */ /* exactly one argument needed, -v and -q don't mix */
opt_complementary = "=1:q--v:v--q"; opt_complementary = "=1:q--v:v--q";
getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I); getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c
if (option_mask32 & OPT_s) datalen = xatou16(opt_s); // -s if (option_mask32 & OPT_s) datalen = xatou16(opt_s); // -s
if (option_mask32 & OPT_I) { // -I if (option_mask32 & OPT_I) { // -I

Some files were not shown because too many files have changed in this diff Show More