From 791b222dd55d3aa0e8b09be1be571e4829465dd6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Oct 2023 13:56:32 +0200 Subject: sleep: fix "sleep -- ARGS" function old new delta sleep_main 116 119 +3 printf_main 860 837 -23 single_argv 50 25 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48) Total: -45 bytes Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 10 +++++----- coreutils/sleep.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'coreutils') 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) /* bash builtin errors out on "printf '-%s-\n' foo", * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". * We will mimic coreutils. */ - if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2]) - argv++; - if (!argv[1]) { + argv = skip_dash_dash(argv); + + if (!argv[0]) { if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF) && applet_name[0] != 'p' ) { @@ -437,8 +437,8 @@ int printf_main(int argc UNUSED_PARAM, char **argv) bb_show_usage(); } - format = argv[1]; - argv2 = argv + 2; + format = argv[0]; + argv2 = argv + 1; conv_err = 0; 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) * + we can't use bb_show_usage * + applet_name can be the name of the shell */ - ++argv; - if (!*argv) { + argv = skip_dash_dash(argv); + if (!argv[0]) { /* Without this, bare "sleep" in ash shows _ash_ --help */ /* (ash can be the "sh" applet as well, so check 2nd char) */ if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') { -- cgit v1.2.3