import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / cftime.c
blobbe0a67c75d54aafff96995cb7b1bac5717abb0bc
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright (c) 2014 Gary Mills
25 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 /* Copyright (c) 1988 AT&T */
30 /* All Rights Reserved */
33 * This routine converts time as follows. The epoch is 0000 Jan 1
34 * 1970 GMT. The argument time is in seconds since then. The
35 * localtime(t) entry returns a pointer to an array containing:
37 * seconds (0-59)
38 * minutes (0-59)
39 * hours (0-23)
40 * day of month (1-31)
41 * month (0-11)
42 * year
43 * weekday (0-6, Sun is 0)
44 * day of the year
45 * daylight savings flag
47 * The routine corrects for daylight saving time and will work in
48 * any time zone provided "timezone" is adjusted to the difference
49 * between Greenwich and local standard time (measured in seconds).
51 * ascftime(buf, format, t) -> where t is produced by localtime
52 * and returns a ptr to a character
53 * string that has the ascii time in
54 * the format specified by the format
55 * argument (see date(1) for format
56 * syntax).
58 * cftime(buf, format, t) -> just calls ascftime.
64 #include "lint.h"
65 #include <mtlib.h>
66 #include <stddef.h>
67 #include <time.h>
68 #include <limits.h>
69 #include <stdlib.h>
70 #include <thread.h>
71 #include <synch.h>
73 int
74 cftime(char *buf, char *format, const time_t *t)
76 struct tm res;
77 struct tm *p;
79 p = localtime_r(t, &res);
80 if (p == NULL) {
81 *buf = '\0';
82 return (0);
84 /* LINTED do not use ascftime() */
85 return (ascftime(buf, format, p));
88 int
89 ascftime(char *buf, const char *format, const struct tm *tm)
91 /* Set format string, if not already set */
92 if (format == NULL || *format == '\0')
93 if (((format = getenv("CFTIME")) == 0) || *format == 0)
94 format = "%+";
96 return ((int)strftime(buf, LONG_MAX, format, tm));