aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 16:38:18 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 17:09:40 +0200
commit036585a911a5fe6c2cd77b808dd9150500f37272 (patch)
treeaa7c65b4d09c74642f622a1ef5da982d6ed4940a /coreutils
parent00677b5e35dd97f415f0b0bef25b55865f55ab33 (diff)
downloadbusybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.tar.gz
busybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.tar.bz2
busybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.zip
getopt32: remove applet_long_options
FEATURE_GETOPT_LONG made dependent on LONG_OPTS. The folloving options are removed, now LONG_OPTS enables long options for affected applets: FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS They either had a small number of long options, or their long options are essential. Example: upstream addgroup and adduser have ONLY longopts, we should probably go further and get rid of non-standard short options. To this end, make addgroup and adduser "select LONG_OPTS". We had this breakage caused by us even in our own package! #if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP /* We try to use --gid, not -g, because "standard" addgroup * has no short option -g, it has only long --gid. */ argv[1] = (char*)"--gid"; #else /* Breaks if system in fact does NOT use busybox addgroup */ argv[1] = (char*)"-g"; #endif xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS. hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime Shorten help texts by omitting long option when short opt alternative exists. Reduction of size comes from the fact that store of an immediate (an address of longopts) to a fixed address (global variable) is a longer insn than pushing that immediate or passing it in a register. This effect is CPU-agnostic. function old new delta getopt32 1350 22 -1328 vgetopt32 - 1318 +1318 getopt32long - 24 +24 tftpd_main 562 567 +5 scan_recursive 376 380 +4 collect_cpu 545 546 +1 date_main 1096 1095 -1 hostname_main 262 259 -3 uname_main 259 255 -4 setpriv_main 362 358 -4 rmdir_main 191 187 -4 mv_main 562 558 -4 ipcalc_main 548 544 -4 ifenslave_main 641 637 -4 gzip_main 192 188 -4 gunzip_main 77 73 -4 fsfreeze_main 81 77 -4 flock_main 318 314 -4 deluser_main 337 333 -4 cp_main 374 370 -4 chown_main 175 171 -4 applet_long_options 4 - -4 xargs_main 894 889 -5 wget_main 2540 2535 -5 udhcpc_main 2767 2762 -5 touch_main 436 431 -5 tar_main 1014 1009 -5 start_stop_daemon_main 1033 1028 -5 sed_main 682 677 -5 script_main 1082 1077 -5 run_parts_main 330 325 -5 rtcwake_main 459 454 -5 od_main 2169 2164 -5 nl_main 201 196 -5 modprobe_main 773 768 -5 mkdir_main 160 155 -5 ls_main 568 563 -5 install_main 773 768 -5 hwclock_main 411 406 -5 getopt_main 622 617 -5 fstrim_main 256 251 -5 env_main 198 193 -5 dumpleases_main 635 630 -5 dpkg_main 3991 3986 -5 diff_main 1355 1350 -5 cryptpw_main 233 228 -5 cpio_main 593 588 -5 conspy_main 1135 1130 -5 chpasswd_main 313 308 -5 adduser_main 887 882 -5 addgroup_main 416 411 -5 ftpgetput_main 351 345 -6 get_terminal_width_height 242 234 -8 expand_main 690 680 -10 static.expand_longopts 18 - -18 static.unexpand_longopts 27 - -27 mkdir_longopts 28 - -28 env_longopts 30 - -30 static.ifenslave_longopts 34 - -34 mv_longopts 46 - -46 static.rmdir_longopts 48 - -48 packed_usage 31739 31687 -52 ------------------------------------------------------------------------------ (add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes text data bss dec hex filename 915681 485 6880 923046 e15a6 busybox_old 915428 485 6876 922789 e14a5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-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
15 files changed, 81 insertions, 160 deletions
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 }