summaryrefslogtreecommitdiff
path: root/posix/getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'posix/getopt.c')
-rw-r--r--posix/getopt.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/posix/getopt.c b/posix/getopt.c
index 88acff0e2f..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
@@ -789,7 +791,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
if (*d->__nextchar == '\0')
++d->optind;
- if (temp == NULL || c == ':')
+ if (temp == NULL || c == ':' || c == ';')
{
if (print_errors)
{
@@ -911,7 +913,10 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
pfound = p;
indfound = option_index;
}
- else
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
@@ -1028,6 +1033,8 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
return optstring[0] == ':' ? ':' : '?';
}
}
+ else
+ d->optarg = NULL;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;