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


On Sunday 06 July 2008, Carlos O'Donell wrote:
> 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.

I was looking into source code because docs look incomplete. Should I paste 
the code? It has hardcoded english day/month names and to me it looks like 
strptime() is supposed to handle english names even in other locales.

>
> 2. Observed behaviour.

Ok, so:

> > 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

Above is current behaviour.

> >
> > 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

Above is observed (in 2.3.6) and expected (in 2.7, 2.8) behaviour.

> >
> > (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.

It should have no impact on first test (see first "DEBUG:" line in glibc 2.8 
test) IMO but it has.

>
> 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);
> > }

Now in "Questions about strptime()/strftime()" thread where I posted a little 
modified test case you wrote that

"This returns "Illegal seek" because "%F", "%z", and "%Z" are not valid 
formats which strptime can convert." but I was using "%z and 4 times and 
strptime failed only once.

>
> Cheers,
> Carlos.



-- 
Arkadiusz MiÅkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/


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