From bf3db314f7202d264439f36c4b50f843640c242a Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 20 Nov 2011 21:48:50 +0000 Subject: [PATCH] sh: Allow unsetting OPTIND. Note that only assigning the decimal value 1 resets getopts, as before. --- bin/sh/options.c | 5 +++-- tools/regression/bin/sh/parameters/optind1.0 | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 tools/regression/bin/sh/parameters/optind1.0 diff --git a/bin/sh/options.c b/bin/sh/options.c index 9104e93270fc..4c2c8ab8e3ec 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -401,9 +401,10 @@ setcmd(int argc, char **argv) void getoptsreset(const char *value) { - if (number(value) == 1) { + while (*value == '0') + value++; + if (strcmp(value, "1") == 0) shellparam.reset = 1; - } } /* diff --git a/tools/regression/bin/sh/parameters/optind1.0 b/tools/regression/bin/sh/parameters/optind1.0 new file mode 100644 index 000000000000..33e0288e861f --- /dev/null +++ b/tools/regression/bin/sh/parameters/optind1.0 @@ -0,0 +1,3 @@ +# $FreeBSD$ + +unset OPTIND && [ -z "$OPTIND" ]