diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-15 15:44:41 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-15 15:44:41 +0200 |
commit | 9832bbaba966f0e52e183f10cd93fad7f8f643fe (patch) | |
tree | e79e43916984e0d1a575c30ae2dd9a3893331316 | |
parent | 4476c703015d026dfd8057a28010c33943aa2a9c (diff) | |
download | busybox-w32-9832bbaba966f0e52e183f10cd93fad7f8f643fe.tar.gz busybox-w32-9832bbaba966f0e52e183f10cd93fad7f8f643fe.tar.bz2 busybox-w32-9832bbaba966f0e52e183f10cd93fad7f8f643fe.zip |
ash: unset OPTARG if getopts exits 1, support OPTERR=0 behavior
function old new delta
getoptscmd 522 547 +25
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c index 58999fac5..703802ff5 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -10948,6 +10948,7 @@ getopts(char *optstr, char *optvar, char **optfirst) | |||
10948 | p = *optnext; | 10948 | p = *optnext; |
10949 | if (p == NULL || *p != '-' || *++p == '\0') { | 10949 | if (p == NULL || *p != '-' || *++p == '\0') { |
10950 | atend: | 10950 | atend: |
10951 | unsetvar("OPTARG"); | ||
10951 | p = NULL; | 10952 | p = NULL; |
10952 | done = 1; | 10953 | done = 1; |
10953 | goto out; | 10954 | goto out; |
@@ -10960,7 +10961,11 @@ getopts(char *optstr, char *optvar, char **optfirst) | |||
10960 | c = *p++; | 10961 | c = *p++; |
10961 | for (q = optstr; *q != c;) { | 10962 | for (q = optstr; *q != c;) { |
10962 | if (*q == '\0') { | 10963 | if (*q == '\0') { |
10963 | if (optstr[0] == ':') { | 10964 | /* OPTERR is a bashism */ |
10965 | const char *cp = lookupvar("OPTERR"); | ||
10966 | if ((cp && LONE_CHAR(cp, '0')) | ||
10967 | || (optstr[0] == ':') | ||
10968 | ) { | ||
10964 | sbuf[0] = c; | 10969 | sbuf[0] = c; |
10965 | /*sbuf[1] = '\0'; - already is */ | 10970 | /*sbuf[1] = '\0'; - already is */ |
10966 | setvar0("OPTARG", sbuf); | 10971 | setvar0("OPTARG", sbuf); |
@@ -10977,7 +10982,11 @@ getopts(char *optstr, char *optvar, char **optfirst) | |||
10977 | 10982 | ||
10978 | if (*++q == ':') { | 10983 | if (*++q == ':') { |
10979 | if (*p == '\0' && (p = *optnext) == NULL) { | 10984 | if (*p == '\0' && (p = *optnext) == NULL) { |
10980 | if (optstr[0] == ':') { | 10985 | /* OPTERR is a bashism */ |
10986 | const char *cp = lookupvar("OPTERR"); | ||
10987 | if ((cp && LONE_CHAR(cp, '0')) | ||
10988 | || (optstr[0] == ':') | ||
10989 | ) { | ||
10981 | sbuf[0] = c; | 10990 | sbuf[0] = c; |
10982 | /*sbuf[1] = '\0'; - already is */ | 10991 | /*sbuf[1] = '\0'; - already is */ |
10983 | setvar0("OPTARG", sbuf); | 10992 | setvar0("OPTARG", sbuf); |