summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/getopt_long.c
diff options
context:
space:
mode:
authorguenther <>2011-03-05 22:10:11 +0000
committerguenther <>2011-03-05 22:10:11 +0000
commit9d057237f371a465ccec3f1a7a68c19af8920051 (patch)
tree448ef6b71a537dcd5d0e6ce2a7893a402dc7c930 /src/lib/libc/stdlib/getopt_long.c
parent40abb7da20d82cdfbe24fc623f51d100e7ae76d4 (diff)
downloadopenbsd-9d057237f371a465ccec3f1a7a68c19af8920051.tar.gz
openbsd-9d057237f371a465ccec3f1a7a68c19af8920051.tar.bz2
openbsd-9d057237f371a465ccec3f1a7a68c19af8920051.zip
Fix PR 6267: recheck POSIXLY_CORRECT each time getopt_long() starts a new
argv and don't suppress the handling of leading '-' in optstring when POSIXLY_CORRECT is set. Based on patch from Eric Blake. ok and manpage update from millert@, manpage ok jmc@
Diffstat (limited to 'src/lib/libc/stdlib/getopt_long.c')
-rw-r--r--src/lib/libc/stdlib/getopt_long.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/getopt_long.c b/src/lib/libc/stdlib/getopt_long.c
index eb1e3ef4be..e149fe0ace 100644
--- a/src/lib/libc/stdlib/getopt_long.c
+++ b/src/lib/libc/stdlib/getopt_long.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getopt_long.c,v 1.24 2010/07/22 19:31:53 blambert Exp $ */ 1/* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */
2/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ 2/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
3 3
4/* 4/*
@@ -285,25 +285,25 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
285 return (-1); 285 return (-1);
286 286
287 /* 287 /*
288 * XXX Some GNU programs (like cvs) set optind to 0 instead of
289 * XXX using optreset. Work around this braindamage.
290 */
291 if (optind == 0)
292 optind = optreset = 1;
293
294 /*
288 * Disable GNU extensions if POSIXLY_CORRECT is set or options 295 * Disable GNU extensions if POSIXLY_CORRECT is set or options
289 * string begins with a '+'. 296 * string begins with a '+'.
290 */ 297 */
291 if (posixly_correct == -1) 298 if (posixly_correct == -1 || optreset)
292 posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); 299 posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
293 if (posixly_correct || *options == '+') 300 if (*options == '-')
294 flags &= ~FLAG_PERMUTE;
295 else if (*options == '-')
296 flags |= FLAG_ALLARGS; 301 flags |= FLAG_ALLARGS;
302 else if (posixly_correct || *options == '+')
303 flags &= ~FLAG_PERMUTE;
297 if (*options == '+' || *options == '-') 304 if (*options == '+' || *options == '-')
298 options++; 305 options++;
299 306
300 /*
301 * XXX Some GNU programs (like cvs) set optind to 0 instead of
302 * XXX using optreset. Work around this braindamage.
303 */
304 if (optind == 0)
305 optind = optreset = 1;
306
307 optarg = NULL; 307 optarg = NULL;
308 if (optreset) 308 if (optreset)
309 nonopt_start = nonopt_end = -1; 309 nonopt_start = nonopt_end = -1;