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.