]>
git.saurik.com Git - apple/libc.git/blob - stdtime/FreeBSD/asctime.c
2 ** This file is in the public domain, so clarified as of
3 ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
9 static char elsieid
[] __unused
= "@(#)asctime.c 7.7";
10 #endif /* !defined NOID */
11 #endif /* !defined lint */
12 __FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.11 2003/02/16 17:29:11 nectar Exp $");
16 #include "namespace.h"
18 #include "un-namespace.h"
22 ** A la X3J11, with core dump avoidance.
28 const struct tm
* timeptr
;
30 static char result
[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
32 return(asctime_r(timeptr
, result
));
36 asctime_r(timeptr
, result
)
37 const struct tm
* timeptr
;
40 static const char wday_name
[][3] = {
41 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
43 static const char mon_name
[][3] = {
44 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
45 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
48 ** Big enough for something such as
49 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
50 ** (two three-character abbreviations, five strings denoting integers,
51 ** three explicit spaces, two explicit colons, a newline,
52 ** and a trailing ASCII nul).
57 if (timeptr
->tm_wday
< 0 || timeptr
->tm_wday
>= DAYSPERWEEK
)
59 else wn
= wday_name
[timeptr
->tm_wday
];
60 if (timeptr
->tm_mon
< 0 || timeptr
->tm_mon
>= MONSPERYEAR
)
62 else mn
= mon_name
[timeptr
->tm_mon
];
64 ** The X3J11-suggested format is
65 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
66 ** Since the .2 in 02.2d is ignored, we drop it.
68 (void) sprintf(result
, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
70 timeptr
->tm_mday
, timeptr
->tm_hour
,
71 timeptr
->tm_min
, timeptr
->tm_sec
,
72 TM_YEAR_BASE
+ timeptr
->tm_year
);