From 4327e193d476bd5cb9bad5ba8fb83b476dbafeb9 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Dec 2004 16:14:36 +0000 Subject: Document why not to set optind = 0. Inspired by and OK jfb@ --- lib/libc/stdlib/getopt.3 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdlib') diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3 index d210852c6bd..76546d29464 100644 --- a/lib/libc/stdlib/getopt.3 +++ b/lib/libc/stdlib/getopt.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: getopt.3,v 1.28 2003/09/22 23:47:26 millert Exp $ +.\" $OpenBSD: getopt.3,v 1.29 2004/12/07 16:14:35 millert Exp $ .\" .Dd December 17, 2002 .Dt GETOPT 3 @@ -95,9 +95,13 @@ and are both initialized to 1. The .Va optind -variable may be set to another value before a set of calls to +variable may be set to another value larger than 0 before a set of calls to .Fn getopt in order to skip over more or less argv entries. +An +.Va optind +value of 0 is reserved for compatibility with GNU +.Fn getopt . .Pp In order to use .Fn getopt @@ -230,6 +234,20 @@ variable was added to make it possible to call the .Fn getopt function multiple times. .It Li o +If the +.Va optind +variable is set to 0, +.Fn getopt +will behave as if the +.Va optreset +variable has been set. +This is for compatibility with +.Tn GNU +.Fn getopt . +New code should use +.Va optreset +instead. +.It Li o If the first character of .Fa optstring is a plus sign -- cgit v1.2.3