]>
git.saurik.com Git - apple/libc.git/blob - stdtime/asctime-fbsd.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.
25 #define EXPECTEDLEN 26
28 asctime_r(const struct tm
* __restrict timeptr
, char * __restrict buf
)
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 char tmp
[EXPECTEDLEN
];
42 if (timeptr
->tm_wday
< 0 || timeptr
->tm_wday
>= DAYSPERWEEK
)
44 else wn
= wday_name
[timeptr
->tm_wday
];
45 if (timeptr
->tm_mon
< 0 || timeptr
->tm_mon
>= MONSPERYEAR
)
47 else mn
= mon_name
[timeptr
->tm_mon
];
49 ** The X3J11-suggested format is
50 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
51 ** Since the .2 in 02.2d is ignored, we drop it.
54 ** Because various values in the tm structure may cause the
55 ** resulting string to be longer than the 26-bytes that is
56 ** specified in the spec, we should return NULL rather than
57 ** possibly overwrite beyond the string.
59 len
= snprintf(tmp
, EXPECTEDLEN
, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
61 timeptr
->tm_mday
, timeptr
->tm_hour
,
62 timeptr
->tm_min
, timeptr
->tm_sec
,
63 TM_YEAR_BASE
+ timeptr
->tm_year
);
64 if (len
>= EXPECTEDLEN
)
72 const struct tm
* timeptr
;
74 static char result
[EXPECTEDLEN
];
76 return asctime_r(timeptr
, result
);