This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strptime vs C locale vs other locale - test case attached


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]