4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * This routine converts time as follows.
34 * The epoch is 0000 Jan 1 1970 GMT.
35 * The argument time is in seconds since then.
36 * The localtime(t) entry returns a pointer to an array
44 * weekday (0-6, Sun is 0)
46 * daylight savings flag
48 * The routine corrects for daylight saving
49 * time and will work in any time zone provided
50 * "timezone" is adjusted to the difference between
51 * Greenwich and local standard time (measured in seconds).
52 * In places like Michigan "daylight" must
53 * be initialized to 0 to prevent the conversion
55 * There is a table which accounts for the peculiarities
56 * undergone by daylight time in 1974-1975.
58 * The routine does not work
59 * in Saudi Arabia which runs on Solar time.
62 * where tvec is produced by localtime
63 * returns a ptr to a character string
64 * that has the ascii time in the form
65 * Thu Jan 01 00:00:00 1970\n\0
66 * 01234567890123456789012345
69 * ctime(t) just calls localtime, then asctime.
71 * tzset() looks for an environment variable named
73 * If the variable is present, it will set the external
74 * variables "timezone", "altzone", "daylight", and "tzname"
75 * appropriately. It is called by localtime, and
76 * may also be called explicitly by the user.
81 #include <sys/types.h>
89 #define dysize(A) (((A)%4)? 365: 366)
93 ct_numb(char *cp
, int n
, char pad
)
97 *cp
++ = (n
/ 10) % 10 + '0';
100 *cp
++ = n
% 10 + '0';
105 * Compatibility aliases: Solaris/illumos have the POSIX.1c Draft versions in
106 * libc with the regular name and the standard versions with mangled names. We
107 * only have the standard versions but keep the mangled symbols here for a
108 * smoother transition.
110 #pragma weak __posix_asctime_r = asctime_r
111 #pragma weak __posix_ctime_r = ctime_r
114 asctime_r(const struct tm
*t
, char *cbuf
)
118 const char *Date
= "Day Mon 00 00:00:00 YYYY\n";
119 const char *Day
= "SunMonTueWedThuFriSat";
120 const char *Month
= "JanFebMarAprMayJunJulAugSepOctNovDec";
122 int year
= t
->tm_year
+ 1900;
125 for (ncp
= Date
; *cp
++ = *ncp
++; /* */)
127 ncp
= Day
+ (3 * t
->tm_wday
);
133 ncp
= Month
+ (3 * t
->tm_mon
);
137 cp
= ct_numb(cp
, t
->tm_mday
, ' ');
138 cp
= ct_numb(cp
, t
->tm_hour
, '0');
139 cp
= ct_numb(cp
, t
->tm_min
, '0');
140 cp
= ct_numb(cp
, t
->tm_sec
, '0');
142 if (year
< 0 || year
>= 10000) {
143 /* Only positive, 4-digit years are supported */
147 cp
= ct_numb(cp
, year
/ 100, '0');
149 (void) ct_numb(cp
, year
, '0');
154 ctime_r(const time_t *t
, char *buffer
)
158 if (localtime_r(t
, &res
) == NULL
)
161 if (asctime_r(&res
, buffer
) == NULL
)
168 ctime(const time_t *t
)
170 char *cbuf
= tsdalloc(_T_CTIME
, CBUFSIZ
, NULL
);
178 return (asctime_r(p
, cbuf
));
182 asctime(const struct tm
*t
)
184 char *cbuf
= tsdalloc(_T_CTIME
, CBUFSIZ
, NULL
);
188 return (asctime_r(t
, cbuf
));