2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * This routine converts time as follows. The epoch is 0000 Jan 1
2N/A * 1970 GMT. The argument time is in seconds since then. The
2N/A * localtime(t) entry returns a pointer to an array containing:
2N/A *
2N/A * seconds (0-59)
2N/A * minutes (0-59)
2N/A * hours (0-23)
2N/A * day of month (1-31)
2N/A * month (0-11)
2N/A * year
2N/A * weekday (0-6, Sun is 0)
2N/A * day of the year
2N/A * daylight savings flag
2N/A *
2N/A * The routine corrects for daylight saving time and will work in
2N/A * any time zone provided "timezone" is adjusted to the difference
2N/A * between Greenwich and local standard time (measured in seconds).
2N/A *
2N/A * ascftime(buf, format, t) -> where t is produced by localtime
2N/A * and returns a ptr to a character
2N/A * string that has the ascii time in
2N/A * the format specified by the format
2N/A * argument (see date(1) for format
2N/A * syntax).
2N/A *
2N/A * cftime(buf, format, t) -> just calls ascftime.
2N/A *
2N/A *
2N/A *
2N/A */
2N/A
2N/A#include "lint.h"
2N/A#include <mtlib.h>
2N/A#include <stddef.h>
2N/A#include <time.h>
2N/A#include <limits.h>
2N/A#include <stdlib.h>
2N/A#include <thread.h>
2N/A#include <synch.h>
2N/A
2N/Aint
2N/Acftime(char *buf, char *format, const time_t *t)
2N/A{
2N/A struct tm res;
2N/A struct tm *p;
2N/A
2N/A p = localtime_r(t, &res);
2N/A if (p == NULL) {
2N/A *buf = '\0';
2N/A return (0);
2N/A }
2N/A /* LINTED do not use ascftime() */
2N/A return (ascftime(buf, format, p));
2N/A}
2N/A
2N/Aint
2N/Aascftime(char *buf, const char *format, const struct tm *tm)
2N/A{
2N/A /* Set format string, if not already set */
2N/A if (format == NULL || *format == '\0')
2N/A if (((format = getenv("CFTIME")) == 0) || *format == 0)
2N/A format = "%C";
2N/A
2N/A return ((int)strftime(buf, LONG_MAX, format, tm));
2N/A}