This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Questions about strptime()/strftime()
- From: Arkadiusz Miskiewicz <arekm at maven dot pl>
- To: libc-help at sourceware dot org
- Cc: "Carlos O'Donell" <carlos at systemhalted dot org>,"Richard Harvey Chapman" <hchapman at 3gfp dot com>
- Date: Tue, 1 Jul 2008 22:14:43 +0200
- Subject: Re: Questions about strptime()/strftime()
- References: <485D4113.9050107@3gfp.com> <119aab440806211122m3374fcd7k4df57496b11a5aef@mail.gmail.com>
On Saturday 21 June 2008, Carlos O'Donell wrote:
> On Sat, Jun 21, 2008 at 1:57 PM, Richard Harvey Chapman
>
> <hchapman@3gfp.com> wrote:
> > result = strptime(str, format, &tt2_r);
>
> This returns "Illegal seek" because "%F", "%z", and "%Z" are not valid
> formats which strptime can convert.
Why it doesn't return NULL on a 2, 3 and 4th test then? Failure in first test is another magic.
$ ./a.out
strptime() == NULL
DEBUG: Parsed as 00-00-00
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
$ more test.c
#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");
memset (&tmp, 0, sizeof (tmp));
if (strptime (date, "%a %b %d %T %z %Y", &tmp) == NULL)
printf("strptime() == NULL\n");
printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, tmp.tm_year);
memset (&tmp, 0, sizeof (tmp));
if (strptime (date, "Mon %b %d %T %z %Y", &tmp) == NULL)
printf("strptime() == NULL\n");
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));
if (strptime (date, "%a %b %d %T %z %Y", &tmp) == NULL)
printf("strptime() == NULL\n");
printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, tmp.tm_year);
memset (&tmp, 0, sizeof (tmp));
if (strptime (date, "Mon %b %d %T %z %Y", &tmp) == NULL)
printf("strptime() == NULL\n");
printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, tmp.tm_year);
}
>
> 1. Please see
> http://www.opengroup.org/onlinepubs/009695399/functions/strptime.html for
> the full list.
> 2. Remember to check return values.
>
> Cheers,
> Carlos.
--
Arkadiusz MiÅkiewicz PLD/Linux Team
arekm / maven.pl http://ftp.pld-linux.org/