This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/11041] New: getopt -W doesn't work with optional arguments


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]