]>
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 ** 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(timeptr
, buf
)
27 const struct tm
* timeptr
;
30 static const char wday_name
[][3] = {
31 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
33 static const char mon_name
[][3] = {
34 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
35 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
40 if (timeptr
->tm_wday
< 0 || timeptr
->tm_wday
>= DAYSPERWEEK
)
42 else wn
= wday_name
[timeptr
->tm_wday
];
43 if (timeptr
->tm_mon
< 0 || timeptr
->tm_mon
>= MONSPERYEAR
)
45 else mn
= mon_name
[timeptr
->tm_mon
];
47 ** The X3J11-suggested format is
48 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
49 ** Since the .2 in 02.2d is ignored, we drop it.
51 (void) sprintf(buf
, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
53 timeptr
->tm_mday
, timeptr
->tm_hour
,
54 timeptr
->tm_min
, timeptr
->tm_sec
,
55 TM_YEAR_BASE
+ timeptr
->tm_year
);
60 ** A la X3J11, with core dump avoidance.
65 const struct tm
* timeptr
;
68 ** Big enough for something such as
69 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
70 ** (two three-character abbreviations, five strings denoting integers,
71 ** three explicit spaces, two explicit colons, a newline,
72 ** and a trailing ASCII nul).
74 static char result
[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
77 return asctime_r(timeptr
, result
);