All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: getopt(3) redundancy/confusion?
       [not found]   ` <979857989.4058982.1485234629697-sAHhhX/85wgbqTNvkayDYw@public.gmane.org>
@ 2017-01-24 21:07     ` Michael Kerrisk (man-pages)
  2017-01-24 21:30       ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kerrisk (man-pages) @ 2017-01-24 21:07 UTC (permalink / raw)
  To: John Wiersba; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hi John!

On 24 January 2017 at 18:10, John Wiersba <jrw32982-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
> Hi, Michael!
>
> These two paragraphs in getopt(3) are confusing to me.  Isn't the first
> paragraph redundant (and incomplete), based on the second paragraph?
>
>        If getopt() does not recognize an option character, it prints an
>        error message to stderr, stores the character in optopt, and returns
>        '?'.  The calling program may prevent the error message by setting
>        opterr to 0.
>
>        If getopt() finds an option character in argv that was not included
>        in optstring, or if it detects a missing option argument, it returns
>        '?' and sets the external variable optopt to the actual option
>        character.  If the first character (following any optional '+' or '-'
>        described above) of optstring is a colon (':'), then getopt() returns
>        ':' instead of '?' to indicate a missing option argument.  If an
>        error was detected, and the first character of optstring is not a
>        colon, and the external variable opterr is nonzero (which is the
>        default), getopt() prints an error message.
>
> My understanding is that starting optstring with ":" is sufficient to
> prevent an option error being printed by getopt().
>
> If my comments are correct, then I can submit a bug report.

Yes, you're correct on all counts. I simply removed the first
paragraph. I'll give some thought to further clarifications. Thanks
for the report.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: getopt(3) redundancy/confusion?
  2017-01-24 21:07     ` getopt(3) redundancy/confusion? Michael Kerrisk (man-pages)
@ 2017-01-24 21:30       ` Michael Kerrisk (man-pages)
       [not found]         ` <1283255103.93836.1485300405004@mail.yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kerrisk (man-pages) @ 2017-01-24 21:30 UTC (permalink / raw)
  To: John Wiersba; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

> I'll give some thought to further clarifications.

Something like this:

       While processing the option list, getopt() can detect two kinds of
       errors: (1) an option character that was  not  specified  in  opt‐
       string  and  (2) a missing option argument (i.e., an option at the
       end of the command  line  without  an  expected  argument).   Such
       errors are handled and reported as follows:

       *  By default, getopt() prints an error message on standard error,
          places the erroneous option character in  optopt,  and  returns
          '?' as the function result.

       *  If  the caller has set the global variable opterr to zero, then
          getopt() does not print  an  error  message.   The  caller  can
          determine  that there was an error by testing whether the func‐
          tion return value is '?'.  (By default, opterr  has  a  nonzero
          value.)

       *  If  the  first  character  (following  any  optional '+' or '-'
          described above) of optstring is a colon (':'),  then  getopt()
          likewise  does  not  print  an  error message.  In addition, it
          returns ':' instead of '?' to indicate a missing  option  argu‐
          ment.   This allows the caller to distinguish the two different
          types of errors.

Easier to parse, I hope(?).

Cheers,

Michael
-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: getopt(3) redundancy/confusion?
       [not found]           ` <1283255103.93836.1485300405004-sAHhhX/85wgbqTNvkayDYw@public.gmane.org>
@ 2017-01-25  0:08             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Kerrisk (man-pages) @ 2017-01-25  0:08 UTC (permalink / raw)
  To: John Wiersba; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

On 25 January 2017 at 12:26, John Wiersba <jrw32982-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
> Yes definitely!  Thanks!

Good.

> Also, what's up with my email bouncing when sent to vger.kernel.org?  Is
> this a "we hate yahoo" kind of thing?

Nah -- it's a "we hate HTML mail" thing. It's a crude filter against
spam and, in any case, most useful stuff such as patches could not be
handled as HTML mail.

Cheers,

Michael
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-01-25  0:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <979857989.4058982.1485234629697.ref@mail.yahoo.com>
     [not found] ` <979857989.4058982.1485234629697@mail.yahoo.com>
     [not found]   ` <979857989.4058982.1485234629697-sAHhhX/85wgbqTNvkayDYw@public.gmane.org>
2017-01-24 21:07     ` getopt(3) redundancy/confusion? Michael Kerrisk (man-pages)
2017-01-24 21:30       ` Michael Kerrisk (man-pages)
     [not found]         ` <1283255103.93836.1485300405004@mail.yahoo.com>
     [not found]           ` <1283255103.93836.1485300405004-sAHhhX/85wgbqTNvkayDYw@public.gmane.org>
2017-01-25  0:08             ` Michael Kerrisk (man-pages)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.