>   The following corrects a bad example in the manual page.  It also
> emphasizes the issue.  See, for example, #655685, which was filed for
> procps.

Hi. Upstream maintainer of man-pages here. I'm not at all sure that
the problem in #655685 is because of getopt(). (How did you conclude
that it is?)

Allowing a space between option character and argument is longstanding
UNIX (and Linux behavior), and as far as I can see POSIX is explicit
in allowing it--POSIX.1-2001 contains this text (note point 2):

       The getopt() function shall return the  next  option  character
       (if  one  is  found) from argv that matches a character in opt‐
       string, if there is one that matches. If the  option  takes  an
       argument,  getopt()  shall  set the variable optarg to point to
       the option-argument as follows:

        1. If the option was the last character in the string  pointed
           to  by  an  element  of argv, then optarg shall contain the
           next element of argv, and optind shall be incremented by 2.
           If the resulting value of optind is greater than argc, this
           indicates a missing  option-argument,  and  getopt()  shall
           return an error indication.

        2. Otherwise,  optarg  shall point to the string following the
           option character in that element of argv, and optind  shall
           be incremented by 1.

Thanks,

Michael

> --- a/getopt.3  2012-03-06 11:33:58.252003620 +0200
> +++ b/getopt.3  2012-03-06 11:33:36.000000000 +0200
> @@ -371,14 +371,28 @@ has a technical error described in POSIX
>  The GNU
>  implementation (and probably all other implementations) implements the
>  correct behavior rather than that specified.
> +.PP
> +There should be no white space between a short option name
> +and its possible arguments.
> +That is, use
> +.IR -unsecs
> +, not
> +.IR "-u nsecs" .
> +With long options, use =, with no space characters either before or
> +after it. That is,
> +.IR --units=nsecs
> +, nothing else.
>  .SH EXAMPLE
>  The following trivial example program uses
>  .BR getopt ()
>  to handle two program options:
>  .IR \-n ,
>  with no associated value; and
> -.IR "\-t val" ,
> +.IR "\-tval" ,
>  which expects an associated value.
> +Note that
> +.IR "\-t val" ,
> +with a space, does not work.
>  .nf
>  .sp
>  #include <unistd.h>
>
>
>
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/



--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to