diff options
author | 2017-09-05 03:16:13 +0000 | |
---|---|---|
committer | 2017-09-05 03:16:13 +0000 | |
commit | 3a628b46e7aaa520a6215eccabf31d313c2e7de0 (patch) | |
tree | c6543ac3a194244f09c381abe688fa69e6c8d49a /lib/libc/time | |
parent | Add additional errno values required by POSIX. (diff) | |
download | wireguard-openbsd-3a628b46e7aaa520a6215eccabf31d313c2e7de0.tar.xz wireguard-openbsd-3a628b46e7aaa520a6215eccabf31d313c2e7de0.zip |
New POSIX xlocale implementation written from scratch.
Complete in the sense that all POSIX *locale(3) and *_l(3) functions
are included, but in OpenBSD, we of course only really care about
LC_CTYPE and we only support ASCII and UTF-8.
With important help from kettenis@, guenther@, and jca@.
Repeated testing in ports bulk builds by naddy@.
Additional testing by jca@, sebastia@, dcoppa@, and others.
OK kettenis@ dcoppa@, and guenther@ on an earlier version.
Riding guenther@'s libc/librthread major bump.
Diffstat (limited to 'lib/libc/time')
-rw-r--r-- | lib/libc/time/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/time/strftime.3 | 50 | ||||
-rw-r--r-- | lib/libc/time/strftime_l.c | 14 |
3 files changed, 59 insertions, 10 deletions
diff --git a/lib/libc/time/Makefile.inc b/lib/libc/time/Makefile.inc index f73cfbc9b56..28aada456e9 100644 --- a/lib/libc/time/Makefile.inc +++ b/lib/libc/time/Makefile.inc @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.10 2016/03/30 06:38:42 jmc Exp $ +# $OpenBSD: Makefile.inc,v 1.11 2017/09/05 03:16:14 schwarze Exp $ .PATH: ${LIBCSRCDIR}/time -SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c wcsftime.c +SRCS+= asctime.c difftime.c localtime.c strftime.c strftime_l.c \ + strptime.c wcsftime.c MAN+= ctime.3 strftime.3 time2posix.3 tzfile.5 tzset.3 strptime.3 wcsftime.3 diff --git a/lib/libc/time/strftime.3 b/lib/libc/time/strftime.3 index 00ca41604ca..a02af262b15 100644 --- a/lib/libc/time/strftime.3 +++ b/lib/libc/time/strftime.3 @@ -1,3 +1,5 @@ +.\" $OpenBSD: strftime.3,v 1.37 2017/09/05 03:16:14 schwarze Exp $ +.\" .\" Copyright (c) 1989, 1991 The Regents of the University of California. .\" All rights reserved. .\" @@ -30,22 +32,33 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 -.\" $OpenBSD: strftime.3,v 1.36 2016/02/08 20:29:11 jmc Exp $ .\" -.Dd $Mdocdate: February 8 2016 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRFTIME 3 .Os .Sh NAME -.Nm strftime +.Nm strftime , +.Nm strftime_l .Nd format date and time .Sh SYNOPSIS .In time.h .Ft size_t -.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" +.Fo strftime +.Fa "char *buf" +.Fa "size_t maxsize" +.Fa "const char *format" +.Fa "const struct tm *timeptr" +.Fc +.Ft size_t +.Fo strftime_l +.Fa "char *buf" +.Fa "size_t maxsize" +.Fa "const char *format" +.Fa "const struct tm *timeptr" +.Fa "locale_t locale" +.Fc .Sh DESCRIPTION -The -.Fn strftime -function formats the information from +These functions format the information from .Fa timeptr (as described in .Xr mktime 3 ) @@ -191,6 +204,13 @@ is replaced by the date and time in .Xr date 1 format. .El +.Pp +The +.Ox +implementation always uses the C locale and ignores +the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES If the total number of resulting characters, including the terminating NUL character, is not more than @@ -199,6 +219,12 @@ NUL character, is not more than returns the number of characters placed in the array, not counting the terminating NUL. Otherwise, zero is returned. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn strftime +may depend on the +.Dv LC_TIME +.Xr locale 1 . .Sh SEE ALSO .Xr date 1 , .Xr printf 1 , @@ -215,6 +241,10 @@ The function conforms to .St -isoC-99 , +and +.Fn strftime_l +to +.St -p1003.1-2008 , except that the .Ql E and @@ -253,7 +283,11 @@ first appeared in The .Fn strftime function has been available since -.Bx 4.3 Reno . +.Bx 4.3 Reno , +and +.Fn strftime_l +since +.Ox 6.2 . .Sh AUTHORS .An Keith Bostic implemented the diff --git a/lib/libc/time/strftime_l.c b/lib/libc/time/strftime_l.c new file mode 100644 index 00000000000..4d3face1c95 --- /dev/null +++ b/lib/libc/time/strftime_l.c @@ -0,0 +1,14 @@ +/* $OpenBSD: strftime_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <time.h> + +size_t +strftime_l(char *s, size_t maxsize, const char *format, const struct tm *t, + locale_t locale __attribute__((__unused__))) +{ + return strftime(s, maxsize, format, t); +} |