[Toybox] People being confused by the existence of octal.
enh
enh at google.com
Mon Nov 18 05:58:11 PST 2024
On Sat, Nov 16, 2024 at 6:54 PM Rob Landley <rob at landley.net> wrote:
> Over on microsoft github, https://github.com/landley/toybox/issues/527
> said:
>
> $ umask
> 0022
> $ test $(umask) -eq 22
> $ echo $?
> 0
> $ toybox test $(umask) -eq 22
> $ echo $?
> 1
>
> Where uname is returning octal (because file permissions are octal) so
> it's comparing an octal number vs a decimal number and my test is
> technically doing the right thing, but A) doing the right thing is
> confusing people, B) the "test" implementations in bash, coreutils, and
> busybox consistently get it wrong in the same way.
>
bsd test seems to accept octal with a 0 prefix but _not_ hex with an 0x
prefix! (while bash behaves as you say, making macOS a confusing place to
call test(1)!)
posix doesn't say anything beyond "integer":
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/test.html
> People being confused by the existence of octal has been reported before
> (in sed and such), and my complaint has always been that I'm as
> interested in the behavior being CONSISTENT as "right".
>
> I'm tempted to switch atolx() default behavior to just hex or decimal
> and NOT do octal, because octal confuses people... except it IS used in
> a few places, ala printf '%d\n' 034 printing 28
> (<strike>Taylor's</strike> Debian's version).
to be fair, even _i_ hate that, let alone the younger generations... if C
didn't have such a bad specification for how \x works, i suspect octal
escapes would have died out here long ago. (the only place i see it is
strace, and on the rare occasions i actually care about non-ascii string
content, i tell strace to use \x anyway.)
> I suspect I'd need to
> audit all the users (around 85 at the moment)...
>
> Anybody have a strong opinion on whether I should change the default?
> Changing the default mostly affects command line parsing for things like
> "truncate -s 077777" which it seems unlikely anyone is doing anyway?
>
yeah, i've never seen octal used [on purpose] for anything but unix
permissions. and if you want to support that, you could always do the
trendy new thing of accepting 0o. (i'm assuming we already get 0b for free
when built against a C23 libc?)
> Looks like I have a few whack-a-mole cases either way because the
> inherited environment we're trying to be compatible with isn't
> consistent, and trying to MAKE it so means I'm not compatible with
> what's there which is itself inconsistent...
>
> Rob
>
> P.S. it's a pity things things like "official posix compliance tests"
> stopped mattering 30 years ago when they cost an arm and a leg and Linux
> officially went "nah, we're good, if it's not published free on the web
> it's not a standard, go do your fortune 500 fundraising elsewhere".
> (That was back in the 90s, modern google can of course no longer find
> it. I could dig though the lwn.net annual summaries but eh...) These
> days, the IDEA of posix publishing a useful automated test suite is so
> blisteringly irrelevant that
> https://www.opengroup.org/testing/testsuites/posix.html has a big link
> to posixcertified.ieee.org which no longer has a DNS entry, and if you
> dig further you can manage "this https used such an old certificate it's
> not even TLS 1.2 which came out in 2008". Sigh...
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20241118/43ed97f5/attachment.htm>
More information about the Toybox
mailing list