aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/printf.c10
-rw-r--r--coreutils/sleep.c4
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/single_argv.c15
-rw-r--r--shell/hush.c8
5 files changed, 19 insertions, 19 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 7763d7c46..4edcfa9b5 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -425,9 +425,9 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
425 /* bash builtin errors out on "printf '-%s-\n' foo", 425 /* bash builtin errors out on "printf '-%s-\n' foo",
426 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". 426 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".
427 * We will mimic coreutils. */ 427 * We will mimic coreutils. */
428 if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2]) 428 argv = skip_dash_dash(argv);
429 argv++; 429
430 if (!argv[1]) { 430 if (!argv[0]) {
431 if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF) 431 if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF)
432 && applet_name[0] != 'p' 432 && applet_name[0] != 'p'
433 ) { 433 ) {
@@ -437,8 +437,8 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
437 bb_show_usage(); 437 bb_show_usage();
438 } 438 }
439 439
440 format = argv[1]; 440 format = argv[0];
441 argv2 = argv + 2; 441 argv2 = argv + 1;
442 442
443 conv_err = 0; 443 conv_err = 0;
444 do { 444 do {
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index 6edff59cc..fa74f1fd4 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -71,8 +71,8 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
71 * + we can't use bb_show_usage 71 * + we can't use bb_show_usage
72 * + applet_name can be the name of the shell 72 * + applet_name can be the name of the shell
73 */ 73 */
74 ++argv; 74 argv = skip_dash_dash(argv);
75 if (!*argv) { 75 if (!argv[0]) {
76 /* Without this, bare "sleep" in ash shows _ash_ --help */ 76 /* Without this, bare "sleep" in ash shows _ash_ --help */
77 /* (ash can be the "sh" applet as well, so check 2nd char) */ 77 /* (ash can be the "sh" applet as well, so check 2nd char) */
78 if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') { 78 if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') {
diff --git a/include/libbb.h b/include/libbb.h
index eb97a9880..0883fb565 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1344,6 +1344,7 @@ int sanitize_env_if_suid(void) FAST_FUNC;
1344/* For top, ps. Some argv[i] are replaced by malloced "-opt" strings */ 1344/* For top, ps. Some argv[i] are replaced by malloced "-opt" strings */
1345void make_all_argv_opts(char **argv) FAST_FUNC; 1345void make_all_argv_opts(char **argv) FAST_FUNC;
1346char* single_argv(char **argv) FAST_FUNC; 1346char* single_argv(char **argv) FAST_FUNC;
1347char **skip_dash_dash(char **argv) FAST_FUNC;
1347extern const char *const bb_argv_dash[]; /* { "-", NULL } */ 1348extern const char *const bb_argv_dash[]; /* { "-", NULL } */
1348extern uint32_t option_mask32; 1349extern uint32_t option_mask32;
1349uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; 1350uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
diff --git a/libbb/single_argv.c b/libbb/single_argv.c
index 64844ddf8..594cb0d8d 100644
--- a/libbb/single_argv.c
+++ b/libbb/single_argv.c
@@ -8,11 +8,18 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11char* FAST_FUNC single_argv(char **argv) 11char** FAST_FUNC skip_dash_dash(char **argv)
12{ 12{
13 if (argv[1] && strcmp(argv[1], "--") == 0) 13 argv++;
14 if (argv[0] && argv[0][0] == '-' && argv[0][1] == '-' && argv[0][2] == '\0')
14 argv++; 15 argv++;
15 if (!argv[1] || argv[2]) 16 return argv;
17}
18
19char* FAST_FUNC single_argv(char **argv)
20{
21 argv = skip_dash_dash(argv);
22 if (!argv[0] || argv[1])
16 bb_show_usage(); 23 bb_show_usage();
17 return argv[1]; 24 return argv[0];
18} 25}
diff --git a/shell/hush.c b/shell/hush.c
index 8e632e0af..ca01e2b5b 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -10883,14 +10883,6 @@ static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM)
10883} 10883}
10884#endif 10884#endif
10885 10885
10886static char **skip_dash_dash(char **argv)
10887{
10888 argv++;
10889 if (argv[0] && argv[0][0] == '-' && argv[0][1] == '-' && argv[0][2] == '\0')
10890 argv++;
10891 return argv;
10892}
10893
10894static int FAST_FUNC builtin_cd(char **argv) 10886static int FAST_FUNC builtin_cd(char **argv)
10895{ 10887{
10896 const char *newdir; 10888 const char *newdir;