Check length of ifname before copying it into to ifreq structure.
[glibc.git] / time / tst-posixtz.c
blob9bec7ae4bb6e97950c217c5f11d1197940e00a50
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <time.h>
5 #include <stdint.h>
7 struct
9 time_t when;
10 const char *tz;
11 const char *result;
12 } tests[] =
14 { 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
15 "1998/10/25 21:54:09 dst=1 zone=AEDST" },
16 { 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
17 "1999/04/23 20:54:09 dst=0 zone=AEST" },
18 { 919973892L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
19 "1999/02/26 07:18:12 dst=1 zone=AEDST" },
20 { 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
21 "1998/10/25 05:54:09 dst=0 zone=EST" },
22 { 909312849L, "EST5EDT,M4.1.0/2,M10.5.0/2",
23 "1998/10/25 05:54:09 dst=0 zone=EST" },
24 { 909312849L, "<EST5>5EDT,M4.1.0/2,M10.5.0/2",
25 "1998/10/25 05:54:09 dst=0 zone=EST5" },
26 { 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
27 "1999/04/23 06:54:09 dst=1 zone=EDT" },
28 { 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
29 "1999/02/25 15:18:12 dst=0 zone=EST" },
32 static int
33 do_test (void)
35 int result = 0;
36 size_t cnt;
38 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
40 char buf[100];
41 struct tm *tmp;
43 printf ("TZ = \"%s\", time = %jd => ", tests[cnt].tz,
44 (intmax_t) tests[cnt].when);
45 fflush (stdout);
47 setenv ("TZ", tests[cnt].tz, 1);
49 tmp = localtime (&tests[cnt].when);
51 snprintf (buf, sizeof (buf),
52 "%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s",
53 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
54 tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst,
55 tzname[tmp->tm_isdst ? 1 : 0]);
57 fputs (buf, stdout);
59 if (strcmp (buf, tests[cnt].result) == 0)
60 puts (", OK");
61 else
63 result = 1;
64 puts (", FAIL");
68 setenv ("TZ", "Universal", 1);
69 localtime (&tests[0].when);
70 printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }",
71 daylight, tzname[0], tzname[1]);
72 if (! daylight)
73 puts (", OK");
74 else
76 result = 1;
77 puts (", FAIL");
80 setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1);
81 tzset ();
82 printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d"
83 " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
84 if (daylight
85 && strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0)
86 puts (", OK");
87 else
89 result = 1;
90 puts (", FAIL");
93 setenv ("TZ", "<AB1>-10<AB2>-11,M10.5.0,M3.5.0", 1);
94 tzset ();
95 printf ("TZ = \"<AB1>-10<AB2>-11,M10.5.0,M3.5.0\" daylight %d"
96 " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
97 if (daylight
98 && strcmp (tzname[0], "AB1") == 0 && strcmp (tzname[1], "AB2") == 0)
99 puts (", OK");
100 else
102 result = 1;
103 puts (", FAIL");
106 setenv ("TZ", "<BB1>-10", 1);
107 tzset ();
108 printf ("TZ = \"<BB1>-10\" daylight %d"
109 " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
110 if (daylight == 0
111 && strcmp (tzname[0], "BB1") == 0 && strcmp (tzname[1], "BB1") == 0)
112 puts (", OK");
113 else
115 result = 1;
116 puts (", FAIL");
119 return result;
122 #define TEST_FUNCTION do_test ()
123 #include "../test-skeleton.c"