Re: getopt(3) redundancy/confusion?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux