Back to index

glibc  2.9
tst-strptime.c
Go to the documentation of this file.
00001 #include <locale.h>
00002 #include <time.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 static int
00007 do_test (void)
00008 {
00009   int result = 0;
00010 
00011   if (setlocale (LC_ALL, "vi_VN.TCVN5712-1") == NULL)
00012     {
00013       puts ("cannot set locale");
00014       return 1;
00015     }
00016   struct tm tm;
00017   memset (&tm, '\0', sizeof (tm));
00018   /* This is November in Vietnamese encoded using TCVN5712-1.  */
00019   static const char s[] = "\
00020 \x54\x68\xb8\x6e\x67\x20\x6d\xad\xea\x69\x20\x6d\xe9\x74\0";
00021   char *r = strptime (s, "%b", &tm);
00022   printf ("r = %p, r-s = %tu, tm.tm_mon = %d\n", r, r - s, tm.tm_mon);
00023   result = r == NULL || r - s != 14 || tm.tm_mon != 10;
00024 
00025   if (setlocale (LC_ALL, "ja_JP.UTF-8") == NULL)
00026     {
00027       puts ("cannot set locale");
00028       return 1;
00029     }
00030   static const char s2[] = "\
00031 \x32\x35\x20\x30\x36\x20\xe5\xb9\xb3\xe6\x88\x90\x32\x30\0";
00032   memset (&tm, '\0', sizeof (tm));
00033   r = strptime (s2, "%d %m %EC%Ey", &tm);
00034   printf ("\
00035 r = %p, r-s2 = %tu, tm.tm_mday = %d, tm.tm_mon = %d, tm.tm_year = %d\n",
00036          r, r - s2, tm.tm_mday, tm.tm_mon, tm.tm_year);
00037   result |= (r == NULL || r - s2 != 14 || tm.tm_mday != 25 || tm.tm_mon != 5
00038             || tm.tm_year != 108);
00039 
00040   static const char s3[] = "\
00041 \x32\x35\x20\x30\x36\x20\xe5\xb9\xb3\xe6\x88\x90\x32\x30\xe5\xb9\xb4\0";
00042   memset (&tm, '\0', sizeof (tm));
00043   r = strptime (s3, "%d %m %EY", &tm);
00044   printf ("\
00045 r = %p, r-s3 = %tu, tm.tm_mday = %d, tm.tm_mon = %d, tm.tm_year = %d\n",
00046          r, r - s3, tm.tm_mday, tm.tm_mon, tm.tm_year);
00047   result |= (r == NULL || r - s3 != 17 || tm.tm_mday != 25 || tm.tm_mon != 5
00048             || tm.tm_year != 108);
00049 
00050   return result;
00051 }
00052 
00053 #define TEST_FUNCTION do_test ()
00054 #include "../test-skeleton.c"