NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/59828: getopt(3) GNU extension wrong behavior
The following reply was made to PR lib/59828; it has been noted by GNATS.
From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: lib/59828: getopt(3) GNU extension wrong behavior
Date: Wed, 10 Dec 2025 19:47:32 +0300
On Wed, Dec 10, 2025 at 15:10:02 +0000, Jose Luis Duran via gnats wrote:
> while ((ch = getopt(argc, argv, "cCd::F:lnoOp:s:u:U:wW")) != -1) {
> printf("ch is %c optarg is %s\n", (char)ch, optarg ? optarg : " NULL");
> }
[...]
> Notice the "d" option has double colons, and is the subject at hand.
> By reading the manual page for getopt(3):
>
> If an individual character is followed by two colons,
> then the option argument is optional; optarg is set
> to the rest of the current argv word,
> or NULL if there were no more characters in the current word.
> This is a NetBSD extension.
[...]
> 1. With a space between "-d" and the option argument:
So you are making a conceptual mistake here. The phrase above is
contradiction in terms.
As the man page says, for double colon optios the argument is:
optarg is set to the rest of the current argv word ...
If the current argv word, "-d", it does not have anything after 'd',
there's no argument. The space that delimts "-d" word is not
"between" anything.
If the option were "-d14", optarg would get set to point after 'd', to
the "14" part of the "-d14" word.
> Current output:
> $ ./getopttest -l -w -d 14 -s /usr/local/admin/tftproot -u admin -U 0
> ch is l optarg is NULL
> ch is w optarg is NULL
> ch is d optarg is NULL
>
> Notice the arguments after "d" are missing.
Right, b/c "14" is not an option, so getopt stops.
-uwe
Home |
Main Index |
Thread Index |
Old Index