1*c9945492SAndroid Build Coastguard Worker #include <time.h>
2*c9945492SAndroid Build Coastguard Worker #include <stdio.h>
3*c9945492SAndroid Build Coastguard Worker #include <langinfo.h>
4*c9945492SAndroid Build Coastguard Worker #include "locale_impl.h"
5*c9945492SAndroid Build Coastguard Worker #include "atomic.h"
6*c9945492SAndroid Build Coastguard Worker
__asctime_r(const struct tm * restrict tm,char * restrict buf)7*c9945492SAndroid Build Coastguard Worker char *__asctime_r(const struct tm *restrict tm, char *restrict buf)
8*c9945492SAndroid Build Coastguard Worker {
9*c9945492SAndroid Build Coastguard Worker if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
10*c9945492SAndroid Build Coastguard Worker __nl_langinfo_l(ABDAY_1+tm->tm_wday, C_LOCALE),
11*c9945492SAndroid Build Coastguard Worker __nl_langinfo_l(ABMON_1+tm->tm_mon, C_LOCALE),
12*c9945492SAndroid Build Coastguard Worker tm->tm_mday, tm->tm_hour,
13*c9945492SAndroid Build Coastguard Worker tm->tm_min, tm->tm_sec,
14*c9945492SAndroid Build Coastguard Worker 1900 + tm->tm_year) >= 26)
15*c9945492SAndroid Build Coastguard Worker {
16*c9945492SAndroid Build Coastguard Worker /* ISO C requires us to use the above format string,
17*c9945492SAndroid Build Coastguard Worker * even if it will not fit in the buffer. Thus asctime_r
18*c9945492SAndroid Build Coastguard Worker * is _supposed_ to crash if the fields in tm are too large.
19*c9945492SAndroid Build Coastguard Worker * We follow this behavior and crash "gracefully" to warn
20*c9945492SAndroid Build Coastguard Worker * application developers that they may not be so lucky
21*c9945492SAndroid Build Coastguard Worker * on other implementations (e.g. stack smashing..).
22*c9945492SAndroid Build Coastguard Worker */
23*c9945492SAndroid Build Coastguard Worker a_crash();
24*c9945492SAndroid Build Coastguard Worker }
25*c9945492SAndroid Build Coastguard Worker return buf;
26*c9945492SAndroid Build Coastguard Worker }
27*c9945492SAndroid Build Coastguard Worker
28*c9945492SAndroid Build Coastguard Worker weak_alias(__asctime_r, asctime_r);
29