This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/11041] New: getopt -W doesn't work with optional arguments
- From: "ebb9 at byu dot net" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 2 Dec 2009 01:15:52 -0000
- Subject: [Bug libc/11041] New: getopt -W doesn't work with optional arguments
- Reply-to: sourceware-bugzilla at sourceware dot org
According to the getopt documentation, if "W;" is part of optstring, then '-W
foo' should behave like '--foo'. But if "foo" uses an optional_argument, this
is not the case, since optarg is not NULL when using -W.
$ cat foo.c
#include <stdio.h>
#include <getopt.h>
static const struct option opts[] =
{
{ "alpha", optional_argument, NULL, 'a' },
{ NULL, 0, NULL, 0 }
};
int
main(int argc, char **argv)
{
int c = getopt_long (argc, argv, "W;", opts, NULL);
if (c == -1)
puts ("got -1");
else
printf ("got %c, with arg %s\n", c, optarg);
return 0;
}
$ ./foo --a
got a, with arg (null)
$ ./foo -W a
got a, with arg a
--
Summary: getopt -W doesn't work with optional arguments
Product: glibc
Version: 2.11
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: ebb9 at byu dot net
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=11041
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.