Rev 9765 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9260 | turbocat | 1 | #include "stddef.h" |
8787 | turbocat | 2 | #include |
9765 | turbocat | 3 | #include |
8787 | turbocat | 4 | #include |
5 | #include |
||
6 | |||
9765 | turbocat | 7 | const char* wday_str[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; |
8 | const char* mon_str[12] = { "Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
||
8787 | turbocat | 9 | |
9260 | turbocat | 10 | #define TIME_STR_MAX 27 |
11 | |||
9765 | turbocat | 12 | char* asctime(const struct tm* tm) |
13 | { |
||
14 | if (!tm) { |
||
15 | __errno = EINVAL; |
||
8787 | turbocat | 16 | return NULL; |
17 | } |
||
9765 | turbocat | 18 | if (tm->tm_wday > 6 || tm->tm_wday < 0 || tm->tm_mon < 0 || tm->tm_mon > 11) { |
9260 | turbocat | 19 | errno = EINVAL; |
20 | return NULL; |
||
21 | } |
||
22 | static char time_str[TIME_STR_MAX]; |
||
9765 | turbocat | 23 | snprintf(time_str, TIME_STR_MAX - 1, "%.3s %.3s%3d %02d:%02d:%02d %d\n", |
9260 | turbocat | 24 | wday_str[tm->tm_wday], |
25 | mon_str[tm->tm_mon], |
||
26 | tm->tm_mday, tm->tm_hour, |
||
27 | tm->tm_min, tm->tm_sec, |
||
9765 | turbocat | 28 | 1900 + tm->tm_year); |
8787 | turbocat | 29 | return time_str; |
9843 | turbocat | 30 | }>> |