2000-01-15 19:59:05 +03:00
|
|
|
/* $NetBSD: strftime.c,v 1.10 2000/01/15 16:59:05 kleink Exp $ */
|
1997-04-30 00:00:14 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1989 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-14 00:25:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
1997-07-14 00:25:30 +04:00
|
|
|
#if 0
|
|
|
|
static char *sccsid = "@(#)strftime.c 5.11 (Berkeley) 2/24/91";
|
|
|
|
#else
|
2000-01-15 19:59:05 +03:00
|
|
|
__RCSID("$NetBSD: strftime.c,v 1.10 2000/01/15 16:59:05 kleink Exp $");
|
1997-07-14 00:25:30 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
1997-07-21 18:06:24 +04:00
|
|
|
#include "namespace.h"
|
1994-09-29 07:57:04 +03:00
|
|
|
#include <sys/localedef.h>
|
1994-05-25 05:20:19 +04:00
|
|
|
#include <locale.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <string.h>
|
1994-04-23 02:11:52 +04:00
|
|
|
#include <tzfile.h>
|
|
|
|
#include <time.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-09-27 20:41:20 +04:00
|
|
|
static int _add __P((const char *, char **, const char *));
|
1998-11-15 20:10:30 +03:00
|
|
|
static int _conv __P((int, int, int, char **, const char *));
|
1998-09-27 20:41:20 +04:00
|
|
|
static int _secs __P((const struct tm *, char **, const char *));
|
|
|
|
static size_t _fmt __P((const char *, const struct tm *, char **,
|
|
|
|
const char *));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
size_t
|
|
|
|
strftime(s, maxsize, format, t)
|
|
|
|
char *s;
|
|
|
|
size_t maxsize;
|
|
|
|
const char *format;
|
|
|
|
const struct tm *t;
|
|
|
|
{
|
1998-09-27 20:41:20 +04:00
|
|
|
char *pt;
|
|
|
|
|
1994-04-23 02:11:52 +04:00
|
|
|
tzset();
|
1998-09-27 20:41:20 +04:00
|
|
|
if (maxsize < 1)
|
|
|
|
return (0);
|
1994-04-23 02:11:52 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
pt = s;
|
1998-09-27 20:41:20 +04:00
|
|
|
if (_fmt(format, t, &pt, s + maxsize)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*pt = '\0';
|
1998-09-27 20:41:20 +04:00
|
|
|
return (pt - s);
|
|
|
|
} else
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-08-19 20:39:47 +04:00
|
|
|
#define SUN_WEEK(t) (((t)->tm_yday + 7 - \
|
|
|
|
((t)->tm_wday)) / 7)
|
|
|
|
#define MON_WEEK(t) (((t)->tm_yday + 7 - \
|
|
|
|
((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7)
|
1998-09-27 20:41:20 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
static size_t
|
1998-09-27 20:41:20 +04:00
|
|
|
_fmt(format, t, pt, ptlim)
|
|
|
|
const char *format;
|
1996-12-20 23:27:22 +03:00
|
|
|
const struct tm *t;
|
1998-09-27 20:41:20 +04:00
|
|
|
char **pt;
|
|
|
|
const char * const ptlim;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
for (; *format; ++format) {
|
1993-08-19 20:39:47 +04:00
|
|
|
if (*format == '%') {
|
|
|
|
++format;
|
|
|
|
if (*format == 'E') {
|
|
|
|
/* Alternate Era */
|
|
|
|
++format;
|
|
|
|
} else if (*format == 'O') {
|
|
|
|
/* Alternate numeric symbols */
|
|
|
|
++format;
|
|
|
|
}
|
1997-04-30 00:00:14 +04:00
|
|
|
switch (*format) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case '\0':
|
|
|
|
--format;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
if (t->tm_wday < 0 || t->tm_wday > 6)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add(_CurrentTimeLocale->day[t->tm_wday],
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
1998-09-27 20:41:20 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'a':
|
|
|
|
if (t->tm_wday < 0 || t->tm_wday > 6)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add(_CurrentTimeLocale->abday[t->tm_wday],
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'B':
|
|
|
|
if (t->tm_mon < 0 || t->tm_mon > 11)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add(_CurrentTimeLocale->mon[t->tm_mon],
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'b':
|
|
|
|
case 'h':
|
|
|
|
if (t->tm_mon < 0 || t->tm_mon > 11)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add(_CurrentTimeLocale->abmon[t->tm_mon],
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'C':
|
1993-08-19 20:39:47 +04:00
|
|
|
if (!_conv((t->tm_year + TM_YEAR_BASE) / 100,
|
1998-09-27 20:41:20 +04:00
|
|
|
2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'c':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt(_CurrentTimeLocale->d_t_fmt, t, pt,
|
|
|
|
ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'D':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt("%m/%d/%y", t, pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'd':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_mday, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'e':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_mday, 2, ' ', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
2000-01-15 19:59:05 +03:00
|
|
|
case 'F':
|
|
|
|
if (!_fmt("%Y-%m-%d", t, pt, ptlim))
|
|
|
|
return (0);
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'H':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_hour, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'I':
|
|
|
|
if (!_conv(t->tm_hour % 12 ?
|
1998-09-27 20:41:20 +04:00
|
|
|
t->tm_hour % 12 : 12, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'j':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_yday + 1, 3, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'k':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_hour, 2, ' ', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'l':
|
|
|
|
if (!_conv(t->tm_hour % 12 ?
|
1998-09-27 20:41:20 +04:00
|
|
|
t->tm_hour % 12: 12, 2, ' ', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'M':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_min, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'm':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_mon + 1, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'n':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add("\n", pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'p':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour
|
|
|
|
>= 12], pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'R':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt("%H:%M", t, pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1994-04-07 10:52:14 +04:00
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'r':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t, pt,
|
|
|
|
ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'S':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_sec, 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 's':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_secs(t, pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'T':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt("%H:%M:%S", t, pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 't':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_add("\t", pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'U':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(SUN_WEEK(t), 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-08-19 20:39:47 +04:00
|
|
|
continue;
|
|
|
|
case 'u':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_wday ? t->tm_wday : 7, 1, '0',
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
1999-02-07 20:33:30 +03:00
|
|
|
case 'V': /* ISO 8601 week number */
|
|
|
|
case 'G': /* ISO 8601 year (four digits) */
|
|
|
|
case 'g': /* ISO 8601 year (two digits) */
|
|
|
|
/*
|
|
|
|
** From Arnold Robbins' strftime version 3.0: "the week number of the
|
|
|
|
** year (the first Monday as the first day of week 1) as a decimal number
|
|
|
|
** (01-53)."
|
|
|
|
** (ado, 1993-05-24)
|
|
|
|
**
|
|
|
|
** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
|
|
|
|
** "Week 01 of a year is per definition the first week which has the
|
|
|
|
** Thursday in this year, which is equivalent to the week which contains
|
|
|
|
** the fourth day of January. In other words, the first week of a new year
|
|
|
|
** is the week which has the majority of its days in the new year. Week 01
|
|
|
|
** might also contain days from the previous year and the week before week
|
|
|
|
** 01 of a year is the last week (52 or 53) of the previous year even if
|
|
|
|
** it contains days from the new year. A week starts with Monday (day 1)
|
|
|
|
** and ends with Sunday (day 7). For example, the first week of the year
|
|
|
|
** 1997 lasts from 1996-12-30 to 1997-01-05..."
|
|
|
|
** (ado, 1996-01-02)
|
|
|
|
*/
|
1993-08-19 20:39:47 +04:00
|
|
|
{
|
1999-02-07 20:33:30 +03:00
|
|
|
int year;
|
|
|
|
int yday;
|
|
|
|
int wday;
|
|
|
|
int w;
|
1996-06-02 01:23:25 +04:00
|
|
|
|
1999-02-07 20:33:30 +03:00
|
|
|
year = t->tm_year + TM_YEAR_BASE;
|
|
|
|
yday = t->tm_yday;
|
|
|
|
wday = t->tm_wday;
|
|
|
|
for ( ; ; ) {
|
|
|
|
int len;
|
|
|
|
int bot;
|
|
|
|
int top;
|
1996-06-02 01:23:25 +04:00
|
|
|
|
1999-02-07 20:33:30 +03:00
|
|
|
len = isleap(year) ?
|
|
|
|
DAYSPERLYEAR :
|
|
|
|
DAYSPERNYEAR;
|
|
|
|
/*
|
|
|
|
** What yday (-3 ... 3) does
|
|
|
|
** the ISO year begin on?
|
|
|
|
*/
|
|
|
|
bot = ((yday + 11 - wday) %
|
|
|
|
DAYSPERWEEK) - 3;
|
|
|
|
/*
|
|
|
|
** What yday does the NEXT
|
|
|
|
** ISO year begin on?
|
|
|
|
*/
|
|
|
|
top = bot -
|
|
|
|
(len % DAYSPERWEEK);
|
|
|
|
if (top < -3)
|
|
|
|
top += DAYSPERWEEK;
|
|
|
|
top += len;
|
|
|
|
if (yday >= top) {
|
|
|
|
++year;
|
|
|
|
w = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (yday >= bot) {
|
|
|
|
w = 1 + ((yday - bot) /
|
|
|
|
DAYSPERWEEK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--year;
|
|
|
|
yday += isleap(year) ?
|
|
|
|
DAYSPERLYEAR :
|
|
|
|
DAYSPERNYEAR;
|
|
|
|
}
|
|
|
|
#ifdef XPG4_1994_04_09
|
|
|
|
if ((w == 52
|
|
|
|
&& t->tm_mon == TM_JANUARY)
|
|
|
|
|| (w == 1
|
|
|
|
&& t->tm_mon == TM_DECEMBER))
|
|
|
|
w = 53;
|
|
|
|
#endif /* defined XPG4_1994_04_09 */
|
|
|
|
if (*format == 'V') {
|
|
|
|
if (!_conv(w, 2, '0',
|
|
|
|
pt, ptlim))
|
|
|
|
return (0);
|
|
|
|
} else if (*format == 'g') {
|
|
|
|
if (!_conv(year % 100, 2, '0',
|
|
|
|
pt, ptlim))
|
|
|
|
return (0);
|
|
|
|
} else if (!_conv(year, 4, '0',
|
|
|
|
pt, ptlim))
|
|
|
|
return (0);
|
1993-08-19 20:39:47 +04:00
|
|
|
}
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'W':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(MON_WEEK(t), 2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'w':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv(t->tm_wday, 1, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'x':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt(_CurrentTimeLocale->d_fmt, t, pt,
|
|
|
|
ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-08-19 20:39:47 +04:00
|
|
|
continue;
|
|
|
|
case 'X':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_fmt(_CurrentTimeLocale->t_fmt, t, pt,
|
|
|
|
ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'y':
|
1993-08-19 20:39:47 +04:00
|
|
|
if (!_conv((t->tm_year + TM_YEAR_BASE) % 100,
|
1998-09-27 20:41:20 +04:00
|
|
|
2, '0', pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'Y':
|
1998-09-27 20:41:20 +04:00
|
|
|
if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0',
|
|
|
|
pt, ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case 'Z':
|
1997-04-30 00:00:14 +04:00
|
|
|
if (tzname[t->tm_isdst ? 1 : 0] &&
|
1998-09-27 20:41:20 +04:00
|
|
|
!_add(tzname[t->tm_isdst ? 1 : 0], pt,
|
|
|
|
ptlim))
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
case '%':
|
|
|
|
/*
|
|
|
|
* X311J/88-090 (4.12.3.5): if conversion char is
|
|
|
|
* undefined, behavior is undefined. Print out the
|
|
|
|
* character itself as printf(3) does.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
break;
|
1993-08-19 20:39:47 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-09-27 20:41:20 +04:00
|
|
|
if (*pt == ptlim)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
*(*pt)++ = *format;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-09-27 20:41:20 +04:00
|
|
|
return (ptlim - *pt);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-05 02:43:54 +03:00
|
|
|
static int
|
1998-09-27 20:41:20 +04:00
|
|
|
_secs(t, pt, ptlim)
|
1996-12-20 23:27:22 +03:00
|
|
|
const struct tm *t;
|
1998-09-27 20:41:20 +04:00
|
|
|
char **pt;
|
|
|
|
const char * const ptlim;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-09-27 20:41:20 +04:00
|
|
|
char buf[15];
|
|
|
|
time_t s;
|
|
|
|
char *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct tm tmp;
|
|
|
|
|
1998-12-01 19:07:11 +03:00
|
|
|
buf[sizeof (buf) - 1] = '\0';
|
1993-03-21 12:45:37 +03:00
|
|
|
/* Make a copy, mktime(3) modifies the tm struct. */
|
|
|
|
tmp = *t;
|
|
|
|
s = mktime(&tmp);
|
|
|
|
for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
|
1998-11-15 20:10:30 +03:00
|
|
|
*p-- = (char)(s % 10 + '0');
|
1998-09-27 20:41:20 +04:00
|
|
|
return (_add(++p, pt, ptlim));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-05 02:43:54 +03:00
|
|
|
static int
|
1998-09-27 20:41:20 +04:00
|
|
|
_conv(n, digits, pad, pt, ptlim)
|
1993-03-21 12:45:37 +03:00
|
|
|
int n, digits;
|
1998-11-15 20:10:30 +03:00
|
|
|
int pad;
|
1998-09-27 20:41:20 +04:00
|
|
|
char **pt;
|
|
|
|
const char * const ptlim;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-09-27 20:41:20 +04:00
|
|
|
char buf[10];
|
|
|
|
char *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-09-27 20:41:20 +04:00
|
|
|
buf[sizeof (buf) - 1] = '\0';
|
1999-11-05 22:21:12 +03:00
|
|
|
p = buf + sizeof(buf) - 2;
|
|
|
|
do {
|
1993-03-21 12:45:37 +03:00
|
|
|
*p-- = n % 10 + '0';
|
1999-11-05 22:21:12 +03:00
|
|
|
n /= 10;
|
|
|
|
--digits;
|
|
|
|
} while (n > 0 && p > buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
while (p > buf && digits-- > 0)
|
|
|
|
*p-- = pad;
|
1998-09-27 20:41:20 +04:00
|
|
|
return (_add(++p, pt, ptlim));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-05 02:43:54 +03:00
|
|
|
static int
|
1998-09-27 20:41:20 +04:00
|
|
|
_add(str, pt, ptlim)
|
|
|
|
const char *str;
|
|
|
|
char **pt;
|
|
|
|
const char * const ptlim;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-09-27 20:41:20 +04:00
|
|
|
|
|
|
|
for (;; ++(*pt)) {
|
|
|
|
if (*pt == ptlim)
|
1997-04-30 00:00:14 +04:00
|
|
|
return (0);
|
1998-09-27 20:41:20 +04:00
|
|
|
if ((**pt = *str++) == '\0')
|
1997-04-30 00:00:14 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|