public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/11041] New: getopt -W doesn't work with optional arguments
@ 2009-12-02  1:16 ebb9 at byu dot net
  2009-12-02  3:25 ` [Bug libc/11041] " ebb9 at byu dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ebb9 at byu dot net @ 2009-12-02  1:16 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-30 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-11041-131@http.sourceware.org/bugzilla/>
2014-06-30 20:36 ` [Bug libc/11041] getopt -W doesn't work with optional arguments fweimer at redhat dot com
2009-12-02  1:16 [Bug libc/11041] New: " ebb9 at byu dot net
2009-12-02  3:25 ` [Bug libc/11041] " ebb9 at byu dot net
2009-12-02 17:52 ` ebb9 at byu dot net
2009-12-02 18:08 ` ebb9 at byu dot net
2009-12-02 18:37 ` ebb9 at byu dot net
2010-04-08  0:18 ` drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).