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