This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: strptime vs C locale vs other locale - test case attached
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: "Arkadiusz Miskiewicz" <arekm at maven dot pl>
- Cc: libc-help at sourceware dot org
- Date: Sun, 6 Jul 2008 12:43:30 -0400
- Subject: Re: strptime vs C locale vs other locale - test case attached
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=MXOCuikUytLVG3YoGG2UARdYgTEHvEP4vDY9/dFQ0Gs=; b=ve1+WWXfSuGiXugXYCmnL43C3zY2PlCp9/pOyR/5eUG5PacZ2U+AwfzG7id9HTpF1j 7dwEnfRUHsbo+bei6HbbQTSH0bJW+enRYzCmBDZlBA2IbhaVwl+NVvTmiJtmq1EFLHOC aFxozpkr8mTJ1oCu6+/u/AYsHNcRJIlqXizTA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=lGrRjBdfcgPzjkcp3J8RCQWCXVwS5U6d/K2B4Ev5wkuixQ/9Rget4hSbf7Ykc4UUC0 PTLKVz0znh39kyyfF/PiXMfgrpDMVGfr/f29rcji1ULvbXkPKUf7vR2gvM7hBmM+6Q0a JPUtap15DCjYjM2Jf3xgZ6uFgh+2AFYJ+zVH8=
- References: <200807010709.38181.arekm@maven.pl>
2008/7/1 Arkadiusz Miskiewicz <arekm@maven.pl>:
> The attached test [1] on glibc 2.8 shows that C locale date isn't parsed
> correctly after chaning LC_TIME. glibc strptime has AFAIK gnu extension
> that makes strptime() parsing C locate dates correctly even
> if LC_TIME is set to some other locale, correct?
Please clearly state
1. Expected behaviour, possibly citing documentation related to the
gnu extension.
2. Observed behaviour.
> glibc 2.7, 2.8
>
> $ ./a.out
> DEBUG: Parsed as 00-00-00
> DEBUG: Parsed as 23-00-108
> DEBUG: Parsed as 23-00-108
> DEBUG: Parsed as 23-00-108
>
> glibc 2.3.6
>
> $ ./a.out
> DEBUG: Parsed as 23-00-108
> DEBUG: Parsed as 23-00-108
> DEBUG: Parsed as 23-00-108
> DEBUG: Parsed as 23-00-108
>
> (don't have machine with other glibc versions to test)
>
> 1. by patrys/pld-linux.org
>
> #define _GNU_SOURCE 1
> #include <string.h>
> #include <stdio.h>
> #include <time.h>
> #include <locale.h>
>
> int main()
> {
> char *date = "Mon Jan 23 14:01:57 +0000 2008";
> struct tm tmp;
> if (setlocale(LC_TIME, "pl_PL") == NULL)
> printf("setlocale() == NULL\n");
Is this supposed to fail or not? This test-case is not clear about
what should happen in the pl_PL locale is not present.
e.g.
setlocale() == NULL
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
> memset (&tmp, 0, sizeof (tmp));
> strptime (date, "%a %b %d %T %z %Y", &tmp);
> printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon,
> tmp.tm_year);
> memset (&tmp, 0, sizeof (tmp));
> strptime (date, "Mon %b %d %T %z %Y", &tmp);
> printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon,
> tmp.tm_year);
> setlocale(LC_TIME, "C");
> memset (&tmp, 0, sizeof (tmp));
> strptime (date, "%a %b %d %T %z %Y", &tmp);
> printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon,
> tmp.tm_year);
> memset (&tmp, 0, sizeof (tmp));
> strptime (date, "Mon %b %d %T %z %Y", &tmp);
> printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon,
> tmp.tm_year);
> }
Cheers,
Carlos.