asctime.c revision 1.1.1.4 1 /*
2 ** This file is in the public domain, so clarified as of
3 ** 1996-06-05 by Arthur David Olson (arthur_david_olson (at) nih.gov).
4 */
5
6 #ifndef lint
7 #ifndef NOID
8 static char elsieid[] = "@(#)asctime.c 7.9";
9 #endif /* !defined NOID */
10 #endif /* !defined lint */
11
12 /*LINTLIBRARY*/
13
14 #include "private.h"
15 #include "tzfile.h"
16
17 /*
18 ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
19 */
20
21 char *
22 asctime_r(timeptr, buf)
23 register const struct tm * timeptr;
24 char * buf;
25 {
26 static const char wday_name[][3] = {
27 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
28 };
29 static const char mon_name[][3] = {
30 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
31 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
32 };
33 register const char * wn;
34 register const char * mn;
35
36 if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
37 wn = "???";
38 else wn = wday_name[timeptr->tm_wday];
39 if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
40 mn = "???";
41 else mn = mon_name[timeptr->tm_mon];
42 /*
43 ** The X3J11-suggested format is
44 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
45 ** Since the .2 in 02.2d is ignored, we drop it.
46 */
47 (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
48 wn, mn,
49 timeptr->tm_mday, timeptr->tm_hour,
50 timeptr->tm_min, timeptr->tm_sec,
51 TM_YEAR_BASE + timeptr->tm_year);
52 return buf;
53 }
54
55 /*
56 ** A la X3J11, with core dump avoidance.
57 */
58
59 char *
60 asctime(timeptr)
61 register const struct tm * timeptr;
62 {
63 /*
64 ** Big enough for something such as
65 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
66 ** (two three-character abbreviations, five strings denoting integers,
67 ** three explicit spaces, two explicit colons, a newline,
68 ** and a trailing ASCII nul).
69 */
70 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
71 3 + 2 + 1 + 1];
72
73 return asctime_r(timeptr, result);
74 }
75