14 memset (&ttm
, 1, sizeof (ttm
));
15 ttm
.tm_zone
= NULL
; /* Dereferenced directly if non-NULL. */
16 rc
= strftime (buf
, sizeof (buf
), "%a %A %b %B %c %z %Z", &ttm
);
21 = "? ? ? ? ? ? 16843009 16843009:16843009:16843009 16844909 +467836 ?";
22 if (0 != strcmp (buf
, expected
))
24 printf ("expected:\n %s\ngot:\n %s\n", expected
, buf
);
30 printf ("expected 66, got %d\n", rc
);
34 /* Check negative values as well. */
35 memset (&ttm
, 0xFF, sizeof (ttm
));
36 ttm
.tm_zone
= NULL
; /* Dereferenced directly if non-NULL. */
37 rc
= strftime (buf
, sizeof (buf
), "%a %A %b %B %c %z %Z", &ttm
);
41 const char expected
[] = "? ? ? ? ? ? -1 -1:-1:-1 1899 ";
42 if (0 != strcmp (buf
, expected
))
44 printf ("expected:\n %s\ngot:\n %s\n", expected
, buf
);
50 printf ("expected 30, got %d\n", rc
);
64 { "%2000Y", 2000, 4000 },
65 { "%02000Y", 2000, 4000 },
66 { "%_2000Y", 2000, 4000 },
67 { "%-2000Y", 2000, 4000 },
69 #define ntests (sizeof (tests) / sizeof (tests[0]))
78 time_t tnow
= time (NULL
);
79 struct tm
*now
= localtime (&tnow
);
81 for (cnt
= 0; cnt
< ntests
; ++cnt
)
90 buf
= (char *) realloc (buf
, size
);
93 puts ("out of memory");
97 res
= strftime (buf
, size
, tests
[cnt
].fmt
, now
);
101 while (size
< tests
[cnt
].max
);
105 printf ("%Zu: %s: res == 0 despite size == %Zu\n",
106 cnt
, tests
[cnt
].fmt
, size
);
109 else if (size
< tests
[cnt
].min
)
111 printf ("%Zu: %s: size == %Zu was enough\n",
112 cnt
, tests
[cnt
].fmt
, size
);
116 printf ("%Zu: %s: size == %Zu: OK\n", cnt
, tests
[cnt
].fmt
, size
);
123 /* Initialize the fields which are needed in the tests. */
138 #define nftests (sizeof (ftests) / sizeof (ftests[0]))
139 for (cnt
= 0; cnt
< nftests
; ++cnt
)
142 size_t r
= strftime (buf
, sizeof (buf
), ftests
[cnt
].fmt
, &ttm
);
143 if (r
!= ftests
[cnt
].n
)
145 printf ("strftime(\"%s\") returned %zu not %zu\n",
146 ftests
[cnt
].fmt
, r
, ftests
[cnt
].n
);
149 if (strcmp (buf
, ftests
[cnt
].exp
) != 0)
151 printf ("strftime(\"%s\") produced \"%s\" not \"%s\"\n",
152 ftests
[cnt
].fmt
, buf
, ftests
[cnt
].exp
);
157 return result
+ do_bz18985 ();
160 #define TEST_FUNCTION do_test ()
161 #include "../test-skeleton.c"