]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libc/stdtime/asctime.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libc / stdtime / asctime.c
1 /*
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).
4 */
5
6 #include <sys/cdefs.h>
7 #ifndef lint
8 #ifndef NOID
9 static char     elsieid[] __unused = "@(#)asctime.c     7.9";
10 #endif /* !defined NOID */
11 #endif /* !defined lint */
12 __FBSDID("$FreeBSD$");
13
14 /*LINTLIBRARY*/
15
16 #include "namespace.h"
17 #include "private.h"
18 #include "un-namespace.h"
19 #include "tzfile.h"
20
21 /*
22 ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
23 */
24
25 char *
26 asctime_r(timeptr, buf)
27 const struct tm *       timeptr;
28 char *                  buf;
29 {
30         static const char       wday_name[][3] = {
31                 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
32         };
33         static const char       mon_name[][3] = {
34                 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
35                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
36         };
37         const char *    wn;
38         const char *    mn;
39
40         if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
41                 wn = "???";
42         else    wn = wday_name[timeptr->tm_wday];
43         if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
44                 mn = "???";
45         else    mn = mon_name[timeptr->tm_mon];
46         /*
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.
50         */
51         (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
52                 wn, mn,
53                 timeptr->tm_mday, timeptr->tm_hour,
54                 timeptr->tm_min, timeptr->tm_sec,
55                 TM_YEAR_BASE + timeptr->tm_year);
56         return buf;
57 }
58
59 /*
60 ** A la X3J11, with core dump avoidance.
61 */
62
63 char *
64 asctime(timeptr)
65 const struct tm *       timeptr;
66 {
67         /*
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).
73         */
74         static char             result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
75                                         3 + 2 + 1 + 1];
76
77         return asctime_r(timeptr, result);
78 }