Print this page
4378 Clean up %C in *time() functions
438 need documentation for strftime %s flag


   3  *
   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*


  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1988 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 /*
  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:
  36  *
  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
  46  *
  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).
  50  *
  51  *       ascftime(buf, format, t)       -> where t is produced by localtime


  74 cftime(char *buf, char *format, const time_t *t)
  75 {
  76         struct tm res;
  77         struct tm *p;
  78 
  79         p = localtime_r(t, &res);
  80         if (p == NULL) {
  81                 *buf = '\0';
  82                 return (0);
  83         }
  84         /* LINTED do not use ascftime() */
  85         return (ascftime(buf, format, p));
  86 }
  87 
  88 int
  89 ascftime(char *buf, const char *format, const struct tm *tm)
  90 {
  91         /* Set format string, if not already set */
  92         if (format == NULL || *format == '\0')
  93                 if (((format = getenv("CFTIME")) == 0) || *format == 0)
  94                         format =  "%C";
  95 
  96         return ((int)strftime(buf, LONG_MAX, format, tm));
  97 }


   3  *
   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2014 Gary Mills
  24  *
  25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*      Copyright (c) 1988 AT&T     */
  30 /*        All Rights Reserved   */
  31 


  32 /*
  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:
  36  *
  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
  46  *
  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).
  50  *
  51  *       ascftime(buf, format, t)       -> where t is produced by localtime


  74 cftime(char *buf, char *format, const time_t *t)
  75 {
  76         struct tm res;
  77         struct tm *p;
  78 
  79         p = localtime_r(t, &res);
  80         if (p == NULL) {
  81                 *buf = '\0';
  82                 return (0);
  83         }
  84         /* LINTED do not use ascftime() */
  85         return (ascftime(buf, format, p));
  86 }
  87 
  88 int
  89 ascftime(char *buf, const char *format, const struct tm *tm)
  90 {
  91         /* Set format string, if not already set */
  92         if (format == NULL || *format == '\0')
  93                 if (((format = getenv("CFTIME")) == 0) || *format == 0)
  94                         format =  "%+";
  95 
  96         return ((int)strftime(buf, LONG_MAX, format, tm));
  97 }