diff options
author | Denys Vlasenko | 2017-08-08 16:38:18 +0200 |
---|---|---|
committer | Denys Vlasenko | 2017-08-08 17:09:40 +0200 |
commit | 036585a911a5fe6c2cd77b808dd9150500f37272 (patch) | |
tree | aa7c65b4d09c74642f622a1ef5da982d6ed4940a /coreutils | |
parent | 00677b5e35dd97f415f0b0bef25b55865f55ab33 (diff) | |
download | busybox-036585a911a5fe6c2cd77b808dd9150500f37272.zip busybox-036585a911a5fe6c2cd77b808dd9150500f37272.tar.gz |
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.c | 7 | ||||
-rw-r--r-- | coreutils/cp.c | 7 | ||||
-rw-r--r-- | coreutils/date.c | 5 | ||||
-rw-r--r-- | coreutils/env.c | 21 | ||||
-rw-r--r-- | coreutils/expand.c | 53 | ||||
-rw-r--r-- | coreutils/install.c | 18 | ||||
-rw-r--r-- | coreutils/ls.c | 3 | ||||
-rw-r--r-- | coreutils/mkdir.c | 33 | ||||
-rw-r--r-- | coreutils/mv.c | 38 | ||||
-rw-r--r-- | coreutils/nl.c | 5 | ||||
-rw-r--r-- | coreutils/nproc.c | 1 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 7 | ||||
-rw-r--r-- | coreutils/rmdir.c | 27 | ||||
-rw-r--r-- | coreutils/touch.c | 13 | ||||
-rw-r--r-- | coreutils/uname.c | 3 |
15 files changed, 81 insertions, 160 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c index 1bfc725..0c77529 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -127,11 +127,12 @@ int chown_main(int argc UNUSED_PARAM, char **argv) int opt, flags; struct param_t param; -#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS - applet_long_options = chown_longopts; -#endif opt_complementary = "-2"; +#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS + opt = getopt32long(argv, OPT_STR, chown_longopts); +#else opt = getopt32(argv, OPT_STR); +#endif argv += optind; /* This matches coreutils behavior (almost - see below) */ diff --git a/coreutils/cp.c b/coreutils/cp.c index 092e395..fe40895 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -81,7 +81,7 @@ int cp_main(int argc, char **argv) // -a = -pdR opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; #if ENABLE_FEATURE_CP_LONG_OPTIONS - applet_long_options = + flags = getopt32long(argv, FILEUTILS_CP_OPTSTR, "archive\0" No_argument "a" "force\0" No_argument "f" "interactive\0" No_argument "i" @@ -94,9 +94,10 @@ int cp_main(int argc, char **argv) "update\0" No_argument "u" "remove-destination\0" No_argument "\xff" "parents\0" No_argument "\xfe" - ; -#endif + ); +#else flags = getopt32(argv, FILEUTILS_CP_OPTSTR); +#endif /* Options of cp from GNU coreutils 6.10: * -a, --archive * -f, --force diff --git a/coreutils/date.c b/coreutils/date.c index 5a4ad5f..33f2104 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -194,9 +194,8 @@ int date_main(int argc UNUSED_PARAM, char **argv) opt_complementary = "d--s:s--d" IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); - IF_LONG_OPTS(applet_long_options = date_longopts;) - opt = getopt32(argv, "Rs:ud:r:" - IF_FEATURE_DATE_ISOFMT("I::D:"), + opt = getopt32long(argv, "Rs:ud:r:" + IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts, &date_str, &date_str, &filename IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); argv += optind; diff --git a/coreutils/env.c b/coreutils/env.c index 3242446..20453e8 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -30,11 +30,6 @@ //config: env is used to set an environment variable and run //config: a command; without options it displays the current //config: environment. -//config: -//config:config FEATURE_ENV_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on ENV && LONG_OPTS //applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) @@ -53,23 +48,17 @@ #include "libbb.h" -#if ENABLE_FEATURE_ENV_LONG_OPTIONS -static const char env_longopts[] ALIGN1 = - "ignore-environment\0" No_argument "i" - "unset\0" Required_argument "u" - ; -#endif - int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int env_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; llist_t *unset_env = NULL; -#if ENABLE_FEATURE_ENV_LONG_OPTIONS - applet_long_options = env_longopts; -#endif - opts = getopt32(argv, "+iu:+", &unset_env); + opts = getopt32long(argv, "+iu:+", + "ignore-environment\0" No_argument "i" + "unset\0" Required_argument "u" + , &unset_env + ); argv += optind; if (argv[0] && LONE_DASH(argv[0])) { opts |= 1; diff --git a/coreutils/expand.c b/coreutils/expand.c index 64f2a53..fa3ff18 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -26,21 +26,11 @@ //config: help //config: By default, convert all tabs to spaces. //config: -//config:config FEATURE_EXPAND_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on EXPAND && LONG_OPTS -//config: //config:config UNEXPAND //config: bool "unexpand (6 kb)" //config: default y //config: help //config: By default, convert only leading sequences of blanks to tabs. -//config: -//config:config FEATURE_UNEXPAND_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on UNEXPAND && LONG_OPTS //applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP)) // APPLET_ODDNAME:name main location suid_type help @@ -53,29 +43,16 @@ //usage: "[-i] [-t N] [FILE]..." //usage:#define expand_full_usage "\n\n" //usage: "Convert tabs to spaces, writing to stdout\n" -//usage: IF_FEATURE_EXPAND_LONG_OPTIONS( -//usage: "\n -i,--initial Don't convert tabs after non blanks" -//usage: "\n -t,--tabs N Tabstops every N chars" -//usage: ) -//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS( //usage: "\n -i Don't convert tabs after non blanks" //usage: "\n -t Tabstops every N chars" -//usage: ) //usage:#define unexpand_trivial_usage //usage: "[-fa][-t N] [FILE]..." //usage:#define unexpand_full_usage "\n\n" //usage: "Convert spaces to tabs, writing to stdout\n" -//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS( -//usage: "\n -a,--all Convert all blanks" -//usage: "\n -f,--first-only Convert only leading blanks" -//usage: "\n -t,--tabs N Tabstops every N chars" -//usage: ) -//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS( //usage: "\n -a Convert all blanks" //usage: "\n -f Convert only leading blanks" //usage: "\n -t N Tabstops every N chars" -//usage: ) #include "libbb.h" #include "unicode.h" @@ -188,31 +165,23 @@ int expand_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int exit_status = EXIT_SUCCESS; -#if ENABLE_FEATURE_EXPAND_LONG_OPTIONS - static const char expand_longopts[] ALIGN1 = - /* name, has_arg, val */ - "initial\0" No_argument "i" - "tabs\0" Required_argument "t" - ; -#endif -#if ENABLE_FEATURE_UNEXPAND_LONG_OPTIONS - static const char unexpand_longopts[] ALIGN1 = - /* name, has_arg, val */ - "first-only\0" No_argument "i" - "tabs\0" Required_argument "t" - "all\0" No_argument "a" - ; -#endif init_unicode(); if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) { - IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts); - opt = getopt32(argv, "it:", &opt_t); + opt = getopt32long(argv, "it:", + "initial\0" No_argument "i" + "tabs\0" Required_argument "t" + , &opt_t + ); } else { - IF_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts); /* -t NUM sets also -a */ opt_complementary = "ta"; - opt = getopt32(argv, "ft:a", &opt_t); + opt = getopt32long(argv, "ft:a", + "first-only\0" No_argument "i" + "tabs\0" Required_argument "t" + "all\0" No_argument "a" + , &opt_t + ); /* -f --first-only is the default */ if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; } diff --git a/coreutils/install.c b/coreutils/install.c index a1342bb..c01750f 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -55,12 +55,17 @@ static const char install_longopts[] ALIGN1 = "target-directory\0" Required_argument "t" /* autofs build insists of using -b --suffix=.orig */ /* TODO? (short option for --suffix is -S) */ -#if ENABLE_SELINUX +# if ENABLE_SELINUX "context\0" Required_argument "Z" "preserve_context\0" No_argument "\xff" "preserve-context\0" No_argument "\xff" -#endif +# endif ; +# define GETOPT32 getopt32long +# define LONGOPTS install_longopts, +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif @@ -135,15 +140,14 @@ int install_main(int argc, char **argv) #endif }; -#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS - applet_long_options = install_longopts; -#endif opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); /* -c exists for backwards compatibility, it's needed */ /* -b is ignored ("make a backup of each existing destination file") */ - opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), + opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), + LONGOPTS &gid_str, &mode_str, &uid_str, &last - IF_SELINUX(, &scontext)); + IF_SELINUX(, &scontext) + ); argc -= optind; argv += optind; diff --git a/coreutils/ls.c b/coreutils/ls.c index 0fe0345..0834cdc 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1093,7 +1093,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) #endif /* process options */ - IF_LONG_OPTS(applet_long_options = ls_longopts;) opt_complementary = /* -n and -g imply -l */ "nl:gl" @@ -1111,7 +1110,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ /* -w NUM: */ IF_FEATURE_LS_WIDTH(":w+"); - opt = getopt32(argv, ls_options + opt = getopt32long(argv, ls_options, ls_longopts IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) IF_FEATURE_LS_COLOR(, &color_opt) ); diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 2285118..986353d 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c @@ -18,11 +18,6 @@ //config: default y //config: help //config: mkdir is used to create directories with the specified names. -//config: -//config:config FEATURE_MKDIR_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on MKDIR && LONG_OPTS //applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir)) @@ -53,19 +48,6 @@ /* This is a NOFORK applet. Be very careful! */ -#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS -static const char mkdir_longopts[] ALIGN1 = - "mode\0" Required_argument "m" - "parents\0" No_argument "p" -#if ENABLE_SELINUX - "context\0" Required_argument "Z" -#endif -#if ENABLE_FEATURE_VERBOSE - "verbose\0" No_argument "v" -#endif - ; -#endif - int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mkdir_main(int argc UNUSED_PARAM, char **argv) { @@ -78,10 +60,17 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv) security_context_t scontext; #endif -#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS - applet_long_options = mkdir_longopts; -#endif - opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); + opt = getopt32long(argv, "m:pv" IF_SELINUX("Z:"), + "mode\0" Required_argument "m" + "parents\0" No_argument "p" +# if ENABLE_SELINUX + "context\0" Required_argument "Z" +# endif +# if ENABLE_FEATURE_VERBOSE + "verbose\0" No_argument "v" +# endif + , &smode IF_SELINUX(,&scontext) + ); if (opt & 1) { mode_t mmode = bb_parse_mode(smode, 0777); if (mmode == (mode_t)-1) { diff --git a/coreutils/mv.c b/coreutils/mv.c index 147dd3b..7f6e9fe 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -16,11 +16,6 @@ //config: default y //config: help //config: mv is used to move or rename files or directories. -//config: -//config:config FEATURE_MV_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on MV && LONG_OPTS //applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP)) @@ -41,23 +36,6 @@ #include "libbb.h" #include "libcoreutils/coreutils.h" -#if ENABLE_FEATURE_MV_LONG_OPTIONS -static const char mv_longopts[] ALIGN1 = - "interactive\0" No_argument "i" - "force\0" No_argument "f" - "no-clobber\0" No_argument "n" - IF_FEATURE_VERBOSE( - "verbose\0" No_argument "v" - ) - ; -#endif - -#define OPT_FORCE (1 << 0) -#define OPT_INTERACTIVE (1 << 1) -#define OPT_NOCLOBBER (1 << 2) -#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE) - - int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mv_main(int argc, char **argv) { @@ -69,15 +47,23 @@ int mv_main(int argc, char **argv) int status = 0; int copy_flag = 0; -#if ENABLE_FEATURE_MV_LONG_OPTIONS - applet_long_options = mv_longopts; -#endif +#define OPT_FORCE (1 << 0) +#define OPT_INTERACTIVE (1 << 1) +#define OPT_NOCLOBBER (1 << 2) +#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE) /* Need at least two arguments. * If more than one of -f, -i, -n is specified , only the final one * takes effect (it unsets previous options). */ opt_complementary = "-2:f-in:i-fn:n-fi"; - flags = getopt32(argv, "finv"); + flags = getopt32long(argv, "finv", + "interactive\0" No_argument "i" + "force\0" No_argument "f" + "no-clobber\0" No_argument "n" + IF_FEATURE_VERBOSE( + "verbose\0" No_argument "v" + ) + ); argc -= optind; argv += optind; last = argv[argc - 1]; diff --git a/coreutils/nl.c b/coreutils/nl.c index 93e78c4..c2f8b10 100644 --- a/coreutils/nl.c +++ b/coreutils/nl.c @@ -57,14 +57,13 @@ int nl_main(int argc UNUSED_PARAM, char **argv) "starting-line-number\0"Required_argument "v" "number-width\0" Required_argument "w" ; - - applet_long_options = nl_longopts; #endif ns.width = 6; ns.start = 1; ns.inc = 1; ns.sep = "\t"; - getopt32(argv, "pw:+s:v:+i:+b:", &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b); + getopt32long(argv, "pw:+s:v:+i:+b:", nl_longopts, + &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b); ns.all = (opt_b[0] == 'a'); ns.nonempty = (opt_b[0] == 't'); ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), ""); diff --git a/coreutils/nproc.c b/coreutils/nproc.c index 0ae55e7..336b176 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c @@ -28,7 +28,6 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) unsigned long mask[1024]; unsigned i, count = 0; - //applet_long_options = ...; //getopt32(argv, ""); //if --all, count /sys/devices/system/cpu/cpuN dirs, else: diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index fa0196c..f19875c 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -61,8 +61,8 @@ enum { OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS, }; -#define OD_GETOPT32() getopt32(argv, \ - "A:N:abcdfhij:lot:*vxsS:w:+:", \ +#define OD_GETOPT32() getopt32long(argv, \ + "A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \ /* -w with optional param */ \ /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ @@ -1213,9 +1213,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) address_pad_len_char = '7'; /* Parse command line */ -#if ENABLE_LONG_OPTS - applet_long_options = od_longopts; -#endif opt = OD_GETOPT32(); argv += optind; if (opt & OPT_A) { diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c index c04ce78..9557404 100644 --- a/coreutils/rmdir.c +++ b/coreutils/rmdir.c @@ -11,14 +11,6 @@ //config: default y //config: help //config: rmdir is used to remove empty directories. -//config: -//config:config FEATURE_RMDIR_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on RMDIR && LONG_OPTS -//config: help -//config: Support long options for the rmdir applet, including -//config: --ignore-fail-on-non-empty for compatibility with GNU rmdir. //applet:IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) @@ -31,12 +23,9 @@ //usage: "[OPTIONS] DIRECTORY..." //usage:#define rmdir_full_usage "\n\n" //usage: "Remove DIRECTORY if it is empty\n" -//usage: IF_FEATURE_RMDIR_LONG_OPTIONS( -//usage: "\n -p|--parents Include parents" -//usage: "\n --ignore-fail-on-non-empty" -//usage: ) -//usage: IF_NOT_FEATURE_RMDIR_LONG_OPTIONS( //usage: "\n -p Include parents" +//usage: IF_LONG_OPTS( +//usage: "\n --ignore-fail-on-non-empty" //usage: ) //usage: //usage:#define rmdir_example_usage @@ -49,7 +38,7 @@ #define PARENTS (1 << 0) #define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE) -#define IGNORE_NON_EMPTY (1 << 2) +#define IGNORE_NON_EMPTY ((1 << 2) * ENABLE_LONG_OPTS) int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int rmdir_main(int argc UNUSED_PARAM, char **argv) @@ -58,8 +47,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) int flags; char *path; -#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS - static const char rmdir_longopts[] ALIGN1 = + flags = getopt32long(argv, "pv", "parents\0" No_argument "p" /* Debian etch: many packages fail to be purged or installed * because they desperately want this option: */ @@ -67,10 +55,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_VERBOSE( "verbose\0" No_argument "v" ) - ; - applet_long_options = rmdir_longopts; -#endif - flags = getopt32(argv, "pv"); + ); argv += optind; if (!*argv) { @@ -86,7 +71,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) } if (rmdir(path) < 0) { -#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS +#if ENABLE_LONG_OPTS if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY) break; #endif diff --git a/coreutils/touch.c b/coreutils/touch.c index 11b40d4..8577615 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c @@ -103,6 +103,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv) "date\0" Required_argument "d" IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") ; +# define GETOPT32 getopt32long +# define LONGOPTS ,touch_longopts +# else +# define GETOPT32 getopt32 +# define LONGOPTS # endif char *reference_file = NULL; char *date_str = NULL; @@ -112,17 +117,17 @@ int touch_main(int argc UNUSED_PARAM, char **argv) # define reference_file NULL # define date_str NULL # define timebuf ((struct timeval*)NULL) +# define GETOPT32 getopt32 +# define LONGOPTS #endif -#if ENABLE_FEATURE_TOUCH_SUSV3 && ENABLE_LONG_OPTS - applet_long_options = touch_longopts; -#endif /* -d and -t both set time. In coreutils, * accepted data format differs a bit between -d and -t. * We accept the same formats for both */ - opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") + opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") IF_FEATURE_TOUCH_NODEREF("h") /*ignored:*/ "fma" + LONGOPTS IF_FEATURE_TOUCH_SUSV3(, &reference_file) IF_FEATURE_TOUCH_SUSV3(, &date_str) IF_FEATURE_TOUCH_SUSV3(, &date_str) diff --git a/coreutils/uname.c b/coreutils/uname.c index be9a3f9..bb2d1fe 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c @@ -147,8 +147,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) "operating-system\0" No_argument "o" ; # endif - IF_LONG_OPTS(applet_long_options = uname_longopts); - toprint = getopt32(argv, options); + toprint = getopt32long(argv, options, uname_longopts); if (argv[optind]) { /* coreutils-6.9 compat */ bb_show_usage(); } |