summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormillert <>1998-01-19 00:07:34 +0000
committermillert <>1998-01-19 00:07:34 +0000
commitc5794ce7414757731fc3cf3dfeb1b09c43e500b6 (patch)
treeee181e7cc91263e5add5ebb310254ec5fe12a680 /src
parent5a4b430a51a73c805d5b876a4a19e85a3b0f6879 (diff)
downloadopenbsd-c5794ce7414757731fc3cf3dfeb1b09c43e500b6.tar.gz
openbsd-c5794ce7414757731fc3cf3dfeb1b09c43e500b6.tar.bz2
openbsd-c5794ce7414757731fc3cf3dfeb1b09c43e500b6.zip
use tzcode strftime(3) as it is kept up to date.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/string/strftime.3201
-rw-r--r--src/lib/libc/string/strftime.c327
2 files changed, 0 insertions, 528 deletions
diff --git a/src/lib/libc/string/strftime.3 b/src/lib/libc/string/strftime.3
deleted file mode 100644
index db666bb315..0000000000
--- a/src/lib/libc/string/strftime.3
+++ /dev/null
@@ -1,201 +0,0 @@
1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strftime.3,v 1.3 1996/08/19 08:34:17 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRFTIME 3
40.Os
41.Sh NAME
42.Nm strftime
43.Nd format date and time
44.Sh SYNOPSIS
45.Fd #include <time.h>
46.Ft size_t
47.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
48.Sh DESCRIPTION
49The
50.Fn strftime
51function formats the information from
52.Fa timeptr
53into the buffer
54.Fa buf
55according to the string pointed to by
56.Fa format .
57.Pp
58The
59.Fa format
60string consists of zero or more conversion specifications and
61ordinary characters.
62All ordinary characters are copied directly into the buffer.
63A conversion specification consists of a percent sign
64.Ql %
65and one other character.
66.Pp
67No more than
68.Fa maxsize
69characters will be placed into the array.
70If the total number of resulting characters, including the terminating
71null character, is not more than
72.Fa maxsize ,
73.Fn strftime
74returns the number of characters in the array, not counting the
75terminating null.
76Otherwise, zero is returned.
77.Pp
78Each conversion specification is replaced by the characters as
79follows which are then copied into the buffer.
80.Bl -tag -width "xxxx"
81.It Cm \&%A
82is replaced by the locale's full weekday name.
83.It Cm %a
84is replaced by the locale's abbreviated weekday name.
85.It Cm \&%B
86is replaced by the locale's full month name.
87.It Cm \&%b No or Cm \&%h
88is replaced by the locale's abbreviated month name.
89.It Cm \&%C
90is replaced by the century (a year divided by 100 and truncated to an integer)
91as a decimal number (00-99).
92.It Cm \&%c
93is replaced by the locale's appropriate date and time representation.
94.It Cm \&%D
95is replaced by the date in the format
96.Dq Li %m/%d/%y .
97.It Cm \&%d
98is replaced by the day of the month as a decimal number (01-31).
99.It Cm \&%e
100is replaced by the day of month as a decimal number (1-31);
101single digits are preceded by a blank.
102.It Cm \&%H
103is replaced by the hour (24-hour clock) as a decimal number (00-23).
104.It Cm \&%I
105is replaced by the hour (12-hour clock) as a decimal number (01-12).
106.It Cm \&%j
107is replaced by the day of the year as a decimal number (001-366).
108.It Cm \&%k
109is replaced by the hour (24-hour clock) as a decimal number (0-23);
110single digits are preceded by a blank.
111.It Cm \&%l
112is replaced by the hour (12-hour clock) as a decimal number (1-12);
113single digits are preceded by a blank.
114.It Cm \&%M
115is replaced by the minute as a decimal number (00-59).
116.It Cm %m
117is replaced by the month as a decimal number (01-12).
118.It Cm %n
119is replaced by a newline.
120.It Cm %p
121is replaced by the locale's equivalent of either
122.Dq Tn AM
123or
124.Dq Tn PM .
125.It Cm \&%R
126is replaced by the time in the format
127.Dq Li %H:%M .
128.It Cm \&%r
129is replaced by the locale's representation of 12-hour clock time
130using AM/PM notation.
131.It Cm \&%T
132is replaced by the time in the format
133.Dq Li %H:%M:%S .
134.It Cm \&%t
135is replaced by a tab.
136.It Cm \&%S
137is replaced by the second as a decimal number (00-60).
138.It Cm %s
139is replaced by the number of seconds since the Epoch, UCT (see
140.Xr mktime 3 ) .
141.It Cm \&%U
142is replaced by the week number of the year (Sunday as the first day of
143the week) as a decimal number (00-53).
144.It Cm \&%u
145is replaced by the weekday (Monday as the first day of the week)
146as a decimal number (1-7).
147.It Cm \&%V
148is replaced by the week number of the year (Monday as the first day of
149the week) as a decimal number (01-53). If the week containing January
1501 has four or more days in the new year, then it is week 1; otherwise
151it is week 53 of the previous year, and the next week is week 1.
152.It Cm \&%W
153is replaced by the week number of the year (Monday as the first day of
154the week) as a decimal number (00-53).
155.It Cm \&%w
156is replaced by the weekday (Sunday as the first day of the week)
157as a decimal number (0-6).
158.It Cm \&%X
159is replaced by the locale's appropriate time representation.
160.It Cm \&%x
161is replaced by the locale's appropriate date representation.
162.It Cm \&%Y
163is replaced by the year with century as a decimal number.
164.It Cm \&%y
165is replaced by the year without century as a decimal number (00-99).
166.It Cm \&%Z
167is replaced by the time zone name.
168.It Cm %%
169is replaced by
170.Ql % .
171.El
172.Sh SEE ALSO
173.Xr date 1 ,
174.Xr ctime 3 ,
175.Xr printf 1 ,
176.Xr printf 3
177.Sh STANDARDS
178The
179.Fn strftime
180function
181conforms to
182.St -ansiC .
183The
184.Ql \&%C ,
185.Ql \&%D ,
186.Ql \&%e ,
187.Ql \&%h ,
188.Ql \&%k ,
189.Ql \&%l ,
190.Ql \&%n ,
191.Ql \&%r ,
192.Ql \&%R ,
193.Ql \&%s .
194.Ql \&%t ,
195.Ql \&%T ,
196.Ql \&%u ,
197and
198.Ql \&%V
199conversion specifications are extensions.
200.Sh BUGS
201There is no conversion specification for the phase of the moon.
diff --git a/src/lib/libc/string/strftime.c b/src/lib/libc/string/strftime.c
deleted file mode 100644
index a72efb8cde..0000000000
--- a/src/lib/libc/string/strftime.c
+++ /dev/null
@@ -1,327 +0,0 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strftime.c,v 1.8 1997/07/25 20:30:14 mickey Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <sys/localedef.h>
39#include <locale.h>
40#include <string.h>
41#include <tzfile.h>
42#include <time.h>
43
44static size_t gsize;
45static char *pt;
46static int _add __P((const char *));
47static int _secs __P((const struct tm *));
48static int _conv __P((int, int, char));
49static size_t _fmt __P((const char *, const struct tm *));
50
51size_t
52strftime(s, maxsize, format, t)
53 char *s;
54 size_t maxsize;
55 const char *format;
56 const struct tm *t;
57{
58 tzset();
59
60 pt = s;
61 if ((gsize = maxsize) < 1)
62 return(0);
63 if (_fmt(format, t)) {
64 *pt = '\0';
65 return(maxsize - gsize);
66 }
67 return(0);
68}
69
70#define SUN_WEEK(t) (((t)->tm_yday + 7 - \
71 ((t)->tm_wday)) / 7)
72#define MON_WEEK(t) (((t)->tm_yday + 7 - \
73 ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7)
74static size_t
75_fmt(format, t)
76 register const char *format;
77 const struct tm *t;
78{
79 for (; *format; ++format) {
80 if (*format == '%') {
81 ++format;
82 if (*format == 'E') {
83 /* Alternate Era */
84 ++format;
85 } else if (*format == 'O') {
86 /* Alternate numeric symbols */
87 ++format;
88 }
89 switch(*format) {
90 case '\0':
91 --format;
92 break;
93 case 'A':
94 if (t->tm_wday < 0 || t->tm_wday > 6)
95 return(0);
96 if (!_add(_CurrentTimeLocale->day[t->tm_wday]))
97 return(0);
98 continue;
99 case 'a':
100 if (t->tm_wday < 0 || t->tm_wday > 6)
101 return(0);
102 if (!_add(_CurrentTimeLocale->abday[t->tm_wday]))
103 return(0);
104 continue;
105 case 'B':
106 if (t->tm_mon < 0 || t->tm_mon > 11)
107 return(0);
108 if (!_add(_CurrentTimeLocale->mon[t->tm_mon]))
109 return(0);
110 continue;
111 case 'b':
112 case 'h':
113 if (t->tm_mon < 0 || t->tm_mon > 11)
114 return(0);
115 if (!_add(_CurrentTimeLocale->abmon[t->tm_mon]))
116 return(0);
117 continue;
118 case 'C':
119 if (!_conv((t->tm_year + TM_YEAR_BASE) / 100,
120 2, '0'))
121 return(0);
122 continue;
123 case 'c':
124 if (!_fmt(_CurrentTimeLocale->d_t_fmt, t))
125 return(0);
126 continue;
127 case 'D':
128 if (!_fmt("%m/%d/%y", t))
129 return(0);
130 continue;
131 case 'd':
132 if (!_conv(t->tm_mday, 2, '0'))
133 return(0);
134 continue;
135 case 'e':
136 if (!_conv(t->tm_mday, 2, ' '))
137 return(0);
138 continue;
139 case 'H':
140 if (!_conv(t->tm_hour, 2, '0'))
141 return(0);
142 continue;
143 case 'I':
144 if (!_conv(t->tm_hour % 12 ?
145 t->tm_hour % 12 : 12, 2, '0'))
146 return(0);
147 continue;
148 case 'j':
149 if (!_conv(t->tm_yday + 1, 3, '0'))
150 return(0);
151 continue;
152 case 'k':
153 if (!_conv(t->tm_hour, 2, ' '))
154 return(0);
155 continue;
156 case 'l':
157 if (!_conv(t->tm_hour % 12 ?
158 t->tm_hour % 12: 12, 2, ' '))
159 return(0);
160 continue;
161 case 'M':
162 if (!_conv(t->tm_min, 2, '0'))
163 return(0);
164 continue;
165 case 'm':
166 if (!_conv(t->tm_mon + 1, 2, '0'))
167 return(0);
168 continue;
169 case 'n':
170 if (!_add("\n"))
171 return(0);
172 continue;
173 case 'p':
174 if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour >= 12]))
175 return(0);
176 continue;
177 case 'R':
178 if (!_fmt("%H:%M", t))
179 return(0);
180 continue;
181 case 'r':
182 if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t))
183 return(0);
184 continue;
185 case 'S':
186 if (!_conv(t->tm_sec, 2, '0'))
187 return(0);
188 continue;
189 case 's':
190 if (!_secs(t))
191 return(0);
192 continue;
193 case 'T':
194 if (!_fmt("%H:%M:%S", t))
195 return(0);
196 continue;
197 case 't':
198 if (!_add("\t"))
199 return(0);
200 continue;
201 case 'U':
202 if (!_conv(SUN_WEEK(t), 2, '0'))
203 return(0);
204 continue;
205 case 'u':
206 if (!_conv(t->tm_wday ? t->tm_wday : 7, 1, '0'))
207 return(0);
208 continue;
209 case 'V':
210 {
211 /* ISO 8601 Week Of Year:
212 If the week (Monday - Sunday) containing
213 January 1 has four or more days in the new
214 year, then it is week 1; otherwise it is
215 week 53 of the previous year and the next
216 week is week one. */
217
218 int week = MON_WEEK(t);
219
220 int days = (((t)->tm_yday + 7 - \
221 ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) % 7);
222
223
224 if (days >= 4) {
225 week++;
226 } else if (week == 0) {
227 week = 53;
228 }
229
230 if (!_conv(week, 2, '0'))
231 return(0);
232 continue;
233 }
234 case 'W':
235 if (!_conv(MON_WEEK(t), 2, '0'))
236 return(0);
237 continue;
238 case 'w':
239 if (!_conv(t->tm_wday, 1, '0'))
240 return(0);
241 continue;
242 case 'x':
243 if (!_fmt(_CurrentTimeLocale->d_fmt, t))
244 return(0);
245 continue;
246 case 'X':
247 if (!_fmt(_CurrentTimeLocale->t_fmt, t))
248 return(0);
249 continue;
250 case 'y':
251 if (!_conv((t->tm_year + TM_YEAR_BASE) % 100,
252 2, '0'))
253 return(0);
254 continue;
255 case 'Y':
256 if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0'))
257 return(0);
258 continue;
259 case 'Z':
260 if (tzname[t->tm_isdst ? 1 : 0] &&
261 !_add(tzname[t->tm_isdst ? 1 : 0]))
262 return(0);
263 continue;
264 case '%':
265 /*
266 * X311J/88-090 (4.12.3.5): if conversion char is
267 * undefined, behavior is undefined. Print out the
268 * character itself as printf(3) does.
269 */
270 default:
271 break;
272 }
273 }
274 if (!gsize--)
275 return(0);
276 *pt++ = *format;
277 }
278 return(gsize);
279}
280
281static int
282_secs(t)
283 const struct tm *t;
284{
285 static char buf[15];
286 register time_t s;
287 register char *p;
288 struct tm tmp;
289
290 /* Make a copy, mktime(3) modifies the tm struct. */
291 tmp = *t;
292 s = mktime(&tmp);
293 for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
294 *p-- = s % 10 + '0';
295 return(_add(++p));
296}
297
298static int
299#ifdef __STDC__
300_conv(int n, int digits, char pad)
301#else
302_conv(n, digits, pad)
303 int n, digits;
304 char pad;
305#endif
306{
307 static char buf[10];
308 register char *p;
309
310 for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
311 *p-- = n % 10 + '0';
312 while (p > buf && digits-- > 0)
313 *p-- = pad;
314 return(_add(++p));
315}
316
317static int
318_add(str)
319 register const char *str;
320{
321 for (;; ++pt, --gsize) {
322 if (!gsize)
323 return(0);
324 if (!(*pt = *str++))
325 return(1);
326 }
327}