diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-08 17:07:47 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-08 17:07:47 +0000 |
commit | 91b767c3db2acbf347c50f2a1830fa4e4fa72056 (patch) | |
tree | bd06c83f09c3a84be5b333147a3cd2c2c8afbda2 /lib | |
parent | 63e624d32431e9175a9dfe08dbaa034ea7998366 (diff) |
If we are passed "-" in argv and the user didn't specify '-' in optstring,
return -1 like POSIX requires.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdlib/getopt_long.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index 2eec98530a6..176ba25bb7d 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 millert Exp $ */ +/* $OpenBSD: getopt_long.c,v 1.9 2002/12/08 17:07:46 millert Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* @@ -64,7 +64,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 millert Exp $"; +static char *rcsid = "$OpenBSD: getopt_long.c,v 1.9 2002/12/08 17:07:46 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <err.h> @@ -320,10 +320,8 @@ getopt_internal(int nargc, char * const *nargv, const char *options, * XXX Some GNU programs (like cvs) set optind to 0 instead of * XXX using optreset. Work around this braindamage. */ - if (optind == 0) { - optind = 1; - optreset = 1; - } + if (optind == 0) + optind = optreset = 1; if (optreset) nonopt_start = nonopt_end = -1; @@ -428,6 +426,12 @@ start: if ((optchar = (int)*place++) == (int)':' || (oli = strchr(options, optchar)) == NULL) { + /* + * If the user didn't specify '-' as an option, + * assume it means -1 as POSIX specifies. + */ + if (optchar == (int)'-') + return (-1); /* option letter unknown or ':' */ if (!*place) ++optind; |