]> git.saurik.com Git - apple/libc.git/blame - stdtime/FreeBSD/asctime.c
Libc-391.tar.gz
[apple/libc.git] / stdtime / FreeBSD / asctime.c
CommitLineData
5b2abdfb
A
1/*
2** This file is in the public domain, so clarified as of
3d9156a7 3** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
5b2abdfb
A
4*/
5
9385eb3d 6#include <sys/cdefs.h>
5b2abdfb
A
7#ifndef lint
8#ifndef NOID
3d9156a7 9static char elsieid[] __unused = "@(#)asctime.c 7.9";
5b2abdfb
A
10#endif /* !defined NOID */
11#endif /* !defined lint */
3d9156a7 12__FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.12 2004/06/14 10:31:52 stefanf Exp $");
5b2abdfb
A
13
14/*LINTLIBRARY*/
15
9385eb3d 16#include "namespace.h"
5b2abdfb 17#include "private.h"
9385eb3d 18#include "un-namespace.h"
5b2abdfb
A
19#include "tzfile.h"
20
21/*
3d9156a7 22** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
5b2abdfb
A
23*/
24
5b2abdfb 25char *
3d9156a7 26asctime_r(timeptr, buf)
5b2abdfb 27const struct tm * timeptr;
3d9156a7 28char * buf;
5b2abdfb
A
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 };
9385eb3d
A
37 const char * wn;
38 const char * mn;
5b2abdfb
A
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 */
3d9156a7 51 (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
5b2abdfb
A
52 wn, mn,
53 timeptr->tm_mday, timeptr->tm_hour,
54 timeptr->tm_min, timeptr->tm_sec,
55 TM_YEAR_BASE + timeptr->tm_year);
3d9156a7
A
56 return buf;
57}
58
59/*
60** A la X3J11, with core dump avoidance.
61*/
62
63char *
64asctime(timeptr)
65const 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);
5b2abdfb 78}