This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

Re: Tried to make getopt() and friends more sus4-like in error handling


On 08/26/2012 06:00 PM, Gregory Pietsch wrote:
> I finally got the a-ha for this. Okay to add? -- Gregory Pietsch
> 
> --- getopt.c.old    2012-08-26 19:24:27.466130300 -0400
> +++ getopt.c    2012-08-26 19:54:39.118121500 -0400
> The
> +colon goes in front of the ordering character (`+' or `-').

Wrong - according to 'man 3 getopt' on a GNU/Linux system,

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.

That is, any leading '+' or '-' comes _before_ a leading ':'.

> @@ -359,12 +375,18 @@
>          {
>            fprintf (stderr, "%s: argument required for option `", argv[0]);
>            if (longopt_match >= 0)
> +        {
>          fprintf (stderr, "--%s'\n", longopts[longopt_match].name);
> +          data->optopt = initial_colon ? ':' : '\?';

'\?' is invalid C code.  Also, your use of space vs. TAB indentation is
inconsistent.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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