diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-26 02:03:37 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-26 02:03:37 +0200 |
commit | a513bf3c3ce0756c991b21c0ca271e24fedcdb51 (patch) | |
tree | 3e2e210badd57f1e9489ff465b79944b1c1904a0 | |
parent | 88e15703acdbfb182440cf35fdb8972fc4931dd2 (diff) | |
download | busybox-w32-a513bf3c3ce0756c991b21c0ca271e24fedcdb51.tar.gz busybox-w32-a513bf3c3ce0756c991b21c0ca271e24fedcdb51.tar.bz2 busybox-w32-a513bf3c3ce0756c991b21c0ca271e24fedcdb51.zip |
ash: [BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1
Upstream commit:
Date: Sat, 6 Oct 2007 18:59:31 +0800
[BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1
Previously setting OPTIND to 0 would cause subsequent getopts calls to fail.
This patch makes dash reset the getopts parameters the same way as OPTIND=1.
Both behaviours are allowed by POSIX but other common shells do tolerate this
case.
function old new delta
getoptsreset 24 30 +6
getoptscmd 632 614 -18
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c index e30d7fe67..647fc81b4 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2019,7 +2019,7 @@ extern struct globals_var *const ash_ptr_to_globals_var; | |||
2019 | static void FAST_FUNC | 2019 | static void FAST_FUNC |
2020 | getoptsreset(const char *value) | 2020 | getoptsreset(const char *value) |
2021 | { | 2021 | { |
2022 | shellparam.optind = number(value); | 2022 | shellparam.optind = number(value) ?: 1; |
2023 | shellparam.optoff = -1; | 2023 | shellparam.optoff = -1; |
2024 | } | 2024 | } |
2025 | #endif | 2025 | #endif |
@@ -10571,8 +10571,6 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt | |||
10571 | 10571 | ||
10572 | sbuf[1] = '\0'; | 10572 | sbuf[1] = '\0'; |
10573 | 10573 | ||
10574 | if (*param_optind < 1) | ||
10575 | return 1; | ||
10576 | optnext = optfirst + *param_optind - 1; | 10574 | optnext = optfirst + *param_optind - 1; |
10577 | 10575 | ||
10578 | if (*param_optind <= 1 || *optoff < 0 || (int)strlen(optnext[-1]) < *optoff) | 10576 | if (*param_optind <= 1 || *optoff < 0 || (int)strlen(optnext[-1]) < *optoff) |