<div dir="auto">On a related note... The BSDs (including Mac) all have a getopt(1) but it's a trivial one, like getopts. util-linux and busybox both have this "full" getopt. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 22, 2019, 08:17 enh <<a href="mailto:enh@google.com">enh@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Nov 22, 2019 at 5:02 AM Rob Landley <<a href="mailto:rob@landley.net" target="_blank" rel="noreferrer">rob@landley.net</a>> wrote:<br>
><br>
> On 11/22/19 6:56 AM, Rob Landley wrote:<br>
> > On 11/21/19 4:13 PM, enh via Toybox wrote:<br>
> >> Includes new tests.<br>
> >> ---<br>
> >> lib/portability.h | 3 ++<br>
> ><br>
> > Applied, by why add this #include to portability.h when it's not in an #ifdef?<br>
> > The main #includes are in toys.h.<br>
><br>
> Also, would someone please explain why posix-2008 has "getopts" with an s:<br>
><br>
> <a href="https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/getopts.html" rel="noreferrer noreferrer" target="_blank">https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/getopts.html</a><br>
><br>
> But the bash builtin and util-linux command are both "getopt" without an s? (And<br>
> gratuitously stomping man 3 getopt with man 1 getopt?)<br>
<br>
are you sure? my bash has getopts built in and an external getopt.<br>
<br>
~$ type getopts<br>
getopts is a shell builtin<br>
~$ type getopt<br>
getopt is /usr/bin/getopt<br>
~$<br>
<br>
the same is true of mksh too. haven't looked at any other shells.<br>
<br>
> I notice this new implementation doesn't link to posix as its spec in the header<br>
> block, I'm guessing they're different commands?<br>
<br>
mostly, yes. the comment in the getopt.c source about "legacy" mode?<br>
POSIX getopts is a subset even of that. legacy mode is more<br>
complicated because you have to deal with cases like "mostly using new<br>
options, but missing -o or an early OPTSTR, so steal the first app<br>
argument".<br>
<br>
on the bright side, getopts is probably two lines of C in the shell<br>
--- basically just a call to non-long getopt(3), although getopts is<br>
also subject to a few extra shell variables that don't mean anything<br>
to getopt(1). that might be the reason why even bash's getopts doesn't<br>
have all the extra stuff that's in a current getopt(1) added to it?<br>
<br>
(there are actually orders of magnitude more references to getopts<br>
than getopt in the Android build, but that's covered by bash for the<br>
time being...)<br>
<br>
> Rob<br>
> _______________________________________________<br>
> Toybox mailing list<br>
> <a href="mailto:Toybox@lists.landley.net" target="_blank" rel="noreferrer">Toybox@lists.landley.net</a><br>
> <a href="http://lists.landley.net/listinfo.cgi/toybox-landley.net" rel="noreferrer noreferrer" target="_blank">http://lists.landley.net/listinfo.cgi/toybox-landley.net</a><br>
</blockquote></div>