bug in newlib strftime
Jeff Johnston
jjohnstn@redhat.com
Thu Jan 20 20:00:00 GMT 2005
Patch checked in.
-- Jeff J.
Jeff Johnston wrote:
> I am looking into the changes requested below and should have something
> checked in by end of day.
>
> Eric Blake wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Newlib has several POSIX compliance issues in strftime(). See
>> http://www.opengroup.org/onlinepubs/009695399/functions/strftime.html for
>> the mandated behavior. Since newlib does not support any locales other
>> than "C", strftime() should be fixed to follow the mandated behavior.
>> The
>> broken behavior of strftime() leads to failures in the coreutils program
>> date on cygwin and any other newlib-based platform.
>>
>> Should coreutils add a configure-time check that looks for broken
>> strftime(), or should I just wait for a new version of newlib that fixes
>> the compliance issues?
>>
>> In newlib, strftime() treats "%r" as "", although Posix requires it to be
>> a synonym for "%I:%M:%S %p" in the POSIX/C locale. Likewise, newlib
>> treats "%x" as "%a %b %d %Y", although Posix mandates "%m/%d/%y".
>> Finally, newlib does not support the %E or %O modifiers, even though
>> Posix
>> mandates that they be ignored for the conversion specifiers that support
>> them (in other words, "%Ey", "%Oy", and "%y" are all required and should
>> behave identically in the "C" locale, but since "%Ea" is not required,
>> its
>> behavior is undefined). In the sample program below, the two output
>> lines
>> should be identical.
>>
>> $ cat foo.c
>> #include <time.h>
>> #include <stdlib.h>
>> #include <locale.h>
>>
>> #define MAX_LEN 80
>>
>> int main()
>> {
>> char str[MAX_LEN];
>> struct tm t;
>> setlocale(LC_ALL, "C");
>> memset(&t, 0, sizeof(t));
>> t.tm_sec = 30;
>> t.tm_min = 15;
>> t.tm_hour = 1; /* 1:15:30 AM */
>> t.tm_mday = 18; /* 18th */
>> t.tm_mon = 0; /* Jan */
>> t.tm_year = 105; /* 2005 */
>> t.tm_wday = 2; /* Tue */
>> strftime(str, MAX_LEN, "%r#%x#%Ey#%Oy", &t);
>> puts(str);
>> strftime(str, MAX_LEN, "%I:%M:%S %p#%m/%d/%y#%y#%y", &t);
>> puts(str);
>> return 0;
>> }
>> $ gcc -o foo foo.c
>> $ ./foo
>> #Tue Jan 18 2005#y#y
>> 01:15:30 AM#01/18/05#05#05
>>
>> - --
>> Life is short - so eat dessert first!
>>
>> Eric Blake ebb9@byu.net
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.0 (Cygwin)
>> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>>
>> iD8DBQFB7mKr84KuGfSFAYARAjNdAKCjNw/IWf0ZxBMvHsAo6dm/T2gwogCfWjyK
>> 4H/w5oTgp9MOZ/nZSTUYp5A=
>> =OA+F
>> -----END PGP SIGNATURE-----
>
>
More information about the Newlib
mailing list