diff options
author | Ron Yorston <rmy@pobox.com> | 2017-08-22 14:56:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-08-22 14:56:12 +0100 |
commit | ce9af1cc5ea23f754587448cf35b5120c77bfeef (patch) | |
tree | 69e5eaba5e75ab909ed92d5045393471b8ff3c13 /coreutils | |
parent | c170026700eabb10147dd848c45c06995b43a32e (diff) | |
parent | e837a0dbbebf4229306df98fe9ee3b9bb30630c4 (diff) | |
download | busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.gz busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.bz2 busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
56 files changed, 299 insertions, 327 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 390254512..7e35fa5ee 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -170,9 +170,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv) | |||
170 | { | 170 | { |
171 | unsigned opts; | 171 | unsigned opts; |
172 | 172 | ||
173 | IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) | 173 | opts = getopt32(argv, IF_FEATURE_CATV("^") |
174 | /* -u is ignored ("unbuffered") */ | 174 | /* -u is ignored ("unbuffered") */ |
175 | opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); | 175 | IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u" |
176 | IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */) | ||
177 | ); | ||
176 | argv += optind; | 178 | argv += optind; |
177 | 179 | ||
178 | /* Read from stdin if there's nothing else to do. */ | 180 | /* Read from stdin if there's nothing else to do. */ |
diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 2174334d1..88989bf67 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c | |||
@@ -123,8 +123,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv) | |||
123 | } | 123 | } |
124 | 124 | ||
125 | /* Parse options */ | 125 | /* Parse options */ |
126 | opt_complementary = "-2"; | 126 | getopt32(argv, "^" OPT_STR "\0" "-2"); |
127 | getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */ | ||
128 | argv += optind; | 127 | argv += optind; |
129 | 128 | ||
130 | /* Restore option-like mode if needed */ | 129 | /* Restore option-like mode if needed */ |
diff --git a/coreutils/chown.c b/coreutils/chown.c index 1bfc725cc..985d18d6f 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -55,7 +55,7 @@ | |||
55 | /* This is a NOEXEC applet. Be very careful! */ | 55 | /* This is a NOEXEC applet. Be very careful! */ |
56 | 56 | ||
57 | 57 | ||
58 | #define OPT_STR ("Rh" IF_DESKTOP("vcfLHP")) | 58 | #define OPT_STR "Rh" IF_DESKTOP("vcfLHP") |
59 | #define BIT_RECURSE 1 | 59 | #define BIT_RECURSE 1 |
60 | #define OPT_RECURSE (opt & 1) | 60 | #define OPT_RECURSE (opt & 1) |
61 | #define OPT_NODEREF (opt & 2) | 61 | #define OPT_NODEREF (opt & 2) |
@@ -128,10 +128,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv) | |||
128 | struct param_t param; | 128 | struct param_t param; |
129 | 129 | ||
130 | #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS | 130 | #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS |
131 | applet_long_options = chown_longopts; | 131 | opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts); |
132 | #else | ||
133 | opt = getopt32(argv, "^" OPT_STR "\0" "=2"); | ||
132 | #endif | 134 | #endif |
133 | opt_complementary = "-2"; | ||
134 | opt = getopt32(argv, OPT_STR); | ||
135 | argv += optind; | 135 | argv += optind; |
136 | 136 | ||
137 | /* This matches coreutils behavior (almost - see below) */ | 137 | /* This matches coreutils behavior (almost - see below) */ |
diff --git a/coreutils/chroot.c b/coreutils/chroot.c index 44a587fe0..78751df84 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c | |||
@@ -11,9 +11,9 @@ | |||
11 | //config: default y | 11 | //config: default y |
12 | //config: help | 12 | //config: help |
13 | //config: chroot is used to change the root directory and run a command. | 13 | //config: chroot is used to change the root directory and run a command. |
14 | //config: The default command is `/bin/sh'. | 14 | //config: The default command is '/bin/sh'. |
15 | 15 | ||
16 | //applet:IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP)) | 16 | //applet:IF_CHROOT(APPLET_NOEXEC(chroot, chroot, BB_DIR_USR_SBIN, BB_SUID_DROP, chroot)) |
17 | 17 | ||
18 | //kbuild:lib-$(CONFIG_CHROOT) += chroot.o | 18 | //kbuild:lib-$(CONFIG_CHROOT) += chroot.o |
19 | 19 | ||
@@ -40,6 +40,7 @@ int chroot_main(int argc UNUSED_PARAM, char **argv) | |||
40 | ++argv; | 40 | ++argv; |
41 | if (!*argv) | 41 | if (!*argv) |
42 | bb_show_usage(); | 42 | bb_show_usage(); |
43 | |||
43 | xchroot(*argv); | 44 | xchroot(*argv); |
44 | 45 | ||
45 | ++argv; | 46 | ++argv; |
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index c0cf65d2a..059a33310 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -13,6 +13,7 @@ | |||
13 | //config: cksum is used to calculate the CRC32 checksum of a file. | 13 | //config: cksum is used to calculate the CRC32 checksum of a file. |
14 | 14 | ||
15 | //applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) | 15 | //applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) |
16 | /* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ | ||
16 | 17 | ||
17 | //kbuild:lib-$(CONFIG_CKSUM) += cksum.o | 18 | //kbuild:lib-$(CONFIG_CKSUM) += cksum.o |
18 | 19 | ||
diff --git a/coreutils/comm.c b/coreutils/comm.c index 5be11468c..4bee77677 100644 --- a/coreutils/comm.c +++ b/coreutils/comm.c | |||
@@ -62,8 +62,7 @@ int comm_main(int argc UNUSED_PARAM, char **argv) | |||
62 | int i; | 62 | int i; |
63 | int order; | 63 | int order; |
64 | 64 | ||
65 | opt_complementary = "=2"; | 65 | getopt32(argv, "^" "123" "\0" "=2"); |
66 | getopt32(argv, "123"); | ||
67 | argv += optind; | 66 | argv += optind; |
68 | 67 | ||
69 | for (i = 0; i < 2; ++i) { | 68 | for (i = 0; i < 2; ++i) { |
diff --git a/coreutils/cp.c b/coreutils/cp.c index 092e39583..5b34c27e7 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -73,15 +73,17 @@ int cp_main(int argc, char **argv) | |||
73 | #endif | 73 | #endif |
74 | }; | 74 | }; |
75 | 75 | ||
76 | // Need at least two arguments | ||
77 | // Soft- and hardlinking doesn't mix | ||
78 | // -P and -d are the same (-P is POSIX, -d is GNU) | ||
79 | // -r and -R are the same | ||
80 | // -R (and therefore -r) turns on -d (coreutils does this) | ||
81 | // -a = -pdR | ||
82 | opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; | ||
83 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | 76 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
84 | applet_long_options = | 77 | flags = getopt32long(argv, "^" |
78 | FILEUTILS_CP_OPTSTR | ||
79 | "\0" | ||
80 | // Need at least two arguments | ||
81 | // Soft- and hardlinking doesn't mix | ||
82 | // -P and -d are the same (-P is POSIX, -d is GNU) | ||
83 | // -r and -R are the same | ||
84 | // -R (and therefore -r) turns on -d (coreutils does this) | ||
85 | // -a = -pdR | ||
86 | "-2:l--s:s--l:Pd:rRd:Rd:apdR", | ||
85 | "archive\0" No_argument "a" | 87 | "archive\0" No_argument "a" |
86 | "force\0" No_argument "f" | 88 | "force\0" No_argument "f" |
87 | "interactive\0" No_argument "i" | 89 | "interactive\0" No_argument "i" |
@@ -94,9 +96,10 @@ int cp_main(int argc, char **argv) | |||
94 | "update\0" No_argument "u" | 96 | "update\0" No_argument "u" |
95 | "remove-destination\0" No_argument "\xff" | 97 | "remove-destination\0" No_argument "\xff" |
96 | "parents\0" No_argument "\xfe" | 98 | "parents\0" No_argument "\xfe" |
97 | ; | 99 | ); |
98 | #endif | 100 | #else |
99 | flags = getopt32(argv, FILEUTILS_CP_OPTSTR); | 101 | flags = getopt32(argv, FILEUTILS_CP_OPTSTR); |
102 | #endif | ||
100 | /* Options of cp from GNU coreutils 6.10: | 103 | /* Options of cp from GNU coreutils 6.10: |
101 | * -a, --archive | 104 | * -a, --archive |
102 | * -f, --force | 105 | * -f, --force |
diff --git a/coreutils/cut.c b/coreutils/cut.c index 6578ce8ce..cdd90ab44 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -42,7 +42,7 @@ | |||
42 | 42 | ||
43 | 43 | ||
44 | /* option vars */ | 44 | /* option vars */ |
45 | static const char optstring[] ALIGN1 = "b:c:f:d:sn"; | 45 | #define OPT_STR "b:c:f:d:sn" |
46 | #define CUT_OPT_BYTE_FLGS (1 << 0) | 46 | #define CUT_OPT_BYTE_FLGS (1 << 0) |
47 | #define CUT_OPT_CHAR_FLGS (1 << 1) | 47 | #define CUT_OPT_CHAR_FLGS (1 << 1) |
48 | #define CUT_OPT_FIELDS_FLGS (1 << 2) | 48 | #define CUT_OPT_FIELDS_FLGS (1 << 2) |
@@ -201,8 +201,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
201 | char *sopt, *ltok; | 201 | char *sopt, *ltok; |
202 | unsigned opt; | 202 | unsigned opt; |
203 | 203 | ||
204 | opt_complementary = "b--bcf:c--bcf:f--bcf"; | 204 | opt = getopt32(argv, "^" |
205 | opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, <ok); | 205 | OPT_STR |
206 | "\0" "b--bcf:c--bcf:f--bcf", | ||
207 | &sopt, &sopt, &sopt, <ok | ||
208 | ); | ||
206 | // argc -= optind; | 209 | // argc -= optind; |
207 | argv += optind; | 210 | argv += optind; |
208 | if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) | 211 | if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) |
diff --git a/coreutils/date.c b/coreutils/date.c index 0fb9f1f00..5b15ce778 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -58,7 +58,8 @@ | |||
58 | //config: the same format. With it on, 'date DATE' additionally supports | 58 | //config: the same format. With it on, 'date DATE' additionally supports |
59 | //config: MMDDhhmm[[YY]YY][.ss] format. | 59 | //config: MMDDhhmm[[YY]YY][.ss] format. |
60 | 60 | ||
61 | //applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP)) | 61 | //applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date)) |
62 | /* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ | ||
62 | 63 | ||
63 | //kbuild:lib-$(CONFIG_DATE) += date.o | 64 | //kbuild:lib-$(CONFIG_DATE) += date.o |
64 | 65 | ||
@@ -66,7 +67,7 @@ | |||
66 | * date [OPTION]... [+FORMAT] | 67 | * date [OPTION]... [+FORMAT] |
67 | * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] | 68 | * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] |
68 | * -d, --date=STRING | 69 | * -d, --date=STRING |
69 | * display time described by STRING, not `now' | 70 | * display time described by STRING, not 'now' |
70 | * -f, --file=DATEFILE | 71 | * -f, --file=DATEFILE |
71 | * like --date once for each line of DATEFILE | 72 | * like --date once for each line of DATEFILE |
72 | * -r, --reference=FILE | 73 | * -r, --reference=FILE |
@@ -152,12 +153,6 @@ enum { | |||
152 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ | 153 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ |
153 | }; | 154 | }; |
154 | 155 | ||
155 | static void maybe_set_utc(int opt) | ||
156 | { | ||
157 | if (opt & OPT_UTC) | ||
158 | putenv((char*)"TZ=UTC0"); | ||
159 | } | ||
160 | |||
161 | #if ENABLE_LONG_OPTS | 156 | #if ENABLE_LONG_OPTS |
162 | static const char date_longopts[] ALIGN1 = | 157 | static const char date_longopts[] ALIGN1 = |
163 | "rfc-822\0" No_argument "R" | 158 | "rfc-822\0" No_argument "R" |
@@ -170,6 +165,19 @@ static const char date_longopts[] ALIGN1 = | |||
170 | ; | 165 | ; |
171 | #endif | 166 | #endif |
172 | 167 | ||
168 | /* We are a NOEXEC applet. | ||
169 | * Obstacles to NOFORK: | ||
170 | * - we change env | ||
171 | * - xasprintf result not freed | ||
172 | * - after xasprintf we use other xfuncs | ||
173 | */ | ||
174 | |||
175 | static void maybe_set_utc(int opt) | ||
176 | { | ||
177 | if (opt & OPT_UTC) | ||
178 | putenv((char*)"TZ=UTC0"); | ||
179 | } | ||
180 | |||
173 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 181 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
174 | int date_main(int argc UNUSED_PARAM, char **argv) | 182 | int date_main(int argc UNUSED_PARAM, char **argv) |
175 | { | 183 | { |
@@ -184,13 +192,16 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
184 | char *filename; | 192 | char *filename; |
185 | char *isofmt_arg = NULL; | 193 | char *isofmt_arg = NULL; |
186 | 194 | ||
187 | opt_complementary = "d--s:s--d" | 195 | opt = getopt32long(argv, "^" |
188 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); | 196 | "Rs:ud:r:" |
189 | IF_LONG_OPTS(applet_long_options = date_longopts;) | 197 | IF_FEATURE_DATE_ISOFMT("I::D:") |
190 | opt = getopt32(argv, "Rs:ud:r:" | 198 | "\0" |
191 | IF_FEATURE_DATE_ISOFMT("I::D:"), | 199 | "d--s:s--d" |
200 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"), | ||
201 | date_longopts, | ||
192 | &date_str, &date_str, &filename | 202 | &date_str, &date_str, &filename |
193 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); | 203 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) |
204 | ); | ||
194 | argv += optind; | 205 | argv += optind; |
195 | maybe_set_utc(opt); | 206 | maybe_set_utc(opt); |
196 | 207 | ||
diff --git a/coreutils/dd.c b/coreutils/dd.c index f7f1c9564..9ea4897d5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -19,7 +19,7 @@ | |||
19 | //config: default y | 19 | //config: default y |
20 | //config: depends on DD | 20 | //config: depends on DD |
21 | //config: help | 21 | //config: help |
22 | //config: Sending a SIGUSR1 signal to a running `dd' process makes it | 22 | //config: Sending a SIGUSR1 signal to a running 'dd' process makes it |
23 | //config: print to standard error the number of records read and written | 23 | //config: print to standard error the number of records read and written |
24 | //config: so far, then to resume copying. | 24 | //config: so far, then to resume copying. |
25 | //config: | 25 | //config: |
diff --git a/coreutils/df.c b/coreutils/df.c index 27dd2b5a8..121da970b 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -33,7 +33,7 @@ | |||
33 | //config: -i Inodes | 33 | //config: -i Inodes |
34 | //config: -B <SIZE> Blocksize | 34 | //config: -B <SIZE> Blocksize |
35 | 35 | ||
36 | //applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP)) | 36 | //applet:IF_DF(APPLET_NOEXEC(df, df, BB_DIR_BIN, BB_SUID_DROP, df)) |
37 | 37 | ||
38 | //kbuild:lib-$(CONFIG_DF) += df.o | 38 | //kbuild:lib-$(CONFIG_DF) += df.o |
39 | 39 | ||
@@ -115,15 +115,18 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
115 | 115 | ||
116 | init_unicode(); | 116 | init_unicode(); |
117 | 117 | ||
118 | opt = getopt32(argv, "^" | ||
119 | "kPT" | ||
120 | IF_FEATURE_DF_FANCY("aiB:") | ||
121 | IF_FEATURE_HUMAN_READABLE("hm") | ||
122 | "\0" | ||
118 | #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY | 123 | #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY |
119 | opt_complementary = "k-mB:m-Bk:B-km"; | 124 | "k-mB:m-Bk:B-km" |
120 | #elif ENABLE_FEATURE_HUMAN_READABLE | 125 | #elif ENABLE_FEATURE_HUMAN_READABLE |
121 | opt_complementary = "k-m:m-k"; | 126 | "k-m:m-k" |
122 | #endif | 127 | #endif |
123 | opt = getopt32(argv, "kPT" | 128 | IF_FEATURE_DF_FANCY(, &chp) |
124 | IF_FEATURE_DF_FANCY("aiB:") | 129 | ); |
125 | IF_FEATURE_HUMAN_READABLE("hm") | ||
126 | IF_FEATURE_DF_FANCY(, &chp)); | ||
127 | if (opt & OPT_MEGA) | 130 | if (opt & OPT_MEGA) |
128 | df_disp_hr = 1024*1024; | 131 | df_disp_hr = 1024*1024; |
129 | 132 | ||
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index a3d008051..9f098e41e 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
@@ -120,8 +120,7 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | /* -u convert to unix, -d convert to dos */ | 122 | /* -u convert to unix, -d convert to dos */ |
123 | opt_complementary = "u--d:d--u"; /* mutually exclusive */ | 123 | o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */ |
124 | o = getopt32(argv, "du"); | ||
125 | 124 | ||
126 | /* Do the conversion requested by an argument else do the default | 125 | /* Do the conversion requested by an argument else do the default |
127 | * conversion depending on our name. */ | 126 | * conversion depending on our name. */ |
diff --git a/coreutils/du.c b/coreutils/du.c index 947c46e74..d5ce46cf2 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -242,8 +242,11 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
242 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 242 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
243 | */ | 243 | */ |
244 | #if ENABLE_FEATURE_HUMAN_READABLE | 244 | #if ENABLE_FEATURE_HUMAN_READABLE |
245 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; | 245 | opt = getopt32(argv, "^" |
246 | opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); | 246 | "aHkLsxd:+lchm" |
247 | "\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s", | ||
248 | &G.max_print_depth | ||
249 | ); | ||
247 | argv += optind; | 250 | argv += optind; |
248 | if (opt & OPT_h_for_humans) { | 251 | if (opt & OPT_h_for_humans) { |
249 | G.disp_unit = 0; | 252 | G.disp_unit = 0; |
@@ -255,8 +258,11 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
255 | G.disp_unit = 1024; | 258 | G.disp_unit = 1024; |
256 | } | 259 | } |
257 | #else | 260 | #else |
258 | opt_complementary = "H-L:L-H:s-d:d-s"; | 261 | opt = getopt32(argv, "^" |
259 | opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); | 262 | "aHkLsxd:+lc" |
263 | "\0" "H-L:L-H:s-d:d-s", | ||
264 | &G.max_print_depth | ||
265 | ); | ||
260 | argv += optind; | 266 | argv += optind; |
261 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 267 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
262 | if (opt & OPT_k_kbytes) { | 268 | if (opt & OPT_k_kbytes) { |
diff --git a/coreutils/echo.c b/coreutils/echo.c index af33319a1..e45b90940 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c | |||
@@ -218,7 +218,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv) | |||
218 | * may be used to endorse or promote products derived from this software | 218 | * may be used to endorse or promote products derived from this software |
219 | * without specific prior written permission. | 219 | * without specific prior written permission. |
220 | * | 220 | * |
221 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 221 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND |
222 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 222 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
223 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 223 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
224 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 224 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
diff --git a/coreutils/env.c b/coreutils/env.c index 8def9c2da..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 | ||
57 | static const char env_longopts[] ALIGN1 = | ||
58 | "ignore-environment\0" No_argument "i" | ||
59 | "unset\0" Required_argument "u" | ||
60 | ; | ||
61 | #endif | ||
62 | |||
63 | int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 51 | int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
64 | int env_main(int argc UNUSED_PARAM, char **argv) | 52 | int 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; |
@@ -129,7 +118,7 @@ int env_main(int argc UNUSED_PARAM, char **argv) | |||
129 | * may be used to endorse or promote products derived from this software | 118 | * may be used to endorse or promote products derived from this software |
130 | * without specific prior written permission. | 119 | * without specific prior written permission. |
131 | * | 120 | * |
132 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 121 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND |
133 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 122 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
134 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 123 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
135 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 124 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
diff --git a/coreutils/expand.c b/coreutils/expand.c index 64f2a539d..91084b80b 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,24 @@ 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); | 177 | opt = getopt32long(argv, "^" |
213 | /* -t NUM sets also -a */ | 178 | "ft:a" |
214 | opt_complementary = "ta"; | 179 | "\0" |
215 | opt = getopt32(argv, "ft:a", &opt_t); | 180 | "ta" /* -t NUM sets -a */, |
181 | "first-only\0" No_argument "i" | ||
182 | "tabs\0" Required_argument "t" | ||
183 | "all\0" No_argument "a" | ||
184 | , &opt_t | ||
185 | ); | ||
216 | /* -f --first-only is the default */ | 186 | /* -f --first-only is the default */ |
217 | if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; | 187 | if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; |
218 | } | 188 | } |
diff --git a/coreutils/expr.c b/coreutils/expr.c index 0cf2b9bd9..00bcf60d4 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -38,7 +38,7 @@ | |||
38 | //config: the applet slightly larger, but will allow computation with very | 38 | //config: the applet slightly larger, but will allow computation with very |
39 | //config: large numbers. | 39 | //config: large numbers. |
40 | 40 | ||
41 | //applet:IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP)) | 41 | //applet:IF_EXPR(APPLET_NOEXEC(expr, expr, BB_DIR_USR_BIN, BB_SUID_DROP, expr)) |
42 | 42 | ||
43 | //kbuild:lib-$(CONFIG_EXPR) += expr.o | 43 | //kbuild:lib-$(CONFIG_EXPR) += expr.o |
44 | 44 | ||
@@ -118,7 +118,10 @@ struct globals { | |||
118 | char **args; | 118 | char **args; |
119 | } FIX_ALIASING; | 119 | } FIX_ALIASING; |
120 | #define G (*(struct globals*)bb_common_bufsiz1) | 120 | #define G (*(struct globals*)bb_common_bufsiz1) |
121 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | 121 | #define INIT_G() do { \ |
122 | setup_common_bufsiz(); \ | ||
123 | /* NB: noexec applet - globals not zeroed */ \ | ||
124 | } while (0) | ||
122 | 125 | ||
123 | /* forward declarations */ | 126 | /* forward declarations */ |
124 | static VALUE *eval(void); | 127 | static VALUE *eval(void); |
diff --git a/coreutils/id.c b/coreutils/id.c index 6043bca61..5a7fb9aaf 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -170,9 +170,12 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
170 | } else { | 170 | } else { |
171 | /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ | 171 | /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ |
172 | /* Don't allow more than one username */ | 172 | /* Don't allow more than one username */ |
173 | opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" | 173 | opt = getopt32(argv, "^" |
174 | IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); | 174 | "rnugG" IF_SELINUX("Z") |
175 | opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); | 175 | "\0" |
176 | "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" | ||
177 | IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G") | ||
178 | ); | ||
176 | } | 179 | } |
177 | 180 | ||
178 | username = argv[optind]; | 181 | username = argv[optind]; |
diff --git a/coreutils/install.c b/coreutils/install.c index a1342bb13..2e4dc257f 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,17 @@ 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")); | ||
142 | /* -c exists for backwards compatibility, it's needed */ | 143 | /* -c exists for backwards compatibility, it's needed */ |
143 | /* -b is ignored ("make a backup of each existing destination file") */ | 144 | /* -b is ignored ("make a backup of each existing destination file") */ |
144 | opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), | 145 | opts = GETOPT32(argv, "^" |
145 | &gid_str, &mode_str, &uid_str, &last | 146 | "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:") |
146 | IF_SELINUX(, &scontext)); | 147 | "\0" |
148 | "t--d:d--t:s--d:d--s" | ||
149 | IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")), | ||
150 | LONGOPTS | ||
151 | &gid_str, &mode_str, &uid_str, &last | ||
152 | IF_SELINUX(, &scontext) | ||
153 | ); | ||
147 | argc -= optind; | 154 | argc -= optind; |
148 | argv += optind; | 155 | argv += optind; |
149 | 156 | ||
diff --git a/coreutils/link.c b/coreutils/link.c index 6e20dafe3..d8d583b7b 100644 --- a/coreutils/link.c +++ b/coreutils/link.c | |||
@@ -27,14 +27,12 @@ | |||
27 | int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 27 | int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
28 | int link_main(int argc UNUSED_PARAM, char **argv) | 28 | int link_main(int argc UNUSED_PARAM, char **argv) |
29 | { | 29 | { |
30 | opt_complementary = "=2"; /* exactly 2 params */ | 30 | getopt32(argv, "^" "" "\0" "=2"); |
31 | getopt32(argv, ""); | ||
32 | argv += optind; | 31 | argv += optind; |
33 | if (link(argv[0], argv[1]) != 0) { | 32 | if (link(argv[0], argv[1]) != 0) { |
34 | /* shared message */ | 33 | /* shared message */ |
35 | bb_perror_msg_and_die("can't create %slink " | 34 | bb_perror_msg_and_die("can't create %slink '%s' to '%s'", |
36 | "'%s' to '%s'", "hard", | 35 | "hard", argv[1], argv[0] |
37 | argv[1], argv[0] | ||
38 | ); | 36 | ); |
39 | } | 37 | } |
40 | return EXIT_SUCCESS; | 38 | return EXIT_SUCCESS; |
diff --git a/coreutils/ln.c b/coreutils/ln.c index fed96af42..2dda5dae9 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
@@ -62,8 +62,7 @@ int ln_main(int argc, char **argv) | |||
62 | struct stat statbuf; | 62 | struct stat statbuf; |
63 | int (*link_func)(const char *, const char *); | 63 | int (*link_func)(const char *, const char *); |
64 | 64 | ||
65 | opt_complementary = "-1"; /* min one arg */ | 65 | opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix); |
66 | opts = getopt32(argv, "sfnbS:vT", &suffix); | ||
67 | 66 | ||
68 | last = argv[argc - 1]; | 67 | last = argv[argc - 1]; |
69 | argv += optind; | 68 | argv += optind; |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 4c0944bb0..9f0462936 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -206,18 +206,18 @@ SPLIT_SUBDIR = 2, | |||
206 | /* -SXvhTw GNU options, busybox optionally supports */ | 206 | /* -SXvhTw GNU options, busybox optionally supports */ |
207 | /* -T WIDTH Ignored (we don't use tabs on output) */ | 207 | /* -T WIDTH Ignored (we don't use tabs on output) */ |
208 | /* -Z SELinux mandated option, busybox optionally supports */ | 208 | /* -Z SELinux mandated option, busybox optionally supports */ |
209 | static const char ls_options[] ALIGN1 = | 209 | #define ls_options \ |
210 | "Cadi1lgnsxAk" /* 12 opts, total 12 */ | 210 | "Cadi1lgnsxAk" /* 12 opts, total 12 */ \ |
211 | IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ | 211 | IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \ |
212 | IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ | 212 | IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \ |
213 | IF_SELINUX("Z") /* 1, 16 */ | 213 | IF_SELINUX("Z") /* 1, 16 */ \ |
214 | "Q" /* 1, 17 */ | 214 | "Q" /* 1, 17 */ \ |
215 | IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ | 215 | IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \ |
216 | IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ | 216 | IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \ |
217 | IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ | 217 | IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \ |
218 | IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ | 218 | IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \ |
219 | IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ | 219 | IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ |
220 | ; | 220 | |
221 | enum { | 221 | enum { |
222 | OPT_C = (1 << 0), | 222 | OPT_C = (1 << 0), |
223 | OPT_a = (1 << 1), | 223 | OPT_a = (1 << 1), |
@@ -1093,25 +1093,26 @@ 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;) | 1096 | opt = getopt32long(argv, "^" |
1097 | opt_complementary = | 1097 | ls_options |
1098 | /* -n and -g imply -l */ | 1098 | "\0" |
1099 | "nl:gl" | 1099 | /* -n and -g imply -l */ |
1100 | /* --full-time implies -l */ | 1100 | "nl:gl" |
1101 | IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) | 1101 | /* --full-time implies -l */ |
1102 | /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: | 1102 | IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) |
1103 | * in some pairs of opts, only last one takes effect: | 1103 | /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: |
1104 | */ | 1104 | * in some pairs of opts, only last one takes effect: |
1105 | IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ | 1105 | */ |
1106 | // ":m-l:l-m" - we don't have -m | 1106 | IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ |
1107 | IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") | 1107 | // ":m-l:l-m" - we don't have -m |
1108 | ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ | 1108 | IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") |
1109 | ":C-1:1-C" /* bycols/oneline */ | 1109 | ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ |
1110 | ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ | 1110 | ":C-1:1-C" /* bycols/oneline */ |
1111 | IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ | 1111 | ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ |
1112 | /* -w NUM: */ | 1112 | IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ |
1113 | IF_FEATURE_LS_WIDTH(":w+"); | 1113 | /* -w NUM: */ |
1114 | opt = getopt32(argv, ls_options | 1114 | IF_FEATURE_LS_WIDTH(":w+") |
1115 | , ls_longopts | ||
1115 | IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) | 1116 | IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) |
1116 | IF_FEATURE_LS_COLOR(, &color_opt) | 1117 | IF_FEATURE_LS_COLOR(, &color_opt) |
1117 | ); | 1118 | ); |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index bcccdd64f..89d6cec0b 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -258,15 +258,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
258 | #endif | 258 | #endif |
259 | 259 | ||
260 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { | 260 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { |
261 | /* -s and -w require -c */ | ||
262 | opt_complementary = "s?c:w?c"; | ||
263 | /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ | 261 | /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ |
262 | /* -s and -w require -c */ | ||
264 | #if ENABLE_SHA3SUM | 263 | #if ENABLE_SHA3SUM |
265 | if (applet_name[3] == HASH_SHA3) | 264 | if (applet_name[3] == HASH_SHA3) |
266 | flags = getopt32(argv, "scwbta:+", &sha3_width); | 265 | flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width); |
267 | else | 266 | else |
268 | #endif | 267 | #endif |
269 | flags = getopt32(argv, "scwbt"); | 268 | flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c"); |
270 | } else { | 269 | } else { |
271 | #if ENABLE_SHA3SUM | 270 | #if ENABLE_SHA3SUM |
272 | if (applet_name[3] == HASH_SHA3) | 271 | if (applet_name[3] == HASH_SHA3) |
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 | ||
57 | static 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 | |||
69 | int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 51 | int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
70 | int mkdir_main(int argc UNUSED_PARAM, char **argv) | 52 | int 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/mktemp.c b/coreutils/mktemp.c index bfef0b4a6..d4ff883fa 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c | |||
@@ -36,7 +36,7 @@ | |||
36 | //config: help | 36 | //config: help |
37 | //config: mktemp is used to create unique temporary files | 37 | //config: mktemp is used to create unique temporary files |
38 | 38 | ||
39 | //applet:IF_MKTEMP(APPLET(mktemp, BB_DIR_BIN, BB_SUID_DROP)) | 39 | //applet:IF_MKTEMP(APPLET_NOEXEC(mktemp, mktemp, BB_DIR_BIN, BB_SUID_DROP, mktemp)) |
40 | 40 | ||
41 | //kbuild:lib-$(CONFIG_MKTEMP) += mktemp.o | 41 | //kbuild:lib-$(CONFIG_MKTEMP) += mktemp.o |
42 | 42 | ||
@@ -80,8 +80,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
80 | if (!path || path[0] == '\0') | 80 | if (!path || path[0] == '\0') |
81 | path = "/tmp"; | 81 | path = "/tmp"; |
82 | 82 | ||
83 | opt_complementary = "?1"; /* 1 argument max */ | 83 | opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path); |
84 | opts = getopt32(argv, "dqtp:u", &path); | ||
85 | 84 | ||
86 | chp = argv[optind]; | 85 | chp = argv[optind]; |
87 | if (!chp) { | 86 | if (!chp) { |
diff --git a/coreutils/mv.c b/coreutils/mv.c index 147dd3bb2..10cbc506f 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 | ||
45 | static 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 | |||
61 | int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 39 | int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
62 | int mv_main(int argc, char **argv) | 40 | int mv_main(int argc, char **argv) |
63 | { | 41 | { |
@@ -69,15 +47,25 @@ 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 | flags = getopt32long(argv, "^" |
80 | flags = getopt32(argv, "finv"); | 59 | "finv" |
60 | "\0" | ||
61 | "-2:f-in:i-fn:n-fi", | ||
62 | "interactive\0" No_argument "i" | ||
63 | "force\0" No_argument "f" | ||
64 | "no-clobber\0" No_argument "n" | ||
65 | IF_FEATURE_VERBOSE( | ||
66 | "verbose\0" No_argument "v" | ||
67 | ) | ||
68 | ); | ||
81 | argc -= optind; | 69 | argc -= optind; |
82 | argv += optind; | 70 | argv += optind; |
83 | last = argv[argc - 1]; | 71 | last = argv[argc - 1]; |
diff --git a/coreutils/nice.c b/coreutils/nice.c index 0bf055299..d6818cf00 100644 --- a/coreutils/nice.c +++ b/coreutils/nice.c | |||
@@ -12,7 +12,7 @@ | |||
12 | //config: help | 12 | //config: help |
13 | //config: nice runs a program with modified scheduling priority. | 13 | //config: nice runs a program with modified scheduling priority. |
14 | 14 | ||
15 | //applet:IF_NICE(APPLET(nice, BB_DIR_BIN, BB_SUID_DROP)) | 15 | //applet:IF_NICE(APPLET_NOEXEC(nice, nice, BB_DIR_BIN, BB_SUID_DROP, nice)) |
16 | 16 | ||
17 | //kbuild:lib-$(CONFIG_NICE) += nice.o | 17 | //kbuild:lib-$(CONFIG_NICE) += nice.o |
18 | 18 | ||
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/nohup.c b/coreutils/nohup.c index 8e28f9029..8a70ec4df 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c | |||
@@ -15,7 +15,7 @@ | |||
15 | //config: help | 15 | //config: help |
16 | //config: run a command immune to hangups, with output to a non-tty. | 16 | //config: run a command immune to hangups, with output to a non-tty. |
17 | 17 | ||
18 | //applet:IF_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP)) | 18 | //applet:IF_NOHUP(APPLET_NOEXEC(nohup, nohup, BB_DIR_USR_BIN, BB_SUID_DROP, nohup)) |
19 | 19 | ||
20 | //kbuild:lib-$(CONFIG_NOHUP) += nohup.o | 20 | //kbuild:lib-$(CONFIG_NOHUP) += nohup.o |
21 | 21 | ||
@@ -31,12 +31,12 @@ | |||
31 | 31 | ||
32 | /* Compat info: nohup (GNU coreutils 6.8) does this: | 32 | /* Compat info: nohup (GNU coreutils 6.8) does this: |
33 | # nohup true | 33 | # nohup true |
34 | nohup: ignoring input and appending output to `nohup.out' | 34 | nohup: ignoring input and appending output to 'nohup.out' |
35 | # nohup true 1>/dev/null | 35 | # nohup true 1>/dev/null |
36 | nohup: ignoring input and redirecting stderr to stdout | 36 | nohup: ignoring input and redirecting stderr to stdout |
37 | # nohup true 2>zz | 37 | # nohup true 2>zz |
38 | # cat zz | 38 | # cat zz |
39 | nohup: ignoring input and appending output to `nohup.out' | 39 | nohup: ignoring input and appending output to 'nohup.out' |
40 | # nohup true 2>zz 1>/dev/null | 40 | # nohup true 2>zz 1>/dev/null |
41 | # cat zz | 41 | # cat zz |
42 | nohup: ignoring input | 42 | nohup: ignoring input |
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index 68a831865..336b176ca 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -9,7 +9,7 @@ | |||
9 | //config: help | 9 | //config: help |
10 | //config: Print number of CPUs | 10 | //config: Print number of CPUs |
11 | 11 | ||
12 | //applet:IF_NPROC(APPLET(nproc, BB_DIR_USR_BIN, BB_SUID_DROP)) | 12 | //applet:IF_NPROC(APPLET_NOFORK(nproc, nproc, BB_DIR_USR_BIN, BB_SUID_DROP, nproc)) |
13 | 13 | ||
14 | //kbuild:lib-$(CONFIG_NPROC) += nproc.o | 14 | //kbuild:lib-$(CONFIG_NPROC) += nproc.o |
15 | 15 | ||
@@ -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.c b/coreutils/od.c index e3a68435b..9a888dd5f 100644 --- a/coreutils/od.c +++ b/coreutils/od.c | |||
@@ -223,7 +223,7 @@ int od_main(int argc, char **argv) | |||
223 | * may be used to endorse or promote products derived from this software | 223 | * may be used to endorse or promote products derived from this software |
224 | * without specific prior written permission. | 224 | * without specific prior written permission. |
225 | * | 225 | * |
226 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 226 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND |
227 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 227 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
228 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 228 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
229 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 229 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 513c8ef37..df7354b7b 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 */ \ |
@@ -1220,9 +1220,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1220 | address_pad_len_char = '7'; | 1220 | address_pad_len_char = '7'; |
1221 | 1221 | ||
1222 | /* Parse command line */ | 1222 | /* Parse command line */ |
1223 | #if ENABLE_LONG_OPTS | ||
1224 | applet_long_options = od_longopts; | ||
1225 | #endif | ||
1226 | opt = OD_GETOPT32(); | 1223 | opt = OD_GETOPT32(); |
1227 | argv += optind; | 1224 | argv += optind; |
1228 | if (opt & OPT_A) { | 1225 | if (opt & OPT_A) { |
diff --git a/coreutils/printf.c b/coreutils/printf.c index d3fc72adb..d1ff183d0 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -43,7 +43,7 @@ | |||
43 | //config: default y | 43 | //config: default y |
44 | //config: help | 44 | //config: help |
45 | //config: printf is used to format and print specified strings. | 45 | //config: printf is used to format and print specified strings. |
46 | //config: It's similar to `echo' except it has more options. | 46 | //config: It's similar to 'echo' except it has more options. |
47 | 47 | ||
48 | //applet:IF_PRINTF(APPLET_NOFORK(printf, printf, BB_DIR_USR_BIN, BB_SUID_DROP, printf)) | 48 | //applet:IF_PRINTF(APPLET_NOFORK(printf, printf, BB_DIR_USR_BIN, BB_SUID_DROP, printf)) |
49 | 49 | ||
diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 9690290e3..b8e327d11 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c | |||
@@ -20,7 +20,7 @@ | |||
20 | //config: help | 20 | //config: help |
21 | //config: Enable the readlink option (-f). | 21 | //config: Enable the readlink option (-f). |
22 | 22 | ||
23 | //applet:IF_READLINK(APPLET(readlink, BB_DIR_USR_BIN, BB_SUID_DROP)) | 23 | //applet:IF_READLINK(APPLET_NOFORK(readlink, readlink, BB_DIR_USR_BIN, BB_SUID_DROP, readlink)) |
24 | 24 | ||
25 | //kbuild:lib-$(CONFIG_READLINK) += readlink.o | 25 | //kbuild:lib-$(CONFIG_READLINK) += readlink.o |
26 | 26 | ||
@@ -71,8 +71,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
71 | IF_FEATURE_READLINK_FOLLOW( | 71 | IF_FEATURE_READLINK_FOLLOW( |
72 | unsigned opt; | 72 | unsigned opt; |
73 | /* We need exactly one non-option argument. */ | 73 | /* We need exactly one non-option argument. */ |
74 | opt_complementary = "=1"; | 74 | opt = getopt32(argv, "^" "fnvsq" "\0" "=1"); |
75 | opt = getopt32(argv, "fnvsq"); | ||
76 | fname = argv[optind]; | 75 | fname = argv[optind]; |
77 | ) | 76 | ) |
78 | IF_NOT_FEATURE_READLINK_FOLLOW( | 77 | IF_NOT_FEATURE_READLINK_FOLLOW( |
@@ -85,6 +84,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
85 | if (!(opt & 4)) /* not -v */ | 84 | if (!(opt & 4)) /* not -v */ |
86 | logmode = LOGMODE_NONE; | 85 | logmode = LOGMODE_NONE; |
87 | 86 | ||
87 | /* NOFORK: only one alloc is allowed; must free */ | ||
88 | if (opt & 1) { /* -f */ | 88 | if (opt & 1) { /* -f */ |
89 | buf = xmalloc_realpath(fname); | 89 | buf = xmalloc_realpath(fname); |
90 | } else { | 90 | } else { |
@@ -94,9 +94,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
94 | if (!buf) | 94 | if (!buf) |
95 | return EXIT_FAILURE; | 95 | return EXIT_FAILURE; |
96 | printf((opt & 2) ? "%s" : "%s\n", buf); | 96 | printf((opt & 2) ? "%s" : "%s\n", buf); |
97 | 97 | free(buf); | |
98 | if (ENABLE_FEATURE_CLEAN_UP) | ||
99 | free(buf); | ||
100 | 98 | ||
101 | fflush_stdout_and_exit(EXIT_SUCCESS); | 99 | fflush_stdout_and_exit(EXIT_SUCCESS); |
102 | } | 100 | } |
diff --git a/coreutils/realpath.c b/coreutils/realpath.c index 6a61c3dc8..f9c630135 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c | |||
@@ -13,7 +13,7 @@ | |||
13 | //config: Return the canonicalized absolute pathname. | 13 | //config: Return the canonicalized absolute pathname. |
14 | //config: This isn't provided by GNU shellutils, but where else does it belong. | 14 | //config: This isn't provided by GNU shellutils, but where else does it belong. |
15 | 15 | ||
16 | //applet:IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP)) | 16 | //applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath)) |
17 | 17 | ||
18 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o | 18 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o |
19 | 19 | ||
@@ -36,6 +36,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | do { | 38 | do { |
39 | /* NOFORK: only one alloc is allowed; must free */ | ||
39 | char *resolved_path = xmalloc_realpath(*argv); | 40 | char *resolved_path = xmalloc_realpath(*argv); |
40 | if (resolved_path != NULL) { | 41 | if (resolved_path != NULL) { |
41 | puts(resolved_path); | 42 | puts(resolved_path); |
diff --git a/coreutils/rm.c b/coreutils/rm.c index f91c94570..b68a82dc4 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c | |||
@@ -16,7 +16,8 @@ | |||
16 | //config: help | 16 | //config: help |
17 | //config: rm is used to remove files or directories. | 17 | //config: rm is used to remove files or directories. |
18 | 18 | ||
19 | //applet:IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm)) | 19 | //applet:IF_RM(APPLET_NOEXEC(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm)) |
20 | /* was NOFORK, but then "rm -i FILE" can't be ^C'ed if run by hush */ | ||
20 | 21 | ||
21 | //kbuild:lib-$(CONFIG_RM) += rm.o | 22 | //kbuild:lib-$(CONFIG_RM) += rm.o |
22 | 23 | ||
@@ -36,7 +37,7 @@ | |||
36 | 37 | ||
37 | #include "libbb.h" | 38 | #include "libbb.h" |
38 | 39 | ||
39 | /* This is a NOFORK applet. Be very careful! */ | 40 | /* This is a NOEXEC applet. Be very careful! */ |
40 | 41 | ||
41 | int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 42 | int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
42 | int rm_main(int argc UNUSED_PARAM, char **argv) | 43 | int rm_main(int argc UNUSED_PARAM, char **argv) |
@@ -45,8 +46,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv) | |||
45 | int flags = 0; | 46 | int flags = 0; |
46 | unsigned opt; | 47 | unsigned opt; |
47 | 48 | ||
48 | opt_complementary = "f-i:i-f"; | 49 | opt = getopt32(argv, "^" "fiRrv" "\0" "f-i:i-f"); |
49 | opt = getopt32(argv, "fiRrv"); | ||
50 | argv += optind; | 50 | argv += optind; |
51 | if (opt & 1) | 51 | if (opt & 1) |
52 | flags |= FILEUTILS_FORCE; | 52 | flags |= FILEUTILS_FORCE; |
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 | ||
54 | int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 43 | int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
55 | int rmdir_main(int argc UNUSED_PARAM, char **argv) | 44 | int 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/seq.c b/coreutils/seq.c index f36dbb4ec..c26ff06b9 100644 --- a/coreutils/seq.c +++ b/coreutils/seq.c | |||
@@ -12,7 +12,8 @@ | |||
12 | //config: help | 12 | //config: help |
13 | //config: print a sequence of numbers | 13 | //config: print a sequence of numbers |
14 | 14 | ||
15 | //applet:IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq)) | 15 | //applet:IF_SEQ(APPLET_NOEXEC(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq)) |
16 | /* was NOFORK, but then "seq 1 999999999" can't be ^C'ed if run by hush */ | ||
16 | 17 | ||
17 | //kbuild:lib-$(CONFIG_SEQ) += seq.o | 18 | //kbuild:lib-$(CONFIG_SEQ) += seq.o |
18 | 19 | ||
@@ -26,7 +27,7 @@ | |||
26 | 27 | ||
27 | #include "libbb.h" | 28 | #include "libbb.h" |
28 | 29 | ||
29 | /* This is a NOFORK applet. Be very careful! */ | 30 | /* This is a NOEXEC applet. Be very careful! */ |
30 | 31 | ||
31 | int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 32 | int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
32 | int seq_main(int argc, char **argv) | 33 | int seq_main(int argc, char **argv) |
diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 403041534..d0caaa2ce 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c | |||
@@ -70,8 +70,11 @@ int shuf_main(int argc, char **argv) | |||
70 | unsigned numlines; | 70 | unsigned numlines; |
71 | char eol; | 71 | char eol; |
72 | 72 | ||
73 | opt_complementary = "e--i:i--e"; /* mutually exclusive */ | 73 | opts = getopt32(argv, "^" |
74 | opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str); | 74 | OPT_STR |
75 | "\0" "e--i:i--e"/* mutually exclusive */, | ||
76 | &opt_i_str, &opt_n_str, &opt_o_str | ||
77 | ); | ||
75 | 78 | ||
76 | argc -= optind; | 79 | argc -= optind; |
77 | argv += optind; | 80 | argv += optind; |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 9860dca64..ceea24491 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -94,7 +94,7 @@ | |||
94 | */ | 94 | */ |
95 | 95 | ||
96 | /* These are sort types */ | 96 | /* These are sort types */ |
97 | static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; | 97 | #define OPT_STR "ngMucszbrdfimS:T:o:k:*t:" |
98 | enum { | 98 | enum { |
99 | FLAG_n = 1, /* Numeric sort */ | 99 | FLAG_n = 1, /* Numeric sort */ |
100 | FLAG_g = 2, /* Sort using strtod() */ | 100 | FLAG_g = 2, /* Sort using strtod() */ |
@@ -378,9 +378,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv) | |||
378 | xfunc_error_retval = 2; | 378 | xfunc_error_retval = 2; |
379 | 379 | ||
380 | /* Parse command line options */ | 380 | /* Parse command line options */ |
381 | /* -o and -t can be given at most once */ | 381 | opts = getopt32(argv, "^" |
382 | opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ | 382 | OPT_STR |
383 | opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); | 383 | "\0" "o--o:t--t"/*-t, -o: at most one of each*/, |
384 | &str_ignored, &str_ignored, &str_o, &lst_k, &str_t | ||
385 | ); | ||
384 | /* global b strips leading and trailing spaces */ | 386 | /* global b strips leading and trailing spaces */ |
385 | if (opts & FLAG_b) | 387 | if (opts & FLAG_b) |
386 | option_mask32 |= FLAG_bb; | 388 | option_mask32 |= FLAG_bb; |
diff --git a/coreutils/split.c b/coreutils/split.c index d0c63573a..4e1db190c 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -100,8 +100,11 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
100 | 100 | ||
101 | setup_common_bufsiz(); | 101 | setup_common_bufsiz(); |
102 | 102 | ||
103 | opt_complementary = "?2"; /* max 2 args; -a N */ | 103 | opt = getopt32(argv, "^" |
104 | opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); | 104 | "l:b:a:+" /* -a N */ |
105 | "\0" "?2"/*max 2 args*/, | ||
106 | &count_p, &count_p, &suffix_len | ||
107 | ); | ||
105 | 108 | ||
106 | if (opt & SPLIT_OPT_l) | 109 | if (opt & SPLIT_OPT_l) |
107 | cnt = XATOOFF(count_p); | 110 | cnt = XATOOFF(count_p); |
diff --git a/coreutils/stat.c b/coreutils/stat.c index 96efa1d5d..177ced2f9 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -35,7 +35,7 @@ | |||
35 | //config: Without this, stat will not support the '-f' option to display | 35 | //config: Without this, stat will not support the '-f' option to display |
36 | //config: information about filesystem status. | 36 | //config: information about filesystem status. |
37 | 37 | ||
38 | //applet:IF_STAT(APPLET(stat, BB_DIR_BIN, BB_SUID_DROP)) | 38 | //applet:IF_STAT(APPLET_NOEXEC(stat, stat, BB_DIR_BIN, BB_SUID_DROP, stat)) |
39 | 39 | ||
40 | //kbuild:lib-$(CONFIG_STAT) += stat.o | 40 | //kbuild:lib-$(CONFIG_STAT) += stat.o |
41 | 41 | ||
@@ -761,11 +761,13 @@ int stat_main(int argc UNUSED_PARAM, char **argv) | |||
761 | unsigned opts; | 761 | unsigned opts; |
762 | statfunc_ptr statfunc = do_stat; | 762 | statfunc_ptr statfunc = do_stat; |
763 | 763 | ||
764 | opt_complementary = "-1"; /* min one arg */ | 764 | opts = getopt32(argv, "^" |
765 | opts = getopt32(argv, "tL" | 765 | "tL" |
766 | IF_FEATURE_STAT_FILESYSTEM("f") | 766 | IF_FEATURE_STAT_FILESYSTEM("f") |
767 | IF_SELINUX("Z") | 767 | IF_SELINUX("Z") |
768 | IF_FEATURE_STAT_FORMAT("c:", &format) | 768 | IF_FEATURE_STAT_FORMAT("c:") |
769 | "\0" "-1" /* min one arg */ | ||
770 | IF_FEATURE_STAT_FORMAT(,&format) | ||
769 | ); | 771 | ); |
770 | #if ENABLE_FEATURE_STAT_FILESYSTEM | 772 | #if ENABLE_FEATURE_STAT_FILESYSTEM |
771 | if (opts & OPT_FILESYS) /* -f */ | 773 | if (opts & OPT_FILESYS) /* -f */ |
diff --git a/coreutils/stty.c b/coreutils/stty.c index f987fbbcf..57e2cc30d 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -25,7 +25,7 @@ | |||
25 | //config: help | 25 | //config: help |
26 | //config: stty is used to change and print terminal line settings. | 26 | //config: stty is used to change and print terminal line settings. |
27 | 27 | ||
28 | //applet:IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP)) | 28 | //applet:IF_STTY(APPLET_NOEXEC(stty, stty, BB_DIR_BIN, BB_SUID_DROP, stty)) |
29 | 29 | ||
30 | //kbuild:lib-$(CONFIG_STTY) += stty.o | 30 | //kbuild:lib-$(CONFIG_STTY) += stty.o |
31 | 31 | ||
@@ -782,12 +782,13 @@ struct globals { | |||
782 | unsigned max_col; | 782 | unsigned max_col; |
783 | /* Current position, to know when to wrap */ | 783 | /* Current position, to know when to wrap */ |
784 | unsigned current_col; | 784 | unsigned current_col; |
785 | char buf[10]; | ||
786 | } FIX_ALIASING; | 785 | } FIX_ALIASING; |
787 | #define G (*(struct globals*)bb_common_bufsiz1) | 786 | #define G (*(struct globals*)bb_common_bufsiz1) |
788 | #define INIT_G() do { \ | 787 | #define INIT_G() do { \ |
788 | setup_common_bufsiz(); \ | ||
789 | G.device_name = bb_msg_standard_input; \ | 789 | G.device_name = bb_msg_standard_input; \ |
790 | G.max_col = 80; \ | 790 | G.max_col = 80; \ |
791 | G.current_col = 0; /* we are noexec, must clear */ \ | ||
791 | } while (0) | 792 | } while (0) |
792 | 793 | ||
793 | static void set_speed_or_die(enum speed_setting type, const char *arg, | 794 | static void set_speed_or_die(enum speed_setting type, const char *arg, |
@@ -1018,6 +1019,8 @@ static void do_display(const struct termios *mode, int all) | |||
1018 | 1019 | ||
1019 | for (i = 0; i != CIDX_min; ++i) { | 1020 | for (i = 0; i != CIDX_min; ++i) { |
1020 | char ch; | 1021 | char ch; |
1022 | char buf10[10]; | ||
1023 | |||
1021 | /* If swtch is the same as susp, don't print both */ | 1024 | /* If swtch is the same as susp, don't print both */ |
1022 | #if VSWTCH == VSUSP | 1025 | #if VSWTCH == VSUSP |
1023 | if (i == CIDX_swtch) | 1026 | if (i == CIDX_swtch) |
@@ -1033,10 +1036,10 @@ static void do_display(const struct termios *mode, int all) | |||
1033 | #endif | 1036 | #endif |
1034 | ch = mode->c_cc[control_info[i].offset]; | 1037 | ch = mode->c_cc[control_info[i].offset]; |
1035 | if (ch == _POSIX_VDISABLE) | 1038 | if (ch == _POSIX_VDISABLE) |
1036 | strcpy(G.buf, "<undef>"); | 1039 | strcpy(buf10, "<undef>"); |
1037 | else | 1040 | else |
1038 | visible(ch, G.buf, 0); | 1041 | visible(ch, buf10, 0); |
1039 | wrapf("%s = %s;", nth_string(control_name, i), G.buf); | 1042 | wrapf("%s = %s;", nth_string(control_name, i), buf10); |
1040 | } | 1043 | } |
1041 | #if VEOF == VMIN | 1044 | #if VEOF == VMIN |
1042 | if ((mode->c_lflag & ICANON) == 0) | 1045 | if ((mode->c_lflag & ICANON) == 0) |
diff --git a/coreutils/sync.c b/coreutils/sync.c index 66445281a..9be47ab64 100644 --- a/coreutils/sync.c +++ b/coreutils/sync.c | |||
@@ -59,8 +59,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
59 | OPT_SYNCFS = (1 << 1), | 59 | OPT_SYNCFS = (1 << 1), |
60 | }; | 60 | }; |
61 | 61 | ||
62 | opt_complementary = "d--f:f--d"; | 62 | opts = getopt32(argv, "^" "df" "\0" "d--f:f--d"); |
63 | opts = getopt32(argv, "df"); | ||
64 | argv += optind; | 63 | argv += optind; |
65 | 64 | ||
66 | /* Handle the no-argument case. */ | 65 | /* Handle the no-argument case. */ |
diff --git a/coreutils/tail.c b/coreutils/tail.c index fd310f422..7335ba11e 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -140,9 +140,11 @@ int tail_main(int argc, char **argv) | |||
140 | #endif | 140 | #endif |
141 | 141 | ||
142 | /* -s NUM, -F imlies -f */ | 142 | /* -s NUM, -F imlies -f */ |
143 | IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) | 143 | opt = getopt32(argv, IF_FEATURE_FANCY_TAIL("^") |
144 | opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), | 144 | "fc:n:"IF_FEATURE_FANCY_TAIL("qs:+vF") |
145 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); | 145 | IF_FEATURE_FANCY_TAIL("\0" "Ff"), |
146 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period) | ||
147 | ); | ||
146 | #define FOLLOW (opt & 0x1) | 148 | #define FOLLOW (opt & 0x1) |
147 | #define COUNT_BYTES (opt & 0x2) | 149 | #define COUNT_BYTES (opt & 0x2) |
148 | //if (opt & 0x1) // -f | 150 | //if (opt & 0x1) // -f |
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/tr.c b/coreutils/tr.c index 64e4efc91..c5872434a 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c | |||
@@ -298,8 +298,8 @@ int tr_main(int argc UNUSED_PARAM, char **argv) | |||
298 | * In POSIX locale, these are the same. | 298 | * In POSIX locale, these are the same. |
299 | */ | 299 | */ |
300 | 300 | ||
301 | opt_complementary = "-1"; | 301 | /* '+': stop at first non-option */ |
302 | opts = getopt32(argv, "+Ccds"); /* '+': stop at first non-option */ | 302 | opts = getopt32(argv, "^+" "Ccds" "\0" "-1"); |
303 | argv += optind; | 303 | argv += optind; |
304 | 304 | ||
305 | str1_length = expand(*argv++, &str1); | 305 | str1_length = expand(*argv++, &str1); |
diff --git a/coreutils/truncate.c b/coreutils/truncate.c index f67abaf40..f693570aa 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c | |||
@@ -50,8 +50,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv) | |||
50 | OPT_SIZE = (1 << 1), | 50 | OPT_SIZE = (1 << 1), |
51 | }; | 51 | }; |
52 | 52 | ||
53 | opt_complementary = "s:-1"; | 53 | opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str); |
54 | opts = getopt32(argv, "cs:", &size_str); | ||
55 | 54 | ||
56 | if (!(opts & OPT_NOCREATE)) | 55 | if (!(opts & OPT_NOCREATE)) |
57 | flags |= O_CREAT; | 56 | flags |= O_CREAT; |
diff --git a/coreutils/tty.c b/coreutils/tty.c index 331941a01..18ad7c566 100644 --- a/coreutils/tty.c +++ b/coreutils/tty.c | |||
@@ -13,7 +13,7 @@ | |||
13 | //config: tty is used to print the name of the current terminal to | 13 | //config: tty is used to print the name of the current terminal to |
14 | //config: standard output. | 14 | //config: standard output. |
15 | 15 | ||
16 | //applet:IF_TTY(APPLET(tty, BB_DIR_USR_BIN, BB_SUID_DROP)) | 16 | //applet:IF_TTY(APPLET_NOFORK(tty, tty, BB_DIR_USR_BIN, BB_SUID_DROP, tty)) |
17 | 17 | ||
18 | //kbuild:lib-$(CONFIG_TTY) += tty.o | 18 | //kbuild:lib-$(CONFIG_TTY) += tty.o |
19 | 19 | ||
diff --git a/coreutils/uname.c b/coreutils/uname.c index aad58cab0..bb2d1fe8d 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -63,9 +63,9 @@ | |||
63 | //config: help | 63 | //config: help |
64 | //config: Same as uname -m. | 64 | //config: Same as uname -m. |
65 | 65 | ||
66 | //applet:IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP)) | 66 | // APPLET_NOFORK:name main location suid_type help |
67 | // APPLET_ODDNAME:name main location suid_type help | 67 | //applet:IF_UNAME(APPLET_NOFORK( uname, uname, BB_DIR_BIN, BB_SUID_DROP, uname)) |
68 | //applet:IF_BB_ARCH(APPLET_ODDNAME(arch, uname, BB_DIR_BIN, BB_SUID_DROP, arch)) | 68 | //applet:IF_BB_ARCH(APPLET_NOFORK(arch, uname, BB_DIR_BIN, BB_SUID_DROP, arch)) |
69 | 69 | ||
70 | //kbuild:lib-$(CONFIG_UNAME) += uname.o | 70 | //kbuild:lib-$(CONFIG_UNAME) += uname.o |
71 | //kbuild:lib-$(CONFIG_BB_ARCH) += uname.o | 71 | //kbuild:lib-$(CONFIG_BB_ARCH) += uname.o |
@@ -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 | } |
@@ -183,7 +182,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
183 | strcpy(uname_info.processor, unknown_str); | 182 | strcpy(uname_info.processor, unknown_str); |
184 | strcpy(uname_info.platform, unknown_str); | 183 | strcpy(uname_info.platform, unknown_str); |
185 | strcpy(uname_info.os, CONFIG_UNAME_OSNAME); | 184 | strcpy(uname_info.os, CONFIG_UNAME_OSNAME); |
186 | # if 0 | 185 | # if ENABLE_FEDORA_COMPAT |
187 | /* Fedora does something like this */ | 186 | /* Fedora does something like this */ |
188 | strcpy(uname_info.processor, uname_info.name.machine); | 187 | strcpy(uname_info.processor, uname_info.name.machine); |
189 | strcpy(uname_info.platform, uname_info.name.machine); | 188 | strcpy(uname_info.platform, uname_info.name.machine); |
diff --git a/coreutils/unlink.c b/coreutils/unlink.c index 3322d5b47..56309b1c7 100644 --- a/coreutils/unlink.c +++ b/coreutils/unlink.c | |||
@@ -11,7 +11,7 @@ | |||
11 | //config: help | 11 | //config: help |
12 | //config: unlink deletes a file by calling unlink() | 12 | //config: unlink deletes a file by calling unlink() |
13 | 13 | ||
14 | //applet:IF_UNLINK(APPLET(unlink, BB_DIR_USR_BIN, BB_SUID_DROP)) | 14 | //applet:IF_UNLINK(APPLET_NOFORK(unlink, unlink, BB_DIR_USR_BIN, BB_SUID_DROP, unlink)) |
15 | 15 | ||
16 | //kbuild:lib-$(CONFIG_UNLINK) += unlink.o | 16 | //kbuild:lib-$(CONFIG_UNLINK) += unlink.o |
17 | 17 | ||
@@ -25,8 +25,7 @@ | |||
25 | int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 25 | int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
26 | int unlink_main(int argc UNUSED_PARAM, char **argv) | 26 | int unlink_main(int argc UNUSED_PARAM, char **argv) |
27 | { | 27 | { |
28 | opt_complementary = "=1"; /* must have exactly 1 param */ | 28 | getopt32(argv, "^" "" "\0" "=1"); |
29 | getopt32(argv, ""); | ||
30 | argv += optind; | 29 | argv += optind; |
31 | xunlink(argv[0]); | 30 | xunlink(argv[0]); |
32 | return 0; | 31 | return 0; |
diff --git a/coreutils/usleep.c b/coreutils/usleep.c index 7c25aada1..684ab781b 100644 --- a/coreutils/usleep.c +++ b/coreutils/usleep.c | |||
@@ -38,6 +38,13 @@ int usleep_main(int argc UNUSED_PARAM, char **argv) | |||
38 | bb_show_usage(); | 38 | bb_show_usage(); |
39 | } | 39 | } |
40 | 40 | ||
41 | /* Safe wrt NOFORK? (noforks are not allowed to run for | ||
42 | * a long time). Try "usleep 99999999" + ^C + "echo $?" | ||
43 | * in hush with FEATURE_SH_NOFORK=y. | ||
44 | * At least on uclibc, usleep() thanslates to nanosleep() | ||
45 | * which returns early on any signal (even caught one), | ||
46 | * and uclibc does not loop back on EINTR. | ||
47 | */ | ||
41 | usleep(xatou(argv[1])); | 48 | usleep(xatou(argv[1])); |
42 | 49 | ||
43 | return EXIT_SUCCESS; | 50 | return EXIT_SUCCESS; |
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 4e72e86ee..5ef05ee4d 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c | |||
@@ -120,8 +120,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) | |||
120 | char *outname = NULL; | 120 | char *outname = NULL; |
121 | char *line; | 121 | char *line; |
122 | 122 | ||
123 | opt_complementary = "?1"; /* 1 argument max */ | 123 | getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname); |
124 | getopt32(argv, "o:", &outname); | ||
125 | argv += optind; | 124 | argv += optind; |
126 | 125 | ||
127 | if (!argv[0]) | 126 | if (!argv[0]) |
@@ -196,8 +195,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv) | |||
196 | FILE *src_stream; | 195 | FILE *src_stream; |
197 | unsigned opts; | 196 | unsigned opts; |
198 | 197 | ||
199 | opt_complementary = "?1"; /* 1 argument max */ | 198 | opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/); |
200 | opts = getopt32(argv, "d"); | ||
201 | argv += optind; | 199 | argv += optind; |
202 | 200 | ||
203 | if (!argv[0]) | 201 | if (!argv[0]) |
diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index 7164f838a..d6e077430 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c | |||
@@ -49,8 +49,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv) | |||
49 | 49 | ||
50 | tbl = bb_uuenc_tbl_std; | 50 | tbl = bb_uuenc_tbl_std; |
51 | mode = 0666 & ~umask(0666); | 51 | mode = 0666 & ~umask(0666); |
52 | opt_complementary = "-1:?2"; /* must have 1 or 2 args */ | 52 | if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) { |
53 | if (getopt32(argv, "m")) { | ||
54 | tbl = bb_uuenc_tbl_base64; | 53 | tbl = bb_uuenc_tbl_base64; |
55 | } | 54 | } |
56 | argv += optind; | 55 | argv += optind; |
diff --git a/coreutils/who.c b/coreutils/who.c index 91f99138c..cfe0c921e 100644 --- a/coreutils/who.c +++ b/coreutils/who.c | |||
@@ -38,10 +38,10 @@ | |||
38 | //config: help | 38 | //config: help |
39 | //config: Print users currently logged on. | 39 | //config: Print users currently logged on. |
40 | 40 | ||
41 | // APPLET_ODDNAME:name main location suid_type help | 41 | // APPLET_NOEXEC:name main location suid_type help |
42 | //applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users)) | 42 | //applet:IF_USERS(APPLET_NOEXEC(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users)) |
43 | //applet:IF_W( APPLET_ODDNAME(w, who, BB_DIR_USR_BIN, BB_SUID_DROP, w)) | 43 | //applet:IF_W( APPLET_NOEXEC(w, who, BB_DIR_USR_BIN, BB_SUID_DROP, w)) |
44 | //applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP)) | 44 | //applet:IF_WHO( APPLET_NOEXEC(who, who, BB_DIR_USR_BIN, BB_SUID_DROP, who)) |
45 | 45 | ||
46 | //kbuild:lib-$(CONFIG_USERS) += who.o | 46 | //kbuild:lib-$(CONFIG_USERS) += who.o |
47 | //kbuild:lib-$(CONFIG_W) += who.o | 47 | //kbuild:lib-$(CONFIG_W) += who.o |
@@ -117,8 +117,7 @@ int who_main(int argc UNUSED_PARAM, char **argv) | |||
117 | unsigned opt; | 117 | unsigned opt; |
118 | const char *fmt = "%s"; | 118 | const char *fmt = "%s"; |
119 | 119 | ||
120 | opt_complementary = "=0"; | 120 | opt = getopt32(argv, do_who ? "^" "aH" "\0" "=0": "^" "" "\0" "=0"); |
121 | opt = getopt32(argv, do_who ? "aH" : ""); | ||
122 | if ((opt & 2) || do_w) /* -H or we are w */ | 121 | if ((opt & 2) || do_w) /* -H or we are w */ |
123 | puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); | 122 | puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); |
124 | 123 | ||
diff --git a/coreutils/yes.c b/coreutils/yes.c index a5a444249..6dc47355e 100644 --- a/coreutils/yes.c +++ b/coreutils/yes.c | |||
@@ -15,9 +15,10 @@ | |||
15 | //config: default y | 15 | //config: default y |
16 | //config: help | 16 | //config: help |
17 | //config: yes is used to repeatedly output a specific string, or | 17 | //config: yes is used to repeatedly output a specific string, or |
18 | //config: the default string `y'. | 18 | //config: the default string 'y'. |
19 | 19 | ||
20 | //applet:IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) | 20 | //applet:IF_YES(APPLET_NOEXEC(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) |
21 | /* was NOFORK, but then yes can't be ^C'ed if run by hush */ | ||
21 | 22 | ||
22 | //kbuild:lib-$(CONFIG_YES) += yes.o | 23 | //kbuild:lib-$(CONFIG_YES) += yes.o |
23 | 24 | ||