[Toybox] [PATCH] Support the %N coreutils/busybox extension to date.

Rob Landley rob at landley.net
Fri May 19 10:25:51 PDT 2017


On 05/09/2017 10:59 AM, enh wrote:
> what's the plan? "half an eye is better than no eye" (especially when
> no-one else has this particular missing eye), or "rewrite the test to
> use --full-time"?
> 
> since i personally have never needed %N except for getting this test
> to run, i'm happy to do either.

I've had the window open for a while, unhappy with the amount of code
added for a seemingly small feature, so I tried to rewrite your commit
to pass through the %xxxN stuff as %xxxld (because that's what
next_printf() does), and worked out that %*N uses completely bespoke
logic to do something nothing else does. (The FSF!)

Which means that using next_printf() is silly, and your first version
would be right... except that didn't handle %%N. So I wrote a simple
version that looped through, found the %N, did the strftime() into
toybuf with length sizeof(toybuf)-10, appended sprintf(blah, "%09u",
TT.nano), and then set blah[width] = 0 to trim it before printing.

And you have tests for %10N and %20N. Inserting zeroes. Which means that
no amount of space I reserve at the end of toybuf is enough.

So, I went to a two step approach where it prints out the strftime data
and then does a printf("%u", TT.nano) except I can't come _up_ with a
%*u syntax that will truncate an integer and give me just the first few
digits. It'll only do that with _strings_, not with numbers.

I really, really hate the way the FSF implemented this feature. It is
bespoke crap that does not act like existing printf() acts, requiring
special case code to implement it for NO OBVIOUS REASON.

(Haven't forgotten, just every time I sit down to deal with this I
tackle the code again rather than the email...)

Rob



More information about the Toybox mailing list