Subject: Re: bin/21970 (printf(1) breaks when format begins with "-")
To: None <gnats-bugs@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-bugs
Date: 11/27/2006 09:21:24
On Mon, 27 Nov 2006, hubertf@NetBSD.org wrote:
> I've sent out a patch as a suggestion, but I'm not sure this came through
> properly, so here it is again... if I missed the point, please let me
> know or do the cut&paste yourself, see also localsrc/legal/TheOpenGroup
> while there.
> 
> 
>  - Hubert
> 
> P.S.: I also have a patch that has  12.1 Utility Argument Syntax
> of the SUSv3 in *roff format, just in case that's what you want to have
> in that manpage. Let me know if so!

Thanks Hubert.  I think it would be useful to add something to
intro(1) explaining that most utilities accept "--" for "end
of options", "-xyz" often means the same as "-x" "-y" "-z",
"-oarg" often means the same as "-o" "arg", option order usually
doesn't matter, etc.  I'd prefer a level of detail somewhere
between your proposed patch and the text from SUSv3 section 12.1
<http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html>,
but your patch is good enough.

I still think it's a bug that printf(1) uses getopt.  I think it's wrong for
any utility that doesn't take options in the usual way to use getopt().

If you compare the SUSv3 descriptions of printf(1) and cat(1)
(<http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html>
and <http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html>),
you can see that "The cat utility shall conform to the Base Definitions
volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax
Guidelines", whereas printf(1) does not.

I don't buy the argument that "OPTIONS None" in SUSv3 means "anybody who
uses printf(1) needs to insert "--" to guarantee that the format is not
misinterpreted as an option".  At least, not unless somebody can point
to text in SUSv3 that says so.

--apb (Alan Barrett)