diff options
author | 2002-12-08 17:07:46 +0000 | |
---|---|---|
committer | 2002-12-08 17:07:46 +0000 | |
commit | 6f1bcab3ffbdf341d73dd479b574ff7644b9a73a (patch) | |
tree | c5bbf07d2a89e8df143a5f3282faebe92c228617 /lib/libc/stdlib/getopt_long.c | |
parent | strncpy is evil. (diff) | |
download | wireguard-openbsd-6f1bcab3ffbdf341d73dd479b574ff7644b9a73a.tar.xz wireguard-openbsd-6f1bcab3ffbdf341d73dd479b574ff7644b9a73a.zip |
If we are passed "-" in argv and the user didn't specify '-' in optstring,
return -1 like POSIX requires.
Diffstat (limited to 'lib/libc/stdlib/getopt_long.c')
-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; |