Subject: lib/6762: getopt(3) matches "--foo" as "--"
To: None <gnats-bugs@gnats.netbsd.org>
From: Simon J. Gerraty <sjg@quick.com.au>
List: netbsd-bugs
Date: 01/08/1999 12:42:55
>Number: 6762
>Category: lib
>Synopsis: getopt(3) matches "--foo" as "--"
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 7 17:50:00 1999
>Last-Modified:
>Originator: Simon J. Gerraty
>Organization:
Zen Programming...
>Release: 19981229
>Environment:
System: NetBSD zen.quick.com.au 1.3.2 NetBSD 1.3.2 (ZEN-PUC) #2: Sun Oct 18 18:37:34 EST 1998 sjg@zen.quick.com.au:/u3/NetBSD/1.3.2/src/sys/arch/i386/compile/ZEN-PUC i386
>Description:
NetBSD's getopt(3) treats --foo the same as --
Eg:
$ getopt "vp:-:" -v -p one --unlink a n c
-v -p one -- a n c
This is compatible with the behaviour on SunOS 4.X, but SunOS 5.X
does the right thing:
: sjg:54; uname -a
SunOS frodo 4.1.4 2 sun4m
: sjg:55; getopt "vp:-:" -v -p one --unlink a n c
-v -p one -- a n c
: sjg:2; uname -a
SunOS zen.cdn.telstra.com.au 5.6 Generic_105181-06 sun4u sparc SUNW,Ultra-60
: sjg:3; getopt "vp:-:" -v -p one --unlink a n c
-v -p one -- unlink -- a n c
: sjg:4; getopt "vp:-:" -v -p one -- --unlink a n c
-v -p one -- --unlink a n c
Not tossing the chars after "--" allows progams to support options like
--unlink without having to resort to GNU's getopt.
>How-To-Repeat:
>Fix:
*** src/lib/libc/stdlib/getopt.c.old Tue Feb 3 23:49:31 1998
--- src/lib/libc/stdlib/getopt.c Fri Jan 8 12:22:08 1999
***************
*** 82,88 ****
place = EMSG;
return (-1);
}
! if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
--- 76,83 ----
place = EMSG;
return (-1);
}
! if (place[1] && *++place == '-' /* found "--" */
! && !place[1]) { /* and not "--foo" */
++optind;
place = EMSG;
return (-1);
>Audit-Trail:
>Unformatted: