From ee169c7e77bc5d28a401dde8533cbd38afd24ae1 Mon Sep 17 00:00:00 2001 From: Gary Mills Date: Fri, 3 Jan 2014 12:54:12 -0600 Subject: 4378 Clean up %C in *time() functions 438 need documentation for strftime %s flag Reviewed by: Garrett D'Amore Approved by: Dan McDonald --- usr/src/cmd/cron/cron.c | 8 ++- usr/src/cmd/fruadm/fruadm.c | 4 +- usr/src/lib/libc/port/gen/cftime.c | 6 +- usr/src/lib/libfru/libnvfru/nvfru.c | 4 +- .../lib/print/libpapi-common/common/attribute.c | 6 +- usr/src/man/man3c/strftime.3c | 82 ++++++++++------------ 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/usr/src/cmd/cron/cron.c b/usr/src/cmd/cron/cron.c index 54d3c9d971..ab36d09037 100644 --- a/usr/src/cmd/cron/cron.c +++ b/usr/src/cmd/cron/cron.c @@ -23,6 +23,8 @@ * Use is subject to license terms. * * Copyright 2013 Joshua M. Clulow + * + * Copyright (c) 2014 Gary Mills */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ @@ -549,7 +551,7 @@ begin: } else { ne_time = next_event->time - t; #ifdef DEBUG - cftime(timebuf, "%C", &next_event->time); + cftime(timebuf, "%+", &next_event->time); (void) fprintf(stderr, "next_time=%ld %s\n", next_event->time, timebuf); #endif @@ -623,7 +625,7 @@ begin: next_time(next_event, (time_t)0); } #ifdef DEBUG - cftime(timebuf, "%C", &next_event->time); + cftime(timebuf, "%+", &next_event->time); (void) fprintf(stderr, "pushing back cron event %s at %ld (%s)\n", next_event->cmd, next_event->time, timebuf); @@ -1271,7 +1273,7 @@ again: } cte_valid(); #ifdef DEBUG - cftime(timebuf, "%C", &e->time); + cftime(timebuf, "%+", &e->time); (void) fprintf(stderr, "inserting cron event %s at %ld (%s)\n", e->cmd, e->time, timebuf); #endif diff --git a/usr/src/cmd/fruadm/fruadm.c b/usr/src/cmd/fruadm/fruadm.c index bbf218966b..0efb6c5539 100644 --- a/usr/src/cmd/fruadm/fruadm.c +++ b/usr/src/cmd/fruadm/fruadm.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2014 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -172,7 +174,7 @@ displayBinary(unsigned char *data, size_t length, fru_elemdef_t *def) char buffer[PATH_MAX]; time_t time; time = (time_t)lldata; - (void) strftime(buffer, PATH_MAX, "%C", + (void) strftime(buffer, PATH_MAX, "%+", localtime(&time)); (void) printf("%s", buffer); return; diff --git a/usr/src/lib/libc/port/gen/cftime.c b/usr/src/lib/libc/port/gen/cftime.c index f4fa872da8..be0a67c75d 100644 --- a/usr/src/lib/libc/port/gen/cftime.c +++ b/usr/src/lib/libc/port/gen/cftime.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2014 Gary Mills + * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -27,8 +29,6 @@ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * This routine converts time as follows. The epoch is 0000 Jan 1 * 1970 GMT. The argument time is in seconds since then. The @@ -91,7 +91,7 @@ ascftime(char *buf, const char *format, const struct tm *tm) /* Set format string, if not already set */ if (format == NULL || *format == '\0') if (((format = getenv("CFTIME")) == 0) || *format == 0) - format = "%C"; + format = "%+"; return ((int)strftime(buf, LONG_MAX, format, tm)); } diff --git a/usr/src/lib/libfru/libnvfru/nvfru.c b/usr/src/lib/libfru/libnvfru/nvfru.c index 08aae7d56a..b5ed00ae4a 100644 --- a/usr/src/lib/libfru/libnvfru/nvfru.c +++ b/usr/src/lib/libfru/libnvfru/nvfru.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2014 Gary Mills + * * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -73,7 +75,7 @@ convert_field(const uint8_t *field, const fru_regdef_t *def, const char *path, } (void) memcpy(&timefield, field, sizeof (timefield)); timefield = BE_32(timefield); - if (strftime(timestring, sizeof (timestring), "%C", + if (strftime(timestring, sizeof (timestring), "%c", localtime(&timefield)) == 0) { /* buffer too small */ return; diff --git a/usr/src/lib/print/libpapi-common/common/attribute.c b/usr/src/lib/print/libpapi-common/common/attribute.c index 244e54555d..76268c7591 100644 --- a/usr/src/lib/print/libpapi-common/common/attribute.c +++ b/usr/src/lib/print/libpapi-common/common/attribute.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2014 Gary Mills + * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -27,8 +29,6 @@ /* $Id: attribute.c 157 2006-04-26 15:07:55Z ktou $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - /*LINTLIBRARY*/ #include @@ -957,7 +957,7 @@ papiAttributeToString(papi_attribute_t *attribute, char *delim, if (tm != NULL) { char string[64]; - strftime(string, sizeof (string), "%C", tm); + strftime(string, sizeof (string), "%c", tm); rc = strlcat(buffer, string, buflen); }} break; diff --git a/usr/src/man/man3c/strftime.3c b/usr/src/man/man3c/strftime.3c index 4d73366ae5..f2b8eff328 100644 --- a/usr/src/man/man3c/strftime.3c +++ b/usr/src/man/man3c/strftime.3c @@ -1,4 +1,5 @@ '\" te +.\" Copyright (c) 2014 Gary Mills .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. @@ -9,7 +10,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH STRFTIME 3C "Sep 5, 2006" +.TH STRFTIME 3C "Jan 3, 2014" .SH NAME strftime, cftime, ascftime \- convert date and time to string .SH SYNOPSIS @@ -50,7 +51,7 @@ that overlap, the behavior is undefined. For \fBstrftime()\fR, no more than .LP If \fIformat\fR is \fB(char *)0\fR, then the locale's default format is used. For \fBstrftime()\fR the default format is the same as \fB%c\fR; for -\fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%C\fR. +\fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%+\fR. \fBcftime()\fR and \fBascftime()\fR first try to use the value of the environment variable \fBCFTIME\fR, and if that is undefined or empty, the default format is used. @@ -107,59 +108,24 @@ Locale's abbreviated month name. Locale's full month name. .RE -.SS "Default" .sp .ne 2 .na \fB\fB%c\fR\fR .ad .RS 6n -Locale's appropriate date and time represented as: -.sp -.in +2 -.nf -%a %b %d %H:%M:%S %Y -.fi -.in -2 - -This is the default behavior as well as standard-conforming behavior for -standards first supported by releases prior to Solaris 2.4. See -\fBstandards\fR(5). -.RE - -.SS "Standard conforming" -.sp -.ne 2 -.na -\fB\fB%c\fR\fR -.ad -.RS 6n -Locale's appropriate date and time represented as: +Locale's appropriate date and time representation. +In the C locale, this format is: .sp .in +2 .nf %a %b %e %H:%M:%S %Y .fi .in -2 - -This is standard-conforming behavior for standards first supported by Solaris -2.4 through Solaris 10. -.RE - -.SS "Default" -.sp -.ne 2 -.na -\fB\fB%C\fR\fR -.ad -.RS 6n -Locale's date and time representation as produced by \fBdate\fR(1). .sp -This is the default behavior as well as standard-conforming behavior for -standards first supported by releases prior to Solaris 2.4. +Other locales may have different locale-specific formats. .RE -.SS "Standard conforming" .sp .ne 2 .na @@ -168,9 +134,6 @@ standards first supported by releases prior to Solaris 2.4. .RS 6n Century number (the year divided by 100 and truncated to an integer as a decimal number [01,99]). -.sp -This is standard-conforming behavior for standards first supported by Solaris -2.4 through Solaris 10. .RE .sp @@ -336,6 +299,15 @@ Appropriate time representation in 12-hour clock format with \fB%p\fR. Time as \fB%H\fR:\fB%M\fR. .RE +.sp +.ne 2 +.na +\fB\fB%s\fR\fR +.ad +.RS 6n +Seconds since 00:00:00 UTC, January 1, 1970. +.RE + .sp .ne 2 .na @@ -384,6 +356,15 @@ Week number of year as a decimal number [00,53], with Sunday as the first day of week 1. .RE +.sp +.ne 2 +.na +\fB\fB%v\fR\fR +.ad +.RS 6n +Date as \fB%e\fR-\fB%b\fR-\fB%Y\fR. +.RE + .sp .ne 2 .na @@ -475,6 +456,15 @@ is negative, no characters are returned. Time zone name or abbreviation, or no bytes if no time zone information exists. .RE +.sp +.ne 2 +.na +\fB\fB%+\fR\fR +.ad +.RS 6n +Locale's date and time representation as produced by \fBdate\fR(1). +.RE + .sp .LP If a conversion specification does not correspond to any of the above or to any @@ -788,3 +778,9 @@ This change was based on the XPG4 specification. If using the \fB%Z\fR specifier and \fBzoneinfo\fR timezones and if the input date is outside the range 20:45:52 UTC, December 13, 1901 to 03:14:07 UTC, January 19, 2038, the timezone name may not be correct. +.sp +.LP +The conversion specification for \fB%+\fR was added in illumos. +It is not part of any standard, although it is available on a number +of other platforms. +Its use is discouraged for conforming applications. -- cgit v1.2.3