Back to index

glibc  2.9
tst-strptime3.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <time.h>
00005 
00006 
00007 int
00008 main (void)
00009 {
00010   int result = 0;
00011   struct tm tm;
00012 
00013   memset (&tm, 0xaa, sizeof (tm));
00014 
00015   /* Test we don't crash on uninitialized struct tm.
00016      Some fields might contain bogus values until everything
00017      needed is initialized, but we shouldn't crash.  */
00018   if (strptime ("2007", "%Y", &tm) == NULL
00019       || strptime ("12", "%d", &tm) == NULL
00020       || strptime ("Feb", "%b", &tm) == NULL
00021       || strptime ("13", "%M", &tm) == NULL
00022       || strptime ("21", "%S", &tm) == NULL
00023       || strptime ("16", "%H", &tm) == NULL)
00024     {
00025       puts ("strptimes failed");
00026       result = 1;
00027     }
00028 
00029   if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
00030       || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107
00031       || tm.tm_wday != 1 || tm.tm_yday != 42)
00032     {
00033       puts ("unexpected tm content");
00034       result = 1;
00035     }
00036 
00037   if (strptime ("8", "%d", &tm) == NULL)
00038     {
00039       puts ("strptime failed");
00040       result = 1;
00041     }
00042 
00043   if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
00044       || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107
00045       || tm.tm_wday != 4 || tm.tm_yday != 38)
00046     {
00047       puts ("unexpected tm content");
00048       result = 1;
00049     }
00050 
00051   if (result == 0)
00052     puts ("all OK");
00053 
00054   return 0;
00055 }