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

Rob Landley rob at landley.net
Sun Apr 16 13:28:28 PDT 2017


On 04/15/2017 01:17 PM, enh wrote:
> 
> Used by the toybox touch test suite (and thus necessary to pass the toybox
> tests on a toybox-only system).

Did I ever actually post my rant on this topic? Or just compose it and
save as draft.

This is really really libc's job, it's a pity the gnu guys didn't
coordinate with the glibc developers. (On the other hand, I suppose
that's why glibc wasn't worse.)

Yes "struct tm" doesn't have nanoseconds, and they don't want to make it
bigger because binary compatibility. But lp64 says int is 32 bits, so
they could stick the nanoseconds in the middle 30 bits of tm_isdst (old
0 and 1 inputs only flip the bottom bit, -1 sets the top bit, middle 30
bits are basically unused and can store 0-999999999; old code that sets
the field to -1 means nanoseconds are over 999999999 and you can treat
that as 0). Then strptime and strftime could both have access to
nanoseconds and could both implement %N. It's a little awkward but more
or less backwards compatible.

I already have date.c accepting nanoseconds input in its
@unixtime.fraction format. I pondered doing it for the
MMDDhhmm[[CC]YY][.ss] one but it doesn't OUTPUT that format which is
just sad. (Be symmetrical, people!) I've pondered _adding_ a flag to
make date output that, but "toybox tests require toybox commands" is a
bridge I haven't crossed yet.

Speaking of which, this patch adds %N to output but not to input, so
date can still only _set_ nanoseconds using the @123456789.123456789
syntax. And you're not checking that "%%N is a literal %N". (Sigh. If
we're going there, may I draw your attention to next_printf() in
lib/lib.c? Example usage in seq and stat.)

It's kind of sad "ls" can't show nanoseconds. Or "stat". I understand
why (nanoseconds were added when makefile dependencies started breaking
as computers got faster and multiple build things happened in the same
second; nothing else actually _needed_ them in the filesystem) but it's
still half-assed.

Grumble grumble...

Rob



More information about the Toybox mailing list