[Top][All Lists]
[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: |
Eric Blake |
Subject: |
bug#7325: new test failure due to non-portability of printf formats like %05.3s |
Date: |
Wed, 03 Nov 2010 15:32:55 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Fedora/3.1.6-1.fc14 Mnenhy/0.8.3 Thunderbird/3.1.6 |
On 11/03/2010 03:26 PM, Jim Meyering wrote:
>> I agree that %05.3:X resulting in 00023 would be ideal. And I agree
>> that we'd have to trim off the 0 modifier before calling the underlying
>> printf %s, and thus be responsible for putting in '0' padding ourselves
>> rather than relying on printf() padding.
>
> Thanks for confirming.
> Here's the patch I'm considering:
>
> diff --git a/src/stat.c b/src/stat.c
> index d05a93b..993db48 100644
> --- a/src/stat.c
> +++ b/src/stat.c
> @@ -472,6 +472,23 @@ epoch_sec (struct timespec t)
> return timetostr (t.tv_sec, str);
> }
>
> +/* Convert a LEN-byte FORMAT modifier, e.g., "0009.4", to "9.4".
> + Do it in place and return the new length. */
> +static size_t
> +sanitize_format_string (char *format, size_t len)
> +{
> + char *p = format;
> + char const *end = format + len;
> + while (p < end && *p == '0')
> + p++;
> + if (p == format)
> + return len;
> +
> + len -= p - format;
> + memmove (format, p, len);
> + return len;
> +}
Not just leading zeros. Think also about "%-0 010.4:X", which must
sanitize to "%- 10.4s" - that is, you must strip any zero until the
first non-zero digit or '.' is found.
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/03
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Eric Blake, 2010/11/03
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/03
- bug#7325: new test failure due to non-portability of printf formats like %05.3s,
Eric Blake <=
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Paul Eggert, 2010/11/03
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/04
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/04
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Paul Eggert, 2010/11/04
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/04
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/05
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Paul Eggert, 2010/11/05
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Pádraig Brady, 2010/11/04
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Jim Meyering, 2010/11/05
- bug#7325: new test failure due to non-portability of printf formats like %05.3s, Paul Eggert, 2010/11/05