diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-23 17:14:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-23 17:14:14 +0000 |
commit | bdc88fdc6844ee6890e31ba4cf56800becc8c682 (patch) | |
tree | 69301e47c6493ad275d72e57ce96467ee13d7ecc | |
parent | 9fe9c1a6d8e66032a9783f98606167764e8ab296 (diff) | |
download | busybox-w32-bdc88fdc6844ee6890e31ba4cf56800becc8c682.tar.gz busybox-w32-bdc88fdc6844ee6890e31ba4cf56800becc8c682.tar.bz2 busybox-w32-bdc88fdc6844ee6890e31ba4cf56800becc8c682.zip |
rework long option handling. saves ~1.2k
function old new delta
tar_longopts - 222 +222
static.udhcpc_longopts - 192 +192
start_stop_daemon_longopts - 150 +150
getopt32 1045 1185 +140
static.wget_longopts - 111 +111
static.od_longopts - 105 +105
getopt_longopts - 96 +96
install_longopts - 67 +67
ipcalc_longopts - 63 +63
static.hwclock_longopts - 54 +54
ftpgetput_longopts - 52 +52
static.dumpleases_longopts - 32 +32
env_longopts - 31 +31
runparts_longopts - 30 +30
mv_longopts - 24 +24
mkdir_longopts - 19 +19
find_pair 164 180 +16
bb_null_long_options - 16 +16
setconsole_longopts - 10 +10
display_speed 91 98 +7
collect_blk 467 474 +7
show_color 4 1 -3
ls_main 913 904 -9
bb_default_long_options 16 - -16
ls_color_opt 32 10 -22
setconsole_long_options 32 - -32
arith 2077 2030 -47
mv_long_options 48 - -48
mkdir_long_options 48 - -48
env_long_options 48 - -48
static.options 248 184 -64
runparts_long_options 80 - -80
ftpgetput_long_options 96 - -96
static.hwclock_long_options 112 - -112
install_long_options 112 - -112
static.long_options 144 - -144
static.wget_long_options 160 - -160
longopts 160 - -160
static.arg_options 304 - -304
tar_long_options 320 - -320
long_options 384 - -384
------------------------------------------------------------------------------
(add/remove: 17/15 grow/shrink: 4/5 up/down: 1444/-2209) Total: -765 bytes
text data bss dec hex filename
782618 1328 11900 795846 c24c6 busybox_old
781354 1328 11900 794582 c1fd6 busybox_unstripped
-rw-r--r-- | archival/tar.c | 45 | ||||
-rw-r--r-- | console-tools/setconsole.c | 9 | ||||
-rw-r--r-- | coreutils/env.c | 11 | ||||
-rw-r--r-- | coreutils/install.c | 25 | ||||
-rw-r--r-- | coreutils/ls.c | 9 | ||||
-rw-r--r-- | coreutils/mkdir.c | 13 | ||||
-rw-r--r-- | coreutils/mv.c | 11 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 23 | ||||
-rw-r--r-- | debianutils/run_parts.c | 19 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 39 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/getopt32.c | 78 | ||||
-rw-r--r-- | loginutils/chpasswd.c | 9 | ||||
-rw-r--r-- | networking/ftpgetput.c | 17 | ||||
-rw-r--r-- | networking/ipcalc.c | 19 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 43 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 13 | ||||
-rw-r--r-- | networking/wget.c | 27 | ||||
-rw-r--r-- | selinux/chcon.c | 29 | ||||
-rw-r--r-- | selinux/runcon.c | 17 | ||||
-rw-r--r-- | util-linux/getopt.c | 25 | ||||
-rw-r--r-- | util-linux/hwclock.c | 19 |
22 files changed, 255 insertions, 250 deletions
diff --git a/archival/tar.c b/archival/tar.c index bcbb7a994..d03b18b9c 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -715,45 +715,44 @@ enum { | |||
715 | OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions | 715 | OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions |
716 | }; | 716 | }; |
717 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | 717 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
718 | static const struct option tar_long_options[] = { | 718 | static const char tar_longopts[] = |
719 | { "list", 0, NULL, 't' }, | 719 | "list\0" No_argument "t" |
720 | { "extract", 0, NULL, 'x' }, | 720 | "extract\0" No_argument "x" |
721 | { "directory", 1, NULL, 'C' }, | 721 | "directory\0" Required_argument "C" |
722 | { "file", 1, NULL, 'f' }, | 722 | "file\0" Required_argument "f" |
723 | { "to-stdout", 0, NULL, 'O' }, | 723 | "to-stdout\0" No_argument "O" |
724 | { "same-permissions", 0, NULL, 'p' }, | 724 | "same-permissions\0" No_argument "p" |
725 | { "verbose", 0, NULL, 'v' }, | 725 | "verbose\0" No_argument "v" |
726 | { "keep-old", 0, NULL, 'k' }, | 726 | "keep-old\0" No_argument "k" |
727 | # if ENABLE_FEATURE_TAR_CREATE | 727 | # if ENABLE_FEATURE_TAR_CREATE |
728 | { "create", 0, NULL, 'c' }, | 728 | "create\0" No_argument "c" |
729 | { "dereference", 0, NULL, 'h' }, | 729 | "dereference\0" No_argument "h" |
730 | # endif | 730 | # endif |
731 | # if ENABLE_FEATURE_TAR_BZIP2 | 731 | # if ENABLE_FEATURE_TAR_BZIP2 |
732 | { "bzip2", 0, NULL, 'j' }, | 732 | "bzip2\0" No_argument "j" |
733 | # endif | 733 | # endif |
734 | # if ENABLE_FEATURE_TAR_LZMA | 734 | # if ENABLE_FEATURE_TAR_LZMA |
735 | { "lzma", 0, NULL, 'a' }, | 735 | "lzma\0" No_argument "a" |
736 | # endif | 736 | # endif |
737 | # if ENABLE_FEATURE_TAR_FROM | 737 | # if ENABLE_FEATURE_TAR_FROM |
738 | { "files-from", 1, NULL, 'T' }, | 738 | "files-from\0" Required_argument "T" |
739 | { "exclude-from", 1, NULL, 'X' }, | 739 | "exclude-from\0" Required_argument "X" |
740 | # endif | 740 | # endif |
741 | # if ENABLE_FEATURE_TAR_GZIP | 741 | # if ENABLE_FEATURE_TAR_GZIP |
742 | { "gzip", 0, NULL, 'z' }, | 742 | "gzip\0" No_argument "z" |
743 | # endif | 743 | # endif |
744 | # if ENABLE_FEATURE_TAR_COMPRESS | 744 | # if ENABLE_FEATURE_TAR_COMPRESS |
745 | { "compress", 0, NULL, 'Z' }, | 745 | "compress\0" No_argument "Z" |
746 | # endif | 746 | # endif |
747 | { "no-same-owner", 0, NULL, 0xfd }, | 747 | "no-same-owner\0" No_argument "\xfd" |
748 | { "no-same-permissions",0, NULL, 0xfe }, | 748 | "no-same-permissions\0" No_argument "\xfe" |
749 | /* --exclude takes next bit position in option mask, */ | 749 | /* --exclude takes next bit position in option mask, */ |
750 | /* therefore we have to either put it _after_ --no-same-perm */ | 750 | /* therefore we have to either put it _after_ --no-same-perm */ |
751 | /* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */ | 751 | /* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */ |
752 | # if ENABLE_FEATURE_TAR_FROM | 752 | # if ENABLE_FEATURE_TAR_FROM |
753 | { "exclude", 1, NULL, 0xff }, | 753 | "exclude\0" Required_argument "\xff" |
754 | # endif | 754 | # endif |
755 | { 0, 0, 0, 0 } | 755 | "\0"; |
756 | }; | ||
757 | #endif | 756 | #endif |
758 | 757 | ||
759 | int tar_main(int argc, char **argv); | 758 | int tar_main(int argc, char **argv); |
@@ -787,7 +786,7 @@ int tar_main(int argc, char **argv) | |||
787 | USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive | 786 | USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive |
788 | SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive | 787 | SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive |
789 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | 788 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
790 | applet_long_options = tar_long_options; | 789 | applet_long_options = tar_longopts; |
791 | #endif | 790 | #endif |
792 | opt = getopt32(argc, argv, | 791 | opt = getopt32(argc, argv, |
793 | "txC:f:Opvk" | 792 | "txC:f:Opvk" |
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index 8745b3be2..2e60c375e 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c | |||
@@ -11,10 +11,9 @@ | |||
11 | #include "libbb.h" | 11 | #include "libbb.h" |
12 | 12 | ||
13 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS | 13 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
14 | static const struct option setconsole_long_options[] = { | 14 | static const char setconsole_longopts[] = |
15 | { "reset", 0, NULL, 'r' }, | 15 | "reset\0" No_argument "r" |
16 | { 0, 0, 0, 0 } | 16 | "\0"; |
17 | }; | ||
18 | #endif | 17 | #endif |
19 | 18 | ||
20 | #define OPT_SETCONS_RESET 1 | 19 | #define OPT_SETCONS_RESET 1 |
@@ -26,7 +25,7 @@ int setconsole_main(int argc, char **argv) | |||
26 | const char *device = CURRENT_TTY; | 25 | const char *device = CURRENT_TTY; |
27 | 26 | ||
28 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS | 27 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
29 | applet_long_options = setconsole_long_options; | 28 | applet_long_options = setconsole_longopts; |
30 | #endif | 29 | #endif |
31 | flags = getopt32(argc, argv, "r"); | 30 | flags = getopt32(argc, argv, "r"); |
32 | 31 | ||
diff --git a/coreutils/env.c b/coreutils/env.c index ad30f0193..8d20eac9c 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -35,11 +35,10 @@ extern char **environ; | |||
35 | #include "libbb.h" | 35 | #include "libbb.h" |
36 | 36 | ||
37 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 37 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
38 | static const struct option env_long_options[] = { | 38 | static const char env_longopts[] = |
39 | { "ignore-environment", 0, NULL, 'i' }, | 39 | "ignore-environment\0" No_argument "i" |
40 | { "unset", 1, NULL, 'u' }, | 40 | "unset\0" Required_argument "u" |
41 | { 0, 0, 0, 0 } | 41 | "\0"; |
42 | }; | ||
43 | #endif | 42 | #endif |
44 | 43 | ||
45 | int env_main(int argc, char** argv); | 44 | int env_main(int argc, char** argv); |
@@ -53,7 +52,7 @@ int env_main(int argc, char** argv) | |||
53 | 52 | ||
54 | opt_complementary = "u::"; | 53 | opt_complementary = "u::"; |
55 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 54 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
56 | applet_long_options = env_long_options; | 55 | applet_long_options = env_longopts; |
57 | #endif | 56 | #endif |
58 | opt = getopt32(argc, argv, "+iu:", &unset_env); | 57 | opt = getopt32(argc, argv, "+iu:", &unset_env); |
59 | argv += optind; | 58 | argv += optind; |
diff --git a/coreutils/install.c b/coreutils/install.c index 8d71fa070..8d5494958 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -16,20 +16,19 @@ | |||
16 | #include "libcoreutils/coreutils.h" | 16 | #include "libcoreutils/coreutils.h" |
17 | 17 | ||
18 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS | 18 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS |
19 | static const struct option install_long_options[] = { | 19 | static const char install_longopts[] = |
20 | { "directory", 0, NULL, 'd' }, | 20 | "directory\0" No_argument "d" |
21 | { "preserve-timestamps", 0, NULL, 'p' }, | 21 | "preserve-timestamps\0" No_argument "p" |
22 | { "strip", 0, NULL, 's' }, | 22 | "strip\0" No_argument "s" |
23 | { "group", 0, NULL, 'g' }, | 23 | "group\0" No_argument "g" |
24 | { "mode", 0, NULL, 'm' }, | 24 | "mode\0" No_argument "m" |
25 | { "owner", 0, NULL, 'o' }, | 25 | "owner\0" No_argument "o" |
26 | #if ENABLE_SELINUX | 26 | #if ENABLE_SELINUX |
27 | { "context", 1, NULL, 'Z' }, | 27 | "context\0" Required_argument "Z" |
28 | { "preserve_context", 0, NULL, 0xff }, | 28 | "preserve_context\0" No_argument "\xff" |
29 | { "preserve-context", 0, NULL, 0xff }, | 29 | "preserve-context\0" No_argument "\xff" |
30 | #endif | 30 | #endif |
31 | { 0, 0, 0, 0 } | 31 | "\0"; |
32 | }; | ||
33 | #endif | 32 | #endif |
34 | 33 | ||
35 | 34 | ||
@@ -97,7 +96,7 @@ int install_main(int argc, char **argv) | |||
97 | }; | 96 | }; |
98 | 97 | ||
99 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS | 98 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS |
100 | applet_long_options = install_long_options; | 99 | applet_long_options = install_longopts; |
101 | #endif | 100 | #endif |
102 | opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z"); | 101 | opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z"); |
103 | /* -c exists for backwards compatibility, it's needed */ | 102 | /* -c exists for backwards compatibility, it's needed */ |
diff --git a/coreutils/ls.c b/coreutils/ls.c index a5bd0e304..8545edda9 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -117,13 +117,12 @@ SPLIT_SUBDIR = 2, | |||
117 | 117 | ||
118 | /* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */ | 118 | /* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */ |
119 | #if ENABLE_FEATURE_LS_COLOR | 119 | #if ENABLE_FEATURE_LS_COLOR |
120 | static int show_color; | 120 | static smallint show_color; |
121 | /* long option entry used only for --color, which has no short option | 121 | /* long option entry used only for --color, which has no short option |
122 | * equivalent */ | 122 | * equivalent */ |
123 | static const struct option ls_color_opt[] = { | 123 | static const char ls_color_opt[] = |
124 | { "color", optional_argument, NULL, 1 }, | 124 | "color\0" Optional_argument "\xff" /* no short equivalent */ |
125 | { NULL, 0, NULL, 0 } | 125 | "\0"; |
126 | }; | ||
127 | #else | 126 | #else |
128 | enum { show_color = 0 }; | 127 | enum { show_color = 0 }; |
129 | #endif | 128 | #endif |
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 60c03a1f9..b0595b43f 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c | |||
@@ -25,14 +25,13 @@ | |||
25 | /* This is a NOFORK applet. Be very careful! */ | 25 | /* This is a NOFORK applet. Be very careful! */ |
26 | 26 | ||
27 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS | 27 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS |
28 | static const struct option mkdir_long_options[] = { | 28 | static const char mkdir_longopts[] = |
29 | { "mode" , 1, NULL, 'm' }, | 29 | "mode\0" Required_argument "m" |
30 | { "parents", 0, NULL, 'p' }, | 30 | "parents\0" No_argument "p" |
31 | #if ENABLE_SELINUX | 31 | #if ENABLE_SELINUX |
32 | { "context", 1, NULL, 'Z' }, | 32 | "context\0" Required_argument "Z" |
33 | #endif | 33 | #endif |
34 | { NULL, 0, NULL, 0 } | 34 | "\0"; |
35 | }; | ||
36 | #endif | 35 | #endif |
37 | 36 | ||
38 | int mkdir_main(int argc, char **argv); | 37 | int mkdir_main(int argc, char **argv); |
@@ -48,7 +47,7 @@ int mkdir_main(int argc, char **argv) | |||
48 | #endif | 47 | #endif |
49 | 48 | ||
50 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS | 49 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS |
51 | applet_long_options = mkdir_long_options; | 50 | applet_long_options = mkdir_longopts; |
52 | #endif | 51 | #endif |
53 | opt = getopt32(argc, argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext)); | 52 | opt = getopt32(argc, argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext)); |
54 | if (opt & 1) { | 53 | if (opt & 1) { |
diff --git a/coreutils/mv.c b/coreutils/mv.c index 8d9c9827a..bb96af8f6 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -21,11 +21,10 @@ | |||
21 | #include "libcoreutils/coreutils.h" | 21 | #include "libcoreutils/coreutils.h" |
22 | 22 | ||
23 | #if ENABLE_FEATURE_MV_LONG_OPTIONS | 23 | #if ENABLE_FEATURE_MV_LONG_OPTIONS |
24 | static const struct option mv_long_options[] = { | 24 | static const char mv_longopts[] = |
25 | { "interactive", 0, NULL, 'i' }, | 25 | "interactive\0" No_argument "i" |
26 | { "force", 0, NULL, 'f' }, | 26 | "force\0" No_argument "f" |
27 | { 0, 0, 0, 0 } | 27 | "\0"; |
28 | }; | ||
29 | #endif | 28 | #endif |
30 | 29 | ||
31 | #define OPT_FILEUTILS_FORCE 1 | 30 | #define OPT_FILEUTILS_FORCE 1 |
@@ -45,7 +44,7 @@ int mv_main(int argc, char **argv) | |||
45 | int copy_flag = 0; | 44 | int copy_flag = 0; |
46 | 45 | ||
47 | #if ENABLE_FEATURE_MV_LONG_OPTIONS | 46 | #if ENABLE_FEATURE_MV_LONG_OPTIONS |
48 | applet_long_options = mv_long_options; | 47 | applet_long_options = mv_longopts; |
49 | #endif | 48 | #endif |
50 | opt_complementary = "f-i:i-f"; | 49 | opt_complementary = "f-i:i-f"; |
51 | flags = getopt32(argc, argv, "fi"); | 50 | flags = getopt32(argc, argv, "fi"); |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index af5eba9ce..335efe7ca 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -1242,17 +1242,16 @@ int od_main(int argc, char **argv) | |||
1242 | OPT_traditional = (1 << 18) * ENABLE_GETOPT_LONG, | 1242 | OPT_traditional = (1 << 18) * ENABLE_GETOPT_LONG, |
1243 | }; | 1243 | }; |
1244 | #if ENABLE_GETOPT_LONG | 1244 | #if ENABLE_GETOPT_LONG |
1245 | static const struct option long_options[] = { | 1245 | static const char od_longopts[] = |
1246 | { "skip-bytes", required_argument, NULL, 'j' }, | 1246 | "skip-bytes\0" Required_argument "j" |
1247 | { "address-radix", required_argument, NULL, 'A' }, | 1247 | "address-radix\0" Required_argument "A" |
1248 | { "read-bytes", required_argument, NULL, 'N' }, | 1248 | "read-bytes\0" Required_argument "N" |
1249 | { "format", required_argument, NULL, 't' }, | 1249 | "format\0" Required_argument "t" |
1250 | { "output-duplicates", no_argument, NULL, 'v' }, | 1250 | "output-duplicates\0" No_argument "v" |
1251 | { "strings", optional_argument, NULL, 'S' }, | 1251 | "strings\0" Optional_argument "S" |
1252 | { "width", optional_argument, NULL, 'w' }, | 1252 | "width\0" Optional_argument "w" |
1253 | { "traditional", no_argument, NULL, 0xff }, | 1253 | "traditional\0" No_argument "\xff" |
1254 | { NULL, 0, NULL, 0 } | 1254 | "\0"; |
1255 | }; | ||
1256 | #endif | 1255 | #endif |
1257 | char *str_A, *str_N, *str_j, *str_S; | 1256 | char *str_A, *str_N, *str_j, *str_S; |
1258 | char *str_w = NULL; | 1257 | char *str_w = NULL; |
@@ -1267,7 +1266,7 @@ int od_main(int argc, char **argv) | |||
1267 | /* Parse command line */ | 1266 | /* Parse command line */ |
1268 | opt_complementary = "t::"; // list | 1267 | opt_complementary = "t::"; // list |
1269 | #if ENABLE_GETOPT_LONG | 1268 | #if ENABLE_GETOPT_LONG |
1270 | applet_long_options = long_options; | 1269 | applet_long_options = od_longopts; |
1271 | #endif | 1270 | #endif |
1272 | opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:" | 1271 | opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:" |
1273 | "w::", // -w with optional param | 1272 | "w::", // -w with optional param |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 42170bcb8..4173987ab 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -35,17 +35,16 @@ | |||
35 | #include "libbb.h" | 35 | #include "libbb.h" |
36 | 36 | ||
37 | #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS | 37 | #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS |
38 | static const struct option runparts_long_options[] = { | 38 | static const char runparts_longopts[] = |
39 | { "arg", 1, NULL, 'a' }, | 39 | "arg\0" Required_argument "a" |
40 | { "umask", 1, NULL, 'u' }, | 40 | "umask\0" Required_argument "u" |
41 | { "test", 0, NULL, 't' }, | 41 | "test\0" No_argument "t" |
42 | #if ENABLE_FEATURE_RUN_PARTS_FANCY | 42 | #if ENABLE_FEATURE_RUN_PARTS_FANCY |
43 | { "list", 0, NULL, 'l' }, | 43 | "list\0" No_argument "l" |
44 | //XXX:TODO: { "reverse", 0, NULL, 'r' }, | 44 | //TODO: "reverse\0" No_argument "r" |
45 | //XXX:TODO: { "verbose", 0, NULL, 'v' }, | 45 | //TODO: "verbose\0" No_argument "v" |
46 | #endif | 46 | #endif |
47 | { 0, 0, 0, 0 } | 47 | "\0"; |
48 | }; | ||
49 | #endif | 48 | #endif |
50 | 49 | ||
51 | struct globals { | 50 | struct globals { |
@@ -120,7 +119,7 @@ int run_parts_main(int argc, char **argv) | |||
120 | /* We require exactly one argument: the directory name */ | 119 | /* We require exactly one argument: the directory name */ |
121 | opt_complementary = "=1:a::"; | 120 | opt_complementary = "=1:a::"; |
122 | #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS | 121 | #if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS |
123 | applet_long_options = runparts_long_options; | 122 | applet_long_options = runparts_longopts; |
124 | #endif | 123 | #endif |
125 | tmp = getopt32(argc, argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p); | 124 | tmp = getopt32(argc, argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p); |
126 | G.mode = tmp &~ (RUN_PARTS_OPT_a|RUN_PARTS_OPT_u); | 125 | G.mode = tmp &~ (RUN_PARTS_OPT_a|RUN_PARTS_OPT_u); |
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index fd9f60ce9..0c8dea760 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -194,29 +194,28 @@ static int do_stop(void) | |||
194 | } | 194 | } |
195 | 195 | ||
196 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS | 196 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS |
197 | static const struct option long_options[] = { | 197 | static const char start_stop_daemon_longopts[] = |
198 | { "stop", 0, NULL, 'K' }, | 198 | "stop\0" No_argument "K" |
199 | { "start", 0, NULL, 'S' }, | 199 | "start\0" No_argument "S" |
200 | { "background", 0, NULL, 'b' }, | 200 | "background\0" No_argument "b" |
201 | { "quiet", 0, NULL, 'q' }, | 201 | "quiet\0" No_argument "q" |
202 | { "make-pidfile", 0, NULL, 'm' }, | 202 | "make-pidfile\0" No_argument "m" |
203 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 203 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
204 | { "oknodo", 0, NULL, 'o' }, | 204 | "oknodo\0" No_argument "o" |
205 | { "verbose", 0, NULL, 'v' }, | 205 | "verbose\0" No_argument "v" |
206 | { "nicelevel", 1, NULL, 'N' }, | 206 | "nicelevel\0" Required_argument "N" |
207 | #endif | 207 | #endif |
208 | { "startas", 1, NULL, 'a' }, | 208 | "startas\0" Required_argument "a" |
209 | { "name", 1, NULL, 'n' }, | 209 | "name\0" Required_argument "n" |
210 | { "signal", 1, NULL, 's' }, | 210 | "signal\0" Required_argument "s" |
211 | { "user", 1, NULL, 'u' }, | 211 | "user\0" Required_argument "u" |
212 | { "chuid", 1, NULL, 'c' }, | 212 | "chuid\0" Required_argument "c" |
213 | { "exec", 1, NULL, 'x' }, | 213 | "exec\0" Required_argument "x" |
214 | { "pidfile", 1, NULL, 'p' }, | 214 | "pidfile\0" Required_argument "p" |
215 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY | 215 | #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY |
216 | { "retry", 1, NULL, 'R' }, | 216 | "retry\0" Required_argument "R" |
217 | #endif | 217 | #endif |
218 | { 0, 0, 0, 0 } | 218 | "\0"; |
219 | }; | ||
220 | #endif | 219 | #endif |
221 | 220 | ||
222 | enum { | 221 | enum { |
@@ -250,7 +249,7 @@ int start_stop_daemon_main(int argc, char **argv) | |||
250 | char *opt_N; | 249 | char *opt_N; |
251 | #endif | 250 | #endif |
252 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS | 251 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS |
253 | applet_long_options = long_options; | 252 | applet_long_options = start_stop_daemon_longopts; |
254 | #endif | 253 | #endif |
255 | 254 | ||
256 | /* Check required one context option was given */ | 255 | /* Check required one context option was given */ |
diff --git a/include/libbb.h b/include/libbb.h index b8ec83927..fe99e5eec 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -590,7 +590,10 @@ void bb_sanitize_stdio(void); | |||
590 | 590 | ||
591 | extern const char *opt_complementary; | 591 | extern const char *opt_complementary; |
592 | #if ENABLE_GETOPT_LONG | 592 | #if ENABLE_GETOPT_LONG |
593 | extern const struct option *applet_long_options; | 593 | #define No_argument "\0" |
594 | #define Required_argument "\001" | ||
595 | #define Optional_argument "\002" | ||
596 | extern const char *applet_long_options; | ||
594 | #endif | 597 | #endif |
595 | extern uint32_t option_mask32; | 598 | extern uint32_t option_mask32; |
596 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); | 599 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); |
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f5aaa70df..e5d97e98c 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -72,24 +72,21 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
72 | env -i ls -d / | 72 | env -i ls -d / |
73 | Here we want env to process just the '-i', not the '-d'. | 73 | Here we want env to process just the '-i', not the '-d'. |
74 | 74 | ||
75 | const struct option *applet_long_options | 75 | const char *applet_long_options |
76 | 76 | ||
77 | This struct allows you to define long options. The syntax for | 77 | This struct allows you to define long options: |
78 | declaring the array is just like that of getopt's longopts. | ||
79 | (see getopt(3)) | ||
80 | 78 | ||
81 | static const struct option applet_long_options[] = { | 79 | static const char applet_longopts[] = |
82 | //name,has_arg,flag,val | 80 | //"name\0" has_arg val |
83 | { "verbose", 0, 0, 'v' }, | 81 | "verbose\0" No_argument "v" |
84 | { 0, 0, 0, 0 } | 82 | "\0"; |
85 | }; | 83 | applet_long_options = applet_longopts; |
86 | applet_long_options = applet_long_options; | ||
87 | 84 | ||
88 | The last member of struct option (val) typically is set to | 85 | The last member of struct option (val) typically is set to |
89 | matching short option from applet_opts. If there is no matching | 86 | matching short option from applet_opts. If there is no matching |
90 | char in applet_opts, then: | 87 | char in applet_opts, then: |
91 | - return bit have next position after short options | 88 | - return bit have next position after short options |
92 | - if has_arg is not "no_argument", use ptr for arg also | 89 | - if has_arg is not "No_argument", use ptr for arg also |
93 | - opt_complementary affects it too | 90 | - opt_complementary affects it too |
94 | 91 | ||
95 | Note: a good applet will make long options configurable via the | 92 | Note: a good applet will make long options configurable via the |
@@ -290,12 +287,10 @@ typedef struct { | |||
290 | 287 | ||
291 | /* You can set applet_long_options for parse called long options */ | 288 | /* You can set applet_long_options for parse called long options */ |
292 | #if ENABLE_GETOPT_LONG | 289 | #if ENABLE_GETOPT_LONG |
293 | static const struct option bb_default_long_options[] = { | 290 | static const struct option bb_null_long_options[1] = { |
294 | /* { "help", 0, NULL, '?' }, */ | ||
295 | { 0, 0, 0, 0 } | 291 | { 0, 0, 0, 0 } |
296 | }; | 292 | }; |
297 | 293 | const char *applet_long_options; | |
298 | const struct option *applet_long_options = bb_default_long_options; | ||
299 | #endif | 294 | #endif |
300 | 295 | ||
301 | uint32_t option_mask32; | 296 | uint32_t option_mask32; |
@@ -312,6 +307,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
312 | va_list p; | 307 | va_list p; |
313 | #if ENABLE_GETOPT_LONG | 308 | #if ENABLE_GETOPT_LONG |
314 | const struct option *l_o; | 309 | const struct option *l_o; |
310 | struct option *long_options = NULL; | ||
315 | #endif | 311 | #endif |
316 | unsigned trigger; | 312 | unsigned trigger; |
317 | char **pargv = NULL; | 313 | char **pargv = NULL; |
@@ -347,19 +343,42 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
347 | } | 343 | } |
348 | 344 | ||
349 | #if ENABLE_GETOPT_LONG | 345 | #if ENABLE_GETOPT_LONG |
350 | for (l_o = applet_long_options; l_o->name; l_o++) { | 346 | if (applet_long_options) { |
351 | if (l_o->flag) | 347 | const char *optstr; |
352 | continue; | 348 | unsigned i, count; |
353 | for (on_off = complementary; on_off->opt != 0; on_off++) | 349 | |
354 | if (on_off->opt == l_o->val) | 350 | count = 1; |
355 | goto next_long; | 351 | optstr = applet_long_options; |
356 | if (c >= 32) break; | 352 | while (optstr[0]) { |
357 | on_off->opt = l_o->val; | 353 | optstr += strlen(optstr) + 3; /* skip \0, has_arg, val */ |
358 | on_off->switch_on = (1 << c); | 354 | count++; |
359 | if (l_o->has_arg != no_argument) | 355 | } |
360 | on_off->optarg = va_arg(p, void **); | 356 | /* count == no. of longopts + 1 */ |
361 | c++; | 357 | long_options = xzalloc(count * sizeof(*long_options)); |
358 | i = 0; | ||
359 | optstr = applet_long_options; | ||
360 | while (--count) { | ||
361 | long_options[i].name = optstr; | ||
362 | optstr += strlen(optstr) + 1; | ||
363 | long_options[i].has_arg = (unsigned char)(*optstr++); | ||
364 | /* long_options[i].flag = NULL; */ | ||
365 | long_options[i].val = (unsigned char)(*optstr++); | ||
366 | i++; | ||
367 | } | ||
368 | for (l_o = long_options; l_o->name; l_o++) { | ||
369 | if (l_o->flag) | ||
370 | continue; | ||
371 | for (on_off = complementary; on_off->opt != 0; on_off++) | ||
372 | if (on_off->opt == l_o->val) | ||
373 | goto next_long; | ||
374 | if (c >= 32) break; | ||
375 | on_off->opt = l_o->val; | ||
376 | on_off->switch_on = (1 << c); | ||
377 | if (l_o->has_arg != no_argument) | ||
378 | on_off->optarg = va_arg(p, void **); | ||
379 | c++; | ||
362 | next_long: ; | 380 | next_long: ; |
381 | } | ||
363 | } | 382 | } |
364 | #endif /* ENABLE_GETOPT_LONG */ | 383 | #endif /* ENABLE_GETOPT_LONG */ |
365 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { | 384 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { |
@@ -457,7 +476,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
457 | * (supposed to act as --header, but doesn't) */ | 476 | * (supposed to act as --header, but doesn't) */ |
458 | #if ENABLE_GETOPT_LONG | 477 | #if ENABLE_GETOPT_LONG |
459 | while ((c = getopt_long(argc, argv, applet_opts, | 478 | while ((c = getopt_long(argc, argv, applet_opts, |
460 | applet_long_options, NULL)) != -1) { | 479 | long_options ? long_options : bb_null_long_options, NULL)) != -1) { |
461 | #else | 480 | #else |
462 | while ((c = getopt(argc, argv, applet_opts)) != -1) { | 481 | while ((c = getopt(argc, argv, applet_opts)) != -1) { |
463 | #endif | 482 | #endif |
@@ -516,6 +535,9 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
516 | if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) | 535 | if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) |
517 | bb_show_usage(); | 536 | bb_show_usage(); |
518 | 537 | ||
538 | #if ENABLE_GETOPT_LONG | ||
539 | free(long_options); | ||
540 | #endif | ||
519 | option_mask32 = flags; | 541 | option_mask32 = flags; |
520 | return flags; | 542 | return flags; |
521 | } | 543 | } |
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index f91ebdc68..a4a9a554f 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -11,11 +11,10 @@ | |||
11 | #if ENABLE_GETOPT_LONG | 11 | #if ENABLE_GETOPT_LONG |
12 | #include <getopt.h> | 12 | #include <getopt.h> |
13 | 13 | ||
14 | static const struct option chpasswd_opts[] = { | 14 | static const char chpasswd_opts[] = |
15 | { "encrypted", no_argument, NULL, 'e' }, | 15 | "encrypted\0" No_argument "e" |
16 | { "md5", no_argument, NULL, 'm' }, | 16 | "md5\0" No_argument "m" |
17 | { NULL, 0, NULL, 0 } | 17 | "\0"; |
18 | }; | ||
19 | #endif | 18 | #endif |
20 | 19 | ||
21 | #define OPT_ENC 1 | 20 | #define OPT_ENC 1 |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 54b5f5a91..011fbac84 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -287,14 +287,13 @@ int ftp_send(ftp_host_info_t *server, FILE *control_stream, | |||
287 | #define FTPGETPUT_OPT_PORT 16 | 287 | #define FTPGETPUT_OPT_PORT 16 |
288 | 288 | ||
289 | #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS | 289 | #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS |
290 | static const struct option ftpgetput_long_options[] = { | 290 | static const char ftpgetput_longopts[] = |
291 | { "continue", 1, NULL, 'c' }, | 291 | "continue\0" Required_argument "c" |
292 | { "verbose", 0, NULL, 'v' }, | 292 | "verbose\0" No_argument "v" |
293 | { "username", 1, NULL, 'u' }, | 293 | "username\0" Required_argument "u" |
294 | { "password", 1, NULL, 'p' }, | 294 | "password\0" Required_argument "p" |
295 | { "port", 1, NULL, 'P' }, | 295 | "port\0" Required_argument "P" |
296 | { 0, 0, 0, 0 } | 296 | "\0"; |
297 | }; | ||
298 | #endif | 297 | #endif |
299 | 298 | ||
300 | int ftpgetput_main(int argc, char **argv); | 299 | int ftpgetput_main(int argc, char **argv); |
@@ -329,7 +328,7 @@ int ftpgetput_main(int argc, char **argv) | |||
329 | * Decipher the command line | 328 | * Decipher the command line |
330 | */ | 329 | */ |
331 | #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS | 330 | #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS |
332 | applet_long_options = ftpgetput_long_options; | 331 | applet_long_options = ftpgetput_longopts; |
333 | #endif | 332 | #endif |
334 | opt_complementary = "=3"; /* must have 3 params */ | 333 | opt_complementary = "=3"; /* must have 3 params */ |
335 | opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port); | 334 | opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port); |
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index a39ad1a67..32b939f96 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -63,17 +63,16 @@ int get_prefix(unsigned long netmask); | |||
63 | #define SILENT 0x20 | 63 | #define SILENT 0x20 |
64 | 64 | ||
65 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS | 65 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS |
66 | static const struct option long_options[] = { | 66 | static const char ipcalc_longopts[] = |
67 | { "netmask", no_argument, NULL, 'm' }, | 67 | "netmask\0" No_argument "m" |
68 | { "broadcast", no_argument, NULL, 'b' }, | 68 | "broadcast\0" No_argument "b" |
69 | { "network", no_argument, NULL, 'n' }, | 69 | "network\0" No_argument "n" |
70 | # if ENABLE_FEATURE_IPCALC_FANCY | 70 | # if ENABLE_FEATURE_IPCALC_FANCY |
71 | { "prefix", no_argument, NULL, 'p' }, | 71 | "prefix\0" No_argument "p" |
72 | { "hostname", no_argument, NULL, 'h' }, | 72 | "hostname\0" No_argument "h" |
73 | { "silent", no_argument, NULL, 's' }, | 73 | "silent\0" No_argument "s" |
74 | # endif | 74 | # endif |
75 | { NULL, 0, NULL, 0 } | 75 | "\0"; |
76 | }; | ||
77 | #endif | 76 | #endif |
78 | 77 | ||
79 | int ipcalc_main(int argc, char **argv); | 78 | int ipcalc_main(int argc, char **argv); |
@@ -86,7 +85,7 @@ int ipcalc_main(int argc, char **argv) | |||
86 | char *ipstr; | 85 | char *ipstr; |
87 | 86 | ||
88 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS | 87 | #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS |
89 | applet_long_options = long_options; | 88 | applet_long_options = ipcalc_longopts; |
90 | #endif | 89 | #endif |
91 | opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); | 90 | opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); |
92 | argc -= optind; | 91 | argc -= optind; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 3165c2d68..2b95c3250 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -181,27 +181,26 @@ int udhcpc_main(int argc, char **argv) | |||
181 | OPT_v = 1 << 17, | 181 | OPT_v = 1 << 17, |
182 | }; | 182 | }; |
183 | #if ENABLE_GETOPT_LONG | 183 | #if ENABLE_GETOPT_LONG |
184 | static const struct option arg_options[] = { | 184 | static const char udhcpc_longopts[] = |
185 | { "clientid", required_argument, 0, 'c' }, | 185 | "clientid\0" Required_argument "c" |
186 | { "clientid-none", no_argument, 0, 'C' }, | 186 | "clientid-none\0" No_argument "C" |
187 | { "vendorclass", required_argument, 0, 'V' }, | 187 | "vendorclass\0" Required_argument "V" |
188 | { "foreground", no_argument, 0, 'f' }, | 188 | "foreground\0" No_argument "f" |
189 | { "background", no_argument, 0, 'b' }, | 189 | "background\0" No_argument "b" |
190 | { "hostname", required_argument, 0, 'H' }, | 190 | "hostname\0" Required_argument "H" |
191 | { "hostname", required_argument, 0, 'h' }, | 191 | "hostname\0" Required_argument "h" |
192 | { "fqdn", required_argument, 0, 'F' }, | 192 | "fqdn\0" Required_argument "F" |
193 | { "interface", required_argument, 0, 'i' }, | 193 | "interface\0" Required_argument "i" |
194 | { "now", no_argument, 0, 'n' }, | 194 | "now\0" No_argument "n" |
195 | { "pidfile", required_argument, 0, 'p' }, | 195 | "pidfile\0" Required_argument "p" |
196 | { "quit", no_argument, 0, 'q' }, | 196 | "quit\0" No_argument "q" |
197 | { "release", no_argument, 0, 'R' }, | 197 | "release\0" No_argument "R" |
198 | { "request", required_argument, 0, 'r' }, | 198 | "request\0" Required_argument "r" |
199 | { "script", required_argument, 0, 's' }, | 199 | "script\0" Required_argument "s" |
200 | { "timeout", required_argument, 0, 'T' }, | 200 | "timeout\0" Required_argument "T" |
201 | { "version", no_argument, 0, 'v' }, | 201 | "version\0" No_argument "v" |
202 | { "retries", required_argument, 0, 't' }, | 202 | "retries\0" Required_argument "t" |
203 | { 0, 0, 0, 0 } | 203 | "\0"; |
204 | }; | ||
205 | #endif | 204 | #endif |
206 | /* Default options. */ | 205 | /* Default options. */ |
207 | client_config.interface = "eth0"; | 206 | client_config.interface = "eth0"; |
@@ -213,7 +212,7 @@ int udhcpc_main(int argc, char **argv) | |||
213 | opt_complementary = "c--C:C--c" // mutually exclusive | 212 | opt_complementary = "c--C:C--c" // mutually exclusive |
214 | ":hH:Hh"; // -h and -H are the same | 213 | ":hH:Hh"; // -h and -H are the same |
215 | #if ENABLE_GETOPT_LONG | 214 | #if ENABLE_GETOPT_LONG |
216 | applet_long_options = arg_options; | 215 | applet_long_options = udhcpc_longopts; |
217 | #endif | 216 | #endif |
218 | opt = getopt32(argc, argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:v", | 217 | opt = getopt32(argc, argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:v", |
219 | &str_c, &str_V, &str_h, &str_h, &str_F, | 218 | &str_c, &str_V, &str_h, &str_h, &str_F, |
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 95df7ea36..fb50d6888 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -24,14 +24,13 @@ int dumpleases_main(int argc, char **argv) | |||
24 | OPT_f = 0x4, // -f | 24 | OPT_f = 0x4, // -f |
25 | }; | 25 | }; |
26 | #if ENABLE_GETOPT_LONG | 26 | #if ENABLE_GETOPT_LONG |
27 | static const struct option options[] = { | 27 | static const char dumpleases_longopts[] = |
28 | { "absolute", no_argument, 0, 'a' }, | 28 | "absolute\0" No_argument "a" |
29 | { "remaining", no_argument, 0, 'r' }, | 29 | "remaining\0" No_argument "r" |
30 | { "file", required_argument, 0, 'f' }, | 30 | "file\0" Required_argument "f" |
31 | { NULL, 0, 0, 0 } | 31 | "\0"; |
32 | }; | ||
33 | 32 | ||
34 | applet_long_options = options; | 33 | applet_long_options = dumpleases_longopts; |
35 | #endif | 34 | #endif |
36 | opt_complementary = "=0:a--r:r--a"; | 35 | opt_complementary = "=0:a--r:r--a"; |
37 | opt = getopt32(argc, argv, "arf:", &file); | 36 | opt = getopt32(argc, argv, "arf:", &file); |
diff --git a/networking/wget.c b/networking/wget.c index 19ff792ed..ad09091d3 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -132,20 +132,19 @@ int wget_main(int argc, char **argv) | |||
132 | WGET_OPT_HEADER = 0x100, | 132 | WGET_OPT_HEADER = 0x100, |
133 | }; | 133 | }; |
134 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 134 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
135 | static const struct option wget_long_options[] = { | 135 | static const char wget_longopts[] = |
136 | /* name, has_arg, flag, val */ | 136 | /* name, has_arg, val */ |
137 | { "continue", no_argument, NULL, 'c' }, | 137 | "continue\0" No_argument "c" |
138 | { "spider", no_argument, NULL, 's' }, | 138 | "spider\0" No_argument "s" |
139 | { "quiet", no_argument, NULL, 'q' }, | 139 | "quiet\0" No_argument "q" |
140 | { "output-document", required_argument, NULL, 'O' }, | 140 | "output-document\0" Required_argument "O" |
141 | { "directory-prefix", required_argument, NULL, 'P' }, | 141 | "directory-prefix\0" Required_argument "P" |
142 | { "proxy", required_argument, NULL, 'Y' }, | 142 | "proxy\0" Required_argument "Y" |
143 | { "user-agent", required_argument, NULL, 'U' }, | 143 | "user-agent\0" Required_argument "U" |
144 | { "passive-ftp", no_argument, NULL, 0xff }, | 144 | "passive-ftp\0" No_argument "\xff" |
145 | { "header", required_argument, NULL, 0xfe }, | 145 | "header\0" Required_argument "\xfe" |
146 | { 0, 0, 0, 0 } | 146 | "\0"; |
147 | }; | 147 | applet_long_options = wget_longopts; |
148 | applet_long_options = wget_long_options; | ||
149 | #endif | 148 | #endif |
150 | /* server.allocated = target.allocated = NULL; */ | 149 | /* server.allocated = target.allocated = NULL; */ |
151 | opt_complementary = "-1" USE_FEATURE_WGET_LONG_OPTIONS(":\xfe::"); | 150 | opt_complementary = "-1" USE_FEATURE_WGET_LONG_OPTIONS(":\xfe::"); |
diff --git a/selinux/chcon.c b/selinux/chcon.c index a8a816be0..689ec8c8c 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c | |||
@@ -105,20 +105,19 @@ skip: | |||
105 | } | 105 | } |
106 | 106 | ||
107 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 107 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS |
108 | static struct option chcon_options[] = { | 108 | static const char chcon_longopts[] = |
109 | { "recursive", 0, NULL, 'R' }, | 109 | "recursive\0" No_argument "R" |
110 | { "changes", 0, NULL, 'c' }, | 110 | "changes\0" No_argument "c" |
111 | { "no-dereference", 0, NULL, 'h' }, | 111 | "no-dereference\0" No_argument "h" |
112 | { "silent", 0, NULL, 'f' }, | 112 | "silent\0" No_argument "f" |
113 | { "quiet", 0, NULL, 'f' }, | 113 | "quiet\0" No_argument "f" |
114 | { "user", 1, NULL, 'u' }, | 114 | "user\0" Required_argument "u" |
115 | { "role", 1, NULL, 'r' }, | 115 | "role\0" Required_argument "r" |
116 | { "type", 1, NULL, 't' }, | 116 | "type\0" Required_argument "t" |
117 | { "range", 1, NULL, 'l' }, | 117 | "range\0" Required_argument "l" |
118 | { "verbose", 0, NULL, 'v' }, | 118 | "verbose\0" No_argument "v" |
119 | { "reference", 1, NULL, 0xff }, /* no short option */ | 119 | "reference\0" Required_argument "\xff" /* no short option */ |
120 | { NULL, 0, NULL, 0 }, | 120 | "\0"; |
121 | }; | ||
122 | #endif | 121 | #endif |
123 | 122 | ||
124 | int chcon_main(int argc, char **argv); | 123 | int chcon_main(int argc, char **argv); |
@@ -129,7 +128,7 @@ int chcon_main(int argc, char **argv) | |||
129 | int i, errors = 0; | 128 | int i, errors = 0; |
130 | 129 | ||
131 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 130 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS |
132 | applet_long_options = chcon_options; | 131 | applet_long_options = chcon_longopts; |
133 | #endif | 132 | #endif |
134 | opt_complementary = "-1" /* at least 1 param */ | 133 | opt_complementary = "-1" /* at least 1 param */ |
135 | ":?" /* error if exclusivity constraints are violated */ | 134 | ":?" /* error if exclusivity constraints are violated */ |
diff --git a/selinux/runcon.c b/selinux/runcon.c index 741c7bba6..3502dcd3a 100644 --- a/selinux/runcon.c +++ b/selinux/runcon.c | |||
@@ -69,15 +69,14 @@ static context_t runcon_compute_new_context(char *user, char *role, char *type, | |||
69 | } | 69 | } |
70 | 70 | ||
71 | #if ENABLE_FEATURE_RUNCON_LONG_OPTIONS | 71 | #if ENABLE_FEATURE_RUNCON_LONG_OPTIONS |
72 | static const struct option runcon_options[] = { | 72 | static const char runcon_options[] = |
73 | { "user", 1, NULL, 'u' }, | 73 | "user\0" Required_argument "u" |
74 | { "role", 1, NULL, 'r' }, | 74 | "role\0" Required_argument "r" |
75 | { "type", 1, NULL, 't' }, | 75 | "type\0" Required_argument "t" |
76 | { "range", 1, NULL, 'l' }, | 76 | "range\0" Required_argument "l" |
77 | { "compute", 0, NULL, 'c' }, | 77 | "compute\0" No_argument "c" |
78 | { "help", 0, NULL, 'h' }, | 78 | "help\0" No_argument "h" |
79 | { NULL, 0, NULL, 0 }, | 79 | "\0"; |
80 | }; | ||
81 | #endif | 80 | #endif |
82 | 81 | ||
83 | #define OPTS_ROLE (1<<0) /* r */ | 82 | #define OPTS_ROLE (1<<0) /* r */ |
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index a5e674368..5ee13ec8b 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -266,18 +266,17 @@ static void set_shell(const char *new_shell) | |||
266 | */ | 266 | */ |
267 | 267 | ||
268 | #if ENABLE_GETOPT_LONG | 268 | #if ENABLE_GETOPT_LONG |
269 | static const struct option longopts[] = { | 269 | static const char getopt_longopts[] = |
270 | { "options", required_argument, NULL, 'o' }, | 270 | "options\0" Required_argument "o" |
271 | { "longoptions", required_argument, NULL, 'l' }, | 271 | "longoptions\0" Required_argument "l" |
272 | { "quiet", no_argument, NULL, 'q' }, | 272 | "quiet\0" No_argument "q" |
273 | { "quiet-output", no_argument, NULL, 'Q' }, | 273 | "quiet-output\0" No_argument "Q" |
274 | { "shell", required_argument, NULL, 's' }, | 274 | "shell\0" Required_argument "s" |
275 | { "test", no_argument, NULL, 'T' }, | 275 | "test\0" No_argument "T" |
276 | { "unquoted", no_argument, NULL, 'u' }, | 276 | "unquoted\0" No_argument "u" |
277 | { "alternative", no_argument, NULL, 'a' }, | 277 | "alternative\0" No_argument "a" |
278 | { "name", required_argument, NULL, 'n' }, | 278 | "name\0" Required_argument "n" |
279 | { NULL, 0, NULL, 0 } | 279 | "\0"; |
280 | }; | ||
281 | #endif | 280 | #endif |
282 | 281 | ||
283 | int getopt_main(int argc, char *argv[]); | 282 | int getopt_main(int argc, char *argv[]); |
@@ -317,7 +316,7 @@ int getopt_main(int argc, char *argv[]) | |||
317 | #if !ENABLE_GETOPT_LONG | 316 | #if !ENABLE_GETOPT_LONG |
318 | opt = getopt32(argc, argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); | 317 | opt = getopt32(argc, argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); |
319 | #else | 318 | #else |
320 | applet_long_options = longopts; | 319 | applet_long_options = getopt_longopts; |
321 | opt_complementary = "l::"; | 320 | opt_complementary = "l::"; |
322 | opt = getopt32(argc, argv, "+o:n:qQs:Tual:", | 321 | opt = getopt32(argc, argv, "+o:n:qQs:Tual:", |
323 | &optstr, &name, &s_arg, &l_arg); | 322 | &optstr, &name, &s_arg, &l_arg); |
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 882a0c55a..ff696a3d7 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -178,16 +178,15 @@ int hwclock_main(int argc, char **argv) | |||
178 | int utc; | 178 | int utc; |
179 | 179 | ||
180 | #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS | 180 | #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS |
181 | static const struct option hwclock_long_options[] = { | 181 | static const char hwclock_longopts[] = |
182 | { "localtime", 0, 0, 'l' }, | 182 | "localtime\0" No_argument "l" |
183 | { "utc", 0, 0, 'u' }, | 183 | "utc\0" No_argument "u" |
184 | { "show", 0, 0, 'r' }, | 184 | "show\0" No_argument "r" |
185 | { "hctosys", 0, 0, 's' }, | 185 | "hctosys\0" No_argument "s" |
186 | { "systohc", 0, 0, 'w' }, | 186 | "systohc\0" No_argument "w" |
187 | { "file", 1, 0, 'f' }, | 187 | "file\0" Required_argument "f" |
188 | { 0, 0, 0, 0 } | 188 | "\0"; |
189 | }; | 189 | applet_long_options = hwclock_longopts; |
190 | applet_long_options = hwclock_long_options; | ||
191 | #endif | 190 | #endif |
192 | opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l"; | 191 | opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l"; |
193 | opt = getopt32(argc, argv, "lurswf:", &rtcname); | 192 | opt = getopt32(argc, argv, "lurswf:", &rtcname); |