]>
git.saurik.com Git - apple/libc.git/blob - stdtime/asctime-fbsd.c
bcdc85efcb3f1f3c096275ba1c1cc06cc974f701
2 ** This file is in the public domain, so clarified as of
3 ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
9 static char elsieid
[] __unused
= "@(#)asctime.c 7.9";
10 #endif /* !defined NOID */
11 #endif /* !defined lint */
12 __FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.12 2004/06/14 10:31:52 stefanf Exp $");
16 #include "namespace.h"
18 #include "un-namespace.h"
22 ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
26 asctime_r(const struct tm
* __restrict timeptr
, char * __restrict buf
)
28 static const char wday_name
[][3] = {
29 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
31 static const char mon_name
[][3] = {
32 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
33 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
38 if (timeptr
->tm_wday
< 0 || timeptr
->tm_wday
>= DAYSPERWEEK
)
40 else wn
= wday_name
[timeptr
->tm_wday
];
41 if (timeptr
->tm_mon
< 0 || timeptr
->tm_mon
>= MONSPERYEAR
)
43 else mn
= mon_name
[timeptr
->tm_mon
];
45 ** The X3J11-suggested format is
46 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
47 ** Since the .2 in 02.2d is ignored, we drop it.
49 (void) sprintf(buf
, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
51 timeptr
->tm_mday
, timeptr
->tm_hour
,
52 timeptr
->tm_min
, timeptr
->tm_sec
,
53 TM_YEAR_BASE
+ timeptr
->tm_year
);
58 ** A la X3J11, with core dump avoidance.
63 const struct tm
* timeptr
;
66 ** Big enough for something such as
67 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
68 ** (two three-character abbreviations, five strings denoting integers,
69 ** three explicit spaces, two explicit colons, a newline,
70 ** and a trailing ASCII nul).
72 static char result
[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
75 return asctime_r(timeptr
, result
);