bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#7325: new test failure due to non-portability of printf formats like


From: Jim Meyering
Subject: bug#7325: new test failure due to non-portability of printf formats like %05.3s
Date: Wed, 03 Nov 2010 19:59:44 +0100

At least on Solaris 10, the new stat-nanoseconds test fails,
due to non-portability of snprintf vs a format like %010.3s:

    FAIL: misc/stat-nanoseconds
    ...
    + touch -d '2010-10-21 18:43:33.023456789' k
    ...
    ++ stat -c %05.3:X k
    + test 00023 = '  023'
    + fail=1

You can demonstrate it with bash's built-in printf, too:

    solaris$ bash -c "printf '%010.3s\n' 23"
    0000000023

    glibc$ bash -c "printf '%010.3s\n' 23"
            23

Note that coreutils' printf does not accept the '0' modifier in a %s format.

    $ env printf '%05.3s\n' 23
    printf: %05.3s: invalid conversion specification

That's because POSIX says the "0" modifier applies only to the
d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversion specifiers.

One solution is to trim off the "0".
It's probably a good idea regardless, in case some implementation rejects it.

On the other hand, I find the zero-padding you currently get
with stat on solaris to be slightly more intuitive.
I'll sleep on it.

Other opinions welcome, as usual.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]