summaryrefslogtreecommitdiff
path: root/posix/getopt.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2010-04-07 17:56:20 -0700
committerPetr Baudis <pasky@ucw.cz>2010-05-12 03:21:15 +0200
commit6b6e2d505cf6e9246872e7f98e338b52922c7b33 (patch)
treebeb1af85e7a7e8170ac40aed992894d8571dc10b /posix/getopt.c
parentd75c76e1d74d3c6fe508738abd442aae0365d690 (diff)
getopt mishandles optstring of "+:"
(cherry picked from commit 66b93be793af309fb78d54199aed2306650079d0)
Diffstat (limited to 'posix/getopt.c')
-rw-r--r--posix/getopt.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/posix/getopt.c b/posix/getopt.c
index b778047cd9..2746364fc7 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -395,8 +395,6 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
- if (optstring[0] == ':')
- print_errors = 0;
if (argc < 1)
return -1;
@@ -411,6 +409,10 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
posixly_correct);
d->__initialized = 1;
}
+ else if (optstring[0] == '-' || optstring[0] == '+')
+ optstring++;
+ if (optstring[0] == ':')
+ print_errors = 0;
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag