Back to index

glibc  2.9
tst-strptime2.c
Go to the documentation of this file.
00001 #include <limits.h>
00002 #include <stdio.h>
00003 #include <time.h>
00004 
00005 
00006 static const struct
00007 {
00008   const char *fmt;
00009   long int gmtoff;
00010 } tests[] =
00011   {
00012     { "1113472456 +1000", 36000 },
00013     { "1113472456 -1000", -36000 },
00014     { "1113472456 +10", 36000 },
00015     { "1113472456 -10", -36000 },
00016     { "1113472456 +1030", 37800 },
00017     { "1113472456 -1030", -37800 },
00018     { "1113472456 +0030", 1800 },
00019     { "1113472456 -0030", -1800 },
00020     { "1113472456 -1330", LONG_MAX },
00021     { "1113472456 +1330", LONG_MAX },
00022     { "1113472456 -1060", LONG_MAX },
00023     { "1113472456 +1060", LONG_MAX },
00024     { "1113472456  1030", LONG_MAX },
00025   };
00026 #define ntests (sizeof (tests) / sizeof (tests[0]))
00027 
00028 
00029 int
00030 main (void)
00031 {
00032   int result = 0;
00033 
00034   for (int i = 0; i < ntests; ++i)
00035     {
00036       struct tm tm;
00037 
00038       if (strptime (tests[i].fmt, "%s %z", &tm) == NULL)
00039        {
00040          if (tests[i].gmtoff != LONG_MAX)
00041            {
00042              printf ("round %d: strptime unexpectedly failed\n", i);
00043              result = 1;
00044            }
00045          continue;
00046        }
00047 
00048       if (tm.tm_gmtoff != tests[i].gmtoff)
00049        {
00050          printf ("round %d: tm_gmtoff is %ld\n", i, (long int) tm.tm_gmtoff);
00051          result = 1;
00052        }
00053     }
00054 
00055   if (result == 0)
00056     puts ("all OK");
00057 
00058   return 0;
00059 }