diff options
| author | thorpej <thorpej@NetBSD.org> | 2000-08-25 17:05:49 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 2000-08-25 17:05:49 +0000 |
| commit | a3fe3d3cf9e322fac3739ba9765b501342366f20 (patch) | |
| tree | 106045958df545ae92411cc54f936e1659ef7649 /lib/libc/stdlib/getopt_long.c | |
| parent | 4f419afab199edc819344f8bc8105815afe3aeb3 (diff) | |
Some (popular) programs expect to be able to re-initialize `optind'
to 0 and have getopt(3)/getopt_long(3) continue to function properly.
This happens to work with GNU getopt_long(3), so mimmick the behavior.
Fixes pkg/10980 (Manuel Bouyer): rsyncd was relying on this behavior.
Diffstat (limited to 'lib/libc/stdlib/getopt_long.c')
| -rw-r--r-- | lib/libc/stdlib/getopt_long.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index dcfde6a870e..f65422a5ca4 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -1,4 +1,4 @@ -/* $NetBSD: getopt_long.c,v 1.7 2000/07/08 14:58:43 sommerfeld Exp $ */ +/* $NetBSD: getopt_long.c,v 1.8 2000/08/25 17:05:49 thorpej Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getopt_long.c,v 1.7 2000/07/08 14:58:43 sommerfeld Exp $"); +__RCSID("$NetBSD: getopt_long.c,v 1.8 2000/08/25 17:05:49 thorpej Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -181,6 +181,14 @@ getopt_internal(nargc, nargv, options) optarg = NULL; + /* + * XXX Some programs (like rsyncd) expect to be able to + * XXX re-initialize optind to 0 and have getopt_long(3) + * XXX properly function again. Work around this braindamage. + */ + if (optind == 0) + optind = 1; + if (optreset) nonopt_start = nonopt_end = -1; start: |
