aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:05:21 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:05:21 +0200
commit81f962f3df0d7194b7a52c6f83259727759094c4 (patch)
tree906d5d55118f0a7c96579c7d12c62b3a14311a7a /shell/hush.c
parent74d40589288890fffea437ed2f38ad1f2dc740e5 (diff)
downloadbusybox-81f962f3df0d7194b7a52c6f83259727759094c4.tar.gz
hush: teach getopts to set/unset OPTARG
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index dba12c12e..f9a8de423 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9874,11 +9874,6 @@ static int FAST_FUNC builtin_getopts(char **argv)
{
/*
TODO:
-if a character is followed by a colon, the option is expected to have
-an argument, which should be separated from it by white space.
-When an option requires an argument, getopts places that argument into
-the variable OPTARG.
-
If an invalid option is seen, getopts places ? into VAR and, if
not silent, prints an error message and unsets OPTARG. If
getopts is silent, the option character found is placed in
@@ -9906,6 +9901,7 @@ Test that VAR is a valid variable name?
opterr = cp ? atoi(cp) : 1;
cp = get_local_var_value("OPTIND");
optind = cp ? atoi(cp) : 0;
+ optarg = NULL;
/* getopts stops on first non-option. Add "+" to force that */
/*if (optstring[0] != '+')*/ {
@@ -9924,6 +9920,10 @@ Test that VAR is a valid variable name?
exitcode = EXIT_FAILURE;
c = '?';
}
+ if (optarg)
+ set_local_var_from_halves("OPTARG", optarg);
+ else
+ unset_local_var("OPTARG");
cbuf[0] = c;
cbuf[1] = '\0';
set_local_var_from_halves(var, cbuf);