aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/bbunzip.c5
-rw-r--r--archival/cpio.c7
-rw-r--r--archival/dpkg.c3
-rw-r--r--archival/gzip.c7
-rw-r--r--archival/tar.c11
-rw-r--r--coreutils/chown.c7
-rw-r--r--coreutils/cp.c7
-rw-r--r--coreutils/date.c5
-rw-r--r--coreutils/env.c21
-rw-r--r--coreutils/expand.c53
-rw-r--r--coreutils/install.c18
-rw-r--r--coreutils/ls.c3
-rw-r--r--coreutils/mkdir.c33
-rw-r--r--coreutils/mv.c38
-rw-r--r--coreutils/nl.c5
-rw-r--r--coreutils/nproc.c1
-rw-r--r--coreutils/od_bloaty.c7
-rw-r--r--coreutils/rmdir.c27
-rw-r--r--coreutils/touch.c13
-rw-r--r--coreutils/uname.c3
-rw-r--r--debianutils/run_parts.c14
-rw-r--r--debianutils/start_stop_daemon.c12
-rw-r--r--editors/diff.c10
-rw-r--r--editors/patch_bbox.c3
-rw-r--r--editors/sed.c8
-rw-r--r--findutils/xargs.c9
-rw-r--r--include/libbb.h25
-rw-r--r--libbb/getopt32.c71
-rw-r--r--libbb/vfork_daemon_rexec.c17
-rw-r--r--loginutils/addgroup.c14
-rw-r--r--loginutils/adduser.c25
-rw-r--r--loginutils/chpasswd.c3
-rw-r--r--loginutils/cryptpw.c4
-rw-r--r--loginutils/deluser.c5
-rw-r--r--miscutils/conspy.c4
-rw-r--r--miscutils/nandwrite.c8
-rw-r--r--modutils/modprobe.c3
-rw-r--r--networking/ftpgetput.c10
-rw-r--r--networking/hostname.c12
-rw-r--r--networking/ifenslave.c14
-rw-r--r--networking/ipcalc.c10
-rw-r--r--networking/udhcp/d6_dhcpc.c4
-rw-r--r--networking/udhcp/dhcpc.c4
-rw-r--r--networking/udhcp/dumpleases.c3
-rw-r--r--networking/wget.c9
-rw-r--r--selinux/chcon.c41
-rw-r--r--selinux/runcon.c22
-rw-r--r--util-linux/flock.c3
-rw-r--r--util-linux/fsfreeze.c9
-rw-r--r--util-linux/fstrim.c3
-rw-r--r--util-linux/getopt.c22
-rw-r--r--util-linux/hwclock.c28
-rw-r--r--util-linux/nsenter.c35
-rw-r--r--util-linux/rtcwake.c4
-rw-r--r--util-linux/script.c4
-rw-r--r--util-linux/setpriv.c9
-rw-r--r--util-linux/unshare.c3
57 files changed, 299 insertions, 459 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 9b9fdc87b..20ab893da 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -389,9 +389,10 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
389int gunzip_main(int argc UNUSED_PARAM, char **argv) 389int gunzip_main(int argc UNUSED_PARAM, char **argv)
390{ 390{
391#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS 391#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
392 applet_long_options = gunzip_longopts; 392 getopt32long(argv, "cfkvqdtn", gunzip_longopts);
393#endif 393#else
394 getopt32(argv, "cfkvqdtn"); 394 getopt32(argv, "cfkvqdtn");
395#endif
395 argv += optind; 396 argv += optind;
396 397
397 /* If called as zcat... 398 /* If called as zcat...
diff --git a/archival/cpio.c b/archival/cpio.c
index 38bab8257..f2165be3a 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -360,9 +360,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
360 char *cpio_owner; 360 char *cpio_owner;
361 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";) 361 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
362 unsigned opt; 362 unsigned opt;
363
364#if ENABLE_LONG_OPTS 363#if ENABLE_LONG_OPTS
365 applet_long_options = 364 const char *long_opts =
366 "extract\0" No_argument "i" 365 "extract\0" No_argument "i"
367 "list\0" No_argument "t" 366 "list\0" No_argument "t"
368#if ENABLE_FEATURE_CPIO_O 367#if ENABLE_FEATURE_CPIO_O
@@ -390,9 +389,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
390 /* -L makes sense only with -o or -p */ 389 /* -L makes sense only with -o or -p */
391 390
392#if !ENABLE_FEATURE_CPIO_O 391#if !ENABLE_FEATURE_CPIO_O
393 opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner); 392 opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner);
394#else 393#else
395 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), 394 opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts,
396 &cpio_filename, &cpio_owner, &cpio_fmt); 395 &cpio_filename, &cpio_owner, &cpio_fmt);
397#endif 396#endif
398 argv += optind; 397 argv += optind;
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 90ad8766c..852e0cac2 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1766,8 +1766,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
1766 1766
1767 INIT_G(); 1767 INIT_G();
1768 1768
1769 IF_LONG_OPTS(applet_long_options = dpkg_longopts); 1769 opt = getopt32long(argv, "CilPruF:", dpkg_longopts, &str_f);
1770 opt = getopt32(argv, "CilPruF:", &str_f);
1771 argv += optind; 1770 argv += optind;
1772 //if (opt & OPT_configure) ... // -C 1771 //if (opt & OPT_configure) ... // -C
1773 if (opt & OPT_force) { // -F (--force in official dpkg) 1772 if (opt & OPT_force) { // -F (--force in official dpkg)
diff --git a/archival/gzip.c b/archival/gzip.c
index 4cf34ac28..9c53895e9 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -2216,11 +2216,12 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2216 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2216 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
2217 + sizeof(struct globals)); 2217 + sizeof(struct globals));
2218 2218
2219#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
2220 applet_long_options = gzip_longopts;
2221#endif
2222 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2219 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
2220#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
2221 opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts);
2222#else
2223 opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789"); 2223 opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
2224#endif
2224#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */ 2225#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
2225 if (opt & 0x30) // -d and/or -t 2226 if (opt & 0x30) // -d and/or -t
2226 return gunzip_main(argc, argv); 2227 return gunzip_main(argc, argv);
diff --git a/archival/tar.c b/archival/tar.c
index f62b33005..44ab246c0 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -940,6 +940,11 @@ static const char tar_longopts[] ALIGN1 =
940 "exclude\0" Required_argument "\xff" 940 "exclude\0" Required_argument "\xff"
941# endif 941# endif
942 ; 942 ;
943# define GETOPT32 getopt32long
944# define LONGOPTS ,tar_longopts
945#else
946# define GETOPT32 getopt32
947# define LONGOPTS
943#endif 948#endif
944 949
945int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 950int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -980,9 +985,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
980 ":\xf9+" // --strip-components=NUM 985 ":\xf9+" // --strip-components=NUM
981#endif 986#endif
982 ; 987 ;
983#if ENABLE_FEATURE_TAR_LONG_OPTIONS
984 applet_long_options = tar_longopts;
985#endif
986#if ENABLE_DESKTOP 988#if ENABLE_DESKTOP
987 /* Lie to buildroot when it starts asking stupid questions. */ 989 /* Lie to buildroot when it starts asking stupid questions. */
988 if (argv[1] && strcmp(argv[1], "--version") == 0) { 990 if (argv[1] && strcmp(argv[1], "--version") == 0) {
@@ -1019,7 +1021,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1019 } 1021 }
1020 } 1022 }
1021#endif 1023#endif
1022 opt = getopt32(argv, 1024 opt = GETOPT32(argv,
1023 "txC:f:Oopvk" 1025 "txC:f:Oopvk"
1024 IF_FEATURE_TAR_CREATE( "ch" ) 1026 IF_FEATURE_TAR_CREATE( "ch" )
1025 IF_FEATURE_SEAMLESS_BZ2( "j" ) 1027 IF_FEATURE_SEAMLESS_BZ2( "j" )
@@ -1030,6 +1032,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1030 IF_FEATURE_SEAMLESS_Z( "Z" ) 1032 IF_FEATURE_SEAMLESS_Z( "Z" )
1031 IF_FEATURE_TAR_NOPRESERVE_TIME("m") 1033 IF_FEATURE_TAR_NOPRESERVE_TIME("m")
1032 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components 1034 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
1035 LONGOPTS
1033 , &base_dir // -C dir 1036 , &base_dir // -C dir
1034 , &tar_filename // -f filename 1037 , &tar_filename // -f filename
1035 IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T 1038 IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 1bfc725cc..0c77529ec 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -127,11 +127,12 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
127 int opt, flags; 127 int opt, flags;
128 struct param_t param; 128 struct param_t param;
129 129
130#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
131 applet_long_options = chown_longopts;
132#endif
133 opt_complementary = "-2"; 130 opt_complementary = "-2";
131#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
132 opt = getopt32long(argv, OPT_STR, chown_longopts);
133#else
134 opt = getopt32(argv, OPT_STR); 134 opt = getopt32(argv, OPT_STR);
135#endif
135 argv += optind; 136 argv += optind;
136 137
137 /* This matches coreutils behavior (almost - see below) */ 138 /* This matches coreutils behavior (almost - see below) */
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 092e39583..fe408950a 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -81,7 +81,7 @@ int cp_main(int argc, char **argv)
81 // -a = -pdR 81 // -a = -pdR
82 opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; 82 opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
83#if ENABLE_FEATURE_CP_LONG_OPTIONS 83#if ENABLE_FEATURE_CP_LONG_OPTIONS
84 applet_long_options = 84 flags = getopt32long(argv, FILEUTILS_CP_OPTSTR,
85 "archive\0" No_argument "a" 85 "archive\0" No_argument "a"
86 "force\0" No_argument "f" 86 "force\0" No_argument "f"
87 "interactive\0" No_argument "i" 87 "interactive\0" No_argument "i"
@@ -94,9 +94,10 @@ int cp_main(int argc, char **argv)
94 "update\0" No_argument "u" 94 "update\0" No_argument "u"
95 "remove-destination\0" No_argument "\xff" 95 "remove-destination\0" No_argument "\xff"
96 "parents\0" No_argument "\xfe" 96 "parents\0" No_argument "\xfe"
97 ; 97 );
98#endif 98#else
99 flags = getopt32(argv, FILEUTILS_CP_OPTSTR); 99 flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
100#endif
100 /* Options of cp from GNU coreutils 6.10: 101 /* Options of cp from GNU coreutils 6.10:
101 * -a, --archive 102 * -a, --archive
102 * -f, --force 103 * -f, --force
diff --git a/coreutils/date.c b/coreutils/date.c
index 5a4ad5fe5..33f210434 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -194,9 +194,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
194 194
195 opt_complementary = "d--s:s--d" 195 opt_complementary = "d--s:s--d"
196 IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); 196 IF_FEATURE_DATE_ISOFMT(":R--I:I--R");
197 IF_LONG_OPTS(applet_long_options = date_longopts;) 197 opt = getopt32long(argv, "Rs:ud:r:"
198 opt = getopt32(argv, "Rs:ud:r:" 198 IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts,
199 IF_FEATURE_DATE_ISOFMT("I::D:"),
200 &date_str, &date_str, &filename 199 &date_str, &date_str, &filename
201 IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); 200 IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
202 argv += optind; 201 argv += optind;
diff --git a/coreutils/env.c b/coreutils/env.c
index 3242446f5..20453e871 100644
--- a/coreutils/env.c
+++ b/coreutils/env.c
@@ -30,11 +30,6 @@
30//config: env is used to set an environment variable and run 30//config: env is used to set an environment variable and run
31//config: a command; without options it displays the current 31//config: a command; without options it displays the current
32//config: environment. 32//config: environment.
33//config:
34//config:config FEATURE_ENV_LONG_OPTIONS
35//config: bool "Enable long options"
36//config: default y
37//config: depends on ENV && LONG_OPTS
38 33
39//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) 34//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
40 35
@@ -53,23 +48,17 @@
53 48
54#include "libbb.h" 49#include "libbb.h"
55 50
56#if ENABLE_FEATURE_ENV_LONG_OPTIONS
57static const char env_longopts[] ALIGN1 =
58 "ignore-environment\0" No_argument "i"
59 "unset\0" Required_argument "u"
60 ;
61#endif
62
63int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 51int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
64int env_main(int argc UNUSED_PARAM, char **argv) 52int env_main(int argc UNUSED_PARAM, char **argv)
65{ 53{
66 unsigned opts; 54 unsigned opts;
67 llist_t *unset_env = NULL; 55 llist_t *unset_env = NULL;
68 56
69#if ENABLE_FEATURE_ENV_LONG_OPTIONS 57 opts = getopt32long(argv, "+iu:+",
70 applet_long_options = env_longopts; 58 "ignore-environment\0" No_argument "i"
71#endif 59 "unset\0" Required_argument "u"
72 opts = getopt32(argv, "+iu:+", &unset_env); 60 , &unset_env
61 );
73 argv += optind; 62 argv += optind;
74 if (argv[0] && LONE_DASH(argv[0])) { 63 if (argv[0] && LONE_DASH(argv[0])) {
75 opts |= 1; 64 opts |= 1;
diff --git a/coreutils/expand.c b/coreutils/expand.c
index 64f2a539d..fa3ff18f4 100644
--- a/coreutils/expand.c
+++ b/coreutils/expand.c
@@ -26,21 +26,11 @@
26//config: help 26//config: help
27//config: By default, convert all tabs to spaces. 27//config: By default, convert all tabs to spaces.
28//config: 28//config:
29//config:config FEATURE_EXPAND_LONG_OPTIONS
30//config: bool "Enable long options"
31//config: default y
32//config: depends on EXPAND && LONG_OPTS
33//config:
34//config:config UNEXPAND 29//config:config UNEXPAND
35//config: bool "unexpand (6 kb)" 30//config: bool "unexpand (6 kb)"
36//config: default y 31//config: default y
37//config: help 32//config: help
38//config: By default, convert only leading sequences of blanks to tabs. 33//config: By default, convert only leading sequences of blanks to tabs.
39//config:
40//config:config FEATURE_UNEXPAND_LONG_OPTIONS
41//config: bool "Enable long options"
42//config: default y
43//config: depends on UNEXPAND && LONG_OPTS
44 34
45//applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP)) 35//applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP))
46// APPLET_ODDNAME:name main location suid_type help 36// APPLET_ODDNAME:name main location suid_type help
@@ -53,29 +43,16 @@
53//usage: "[-i] [-t N] [FILE]..." 43//usage: "[-i] [-t N] [FILE]..."
54//usage:#define expand_full_usage "\n\n" 44//usage:#define expand_full_usage "\n\n"
55//usage: "Convert tabs to spaces, writing to stdout\n" 45//usage: "Convert tabs to spaces, writing to stdout\n"
56//usage: IF_FEATURE_EXPAND_LONG_OPTIONS(
57//usage: "\n -i,--initial Don't convert tabs after non blanks"
58//usage: "\n -t,--tabs N Tabstops every N chars"
59//usage: )
60//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS(
61//usage: "\n -i Don't convert tabs after non blanks" 46//usage: "\n -i Don't convert tabs after non blanks"
62//usage: "\n -t Tabstops every N chars" 47//usage: "\n -t Tabstops every N chars"
63//usage: )
64 48
65//usage:#define unexpand_trivial_usage 49//usage:#define unexpand_trivial_usage
66//usage: "[-fa][-t N] [FILE]..." 50//usage: "[-fa][-t N] [FILE]..."
67//usage:#define unexpand_full_usage "\n\n" 51//usage:#define unexpand_full_usage "\n\n"
68//usage: "Convert spaces to tabs, writing to stdout\n" 52//usage: "Convert spaces to tabs, writing to stdout\n"
69//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS(
70//usage: "\n -a,--all Convert all blanks"
71//usage: "\n -f,--first-only Convert only leading blanks"
72//usage: "\n -t,--tabs N Tabstops every N chars"
73//usage: )
74//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS(
75//usage: "\n -a Convert all blanks" 53//usage: "\n -a Convert all blanks"
76//usage: "\n -f Convert only leading blanks" 54//usage: "\n -f Convert only leading blanks"
77//usage: "\n -t N Tabstops every N chars" 55//usage: "\n -t N Tabstops every N chars"
78//usage: )
79 56
80#include "libbb.h" 57#include "libbb.h"
81#include "unicode.h" 58#include "unicode.h"
@@ -188,31 +165,23 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
188 unsigned opt; 165 unsigned opt;
189 int exit_status = EXIT_SUCCESS; 166 int exit_status = EXIT_SUCCESS;
190 167
191#if ENABLE_FEATURE_EXPAND_LONG_OPTIONS
192 static const char expand_longopts[] ALIGN1 =
193 /* name, has_arg, val */
194 "initial\0" No_argument "i"
195 "tabs\0" Required_argument "t"
196 ;
197#endif
198#if ENABLE_FEATURE_UNEXPAND_LONG_OPTIONS
199 static const char unexpand_longopts[] ALIGN1 =
200 /* name, has_arg, val */
201 "first-only\0" No_argument "i"
202 "tabs\0" Required_argument "t"
203 "all\0" No_argument "a"
204 ;
205#endif
206 init_unicode(); 168 init_unicode();
207 169
208 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) { 170 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
209 IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts); 171 opt = getopt32long(argv, "it:",
210 opt = getopt32(argv, "it:", &opt_t); 172 "initial\0" No_argument "i"
173 "tabs\0" Required_argument "t"
174 , &opt_t
175 );
211 } else { 176 } else {
212 IF_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
213 /* -t NUM sets also -a */ 177 /* -t NUM sets also -a */
214 opt_complementary = "ta"; 178 opt_complementary = "ta";
215 opt = getopt32(argv, "ft:a", &opt_t); 179 opt = getopt32long(argv, "ft:a",
180 "first-only\0" No_argument "i"
181 "tabs\0" Required_argument "t"
182 "all\0" No_argument "a"
183 , &opt_t
184 );
216 /* -f --first-only is the default */ 185 /* -f --first-only is the default */
217 if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; 186 if (!(opt & OPT_ALL)) opt |= OPT_INITIAL;
218 } 187 }
diff --git a/coreutils/install.c b/coreutils/install.c
index a1342bb13..c01750f81 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -55,12 +55,17 @@ static const char install_longopts[] ALIGN1 =
55 "target-directory\0" Required_argument "t" 55 "target-directory\0" Required_argument "t"
56/* autofs build insists of using -b --suffix=.orig */ 56/* autofs build insists of using -b --suffix=.orig */
57/* TODO? (short option for --suffix is -S) */ 57/* TODO? (short option for --suffix is -S) */
58#if ENABLE_SELINUX 58# if ENABLE_SELINUX
59 "context\0" Required_argument "Z" 59 "context\0" Required_argument "Z"
60 "preserve_context\0" No_argument "\xff" 60 "preserve_context\0" No_argument "\xff"
61 "preserve-context\0" No_argument "\xff" 61 "preserve-context\0" No_argument "\xff"
62#endif 62# endif
63 ; 63 ;
64# define GETOPT32 getopt32long
65# define LONGOPTS install_longopts,
66#else
67# define GETOPT32 getopt32
68# define LONGOPTS
64#endif 69#endif
65 70
66 71
@@ -135,15 +140,14 @@ int install_main(int argc, char **argv)
135#endif 140#endif
136 }; 141 };
137 142
138#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
139 applet_long_options = install_longopts;
140#endif
141 opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); 143 opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
142 /* -c exists for backwards compatibility, it's needed */ 144 /* -c exists for backwards compatibility, it's needed */
143 /* -b is ignored ("make a backup of each existing destination file") */ 145 /* -b is ignored ("make a backup of each existing destination file") */
144 opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), 146 opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
147 LONGOPTS
145 &gid_str, &mode_str, &uid_str, &last 148 &gid_str, &mode_str, &uid_str, &last
146 IF_SELINUX(, &scontext)); 149 IF_SELINUX(, &scontext)
150 );
147 argc -= optind; 151 argc -= optind;
148 argv += optind; 152 argv += optind;
149 153
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 0fe0345b3..0834cdc63 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -1093,7 +1093,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1093#endif 1093#endif
1094 1094
1095 /* process options */ 1095 /* process options */
1096 IF_LONG_OPTS(applet_long_options = ls_longopts;)
1097 opt_complementary = 1096 opt_complementary =
1098 /* -n and -g imply -l */ 1097 /* -n and -g imply -l */
1099 "nl:gl" 1098 "nl:gl"
@@ -1111,7 +1110,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1111 IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ 1110 IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
1112 /* -w NUM: */ 1111 /* -w NUM: */
1113 IF_FEATURE_LS_WIDTH(":w+"); 1112 IF_FEATURE_LS_WIDTH(":w+");
1114 opt = getopt32(argv, ls_options 1113 opt = getopt32long(argv, ls_options, ls_longopts
1115 IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) 1114 IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
1116 IF_FEATURE_LS_COLOR(, &color_opt) 1115 IF_FEATURE_LS_COLOR(, &color_opt)
1117 ); 1116 );
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 22851187c..986353dc6 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -18,11 +18,6 @@
18//config: default y 18//config: default y
19//config: help 19//config: help
20//config: mkdir is used to create directories with the specified names. 20//config: mkdir is used to create directories with the specified names.
21//config:
22//config:config FEATURE_MKDIR_LONG_OPTIONS
23//config: bool "Enable long options"
24//config: default y
25//config: depends on MKDIR && LONG_OPTS
26 21
27//applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir)) 22//applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
28 23
@@ -53,19 +48,6 @@
53 48
54/* This is a NOFORK applet. Be very careful! */ 49/* This is a NOFORK applet. Be very careful! */
55 50
56#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
57static const char mkdir_longopts[] ALIGN1 =
58 "mode\0" Required_argument "m"
59 "parents\0" No_argument "p"
60#if ENABLE_SELINUX
61 "context\0" Required_argument "Z"
62#endif
63#if ENABLE_FEATURE_VERBOSE
64 "verbose\0" No_argument "v"
65#endif
66 ;
67#endif
68
69int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 51int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
70int mkdir_main(int argc UNUSED_PARAM, char **argv) 52int mkdir_main(int argc UNUSED_PARAM, char **argv)
71{ 53{
@@ -78,10 +60,17 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
78 security_context_t scontext; 60 security_context_t scontext;
79#endif 61#endif
80 62
81#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS 63 opt = getopt32long(argv, "m:pv" IF_SELINUX("Z:"),
82 applet_long_options = mkdir_longopts; 64 "mode\0" Required_argument "m"
83#endif 65 "parents\0" No_argument "p"
84 opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); 66# if ENABLE_SELINUX
67 "context\0" Required_argument "Z"
68# endif
69# if ENABLE_FEATURE_VERBOSE
70 "verbose\0" No_argument "v"
71# endif
72 , &smode IF_SELINUX(,&scontext)
73 );
85 if (opt & 1) { 74 if (opt & 1) {
86 mode_t mmode = bb_parse_mode(smode, 0777); 75 mode_t mmode = bb_parse_mode(smode, 0777);
87 if (mmode == (mode_t)-1) { 76 if (mmode == (mode_t)-1) {
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 147dd3bb2..7f6e9fef5 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -16,11 +16,6 @@
16//config: default y 16//config: default y
17//config: help 17//config: help
18//config: mv is used to move or rename files or directories. 18//config: mv is used to move or rename files or directories.
19//config:
20//config:config FEATURE_MV_LONG_OPTIONS
21//config: bool "Enable long options"
22//config: default y
23//config: depends on MV && LONG_OPTS
24 19
25//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP)) 20//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
26 21
@@ -41,23 +36,6 @@
41#include "libbb.h" 36#include "libbb.h"
42#include "libcoreutils/coreutils.h" 37#include "libcoreutils/coreutils.h"
43 38
44#if ENABLE_FEATURE_MV_LONG_OPTIONS
45static const char mv_longopts[] ALIGN1 =
46 "interactive\0" No_argument "i"
47 "force\0" No_argument "f"
48 "no-clobber\0" No_argument "n"
49 IF_FEATURE_VERBOSE(
50 "verbose\0" No_argument "v"
51 )
52 ;
53#endif
54
55#define OPT_FORCE (1 << 0)
56#define OPT_INTERACTIVE (1 << 1)
57#define OPT_NOCLOBBER (1 << 2)
58#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
59
60
61int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 39int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
62int mv_main(int argc, char **argv) 40int mv_main(int argc, char **argv)
63{ 41{
@@ -69,15 +47,23 @@ int mv_main(int argc, char **argv)
69 int status = 0; 47 int status = 0;
70 int copy_flag = 0; 48 int copy_flag = 0;
71 49
72#if ENABLE_FEATURE_MV_LONG_OPTIONS 50#define OPT_FORCE (1 << 0)
73 applet_long_options = mv_longopts; 51#define OPT_INTERACTIVE (1 << 1)
74#endif 52#define OPT_NOCLOBBER (1 << 2)
53#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
75 /* Need at least two arguments. 54 /* Need at least two arguments.
76 * If more than one of -f, -i, -n is specified , only the final one 55 * If more than one of -f, -i, -n is specified , only the final one
77 * takes effect (it unsets previous options). 56 * takes effect (it unsets previous options).
78 */ 57 */
79 opt_complementary = "-2:f-in:i-fn:n-fi"; 58 opt_complementary = "-2:f-in:i-fn:n-fi";
80 flags = getopt32(argv, "finv"); 59 flags = getopt32long(argv, "finv",
60 "interactive\0" No_argument "i"
61 "force\0" No_argument "f"
62 "no-clobber\0" No_argument "n"
63 IF_FEATURE_VERBOSE(
64 "verbose\0" No_argument "v"
65 )
66 );
81 argc -= optind; 67 argc -= optind;
82 argv += optind; 68 argv += optind;
83 last = argv[argc - 1]; 69 last = argv[argc - 1];
diff --git a/coreutils/nl.c b/coreutils/nl.c
index 93e78c490..c2f8b1042 100644
--- a/coreutils/nl.c
+++ b/coreutils/nl.c
@@ -57,14 +57,13 @@ int nl_main(int argc UNUSED_PARAM, char **argv)
57 "starting-line-number\0"Required_argument "v" 57 "starting-line-number\0"Required_argument "v"
58 "number-width\0" Required_argument "w" 58 "number-width\0" Required_argument "w"
59 ; 59 ;
60
61 applet_long_options = nl_longopts;
62#endif 60#endif
63 ns.width = 6; 61 ns.width = 6;
64 ns.start = 1; 62 ns.start = 1;
65 ns.inc = 1; 63 ns.inc = 1;
66 ns.sep = "\t"; 64 ns.sep = "\t";
67 getopt32(argv, "pw:+s:v:+i:+b:", &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b); 65 getopt32long(argv, "pw:+s:v:+i:+b:", nl_longopts,
66 &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b);
68 ns.all = (opt_b[0] == 'a'); 67 ns.all = (opt_b[0] == 'a');
69 ns.nonempty = (opt_b[0] == 't'); 68 ns.nonempty = (opt_b[0] == 't');
70 ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), ""); 69 ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), "");
diff --git a/coreutils/nproc.c b/coreutils/nproc.c
index 0ae55e70a..336b176ca 100644
--- a/coreutils/nproc.c
+++ b/coreutils/nproc.c
@@ -28,7 +28,6 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
28 unsigned long mask[1024]; 28 unsigned long mask[1024];
29 unsigned i, count = 0; 29 unsigned i, count = 0;
30 30
31 //applet_long_options = ...;
32 //getopt32(argv, ""); 31 //getopt32(argv, "");
33 32
34 //if --all, count /sys/devices/system/cpu/cpuN dirs, else: 33 //if --all, count /sys/devices/system/cpu/cpuN dirs, else:
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index fa0196ca4..f19875c42 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -61,8 +61,8 @@ enum {
61 OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS, 61 OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS,
62}; 62};
63 63
64#define OD_GETOPT32() getopt32(argv, \ 64#define OD_GETOPT32() getopt32long(argv, \
65 "A:N:abcdfhij:lot:*vxsS:w:+:", \ 65 "A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \
66 /* -w with optional param */ \ 66 /* -w with optional param */ \
67 /* -S was -s and also had optional parameter */ \ 67 /* -S was -s and also had optional parameter */ \
68 /* but in coreutils 6.3 it was renamed and now has */ \ 68 /* but in coreutils 6.3 it was renamed and now has */ \
@@ -1213,9 +1213,6 @@ int od_main(int argc UNUSED_PARAM, char **argv)
1213 address_pad_len_char = '7'; 1213 address_pad_len_char = '7';
1214 1214
1215 /* Parse command line */ 1215 /* Parse command line */
1216#if ENABLE_LONG_OPTS
1217 applet_long_options = od_longopts;
1218#endif
1219 opt = OD_GETOPT32(); 1216 opt = OD_GETOPT32();
1220 argv += optind; 1217 argv += optind;
1221 if (opt & OPT_A) { 1218 if (opt & OPT_A) {
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index c04ce78f8..955740494 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -11,14 +11,6 @@
11//config: default y 11//config: default y
12//config: help 12//config: help
13//config: rmdir is used to remove empty directories. 13//config: rmdir is used to remove empty directories.
14//config:
15//config:config FEATURE_RMDIR_LONG_OPTIONS
16//config: bool "Enable long options"
17//config: default y
18//config: depends on RMDIR && LONG_OPTS
19//config: help
20//config: Support long options for the rmdir applet, including
21//config: --ignore-fail-on-non-empty for compatibility with GNU rmdir.
22 14
23//applet:IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) 15//applet:IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir))
24 16
@@ -31,12 +23,9 @@
31//usage: "[OPTIONS] DIRECTORY..." 23//usage: "[OPTIONS] DIRECTORY..."
32//usage:#define rmdir_full_usage "\n\n" 24//usage:#define rmdir_full_usage "\n\n"
33//usage: "Remove DIRECTORY if it is empty\n" 25//usage: "Remove DIRECTORY if it is empty\n"
34//usage: IF_FEATURE_RMDIR_LONG_OPTIONS(
35//usage: "\n -p|--parents Include parents"
36//usage: "\n --ignore-fail-on-non-empty"
37//usage: )
38//usage: IF_NOT_FEATURE_RMDIR_LONG_OPTIONS(
39//usage: "\n -p Include parents" 26//usage: "\n -p Include parents"
27//usage: IF_LONG_OPTS(
28//usage: "\n --ignore-fail-on-non-empty"
40//usage: ) 29//usage: )
41//usage: 30//usage:
42//usage:#define rmdir_example_usage 31//usage:#define rmdir_example_usage
@@ -49,7 +38,7 @@
49 38
50#define PARENTS (1 << 0) 39#define PARENTS (1 << 0)
51#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE) 40#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
52#define IGNORE_NON_EMPTY (1 << 2) 41#define IGNORE_NON_EMPTY ((1 << 2) * ENABLE_LONG_OPTS)
53 42
54int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 43int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
55int rmdir_main(int argc UNUSED_PARAM, char **argv) 44int rmdir_main(int argc UNUSED_PARAM, char **argv)
@@ -58,8 +47,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
58 int flags; 47 int flags;
59 char *path; 48 char *path;
60 49
61#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS 50 flags = getopt32long(argv, "pv",
62 static const char rmdir_longopts[] ALIGN1 =
63 "parents\0" No_argument "p" 51 "parents\0" No_argument "p"
64 /* Debian etch: many packages fail to be purged or installed 52 /* Debian etch: many packages fail to be purged or installed
65 * because they desperately want this option: */ 53 * because they desperately want this option: */
@@ -67,10 +55,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
67 IF_FEATURE_VERBOSE( 55 IF_FEATURE_VERBOSE(
68 "verbose\0" No_argument "v" 56 "verbose\0" No_argument "v"
69 ) 57 )
70 ; 58 );
71 applet_long_options = rmdir_longopts;
72#endif
73 flags = getopt32(argv, "pv");
74 argv += optind; 59 argv += optind;
75 60
76 if (!*argv) { 61 if (!*argv) {
@@ -86,7 +71,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
86 } 71 }
87 72
88 if (rmdir(path) < 0) { 73 if (rmdir(path) < 0) {
89#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS 74#if ENABLE_LONG_OPTS
90 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY) 75 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
91 break; 76 break;
92#endif 77#endif
diff --git a/coreutils/touch.c b/coreutils/touch.c
index 11b40d427..857761578 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -103,6 +103,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
103 "date\0" Required_argument "d" 103 "date\0" Required_argument "d"
104 IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") 104 IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
105 ; 105 ;
106# define GETOPT32 getopt32long
107# define LONGOPTS ,touch_longopts
108# else
109# define GETOPT32 getopt32
110# define LONGOPTS
106# endif 111# endif
107 char *reference_file = NULL; 112 char *reference_file = NULL;
108 char *date_str = NULL; 113 char *date_str = NULL;
@@ -112,17 +117,17 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
112# define reference_file NULL 117# define reference_file NULL
113# define date_str NULL 118# define date_str NULL
114# define timebuf ((struct timeval*)NULL) 119# define timebuf ((struct timeval*)NULL)
120# define GETOPT32 getopt32
121# define LONGOPTS
115#endif 122#endif
116 123
117#if ENABLE_FEATURE_TOUCH_SUSV3 && ENABLE_LONG_OPTS
118 applet_long_options = touch_longopts;
119#endif
120 /* -d and -t both set time. In coreutils, 124 /* -d and -t both set time. In coreutils,
121 * accepted data format differs a bit between -d and -t. 125 * accepted data format differs a bit between -d and -t.
122 * We accept the same formats for both */ 126 * We accept the same formats for both */
123 opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") 127 opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:")
124 IF_FEATURE_TOUCH_NODEREF("h") 128 IF_FEATURE_TOUCH_NODEREF("h")
125 /*ignored:*/ "fma" 129 /*ignored:*/ "fma"
130 LONGOPTS
126 IF_FEATURE_TOUCH_SUSV3(, &reference_file) 131 IF_FEATURE_TOUCH_SUSV3(, &reference_file)
127 IF_FEATURE_TOUCH_SUSV3(, &date_str) 132 IF_FEATURE_TOUCH_SUSV3(, &date_str)
128 IF_FEATURE_TOUCH_SUSV3(, &date_str) 133 IF_FEATURE_TOUCH_SUSV3(, &date_str)
diff --git a/coreutils/uname.c b/coreutils/uname.c
index be9a3f90d..bb2d1fe8d 100644
--- a/coreutils/uname.c
+++ b/coreutils/uname.c
@@ -147,8 +147,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
147 "operating-system\0" No_argument "o" 147 "operating-system\0" No_argument "o"
148 ; 148 ;
149# endif 149# endif
150 IF_LONG_OPTS(applet_long_options = uname_longopts); 150 toprint = getopt32long(argv, options, uname_longopts);
151 toprint = getopt32(argv, options);
152 if (argv[optind]) { /* coreutils-6.9 compat */ 151 if (argv[optind]) { /* coreutils-6.9 compat */
153 bb_show_usage(); 152 bb_show_usage();
154 } 153 }
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c
index c6a90a486..b770383c4 100644
--- a/debianutils/run_parts.c
+++ b/debianutils/run_parts.c
@@ -159,10 +159,15 @@ static const char runparts_longopts[] ALIGN1 =
159 "reverse\0" No_argument "\xf0" 159 "reverse\0" No_argument "\xf0"
160 "test\0" No_argument "\xf1" 160 "test\0" No_argument "\xf1"
161 "exit-on-error\0" No_argument "\xf2" 161 "exit-on-error\0" No_argument "\xf2"
162#if ENABLE_FEATURE_RUN_PARTS_FANCY 162# if ENABLE_FEATURE_RUN_PARTS_FANCY
163 "list\0" No_argument "\xf3" 163 "list\0" No_argument "\xf3"
164#endif 164# endif
165 ; 165 ;
166# define GETOPT32 getopt32long
167# define LONGOPTS ,runparts_longopts
168#else
169# define GETOPT32 getopt32
170# define LONGOPTS
166#endif 171#endif
167 172
168int run_parts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 173int run_parts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -175,12 +180,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
175 180
176 INIT_G(); 181 INIT_G();
177 182
178#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
179 applet_long_options = runparts_longopts;
180#endif
181 /* We require exactly one argument: the directory name */ 183 /* We require exactly one argument: the directory name */
182 opt_complementary = "=1"; 184 opt_complementary = "=1";
183 getopt32(argv, "a:*u:", &arg_list, &umask_p); 185 GETOPT32(argv, "a:*u:" LONGOPTS, &arg_list, &umask_p);
184 186
185 umask(xstrtou_range(umask_p, 8, 0, 07777)); 187 umask(xstrtou_range(umask_p, 8, 0, 07777));
186 188
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 9effdc80b..45c277a53 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -426,6 +426,11 @@ static const char start_stop_daemon_longopts[] ALIGN1 =
426 "retry\0" Required_argument "R" 426 "retry\0" Required_argument "R"
427# endif 427# endif
428 ; 428 ;
429# define GETOPT32 getopt32long
430# define LONGOPTS start_stop_daemon_longopts,
431#else
432# define GETOPT32 getopt32
433# define LONGOPTS
429#endif 434#endif
430 435
431int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 436int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -446,10 +451,6 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
446 451
447 INIT_G(); 452 INIT_G();
448 453
449#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
450 applet_long_options = start_stop_daemon_longopts;
451#endif
452
453 /* -K or -S is required; they are mutually exclusive */ 454 /* -K or -S is required; they are mutually exclusive */
454 /* -p is required if -m is given */ 455 /* -p is required if -m is given */
455 /* -xpun (at least one) is required if -K is given */ 456 /* -xpun (at least one) is required if -K is given */
@@ -457,8 +458,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
457 /* -q turns off -v */ 458 /* -q turns off -v */
458 opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa" 459 opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa"
459 IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"); 460 IF_FEATURE_START_STOP_DAEMON_FANCY("q-v");
460 opt = getopt32(argv, "KSbqtma:n:s:u:c:x:p:" 461 opt = GETOPT32(argv, "KSbqtma:n:s:u:c:x:p:"
461 IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), 462 IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"),
463 LONGOPTS
462 &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile 464 &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile
463 IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) 465 IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N)
464 /* We accept and ignore -R <param> / --retry <param> */ 466 /* We accept and ignore -R <param> / --retry <param> */
diff --git a/editors/diff.c b/editors/diff.c
index 03c13908e..d90ac8f94 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -967,6 +967,11 @@ static const char diff_longopts[] ALIGN1 =
967 "starting-file\0" Required_argument "S" 967 "starting-file\0" Required_argument "S"
968 "minimal\0" No_argument "d" 968 "minimal\0" No_argument "d"
969 ; 969 ;
970# define GETOPT32 getopt32long
971# define LONGOPTS ,diff_longopts
972#else
973# define GETOPT32 getopt32
974# define LONGOPTS
970#endif 975#endif
971 976
972int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 977int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -980,10 +985,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
980 985
981 /* exactly 2 params; collect multiple -L <label>; -U N */ 986 /* exactly 2 params; collect multiple -L <label>; -U N */
982 opt_complementary = "=2"; 987 opt_complementary = "=2";
983#if ENABLE_FEATURE_DIFF_LONG_OPTIONS 988 GETOPT32(argv, "abdiL:*NqrsS:tTU:+wupBE" LONGOPTS,
984 applet_long_options = diff_longopts;
985#endif
986 getopt32(argv, "abdiL:*NqrsS:tTU:+wupBE",
987 &L_arg, &s_start, &opt_U_context); 989 &L_arg, &s_start, &opt_U_context);
988 argv += optind; 990 argv += optind;
989 while (L_arg) 991 while (L_arg)
diff --git a/editors/patch_bbox.c b/editors/patch_bbox.c
index aae7b7987..8e09ef488 100644
--- a/editors/patch_bbox.c
+++ b/editors/patch_bbox.c
@@ -111,10 +111,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
111 "no-backup-if-mismatch\0" No_argument "\xff" /*ignored*/ 111 "no-backup-if-mismatch\0" No_argument "\xff" /*ignored*/
112# endif 112# endif
113 ; 113 ;
114 applet_long_options = patch_longopts;
115#endif 114#endif
116 /* -f,-E,-g are ignored */ 115 /* -f,-E,-g are ignored */
117 opt = getopt32(argv, "p:i:RN""fEg:", &p, &i, NULL); 116 opt = getopt32long(argv, "p:i:RN""fEg:", patch_longopts, &p, &i, NULL);
118 if (opt & OPT_R) 117 if (opt & OPT_R)
119 plus = '-'; 118 plus = '-';
120 patch_level = xatoi(p); /* can be negative! */ 119 patch_level = xatoi(p); /* can be negative! */
diff --git a/editors/sed.c b/editors/sed.c
index 22580cf71..1a1098859 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1508,16 +1508,14 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1508 opt_e = opt_f = NULL; 1508 opt_e = opt_f = NULL;
1509 opt_i = NULL; 1509 opt_i = NULL;
1510 opt_complementary = "nn"; /* count -n */ 1510 opt_complementary = "nn"; /* count -n */
1511
1512 IF_LONG_OPTS(applet_long_options = sed_longopts);
1513
1514 /* -i must be first, to match OPT_in_place definition */ 1511 /* -i must be first, to match OPT_in_place definition */
1515 /* -E is a synonym of -r: 1512 /* -E is a synonym of -r:
1516 * GNU sed 4.2.1 mentions it in neither --help 1513 * GNU sed 4.2.1 mentions it in neither --help
1517 * nor manpage, but does recognize it. 1514 * nor manpage, but does recognize it.
1518 */ 1515 */
1519 opt = getopt32(argv, "i::rEne:*f:*", &opt_i, &opt_e, &opt_f, 1516 opt = getopt32long(argv, "i::rEne:*f:*", sed_longopts,
1520 &G.be_quiet); /* counter for -n */ 1517 &opt_i, &opt_e, &opt_f,
1518 &G.be_quiet); /* counter for -n */
1521 //argc -= optind; 1519 //argc -= optind;
1522 argv += optind; 1520 argv += optind;
1523 if (opt & OPT_in_place) { // -i 1521 if (opt & OPT_in_place) { // -i
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 2d0d1c8b9..c3d37a64d 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -495,13 +495,8 @@ int xargs_main(int argc, char **argv)
495 495
496 INIT_G(); 496 INIT_G();
497 497
498#if ENABLE_DESKTOP && ENABLE_LONG_OPTS 498 opt = getopt32long(argv, OPTION_STR,
499 /* For example, Fedora's build system uses --no-run-if-empty */ 499 "no-run-if-empty\0" No_argument "r",
500 applet_long_options =
501 "no-run-if-empty\0" No_argument "r"
502 ;
503#endif
504 opt = getopt32(argv, OPTION_STR,
505 &max_args, &max_chars, &G.eof_str, &G.eof_str 500 &max_args, &max_chars, &G.eof_str, &G.eof_str
506 IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str) 501 IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str)
507 ); 502 );
diff --git a/include/libbb.h b/include/libbb.h
index 3f3e033fe..64d1f2fcb 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1180,19 +1180,24 @@ void bb_sanitize_stdio(void) FAST_FUNC;
1180int sanitize_env_if_suid(void) FAST_FUNC; 1180int sanitize_env_if_suid(void) FAST_FUNC;
1181 1181
1182 1182
1183/* For top, ps. Some argv[i] are replaced by malloced "-opt" strings */
1184void make_all_argv_opts(char **argv) FAST_FUNC;
1183char* single_argv(char **argv) FAST_FUNC; 1185char* single_argv(char **argv) FAST_FUNC;
1184extern const char *const bb_argv_dash[]; /* "-", NULL */ 1186extern const char *const bb_argv_dash[]; /* { "-", NULL } */
1185extern const char *opt_complementary;
1186#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG
1187#define No_argument "\0"
1188#define Required_argument "\001"
1189#define Optional_argument "\002"
1190extern const char *applet_long_options;
1191#endif
1192extern uint32_t option_mask32; 1187extern uint32_t option_mask32;
1188//TODO: get rid of this global variable. How about a trick where optstring can be
1189// "^optchars""\0""complementary" (the leading "^" is an indicator)?
1190extern const char *opt_complementary;
1193uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; 1191uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
1194/* For top, ps. Some argv[i] are replaced by malloced "-opt" strings */ 1192# define No_argument "\0"
1195void make_all_argv_opts(char **argv) FAST_FUNC; 1193# define Required_argument "\001"
1194# define Optional_argument "\002"
1195#if ENABLE_LONG_OPTS
1196uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...) FAST_FUNC;
1197#else
1198#define getopt32long(argv,optstring,longopts,...) \
1199 getopt32(argv,optstring,##__VA_ARGS__)
1200#endif
1196/* BSD-derived getopt() functions require that optind be set to 1 in 1201/* BSD-derived getopt() functions require that optind be set to 1 in
1197 * order to reset getopt() state. This used to be generally accepted 1202 * order to reset getopt() state. This used to be generally accepted
1198 * way of resetting getopt(). However, glibc's getopt() 1203 * way of resetting getopt(). However, glibc's getopt()
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 513415894..b2b4de8cb 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG 9#if ENABLE_LONG_OPTS
10# include <getopt.h> 10# include <getopt.h>
11#endif 11#endif
12#include "libbb.h" 12#include "libbb.h"
@@ -99,17 +99,18 @@ getopt32(char **argv, const char *applet_opts, ...)
99 "!" Report bad option, missing required options, 99 "!" Report bad option, missing required options,
100 inconsistent options with all-ones return value (instead of abort). 100 inconsistent options with all-ones return value (instead of abort).
101 101
102const char *applet_long_options 102uint32_t
103getopt32long(char **argv, const char *applet_opts, const char *logopts...)
103 104
104 This struct allows you to define long options: 105 This allows you to define long options:
105 106
106 static const char applet_longopts[] ALIGN1 = 107 static const char applet_longopts[] ALIGN1 =
107 //"name\0" has_arg val 108 //"name\0" has_arg val
108 "verbose\0" No_argument "v" 109 "verbose\0" No_argument "v"
109 ; 110 ;
110 applet_long_options = applet_longopts; 111 opt = getopt32long(argv, applet_opts, applet_longopts, ...);
111 112
112 The last member of struct option (val) typically is set to 113 The last element (val) typically is set to
113 matching short option from applet_opts. If there is no matching 114 matching short option from applet_opts. If there is no matching
114 char in applet_opts, then: 115 char in applet_opts, then:
115 - return bit has next position after short options 116 - return bit has next position after short options
@@ -317,20 +318,21 @@ typedef struct {
317 int *counter; 318 int *counter;
318} t_complementary; 319} t_complementary;
319 320
320/* You can set applet_long_options for parse called long options */ 321uint32_t option_mask32;
321#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG 322
323#if ENABLE_LONG_OPTS
322static const struct option bb_null_long_options[1] = { 324static const struct option bb_null_long_options[1] = {
323 { 0, 0, 0, 0 } 325 { 0, 0, 0, 0 }
324}; 326};
325const char *applet_long_options; 327#else
328#define vgetopt32(argv,applet_opts,applet_long_options,p) \
329 vgetopt32(argv,applet_opts,p)
326#endif 330#endif
327 331
328uint32_t option_mask32;
329
330/* Please keep getopt32 free from xmalloc */ 332/* Please keep getopt32 free from xmalloc */
331 333
332uint32_t FAST_FUNC 334static uint32_t
333getopt32(char **argv, const char *applet_opts, ...) 335vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, va_list p)
334{ 336{
335 int argc; 337 int argc;
336 unsigned flags = 0; 338 unsigned flags = 0;
@@ -340,8 +342,7 @@ getopt32(char **argv, const char *applet_opts, ...)
340 int c; 342 int c;
341 const unsigned char *s; 343 const unsigned char *s;
342 t_complementary *on_off; 344 t_complementary *on_off;
343 va_list p; 345#if ENABLE_LONG_OPTS
344#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG
345 const struct option *l_o; 346 const struct option *l_o;
346 struct option *long_options = (struct option *) &bb_null_long_options; 347 struct option *long_options = (struct option *) &bb_null_long_options;
347#endif 348#endif
@@ -356,8 +357,6 @@ getopt32(char **argv, const char *applet_opts, ...)
356 /* skip 0: some applets cheat: they do not actually HAVE argv[0] */ 357 /* skip 0: some applets cheat: they do not actually HAVE argv[0] */
357 argc = 1 + string_array_len(argv + 1); 358 argc = 1 + string_array_len(argv + 1);
358 359
359 va_start(p, applet_opts);
360
361 on_off = complementary; 360 on_off = complementary;
362 memset(on_off, 0, sizeof(complementary)); 361 memset(on_off, 0, sizeof(complementary));
363 362
@@ -394,7 +393,7 @@ getopt32(char **argv, const char *applet_opts, ...)
394 c++; 393 c++;
395 } 394 }
396 395
397#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG 396#if ENABLE_LONG_OPTS
398 if (applet_long_options) { 397 if (applet_long_options) {
399 const char *optstr; 398 const char *optstr;
400 unsigned i, count; 399 unsigned i, count;
@@ -433,12 +432,8 @@ getopt32(char **argv, const char *applet_opts, ...)
433 c++; 432 c++;
434 next_long: ; 433 next_long: ;
435 } 434 }
436 /* Make it unnecessary to clear applet_long_options
437 * by hand after each call to getopt32
438 */
439 applet_long_options = NULL;
440 } 435 }
441#endif /* ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG */ 436#endif /* ENABLE_LONG_OPTS */
442 437
443 for (s = (const unsigned char *)opt_complementary; s && *s; s++) { 438 for (s = (const unsigned char *)opt_complementary; s && *s; s++) {
444 t_complementary *pair; 439 t_complementary *pair;
@@ -517,9 +512,9 @@ getopt32(char **argv, const char *applet_opts, ...)
517 } 512 }
518 s--; 513 s--;
519 } 514 }
520 opt_complementary = NULL;
521 va_end(p);
522 515
516 /* Make it unnecessary to clear it by hand after each getopt32 call */
517 opt_complementary = NULL;
523 /* In case getopt32 was already called: 518 /* In case getopt32 was already called:
524 * reset the libc getopt() function, which keeps internal state. 519 * reset the libc getopt() function, which keeps internal state.
525 * run_nofork_applet() does this, but we might end up here 520 * run_nofork_applet() does this, but we might end up here
@@ -531,7 +526,7 @@ getopt32(char **argv, const char *applet_opts, ...)
531 * "fake" short options, like this one: 526 * "fake" short options, like this one:
532 * wget $'-\203' "Test: test" http://kernel.org/ 527 * wget $'-\203' "Test: test" http://kernel.org/
533 * (supposed to act as --header, but doesn't) */ 528 * (supposed to act as --header, but doesn't) */
534#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG 529#if ENABLE_LONG_OPTS
535 while ((c = getopt_long(argc, argv, applet_opts, 530 while ((c = getopt_long(argc, argv, applet_opts,
536 long_options, NULL)) != -1) { 531 long_options, NULL)) != -1) {
537#else 532#else
@@ -592,3 +587,29 @@ getopt32(char **argv, const char *applet_opts, ...)
592 bb_show_usage(); 587 bb_show_usage();
593 return (int32_t)-1; 588 return (int32_t)-1;
594} 589}
590
591uint32_t FAST_FUNC
592getopt32(char **argv, const char *applet_opts, ...)
593{
594 uint32_t opt;
595 va_list p;
596
597 va_start(p, applet_opts);
598 opt = vgetopt32(argv, applet_opts, NULL, p);
599 va_end(p);
600 return opt;
601}
602
603#if ENABLE_LONG_OPTS
604uint32_t FAST_FUNC
605getopt32long(char **argv, const char *applet_opts, const char *longopts, ...)
606{
607 uint32_t opt;
608 va_list p;
609
610 va_start(p, longopts);
611 opt = vgetopt32(argv, applet_opts, longopts, p);
612 va_end(p);
613 return opt;
614}
615#endif
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index e55847f93..15c92a7cd 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -45,14 +45,15 @@ static void jump(void)
45{ 45{
46 /* Special case. We arrive here if NOFORK applet 46 /* Special case. We arrive here if NOFORK applet
47 * calls xfunc, which then decides to die. 47 * calls xfunc, which then decides to die.
48 * We don't die, but jump instead back to caller. 48 * We don't die, but instead jump back to caller.
49 * NOFORK applets still cannot carelessly call xfuncs: 49 * NOFORK applets still cannot carelessly call xfuncs:
50 * p = xmalloc(10); 50 * p = xmalloc(10);
51 * q = xmalloc(10); // BUG! if this dies, we leak p! 51 * q = xmalloc(10); // BUG! if this dies, we leak p!
52 */ 52 */
53 /* | 0x100 allows to pass zero exitcode (longjmp can't pass 0). 53 /* | 0x100 allows to pass zero exitcode (longjmp can't pass 0).
54 * This works because exitcodes are bytes, 54 * This works because exitcodes are bytes,
55 * run_nofork_applet() ensures that by "& 0xff" */ 55 * run_nofork_applet() ensures that by "& 0xff"
56 */
56 longjmp(die_jmp, xfunc_error_retval | 0x100); 57 longjmp(die_jmp, xfunc_error_retval | 0x100);
57} 58}
58 59
@@ -92,12 +93,12 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
92 93
93 logmode = LOGMODE_STDIO; 94 logmode = LOGMODE_STDIO;
94 xfunc_error_retval = EXIT_FAILURE; 95 xfunc_error_retval = EXIT_FAILURE;
95 /* In case getopt() or getopt32() was already called: 96 /* In case getopt() was already called:
96 * reset the libc getopt() function, which keeps internal state. 97 * reset the libc getopt() function, which keeps internal state.
98 * (getopt32() does it itself, but getopt() doesn't (and can't))
97 */ 99 */
98 GETOPT_RESET(); 100 GETOPT_RESET();
99//? applet_long_options = NULL; 101 /* opt_complementary = NULL; - cleared by each getopt32() call anyway */
100//? opt_complementary = NULL;
101 102
102 argc = string_array_len(argv); 103 argc = string_array_len(argv);
103 104
@@ -122,8 +123,7 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
122 restore_nofork_data(&old); 123 restore_nofork_data(&old);
123 /* Other globals can be simply reset to defaults */ 124 /* Other globals can be simply reset to defaults */
124 GETOPT_RESET(); 125 GETOPT_RESET();
125//? applet_long_options = NULL; 126 /* opt_complementary = NULL; - cleared by each getopt32() call anyway */
126//? opt_complementary = NULL;
127 127
128 return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ 128 return rc & 0xff; /* don't confuse people with "exitcodes" >255 */
129} 129}
@@ -138,8 +138,7 @@ void FAST_FUNC run_noexec_applet_and_exit(int a, const char *name, char **argv)
138 xfunc_error_retval = EXIT_FAILURE; 138 xfunc_error_retval = EXIT_FAILURE;
139 die_func = NULL; 139 die_func = NULL;
140 GETOPT_RESET(); 140 GETOPT_RESET();
141//? applet_long_options = NULL; 141 /* opt_complementary = NULL; - cleared by each getopt32() call anyway */
142//? opt_complementary = NULL;
143 142
144//TODO: think pidof, pgrep, pkill! 143//TODO: think pidof, pgrep, pkill!
145//set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"), 144//set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"),
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index 30f7e72dc..5a2b04352 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -12,14 +12,10 @@
12//config:config ADDGROUP 12//config:config ADDGROUP
13//config: bool "addgroup (8.2 kb)" 13//config: bool "addgroup (8.2 kb)"
14//config: default y 14//config: default y
15//config: select LONG_OPTS
15//config: help 16//config: help
16//config: Utility for creating a new group account. 17//config: Utility for creating a new group account.
17//config: 18//config:
18//config:config FEATURE_ADDGROUP_LONG_OPTIONS
19//config: bool "Enable long options"
20//config: default y
21//config: depends on ADDGROUP && LONG_OPTS
22//config:
23//config:config FEATURE_ADDUSER_TO_GROUP 19//config:config FEATURE_ADDUSER_TO_GROUP
24//config: bool "Support adding users to groups" 20//config: bool "Support adding users to groups"
25//config: default y 21//config: default y
@@ -131,12 +127,11 @@ static void new_group(char *group, gid_t gid)
131#endif 127#endif
132} 128}
133 129
134#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS 130//FIXME: upstream addgroup has no short options! NOT COMPATIBLE!
135static const char addgroup_longopts[] ALIGN1 = 131static const char addgroup_longopts[] ALIGN1 =
136 "gid\0" Required_argument "g" 132 "gid\0" Required_argument "g"
137 "system\0" No_argument "S" 133 "system\0" No_argument "S"
138 ; 134 ;
139#endif
140 135
141/* 136/*
142 * addgroup will take a login_name as its first parameter. 137 * addgroup will take a login_name as its first parameter.
@@ -155,16 +150,13 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
155 if (geteuid()) { 150 if (geteuid()) {
156 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 151 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
157 } 152 }
158#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS
159 applet_long_options = addgroup_longopts;
160#endif
161 /* Syntax: 153 /* Syntax:
162 * addgroup group 154 * addgroup group
163 * addgroup -g num group 155 * addgroup -g num group
164 * addgroup user group 156 * addgroup user group
165 * Check for min, max and missing args */ 157 * Check for min, max and missing args */
166 opt_complementary = "-1:?2"; 158 opt_complementary = "-1:?2";
167 opts = getopt32(argv, "g:S", &gid); 159 opts = getopt32long(argv, "g:S", addgroup_longopts, &gid);
168 /* move past the commandline options */ 160 /* move past the commandline options */
169 argv += optind; 161 argv += optind;
170 //argc -= optind; 162 //argc -= optind;
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index 913dbaf83..8b92df923 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -10,14 +10,10 @@
10//config:config ADDUSER 10//config:config ADDUSER
11//config: bool "adduser (15 kb)" 11//config: bool "adduser (15 kb)"
12//config: default y 12//config: default y
13//config: select LONG_OPTS
13//config: help 14//config: help
14//config: Utility for creating a new user account. 15//config: Utility for creating a new user account.
15//config: 16//config:
16//config:config FEATURE_ADDUSER_LONG_OPTIONS
17//config: bool "Enable long options"
18//config: default y
19//config: depends on ADDUSER && LONG_OPTS
20//config:
21//config:config FEATURE_CHECK_NAMES 17//config:config FEATURE_CHECK_NAMES
22//config: bool "Enable sanity check on user/group names in adduser and addgroup" 18//config: bool "Enable sanity check on user/group names in adduser and addgroup"
23//config: default n 19//config: default n
@@ -148,15 +144,7 @@ static int addgroup_wrapper(struct passwd *p, const char *group_name)
148 /* Add user to his own group with the first free gid 144 /* Add user to his own group with the first free gid
149 * found in passwd_study. 145 * found in passwd_study.
150 */ 146 */
151#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS || !ENABLE_ADDGROUP
152 /* We try to use --gid, not -g, because "standard" addgroup
153 * has no short option -g, it has only long --gid.
154 */
155 argv[1] = (char*)"--gid"; 147 argv[1] = (char*)"--gid";
156#else
157 /* Breaks if system in fact does NOT use busybox addgroup */
158 argv[1] = (char*)"-g";
159#endif
160 argv[2] = utoa(p->pw_gid); 148 argv[2] = utoa(p->pw_gid);
161 argv[3] = (char*)"--"; 149 argv[3] = (char*)"--";
162 argv[4] = p->pw_name; 150 argv[4] = p->pw_name;
@@ -174,7 +162,7 @@ static void passwd_wrapper(const char *login_name)
174 bb_error_msg_and_die("can't execute passwd, you must set password manually"); 162 bb_error_msg_and_die("can't execute passwd, you must set password manually");
175} 163}
176 164
177#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS 165//FIXME: upstream adduser has no short options! NOT COMPATIBLE!
178static const char adduser_longopts[] ALIGN1 = 166static const char adduser_longopts[] ALIGN1 =
179 "home\0" Required_argument "h" 167 "home\0" Required_argument "h"
180 "gecos\0" Required_argument "g" 168 "gecos\0" Required_argument "g"
@@ -187,7 +175,6 @@ static const char adduser_longopts[] ALIGN1 =
187 "uid\0" Required_argument "u" 175 "uid\0" Required_argument "u"
188 "skel\0" Required_argument "k" 176 "skel\0" Required_argument "k"
189 ; 177 ;
190#endif
191 178
192/* 179/*
193 * adduser will take a login_name as its first parameter. 180 * adduser will take a login_name as its first parameter.
@@ -204,10 +191,6 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
204 char *uid; 191 char *uid;
205 const char *skel = "/etc/skel"; 192 const char *skel = "/etc/skel";
206 193
207#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
208 applet_long_options = adduser_longopts;
209#endif
210
211 /* got root? */ 194 /* got root? */
212 if (geteuid()) { 195 if (geteuid()) {
213 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 196 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
@@ -221,7 +204,9 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
221 /* at least one and at most two non-option args */ 204 /* at least one and at most two non-option args */
222 /* disable interactive passwd for system accounts */ 205 /* disable interactive passwd for system accounts */
223 opt_complementary = "-1:?2:SD"; 206 opt_complementary = "-1:?2:SD";
224 opts = getopt32(argv, "h:g:s:G:DSHu:k:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid, &skel); 207 opts = getopt32long(argv, "h:g:s:G:DSHu:k:", adduser_longopts,
208 &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell,
209 &usegroup, &uid, &skel);
225 if (opts & OPT_UID) 210 if (opts & OPT_UID)
226 pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID); 211 pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID);
227 212
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c
index e390da647..3c9ed68b9 100644
--- a/loginutils/chpasswd.c
+++ b/loginutils/chpasswd.c
@@ -62,8 +62,7 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv)
62 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 62 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
63 63
64 opt_complementary = "m--ec:e--mc:c--em"; 64 opt_complementary = "m--ec:e--mc:c--em";
65 IF_LONG_OPTS(applet_long_options = chpasswd_longopts;) 65 opt = getopt32long(argv, "emc:", chpasswd_longopts, &algo);
66 opt = getopt32(argv, "emc:", &algo);
67 66
68 while ((name = xmalloc_fgetline(stdin)) != NULL) { 67 while ((name = xmalloc_fgetline(stdin)) != NULL) {
69 char *free_me; 68 char *free_me;
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
index 136c619bb..c10a0c8bd 100644
--- a/loginutils/cryptpw.c
+++ b/loginutils/cryptpw.c
@@ -106,14 +106,14 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
106 "salt\0" Required_argument "S" 106 "salt\0" Required_argument "S"
107 "method\0" Required_argument "m" 107 "method\0" Required_argument "m"
108 ; 108 ;
109 applet_long_options = mkpasswd_longopts;
110#endif 109#endif
111 fd = STDIN_FILENO; 110 fd = STDIN_FILENO;
112 opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; 111 opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
113 opt_S = NULL; 112 opt_S = NULL;
114 /* at most two non-option arguments; -P NUM */ 113 /* at most two non-option arguments; -P NUM */
115 opt_complementary = "?2"; 114 opt_complementary = "?2";
116 getopt32(argv, "sP:+S:m:a:", &fd, &opt_S, &opt_m, &opt_m); 115 getopt32long(argv, "sP:+S:m:a:", mkpasswd_longopts,
116 &fd, &opt_S, &opt_m, &opt_m);
117 argv += optind; 117 argv += optind;
118 118
119 /* have no idea how to handle -s... */ 119 /* have no idea how to handle -s... */
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index f5bc3c28a..5ee22d4f1 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -68,9 +68,8 @@ int deluser_main(int argc, char **argv)
68#else 68#else
69 int opt_delhome = 0; 69 int opt_delhome = 0;
70 if (do_deluser) { 70 if (do_deluser) {
71 applet_long_options = 71 opt_delhome = getopt32long(argv, "",
72 "remove-home\0" No_argument "\xff"; 72 "remove-home\0" No_argument "\xff");
73 opt_delhome = getopt32(argv, "");
74 argv += opt_delhome; 73 argv += opt_delhome;
75 argc -= opt_delhome; 74 argc -= opt_delhome;
76 } 75 }
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 22b29cbf3..a0e0d4e4b 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -377,8 +377,6 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
377 "follow\0" No_argument "f" 377 "follow\0" No_argument "f"
378 "framebuffer\0" No_argument "F" 378 "framebuffer\0" No_argument "F"
379 ; 379 ;
380
381 applet_long_options = conspy_longopts;
382#endif 380#endif
383#define keybuf bb_common_bufsiz1 381#define keybuf bb_common_bufsiz1
384 setup_common_bufsiz(); 382 setup_common_bufsiz();
@@ -387,7 +385,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
387 strcpy(G.vcsa_name, DEV_VCSA); 385 strcpy(G.vcsa_name, DEV_VCSA);
388 386
389 // numeric params 387 // numeric params
390 opts = getopt32(argv, "vcQsndfFx:+y:+", &G.x, &G.y); 388 opts = getopt32long(argv, "vcQsndfFx:+y:+", conspy_longopts, &G.x, &G.y);
391 argv += optind; 389 argv += optind;
392 ttynum = 0; 390 ttynum = 0;
393 if (argv[0]) { 391 if (argv[0]) {
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
index 14b1ed056..5986ab272 100644
--- a/miscutils/nandwrite.c
+++ b/miscutils/nandwrite.c
@@ -124,11 +124,9 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
124 124
125 if (IS_NANDDUMP) { 125 if (IS_NANDDUMP) {
126 opt_complementary = "=1"; 126 opt_complementary = "=1";
127#if ENABLE_LONG_OPTS 127 opts = getopt32long(argv, "ons:f:l:",
128 applet_long_options = 128 "bb\0" Required_argument "\xff", /* no short equivalent */
129 "bb\0" Required_argument "\xff"; /* no short equivalent */ 129 &opt_s, &opt_f, &opt_l, &opt_bb);
130#endif
131 opts = getopt32(argv, "ons:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb);
132 } else { /* nandwrite */ 130 } else { /* nandwrite */
133 opt_complementary = "-1:?2"; 131 opt_complementary = "-1:?2";
134 opts = getopt32(argv, "pns:", &opt_s); 132 opts = getopt32(argv, "pns:", &opt_s);
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index e899935c4..2dac8a895 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -566,9 +566,8 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
566 566
567 INIT_G(); 567 INIT_G();
568 568
569 IF_LONG_OPTS(applet_long_options = modprobe_longopts;)
570 opt_complementary = MODPROBE_COMPLEMENTARY; 569 opt_complementary = MODPROBE_COMPLEMENTARY;
571 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS); 570 opt = getopt32long(argv, INSMOD_OPTS MODPROBE_OPTS, modprobe_longopts INSMOD_ARGS);
572 argv += optind; 571 argv += optind;
573 572
574 /* Goto modules location */ 573 /* Goto modules location */
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index d70f4ca77..1fc20364f 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -361,12 +361,14 @@ int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
361 /* 361 /*
362 * Decipher the command line 362 * Decipher the command line
363 */ 363 */
364 opt_complementary = "-2:vv:cc"; /* must have 2 to 3 params; -v and -c count */
364#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS 365#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
365 applet_long_options = ftpgetput_longopts; 366 getopt32long(argv, "cvu:p:P:", ftpgetput_longopts,
367#else
368 getopt32(argv, "cvu:p:P:",
366#endif 369#endif
367 opt_complementary = "-2:vv:cc"; /* must have 2 to 3 params; -v and -c count */ 370 &user, &password, &port, &verbose_flag, &do_continue
368 getopt32(argv, "cvu:p:P:", &user, &password, &port, 371 );
369 &verbose_flag, &do_continue);
370 argv += optind; 372 argv += optind;
371 373
372 /* We want to do exactly _one_ DNS lookup, since some 374 /* We want to do exactly _one_ DNS lookup, since some
diff --git a/networking/hostname.c b/networking/hostname.c
index ea0ff95b7..d87f6562f 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -132,8 +132,9 @@ int hostname_main(int argc UNUSED_PARAM, char **argv)
132 char *buf; 132 char *buf;
133 char *hostname_str; 133 char *hostname_str;
134 134
135#if ENABLE_LONG_OPTS 135 /* dnsdomainname from net-tools 1.60, hostname 1.100 (2001-04-14),
136 applet_long_options = 136 * supports hostname's options too (not just -v as manpage says) */
137 opts = getopt32(argv, "dfisF:v", &hostname_str,
137 "domain\0" No_argument "d" 138 "domain\0" No_argument "d"
138 "fqdn\0" No_argument "f" 139 "fqdn\0" No_argument "f"
139 //Enable if seen in active use in some distro: 140 //Enable if seen in active use in some distro:
@@ -142,12 +143,7 @@ int hostname_main(int argc UNUSED_PARAM, char **argv)
142 // "short\0" No_argument "s" 143 // "short\0" No_argument "s"
143 // "verbose\0" No_argument "v" 144 // "verbose\0" No_argument "v"
144 "file\0" No_argument "F" 145 "file\0" No_argument "F"
145 ; 146 );
146
147#endif
148 /* dnsdomainname from net-tools 1.60, hostname 1.100 (2001-04-14),
149 * supports hostname's options too (not just -v as manpage says) */
150 opts = getopt32(argv, "dfisF:v", &hostname_str);
151 argv += optind; 147 argv += optind;
152 buf = safe_gethostname(); 148 buf = safe_gethostname();
153 if (ENABLE_DNSDOMAINNAME) { 149 if (ENABLE_DNSDOMAINNAME) {
diff --git a/networking/ifenslave.c b/networking/ifenslave.c
index a845c4e7e..5e769b61d 100644
--- a/networking/ifenslave.c
+++ b/networking/ifenslave.c
@@ -493,19 +493,15 @@ int ifenslave_main(int argc UNUSED_PARAM, char **argv)
493 OPT_d = (1 << 1), 493 OPT_d = (1 << 1),
494 OPT_f = (1 << 2), 494 OPT_f = (1 << 2),
495 }; 495 };
496#if ENABLE_LONG_OPTS 496
497 static const char ifenslave_longopts[] ALIGN1 = 497 INIT_G();
498
499 opt = getopt32long(argv, "cdfa",
498 "change-active\0" No_argument "c" 500 "change-active\0" No_argument "c"
499 "detach\0" No_argument "d" 501 "detach\0" No_argument "d"
500 "force\0" No_argument "f" 502 "force\0" No_argument "f"
501 /* "all-interfaces\0" No_argument "a" */ 503 /* "all-interfaces\0" No_argument "a" */
502 ; 504 );
503
504 applet_long_options = ifenslave_longopts;
505#endif
506 INIT_G();
507
508 opt = getopt32(argv, "cdfa");
509 argv += optind; 505 argv += optind;
510 if (opt & (opt-1)) /* Only one option can be given */ 506 if (opt & (opt-1)) /* Only one option can be given */
511 bb_show_usage(); 507 bb_show_usage();
diff --git a/networking/ipcalc.c b/networking/ipcalc.c
index 83937828f..1d5db969c 100644
--- a/networking/ipcalc.c
+++ b/networking/ipcalc.c
@@ -108,6 +108,11 @@ int get_prefix(unsigned long netmask);
108 "silent\0" No_argument "s" // don’t ever display error messages 108 "silent\0" No_argument "s" // don’t ever display error messages
109# endif 109# endif
110 ; 110 ;
111# define GETOPT32 getopt32long
112# define LONGOPTS ,ipcalc_longopts
113#else
114# define GETOPT32 getopt32
115# define LONGOPTS
111#endif 116#endif
112 117
113int ipcalc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 118int ipcalc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -125,11 +130,8 @@ int ipcalc_main(int argc UNUSED_PARAM, char **argv)
125#define ipaddr (s_ipaddr.s_addr) 130#define ipaddr (s_ipaddr.s_addr)
126 char *ipstr; 131 char *ipstr;
127 132
128#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
129 applet_long_options = ipcalc_longopts;
130#endif
131 opt_complementary = "-1:?2"; /* minimum 1 arg, maximum 2 args */ 133 opt_complementary = "-1:?2"; /* minimum 1 arg, maximum 2 args */
132 opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs")); 134 opt = GETOPT32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs") LONGOPTS);
133 argv += optind; 135 argv += optind;
134 if (opt & SILENT) 136 if (opt & SILENT)
135 logmode = LOGMODE_NONE; /* suppress error_msg() output */ 137 logmode = LOGMODE_NONE; /* suppress error_msg() output */
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 43081efca..84969aa81 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -1103,12 +1103,12 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1103 /* Parse command line */ 1103 /* Parse command line */
1104 /* O,x: list; -T,-t,-A take numeric param */ 1104 /* O,x: list; -T,-t,-A take numeric param */
1105 IF_UDHCP_VERBOSE(opt_complementary = "vv";) 1105 IF_UDHCP_VERBOSE(opt_complementary = "vv";)
1106 IF_LONG_OPTS(applet_long_options = udhcpc6_longopts;) 1106 opt = getopt32long(argv, "i:np:qRr:s:T:+t:+SA:+O:*ox:*f"
1107 opt = getopt32(argv, "i:np:qRr:s:T:+t:+SA:+O:*ox:*f"
1108 USE_FOR_MMU("b") 1107 USE_FOR_MMU("b")
1109 ///IF_FEATURE_UDHCPC_ARPING("a") 1108 ///IF_FEATURE_UDHCPC_ARPING("a")
1110 IF_FEATURE_UDHCP_PORT("P:") 1109 IF_FEATURE_UDHCP_PORT("P:")
1111 "v" 1110 "v"
1111 , udhcpc6_longopts
1112 , &client_config.interface, &client_config.pidfile, &str_r /* i,p */ 1112 , &client_config.interface, &client_config.pidfile, &str_r /* i,p */
1113 , &client_config.script /* s */ 1113 , &client_config.script /* s */
1114 , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ 1114 , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index ccf04993d..5f87f8586 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1297,12 +1297,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1297 /* Parse command line */ 1297 /* Parse command line */
1298 /* O,x: list; -T,-t,-A take numeric param */ 1298 /* O,x: list; -T,-t,-A take numeric param */
1299 IF_UDHCP_VERBOSE(opt_complementary = "vv";) 1299 IF_UDHCP_VERBOSE(opt_complementary = "vv";)
1300 IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) 1300 opt = getopt32long(argv, "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
1301 opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
1302 USE_FOR_MMU("b") 1301 USE_FOR_MMU("b")
1303 IF_FEATURE_UDHCPC_ARPING("a::") 1302 IF_FEATURE_UDHCPC_ARPING("a::")
1304 IF_FEATURE_UDHCP_PORT("P:") 1303 IF_FEATURE_UDHCP_PORT("P:")
1305 "v" 1304 "v"
1305 , udhcpc_longopts
1306 , &str_V, &str_h, &str_h, &str_F 1306 , &str_V, &str_h, &str_h, &str_F
1307 , &client_config.interface, &client_config.pidfile, &str_r /* i,p */ 1307 , &client_config.interface, &client_config.pidfile, &str_r /* i,p */
1308 , &client_config.script /* s */ 1308 , &client_config.script /* s */
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 8aafc0d57..fb1860ff6 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -51,12 +51,11 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
51 "decimal\0" No_argument "d" 51 "decimal\0" No_argument "d"
52 ; 52 ;
53 53
54 applet_long_options = dumpleases_longopts;
55#endif 54#endif
56 init_unicode(); 55 init_unicode();
57 56
58 opt_complementary = "=0:a--r:r--a"; 57 opt_complementary = "=0:a--r:r--a";
59 opt = getopt32(argv, "arf:d", &file); 58 opt = getopt32long(argv, "arf:d", dumpleases_longopts, &file);
60 59
61 fd = xopen(file, O_RDONLY); 60 fd = xopen(file, O_RDONLY);
62 61
diff --git a/networking/wget.c b/networking/wget.c
index e47c9a51b..b661f727b 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -1365,6 +1365,11 @@ IF_DESKTOP( "no-clobber\0" No_argument "\xf0")
1365IF_DESKTOP( "no-host-directories\0" No_argument "\xf0") 1365IF_DESKTOP( "no-host-directories\0" No_argument "\xf0")
1366IF_DESKTOP( "no-parent\0" No_argument "\xf0") 1366IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1367 ; 1367 ;
1368# define GETOPT32 getopt32long
1369# define LONGOPTS ,wget_longopts
1370#else
1371# define GETOPT32 getopt32
1372# define LONGOPTS
1368#endif 1373#endif
1369 1374
1370#if ENABLE_FEATURE_WGET_LONG_OPTIONS 1375#if ENABLE_FEATURE_WGET_LONG_OPTIONS
@@ -1381,11 +1386,10 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1381 G.user_agent = "Wget"; /* "User-Agent" header field */ 1386 G.user_agent = "Wget"; /* "User-Agent" header field */
1382 1387
1383#if ENABLE_FEATURE_WGET_LONG_OPTIONS 1388#if ENABLE_FEATURE_WGET_LONG_OPTIONS
1384 applet_long_options = wget_longopts;
1385#endif 1389#endif
1386 opt_complementary = "-1" /* at least one URL */ 1390 opt_complementary = "-1" /* at least one URL */
1387 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */ 1391 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */
1388 getopt32(argv, "cqSO:P:Y:U:T:+" 1392 GETOPT32(argv, "cqSO:P:Y:U:T:+"
1389 /*ignored:*/ "t:" 1393 /*ignored:*/ "t:"
1390 /*ignored:*/ "n::" 1394 /*ignored:*/ "n::"
1391 /* wget has exactly four -n<letter> opts, all of which we can ignore: 1395 /* wget has exactly four -n<letter> opts, all of which we can ignore:
@@ -1396,6 +1400,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1396 * "n::" above says that we accept -n[ARG]. 1400 * "n::" above says that we accept -n[ARG].
1397 * Specifying "n:" would be a bug: "-n ARG" would eat ARG! 1401 * Specifying "n:" would be a bug: "-n ARG" would eat ARG!
1398 */ 1402 */
1403 LONGOPTS
1399 , &G.fname_out, &G.dir_prefix, 1404 , &G.fname_out, &G.dir_prefix,
1400 &G.proxy_flag, &G.user_agent, 1405 &G.proxy_flag, &G.user_agent,
1401 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL), 1406 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
diff --git a/selinux/chcon.c b/selinux/chcon.c
index ae87fb554..3cf9e928a 100644
--- a/selinux/chcon.c
+++ b/selinux/chcon.c
@@ -13,11 +13,6 @@
13//config: depends on SELINUX 13//config: depends on SELINUX
14//config: help 14//config: help
15//config: Enable support to change the security context of file. 15//config: Enable support to change the security context of file.
16//config:
17//config:config FEATURE_CHCON_LONG_OPTIONS
18//config: bool "Enable long options"
19//config: default y
20//config: depends on CHCON && LONG_OPTS
21 16
22//applet:IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) 17//applet:IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP))
23 18
@@ -26,34 +21,22 @@
26//usage:#define chcon_trivial_usage 21//usage:#define chcon_trivial_usage
27//usage: "[OPTIONS] CONTEXT FILE..." 22//usage: "[OPTIONS] CONTEXT FILE..."
28//usage: "\n chcon [OPTIONS] [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE..." 23//usage: "\n chcon [OPTIONS] [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE..."
29//usage: IF_FEATURE_CHCON_LONG_OPTIONS(
30//usage: "\n chcon [OPTIONS] --reference=RFILE FILE..." 24//usage: "\n chcon [OPTIONS] --reference=RFILE FILE..."
31//usage: ) 25//usage:
32//usage:#define chcon_full_usage "\n\n" 26//usage:#define chcon_full_usage "\n\n"
33//usage: "Change the security context of each FILE to CONTEXT\n" 27//usage: "Change the security context of each FILE to CONTEXT\n"
34//usage: IF_FEATURE_CHCON_LONG_OPTIONS(
35//usage: "\n -v,--verbose Verbose"
36//usage: "\n -c,--changes Report changes made"
37//usage: "\n -h,--no-dereference Affect symlinks instead of their targets"
38//usage: "\n -f,--silent,--quiet Suppress most error messages"
39//usage: "\n --reference RFILE Use RFILE's group instead of using a CONTEXT value"
40//usage: "\n -u,--user USER Set user/role/type/range in the target"
41//usage: "\n -r,--role ROLE security context"
42//usage: "\n -t,--type TYPE"
43//usage: "\n -l,--range RANGE"
44//usage: "\n -R,--recursive Recurse"
45//usage: )
46//usage: IF_NOT_FEATURE_CHCON_LONG_OPTIONS(
47//usage: "\n -v Verbose" 28//usage: "\n -v Verbose"
48//usage: "\n -c Report changes made" 29//usage: "\n -c Report changes made"
49//usage: "\n -h Affect symlinks instead of their targets" 30//usage: "\n -h Affect symlinks instead of their targets"
50//usage: "\n -f Suppress most error messages" 31//usage: "\n -f Suppress most error messages"
32//usage: IF_LONG_OPTS(
33//usage: "\n --reference RFILE Use RFILE's group instead of using a CONTEXT value"
34//usage: )
51//usage: "\n -u USER Set user/role/type/range in the target security context" 35//usage: "\n -u USER Set user/role/type/range in the target security context"
52//usage: "\n -r ROLE" 36//usage: "\n -r ROLE"
53//usage: "\n -t TYPE" 37//usage: "\n -t TYPE"
54//usage: "\n -l RNG" 38//usage: "\n -l RNG"
55//usage: "\n -R Recurse" 39//usage: "\n -R Recurse"
56//usage: )
57 40
58#include <selinux/context.h> 41#include <selinux/context.h>
59 42
@@ -68,7 +51,7 @@
68#define OPT_TYPE (1<<6) /* 't' */ 51#define OPT_TYPE (1<<6) /* 't' */
69#define OPT_RANGE (1<<7) /* 'l' */ 52#define OPT_RANGE (1<<7) /* 'l' */
70#define OPT_VERBOSE (1<<8) /* 'v' */ 53#define OPT_VERBOSE (1<<8) /* 'v' */
71#define OPT_REFERENCE ((1<<9) * ENABLE_FEATURE_CHCON_LONG_OPTIONS) 54#define OPT_REFERENCE ((1<<9) * ENABLE_LONG_OPTS)
72#define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE) 55#define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE)
73 56
74static char *user = NULL; 57static char *user = NULL;
@@ -157,7 +140,7 @@ skip:
157 return rc; 140 return rc;
158} 141}
159 142
160#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 143#if ENABLE_LONG_OPTS
161static const char chcon_longopts[] ALIGN1 = 144static const char chcon_longopts[] ALIGN1 =
162 "recursive\0" No_argument "R" 145 "recursive\0" No_argument "R"
163 "changes\0" No_argument "c" 146 "changes\0" No_argument "c"
@@ -180,20 +163,18 @@ int chcon_main(int argc UNUSED_PARAM, char **argv)
180 char *fname; 163 char *fname;
181 int i, errors = 0; 164 int i, errors = 0;
182 165
183#if ENABLE_FEATURE_CHCON_LONG_OPTIONS
184 applet_long_options = chcon_longopts;
185#endif
186 opt_complementary = "-1" /* at least 1 param */ 166 opt_complementary = "-1" /* at least 1 param */
187 ":?" /* error if exclusivity constraints are violated */ 167 ":?" /* error if exclusivity constraints are violated */
188#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 168#if ENABLE_LONG_OPTS
189 ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff" 169 ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff"
190#endif 170#endif
191 ":f--v:v--f"; /* 'verbose' and 'quiet' are exclusive */ 171 ":f--v:v--f"; /* 'verbose' and 'quiet' are exclusive */
192 getopt32(argv, "Rchfu:r:t:l:v", 172 getopt32long(argv, "Rchfu:r:t:l:v", chcon_longopts,
193 &user, &role, &type, &range, &reference_file); 173 &user, &role, &type, &range, &reference_file
174 );
194 argv += optind; 175 argv += optind;
195 176
196#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 177#if ENABLE_LONG_OPTS
197 if (option_mask32 & OPT_REFERENCE) { 178 if (option_mask32 & OPT_REFERENCE) {
198 /* FIXME: lgetfilecon() should be used when '-h' is specified. 179 /* FIXME: lgetfilecon() should be used when '-h' is specified.
199 * But current implementation follows the original one. */ 180 * But current implementation follows the original one. */
diff --git a/selinux/runcon.c b/selinux/runcon.c
index 09082d6c2..199da25c6 100644
--- a/selinux/runcon.c
+++ b/selinux/runcon.c
@@ -34,11 +34,6 @@
34//config: depends on SELINUX 34//config: depends on SELINUX
35//config: help 35//config: help
36//config: Enable support to run command in specified security context. 36//config: Enable support to run command in specified security context.
37//config:
38//config:config FEATURE_RUNCON_LONG_OPTIONS
39//config: bool "Enable long options"
40//config: default y
41//config: depends on RUNCON && LONG_OPTS
42 37
43//applet:IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) 38//applet:IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP))
44 39
@@ -50,20 +45,11 @@
50//usage:#define runcon_full_usage "\n\n" 45//usage:#define runcon_full_usage "\n\n"
51//usage: "Run PROG in a different security context\n" 46//usage: "Run PROG in a different security context\n"
52//usage: "\n CONTEXT Complete security context\n" 47//usage: "\n CONTEXT Complete security context\n"
53//usage: IF_FEATURE_RUNCON_LONG_OPTIONS(
54//usage: "\n -c,--compute Compute process transition context before modifying"
55//usage: "\n -t,--type TYPE Type (for same role as parent)"
56//usage: "\n -u,--user USER User identity"
57//usage: "\n -r,--role ROLE Role"
58//usage: "\n -l,--range RNG Levelrange"
59//usage: )
60//usage: IF_NOT_FEATURE_RUNCON_LONG_OPTIONS(
61//usage: "\n -c Compute process transition context before modifying" 48//usage: "\n -c Compute process transition context before modifying"
62//usage: "\n -t TYPE Type (for same role as parent)" 49//usage: "\n -t TYPE Type (for same role as parent)"
63//usage: "\n -u USER User identity" 50//usage: "\n -u USER User identity"
64//usage: "\n -r ROLE Role" 51//usage: "\n -r ROLE Role"
65//usage: "\n -l RNG Levelrange" 52//usage: "\n -l RNG Levelrange"
66//usage: )
67 53
68#include <selinux/context.h> 54#include <selinux/context.h>
69/* from deprecated <selinux/flask.h>: */ 55/* from deprecated <selinux/flask.h>: */
@@ -108,7 +94,7 @@ static context_t runcon_compute_new_context(char *user, char *role, char *type,
108 return con; 94 return con;
109} 95}
110 96
111#if ENABLE_FEATURE_RUNCON_LONG_OPTIONS 97#if ENABLE_LONG_OPTS
112static const char runcon_longopts[] ALIGN1 = 98static const char runcon_longopts[] ALIGN1 =
113 "user\0" Required_argument "u" 99 "user\0" Required_argument "u"
114 "role\0" Required_argument "r" 100 "role\0" Required_argument "r"
@@ -140,11 +126,9 @@ int runcon_main(int argc UNUSED_PARAM, char **argv)
140 126
141 selinux_or_die(); 127 selinux_or_die();
142 128
143#if ENABLE_FEATURE_RUNCON_LONG_OPTIONS
144 applet_long_options = runcon_longopts;
145#endif
146 opt_complementary = "-1"; 129 opt_complementary = "-1";
147 opts = getopt32(argv, "r:t:u:l:ch", &role, &type, &user, &range); 130 opts = getopt32long(argv, "r:t:u:l:ch", runcon_longopts,
131 &role, &type, &user, &range);
148 argv += optind; 132 argv += optind;
149 133
150 if (!(opts & OPTS_CONTEXT_COMPONENT)) { 134 if (!(opts & OPTS_CONTEXT_COMPONENT)) {
diff --git a/util-linux/flock.c b/util-linux/flock.c
index b55e07adb..0c9158508 100644
--- a/util-linux/flock.c
+++ b/util-linux/flock.c
@@ -44,11 +44,10 @@ int flock_main(int argc UNUSED_PARAM, char **argv)
44 "unlock\0" No_argument "u" 44 "unlock\0" No_argument "u"
45 "nonblock\0" No_argument "n" 45 "nonblock\0" No_argument "n"
46 ; 46 ;
47 applet_long_options = flock_longopts;
48#endif 47#endif
49 opt_complementary = "-1"; 48 opt_complementary = "-1";
50 49
51 opt = getopt32(argv, "+sxnu"); 50 opt = getopt32long(argv, "+sxnu", flock_longopts);
52 argv += optind; 51 argv += optind;
53 52
54 if (argv[1]) { 53 if (argv[1]) {
diff --git a/util-linux/fsfreeze.c b/util-linux/fsfreeze.c
index c1f31569f..af715da5e 100644
--- a/util-linux/fsfreeze.c
+++ b/util-linux/fsfreeze.c
@@ -36,15 +36,14 @@ int fsfreeze_main(int argc UNUSED_PARAM, char **argv)
36 unsigned opts; 36 unsigned opts;
37 int fd; 37 int fd;
38 38
39 applet_long_options =
40 "freeze\0" No_argument "\xff"
41 "unfreeze\0" No_argument "\xfe"
42 ;
43 /* exactly one non-option arg: the mountpoint */ 39 /* exactly one non-option arg: the mountpoint */
44 /* one of opts is required */ 40 /* one of opts is required */
45 /* opts are mutually exclusive */ 41 /* opts are mutually exclusive */
46 opt_complementary = "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff"; 42 opt_complementary = "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff";
47 opts = getopt32(argv, ""); 43 opts = getopt32long(argv, "",
44 "freeze\0" No_argument "\xff"
45 "unfreeze\0" No_argument "\xfe"
46 );
48 47
49 fd = xopen(argv[optind], O_RDONLY); 48 fd = xopen(argv[optind], O_RDONLY);
50 /* Works with NULL arg on linux-4.8.0 */ 49 /* Works with NULL arg on linux-4.8.0 */
diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c
index 1fbf0c857..8f0a0538f 100644
--- a/util-linux/fstrim.c
+++ b/util-linux/fstrim.c
@@ -69,11 +69,10 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv)
69 "minimum\0" Required_argument "m" 69 "minimum\0" Required_argument "m"
70 "verbose\0" No_argument "v" 70 "verbose\0" No_argument "v"
71 ; 71 ;
72 applet_long_options = fstrim_longopts;
73#endif 72#endif
74 73
75 opt_complementary = "=1"; /* exactly one non-option arg: the mountpoint */ 74 opt_complementary = "=1"; /* exactly one non-option arg: the mountpoint */
76 opts = getopt32(argv, "o:l:m:v", &arg_o, &arg_l, &arg_m); 75 opts = getopt32long(argv, "o:l:m:v", fstrim_longopts, &arg_o, &arg_l, &arg_m);
77 76
78 memset(&range, 0, sizeof(range)); 77 memset(&range, 0, sizeof(range));
79 range.len = ULLONG_MAX; 78 range.len = ULLONG_MAX;
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index 5fe0da7cd..a151b7e56 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -42,8 +42,8 @@
42//config: 42//config:
43//config:config FEATURE_GETOPT_LONG 43//config:config FEATURE_GETOPT_LONG
44//config: bool "Support -l LONGOPTs" 44//config: bool "Support -l LONGOPTs"
45//config: default y if LONG_OPTS 45//config: default y
46//config: depends on GETOPT 46//config: depends on GETOPT && LONG_OPTS
47//config: help 47//config: help
48//config: Enable support for long options (option -l). 48//config: Enable support for long options (option -l).
49 49
@@ -54,20 +54,6 @@
54//usage:#define getopt_trivial_usage 54//usage:#define getopt_trivial_usage
55//usage: "[OPTIONS] [--] OPTSTRING PARAMS" 55//usage: "[OPTIONS] [--] OPTSTRING PARAMS"
56//usage:#define getopt_full_usage "\n\n" 56//usage:#define getopt_full_usage "\n\n"
57//usage: IF_LONG_OPTS(
58//usage: IF_FEATURE_GETOPT_LONG(
59//usage: " -a,--alternative Allow long options starting with single -\n"
60//usage: " -l,--longoptions LOPT[,...] Long options to recognize\n"
61//usage: )
62//usage: " -n,--name PROGNAME The name under which errors are reported"
63//usage: "\n -o,--options OPTSTRING Short options to recognize"
64//usage: "\n -q,--quiet No error messages on unrecognized options"
65//usage: "\n -Q,--quiet-output No normal output"
66//usage: "\n -s,--shell SHELL Set shell quoting conventions"
67//usage: "\n -T,--test Version test (exits with 4)"
68//usage: "\n -u,--unquoted Don't quote output"
69//usage: )
70//usage: IF_NOT_LONG_OPTS(
71//usage: IF_FEATURE_GETOPT_LONG( 57//usage: IF_FEATURE_GETOPT_LONG(
72//usage: " -a Allow long options starting with single -\n" 58//usage: " -a Allow long options starting with single -\n"
73//usage: " -l LOPT[,...] Long options to recognize\n" 59//usage: " -l LOPT[,...] Long options to recognize\n"
@@ -79,7 +65,6 @@
79//usage: "\n -s SHELL Set shell quoting conventions" 65//usage: "\n -s SHELL Set shell quoting conventions"
80//usage: "\n -T Version test (exits with 4)" 66//usage: "\n -T Version test (exits with 4)"
81//usage: "\n -u Don't quote output" 67//usage: "\n -u Don't quote output"
82//usage: )
83//usage: IF_FEATURE_GETOPT_LONG( /* example uses -l, needs FEATURE_GETOPT_LONG */ 68//usage: IF_FEATURE_GETOPT_LONG( /* example uses -l, needs FEATURE_GETOPT_LONG */
84//usage: "\n" 69//usage: "\n"
85//usage: "\nExample:" 70//usage: "\nExample:"
@@ -411,8 +396,7 @@ int getopt_main(int argc, char **argv)
411#if !ENABLE_FEATURE_GETOPT_LONG 396#if !ENABLE_FEATURE_GETOPT_LONG
412 opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); 397 opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg);
413#else 398#else
414 applet_long_options = getopt_longopts; 399 opt = getopt32long(argv, "+o:n:qQs:Tual:*", getopt_longopts,
415 opt = getopt32(argv, "+o:n:qQs:Tual:*",
416 &optstr, &name, &s_arg, &l_arg); 400 &optstr, &name, &s_arg, &l_arg);
417 /* Effectuate the read options for the applet itself */ 401 /* Effectuate the read options for the applet itself */
418 while (l_arg) { 402 while (l_arg) {
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 5df56de15..50f83d8c4 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -16,11 +16,6 @@
16//config: shutdown in the hardware clock, so the hardware will keep the 16//config: shutdown in the hardware clock, so the hardware will keep the
17//config: correct time when Linux is _not_ running. 17//config: correct time when Linux is _not_ running.
18//config: 18//config:
19//config:config FEATURE_HWCLOCK_LONG_OPTIONS
20//config: bool "Support long options (--hctosys,...)"
21//config: default y
22//config: depends on HWCLOCK && LONG_OPTS
23//config:
24//config:config FEATURE_HWCLOCK_ADJTIME_FHS 19//config:config FEATURE_HWCLOCK_ADJTIME_FHS
25//config: bool "Use FHS /var/lib/hwclock/adjtime" 20//config: bool "Use FHS /var/lib/hwclock/adjtime"
26//config: default n # util-linux-ng in Fedora 13 still uses /etc/adjtime 21//config: default n # util-linux-ng in Fedora 13 still uses /etc/adjtime
@@ -293,12 +288,12 @@ static void set_system_clock_timezone(int utc)
293} 288}
294 289
295//usage:#define hwclock_trivial_usage 290//usage:#define hwclock_trivial_usage
296//usage: IF_FEATURE_HWCLOCK_LONG_OPTIONS( 291//usage: IF_LONG_OPTS(
297//usage: "[-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz]" 292//usage: "[-r|--show] [-s|--hctosys] [-w|--systohc] [--systz]"
298//usage: " [-l|--localtime] [-u|--utc]" 293//usage: " [--localtime] [-u|--utc]"
299//usage: " [-f|--rtc FILE]" 294//usage: " [-f|--rtc FILE]"
300//usage: ) 295//usage: )
301//usage: IF_NOT_FEATURE_HWCLOCK_LONG_OPTIONS( 296//usage: IF_NOT_LONG_OPTS(
302//usage: "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]" 297//usage: "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]"
303//usage: ) 298//usage: )
304//usage:#define hwclock_full_usage "\n\n" 299//usage:#define hwclock_full_usage "\n\n"
@@ -306,12 +301,18 @@ static void set_system_clock_timezone(int utc)
306//usage: "\n -r Show hardware clock time" 301//usage: "\n -r Show hardware clock time"
307//usage: "\n -s Set system time from hardware clock" 302//usage: "\n -s Set system time from hardware clock"
308//usage: "\n -w Set hardware clock from system time" 303//usage: "\n -w Set hardware clock from system time"
309//usage: "\n -t Set in-kernel timezone, correct system time" 304//usage: IF_LONG_OPTS(
305//usage: "\n --systz Set in-kernel timezone, correct system time"
306//usage: )
310//usage: "\n if hardware clock is in local time" 307//usage: "\n if hardware clock is in local time"
311//usage: "\n -u Assume hardware clock is kept in UTC" 308//usage: "\n -u Assume hardware clock is kept in UTC"
312//usage: "\n -l Assume hardware clock is kept in local time" 309//usage: IF_LONG_OPTS(
310//usage: "\n --localtime Assume hardware clock is kept in local time"
311//usage: )
313//usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)" 312//usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)"
314 313
314//TODO: get rid of incompatible -t and -l aliases to --systz and --localtime
315
315#define HWCLOCK_OPT_LOCALTIME 0x01 316#define HWCLOCK_OPT_LOCALTIME 0x01
316#define HWCLOCK_OPT_UTC 0x02 317#define HWCLOCK_OPT_UTC 0x02
317#define HWCLOCK_OPT_SHOW 0x04 318#define HWCLOCK_OPT_SHOW 0x04
@@ -327,7 +328,7 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv)
327 unsigned opt; 328 unsigned opt;
328 int utc; 329 int utc;
329 330
330#if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS 331#if ENABLE_LONG_OPTS
331 static const char hwclock_longopts[] ALIGN1 = 332 static const char hwclock_longopts[] ALIGN1 =
332 "localtime\0" No_argument "l" /* short opt is non-standard */ 333 "localtime\0" No_argument "l" /* short opt is non-standard */
333 "utc\0" No_argument "u" 334 "utc\0" No_argument "u"
@@ -337,14 +338,13 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv)
337 "systz\0" No_argument "t" /* short opt is non-standard */ 338 "systz\0" No_argument "t" /* short opt is non-standard */
338 "rtc\0" Required_argument "f" 339 "rtc\0" Required_argument "f"
339 ; 340 ;
340 applet_long_options = hwclock_longopts;
341#endif 341#endif
342 342
343 /* Initialize "timezone" (libc global variable) */ 343 /* Initialize "timezone" (libc global variable) */
344 tzset(); 344 tzset();
345 345
346 opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l"; 346 opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l";
347 opt = getopt32(argv, "lurswtf:", &rtcname); 347 opt = getopt32long(argv, "lurswtf:", hwclock_longopts, &rtcname);
348 348
349 /* If -u or -l wasn't given check if we are using utc */ 349 /* If -u or -l wasn't given check if we are using utc */
350 if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) 350 if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME))
diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c
index 12c86b0ed..d91b0b509 100644
--- a/util-linux/nsenter.c
+++ b/util-linux/nsenter.c
@@ -13,14 +13,6 @@
13//config: select PLATFORM_LINUX 13//config: select PLATFORM_LINUX
14//config: help 14//config: help
15//config: Run program with namespaces of other processes. 15//config: Run program with namespaces of other processes.
16//config:
17//config:config FEATURE_NSENTER_LONG_OPTS
18//config: bool "Enable long options"
19//config: default y
20//config: depends on NSENTER && LONG_OPTS
21//config: help
22//config: Support long options for the nsenter applet. This makes
23//config: the busybox implementation more compatible with upstream.
24 16
25//applet:IF_NSENTER(APPLET(nsenter, BB_DIR_USR_BIN, BB_SUID_DROP)) 17//applet:IF_NSENTER(APPLET(nsenter, BB_DIR_USR_BIN, BB_SUID_DROP))
26 18
@@ -28,22 +20,6 @@
28 20
29//usage:#define nsenter_trivial_usage 21//usage:#define nsenter_trivial_usage
30//usage: "[OPTIONS] [PROG [ARGS]]" 22//usage: "[OPTIONS] [PROG [ARGS]]"
31//usage:#if ENABLE_FEATURE_NSENTER_LONG_OPTS
32//usage:#define nsenter_full_usage "\n"
33//usage: "\n -t,--target PID Target process to get namespaces from"
34//usage: "\n -m,--mount[=FILE] Enter mount namespace"
35//usage: "\n -u,--uts[=FILE] Enter UTS namespace (hostname etc)"
36//usage: "\n -i,--ipc[=FILE] Enter System V IPC namespace"
37//usage: "\n -n,--net[=FILE] Enter network namespace"
38//usage: "\n -p,--pid[=FILE] Enter pid namespace"
39//usage: "\n -U,--user[=FILE] Enter user namespace"
40//usage: "\n -S,--setuid UID Set uid in entered namespace"
41//usage: "\n -G,--setgid GID Set gid in entered namespace"
42//usage: "\n --preserve-credentials Don't touch uids or gids"
43//usage: "\n -r,--root[=DIR] Set root directory"
44//usage: "\n -w,--wd[=DIR] Set working directory"
45//usage: "\n -F,--no-fork Don't fork before exec'ing PROG"
46//usage:#else
47//usage:#define nsenter_full_usage "\n" 23//usage:#define nsenter_full_usage "\n"
48//usage: "\n -t PID Target process to get namespaces from" 24//usage: "\n -t PID Target process to get namespaces from"
49//usage: "\n -m[FILE] Enter mount namespace" 25//usage: "\n -m[FILE] Enter mount namespace"
@@ -54,10 +30,12 @@
54//usage: "\n -U[FILE] Enter user namespace" 30//usage: "\n -U[FILE] Enter user namespace"
55//usage: "\n -S UID Set uid in entered namespace" 31//usage: "\n -S UID Set uid in entered namespace"
56//usage: "\n -G GID Set gid in entered namespace" 32//usage: "\n -G GID Set gid in entered namespace"
33//usage: IF_LONG_OPTS(
34//usage: "\n --preserve-credentials Don't touch uids or gids"
35//usage: )
57//usage: "\n -r[DIR] Set root directory" 36//usage: "\n -r[DIR] Set root directory"
58//usage: "\n -w[DIR] Set working directory" 37//usage: "\n -w[DIR] Set working directory"
59//usage: "\n -F Don't fork before exec'ing PROG" 38//usage: "\n -F Don't fork before exec'ing PROG"
60//usage:#endif
61 39
62#include <sched.h> 40#include <sched.h>
63#ifndef CLONE_NEWUTS 41#ifndef CLONE_NEWUTS
@@ -101,7 +79,7 @@ enum {
101 OPT_root = 1 << 9, 79 OPT_root = 1 << 9,
102 OPT_wd = 1 << 10, 80 OPT_wd = 1 << 10,
103 OPT_nofork = 1 << 11, 81 OPT_nofork = 1 << 11,
104 OPT_prescred = (1 << 12) * ENABLE_FEATURE_NSENTER_LONG_OPTS, 82 OPT_prescred = (1 << 12) * ENABLE_LONG_OPTS,
105}; 83};
106enum { 84enum {
107 NS_USR_POS = 0, 85 NS_USR_POS = 0,
@@ -130,7 +108,7 @@ static const struct namespace_descr ns_list[] = {
130 */ 108 */
131static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t+S+G+r::w::F"; 109static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t+S+G+r::w::F";
132 110
133#if ENABLE_FEATURE_NSENTER_LONG_OPTS 111#if ENABLE_LONG_OPTS
134static const char nsenter_longopts[] ALIGN1 = 112static const char nsenter_longopts[] ALIGN1 =
135 "user\0" Optional_argument "U" 113 "user\0" Optional_argument "U"
136 "ipc\0" Optional_argument "i" 114 "ipc\0" Optional_argument "i"
@@ -190,8 +168,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
190 168
191 memset(ns_ctx_list, 0, sizeof(ns_ctx_list)); 169 memset(ns_ctx_list, 0, sizeof(ns_ctx_list));
192 170
193 IF_FEATURE_NSENTER_LONG_OPTS(applet_long_options = nsenter_longopts); 171 opts = getopt32long(argv, opt_str, nsenter_longopts,
194 opts = getopt32(argv, opt_str,
195 &ns_ctx_list[NS_USR_POS].path, 172 &ns_ctx_list[NS_USR_POS].path,
196 &ns_ctx_list[NS_IPC_POS].path, 173 &ns_ctx_list[NS_IPC_POS].path,
197 &ns_ctx_list[NS_UTS_POS].path, 174 &ns_ctx_list[NS_UTS_POS].path,
diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c
index 4c47c5369..2a3d61f21 100644
--- a/util-linux/rtcwake.c
+++ b/util-linux/rtcwake.c
@@ -154,11 +154,11 @@ int rtcwake_main(int argc UNUSED_PARAM, char **argv)
154 "seconds\0" Required_argument "s" 154 "seconds\0" Required_argument "s"
155 "time\0" Required_argument "t" 155 "time\0" Required_argument "t"
156 ; 156 ;
157 applet_long_options = rtcwake_longopts;
158#endif 157#endif
159 /* Must have -s or -t, exclusive */ 158 /* Must have -s or -t, exclusive */
160 opt_complementary = "s:t:s--t:t--s"; 159 opt_complementary = "s:t:s--t:t--s";
161 opt = getopt32(argv, "alud:m:s:t:", &rtcname, &suspend, &opt_seconds, &opt_time); 160 opt = getopt32long(argv, "alud:m:s:t:", rtcwake_longopts,
161 &rtcname, &suspend, &opt_seconds, &opt_time);
162 162
163 /* this is the default 163 /* this is the default
164 if (opt & RTCWAKE_OPT_AUTO) 164 if (opt & RTCWAKE_OPT_AUTO)
diff --git a/util-linux/script.c b/util-linux/script.c
index 4cb9842a0..8174c65bf 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -78,12 +78,10 @@ int script_main(int argc UNUSED_PARAM, char **argv)
78 "quiet\0" No_argument "q" 78 "quiet\0" No_argument "q"
79 "timing\0" Optional_argument "t" 79 "timing\0" Optional_argument "t"
80 ; 80 ;
81
82 applet_long_options = script_longopts;
83#endif 81#endif
84 82
85 opt_complementary = "?1"; /* max one arg */ 83 opt_complementary = "?1"; /* max one arg */
86 opt = getopt32(argv, "ac:fqt::", &shell_arg, &str_t); 84 opt = getopt32long(argv, "ac:fqt::", script_longopts, &shell_arg, &str_t);
87 //argc -= optind; 85 //argc -= optind;
88 argv += optind; 86 argv += optind;
89 if (argv[0]) { 87 if (argv[0]) {
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c
index 0f85428ab..5c532d637 100644
--- a/util-linux/setpriv.c
+++ b/util-linux/setpriv.c
@@ -421,9 +421,12 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
421 int opts; 421 int opts;
422 IF_FEATURE_SETPRIV_CAPABILITIES(char *inh_caps, *ambient_caps;) 422 IF_FEATURE_SETPRIV_CAPABILITIES(char *inh_caps, *ambient_caps;)
423 423
424 applet_long_options = setpriv_longopts; 424 opts = getopt32long(argv,
425 opts = getopt32(argv, "+"IF_FEATURE_SETPRIV_DUMP("d") 425 "+"IF_FEATURE_SETPRIV_DUMP("d")
426 IF_FEATURE_SETPRIV_CAPABILITIES("\xfe:\xfd:", &inh_caps, &ambient_caps)); 426 IF_FEATURE_SETPRIV_CAPABILITIES("\xfe:\xfd:"),
427 setpriv_longopts
428 IF_FEATURE_SETPRIV_CAPABILITIES(, &inh_caps, &ambient_caps)
429 );
427 argv += optind; 430 argv += optind;
428 431
429#if ENABLE_FEATURE_SETPRIV_DUMP 432#if ENABLE_FEATURE_SETPRIV_DUMP
diff --git a/util-linux/unshare.c b/util-linux/unshare.c
index e7b95c72b..df377478f 100644
--- a/util-linux/unshare.c
+++ b/util-linux/unshare.c
@@ -220,8 +220,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
220 ":ru" /* --map-root-user or -r implies -u */ 220 ":ru" /* --map-root-user or -r implies -u */
221 ":\xfd""m" /* --mount-proc implies -m */ 221 ":\xfd""m" /* --mount-proc implies -m */
222 ; 222 ;
223 applet_long_options = unshare_longopts; 223 opts = getopt32long(argv, opt_str, unshare_longopts,
224 opts = getopt32(argv, opt_str,
225 &proc_mnt_target, &prop_str, &setgrp_str, 224 &proc_mnt_target, &prop_str, &setgrp_str,
226 &ns_ctx_list[NS_MNT_POS].path, 225 &ns_ctx_list[NS_MNT_POS].path,
227 &ns_ctx_list[NS_UTS_POS].path, 226 &ns_ctx_list[NS_UTS_POS].path,