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

Eric Blake eblake@redhat.com
Thu Aug 30 06:50:00 GMT 2012


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20120830/e5f735ae/attachment.sig>


More information about the Newlib mailing list