summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschwarze <>2017-09-05 03:16:14 +0000
committerschwarze <>2017-09-05 03:16:14 +0000
commitf63c4fd91b8483c7d4364046fd6ef2d2679dd63a (patch)
treed7f851bfa426cf869a3a3aec05ffba386b6f2ce5
parentc1d0fec9b838e4df93e396d54f1e4b9a41f7401a (diff)
downloadopenbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.tar.gz
openbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.tar.bz2
openbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.zip
New POSIX xlocale implementation written from scratch.libressl-v2.6.1
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.
-rw-r--r--src/lib/libc/string/Makefile.inc10
-rw-r--r--src/lib/libc/string/strcasecmp.376
-rw-r--r--src/lib/libc/string/strcasecmp_l.c21
-rw-r--r--src/lib/libc/string/strcoll.353
-rw-r--r--src/lib/libc/string/strcoll_l.c14
-rw-r--r--src/lib/libc/string/strerror.375
-rw-r--r--src/lib/libc/string/strerror_l.c33
-rw-r--r--src/lib/libc/string/strxfrm.357
-rw-r--r--src/lib/libc/string/strxfrm_l.c14
-rw-r--r--src/lib/libc/string/wcscasecmp.376
-rw-r--r--src/lib/libc/string/wcscasecmp_l.c63
11 files changed, 396 insertions, 96 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc
index 95eb93006b..a1b1934aad 100644
--- a/src/lib/libc/string/Makefile.inc
+++ b/src/lib/libc/string/Makefile.inc
@@ -1,17 +1,17 @@
1# $OpenBSD: Makefile.inc,v 1.38 2016/03/30 06:38:41 jmc Exp $ 1# $OpenBSD: Makefile.inc,v 1.39 2017/09/05 03:16:13 schwarze Exp $
2 2
3# string sources 3# string sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string
5 5
6SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \ 6SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \
7 strcasecmp.c strcasestr.c strcoll.c strdup.c \ 7 strcasecmp.c strcasecmp_l.c strcasestr.c strcoll.c strcoll_l.c \
8 strerror.c strerror_r.c strmode.c strndup.c strnlen.c \ 8 strdup.c strerror.c strerror_l.c strerror_r.c strmode.c \
9 strsignal.c strtok.c strxfrm.c \ 9 strndup.c strnlen.c strsignal.c strtok.c strxfrm.c strxfrm_l.c \
10 timingsafe_bcmp.c timingsafe_memcmp.c \ 10 timingsafe_bcmp.c timingsafe_memcmp.c \
11 wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ 11 wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \
12 wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ 12 wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \
13 wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ 13 wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \
14 wmemmove.c wmemset.c wcsdup.c wcscasecmp.c 14 wmemmove.c wmemset.c wcsdup.c wcscasecmp.c wcscasecmp_l.c
15 15
16# machine-dependent net sources 16# machine-dependent net sources
17# ../arch/ARCH/Makefile.inc must include sources for: 17# ../arch/ARCH/Makefile.inc must include sources for:
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3
index 3870362216..bb39df895a 100644
--- a/src/lib/libc/string/strcasecmp.3
+++ b/src/lib/libc/string/strcasecmp.3
@@ -1,7 +1,8 @@
1.\" $OpenBSD: strcasecmp.3,v 1.13 2015/11/24 09:14:35 daniel Exp $ 1.\" $OpenBSD: strcasecmp.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1991, 1993 3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5.\" 6.\"
6.\" This code is derived from software contributed to Berkeley by 7.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek. 8.\" Chris Torek.
@@ -31,25 +32,43 @@
31.\" 32.\"
32.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 33.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
33.\" 34.\"
34.Dd $Mdocdate: November 24 2015 $ 35.Dd $Mdocdate: September 5 2017 $
35.Dt STRCASECMP 3 36.Dt STRCASECMP 3
36.Os 37.Os
37.Sh NAME 38.Sh NAME
38.Nm strcasecmp , 39.Nm strcasecmp ,
39.Nm strncasecmp 40.Nm strcasecmp_l ,
41.Nm strncasecmp ,
42.Nm strncasecmp_l
40.Nd compare strings, ignoring case 43.Nd compare strings, ignoring case
41.Sh SYNOPSIS 44.Sh SYNOPSIS
42.In strings.h 45.In strings.h
43.Ft int 46.Ft int
44.Fn strcasecmp "const char *s1" "const char *s2" 47.Fo strcasecmp
48.Fa "const char *s1"
49.Fa "const char *s2"
50.Fc
45.Ft int 51.Ft int
46.Fn strncasecmp "const char *s1" "const char *s2" "size_t len" 52.Fo strcasecmp_l
53.Fa "const char *s1"
54.Fa "const char *s2"
55.Fa "locale_t locale"
56.Fc
57.Ft int
58.Fo strncasecmp
59.Fa "const char *s1"
60.Fa "const char *s2"
61.Fa "size_t len"
62.Fc
63.Ft int
64.Fo strncasecmp_l
65.Fa "const char *s1"
66.Fa "const char *s2"
67.Fa "size_t len"
68.Fa "locale_t locale"
69.Fc
47.Sh DESCRIPTION 70.Sh DESCRIPTION
48The 71These functions compare the NUL-terminated strings
49.Fn strcasecmp
50and
51.Fn strncasecmp
52functions compare the NUL-terminated strings
53.Fa s1 72.Fa s1
54and 73and
55.Fa s2 74.Fa s2
@@ -66,27 +85,44 @@ is greater than
66.Ql \e0 . 85.Ql \e0 .
67.Pp 86.Pp
68.Fn strncasecmp 87.Fn strncasecmp
69compares at most 88and
89.Fn strncasecmp_l
90compare at most
70.Fa len 91.Fa len
71characters. 92characters.
93.Pp
94On
95.Ox ,
96these functions always use the C locale and ignore
97the global locale, the thread-specific locale, and the
98.Fa locale
99argument.
100.Sh ENVIRONMENT
101On other operating systems, the behaviour of
102.Fn strcasecmp
103and
104.Fn strncasecmp
105may depend on the
106.Dv LC_CTYPE
107.Xr locale 1 .
72.Sh SEE ALSO 108.Sh SEE ALSO
73.Xr bcmp 3 ,
74.Xr memcmp 3 ,
75.Xr strcmp 3 , 109.Xr strcmp 3 ,
76.Xr strcoll 3 , 110.Xr strcoll 3 ,
77.Xr strxfrm 3 , 111.Xr strxfrm 3 ,
78.Xr wcscasecmp 3 112.Xr wcscasecmp 3
79.Sh STANDARDS 113.Sh STANDARDS
80The 114These functions conform to
81.Fn strcasecmp
82and
83.Fn strncasecmp
84functions conform to
85.St -p1003.1-2008 . 115.St -p1003.1-2008 .
86.Sh HISTORY 116.Sh HISTORY
87The 117The
88.Fn strcasecmp 118.Fn strcasecmp
89and 119and
90.Fn strncasecmp 120.Fn strncasecmp
91functions first appeared in 121functions have been available since
92.Bx 4.3 Tahoe . 122.Bx 4.3 Tahoe ,
123and
124.Fn strcasecmp_l
125and
126.Fn strncasecmp_l
127since
128.Ox 6.2 .
diff --git a/src/lib/libc/string/strcasecmp_l.c b/src/lib/libc/string/strcasecmp_l.c
new file mode 100644
index 0000000000..a9543dda11
--- /dev/null
+++ b/src/lib/libc/string/strcasecmp_l.c
@@ -0,0 +1,21 @@
1/* $OpenBSD: strcasecmp_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */
2/*
3 * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>.
4 * Released into the public domain.
5 */
6
7#include <string.h>
8
9int
10strcasecmp_l(const char *s1, const char *s2,
11 locale_t locale __attribute__((__unused__)))
12{
13 return strcasecmp(s1, s2);
14}
15
16int
17strncasecmp_l(const char *s1, const char *s2, size_t n,
18 locale_t locale __attribute__((__unused__)))
19{
20 return strncasecmp(s1, s2, n);
21}
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3
index d421200b62..4ba1f22677 100644
--- a/src/lib/libc/string/strcoll.3
+++ b/src/lib/libc/string/strcoll.3
@@ -1,4 +1,7 @@
1.\" $OpenBSD: strcoll.3,v 1.10 2017/09/05 03:16:13 schwarze Exp $
2.\"
1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
2.\" All rights reserved. 5.\" All rights reserved.
3.\" 6.\"
4.\" This code is derived from software contributed to Berkeley by 7.\" This code is derived from software contributed to Berkeley by
@@ -29,45 +32,69 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 33.\" SUCH DAMAGE.
31.\" 34.\"
32.\" $OpenBSD: strcoll.3,v 1.9 2013/06/05 03:39:23 tedu Exp $ 35.Dd $Mdocdate: September 5 2017 $
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt STRCOLL 3 36.Dt STRCOLL 3
36.Os 37.Os
37.Sh NAME 38.Sh NAME
38.Nm strcoll 39.Nm strcoll ,
40.Nm strcoll_l
39.Nd compare strings according to current collation 41.Nd compare strings according to current collation
40.Sh SYNOPSIS 42.Sh SYNOPSIS
41.In string.h 43.In string.h
42.Ft int 44.Ft int
43.Fn strcoll "const char *s1" "const char *s2" 45.Fn strcoll "const char *s1" "const char *s2"
46.Ft int
47.Fn strcoll_l "const char *s1" "const char *s2" "locale_t locale"
44.Sh DESCRIPTION 48.Sh DESCRIPTION
45The 49The
46.Fn strcoll 50.Fn strcoll
47function lexicographically compares the NUL-terminated strings 51and
52.Fn strcoll_l
53functions lexicographically compare the NUL-terminated strings
48.Fa s1 54.Fa s1
49and 55and
50.Fa s2 56.Fa s2
51according to the current locale collation 57according to the current locale collation
52and returns an integer greater than, equal to, or less than 0, 58and return an integer greater than, equal to, or less than 0,
53according to whether 59according to whether
54.Fa s1 60.Fa s1
55is greater than, equal to, or less than 61is greater than, equal to, or less than
56.Fa s2 . 62.Fa s2 .
63.Pp
64On
65.Ox ,
66they have the same effect as
67.Xr strcmp 3 ,
68and the global locale, the thread-specific locale, and the
69.Fa locale
70argument are ignored.
71.Sh ENVIRONMENT
72On other operating systems, the behaviour of
73.Fn strcoll
74may depend on the
75.Dv LC_CTYPE
76.Xr locale 1 .
57.Sh SEE ALSO 77.Sh SEE ALSO
58.Xr bcmp 3 , 78.Xr newlocale 3 ,
59.Xr memcmp 3 ,
60.Xr setlocale 3 , 79.Xr setlocale 3 ,
61.Xr strcasecmp 3 ,
62.Xr strcmp 3 , 80.Xr strcmp 3 ,
63.Xr strxfrm 3 81.Xr strxfrm 3 ,
82.Xr wcscoll 3
64.Sh STANDARDS 83.Sh STANDARDS
65The 84The
66.Fn strcoll 85.Fn strcoll
67function conforms to 86function conforms to
68.St -ansiC . 87.St -ansiC ,
88and
89.Fn strcoll_l
90to
91.St -p1003.1-2008 .
69.Sh HISTORY 92.Sh HISTORY
70The 93The
71.Fn strcoll 94.Fn strcoll
72function first appeared in 95function has been available since
73.Bx 4.3 Reno . 96.Bx 4.3 Reno ,
97and
98.Fn strcoll_l
99since
100.Ox 6.2 .
diff --git a/src/lib/libc/string/strcoll_l.c b/src/lib/libc/string/strcoll_l.c
new file mode 100644
index 0000000000..bcd5b0f417
--- /dev/null
+++ b/src/lib/libc/string/strcoll_l.c
@@ -0,0 +1,14 @@
1/* $OpenBSD: strcoll_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */
2/*
3 * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>.
4 * Released into the public domain.
5 */
6
7#include <string.h>
8
9int
10strcoll_l(const char *s1, const char *s2,
11 locale_t locale __attribute__((__unused__)))
12{
13 return strcmp(s1, s2);
14}
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3
index 8b2d32ea75..0d4f084e5e 100644
--- a/src/lib/libc/string/strerror.3
+++ b/src/lib/libc/string/strerror.3
@@ -1,4 +1,7 @@
1.\" $OpenBSD: strerror.3,v 1.15 2017/09/05 03:16:13 schwarze Exp $
2.\"
1.\" Copyright (c) 1980, 1991 Regents of the University of California. 3.\" Copyright (c) 1980, 1991 Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
2.\" All rights reserved. 5.\" All rights reserved.
3.\" 6.\"
4.\" This code is derived from software contributed to Berkeley by 7.\" This code is derived from software contributed to Berkeley by
@@ -29,46 +32,61 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 33.\" SUCH DAMAGE.
31.\" 34.\"
32.\" $OpenBSD: strerror.3,v 1.14 2014/11/30 21:21:59 schwarze Exp $ 35.Dd $Mdocdate: September 5 2017 $
33.\"
34.Dd $Mdocdate: November 30 2014 $
35.Dt STRERROR 3 36.Dt STRERROR 3
36.Os 37.Os
37.Sh NAME 38.Sh NAME
38.Nm strerror , 39.Nm strerror ,
40.Nm strerror_l ,
39.Nm strerror_r 41.Nm strerror_r
40.Nd get error message string 42.Nd get error message string
41.Sh SYNOPSIS 43.Sh SYNOPSIS
42.In string.h 44.In string.h
43.Ft char * 45.Ft char *
44.Fn strerror "int errnum" 46.Fn strerror "int errnum"
47.Ft char *
48.Fn strerror_l "int errnum" "locale_t locale"
45.Ft int 49.Ft int
46.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" 50.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen"
47.Sh DESCRIPTION 51.Sh DESCRIPTION
48The 52These functions map the error number
49.Fn strerror
50and
51.Fn strerror_r
52functions map the error number
53.Fa errnum 53.Fa errnum
54to a language-dependent error message string. 54to an error message string.
55.Pp 55.Pp
56.Fn strerror 56.Fn strerror
57returns a string containing a maximum of 57and
58.Fn strerror_l
59return a string containing a maximum of
58.Dv NL_TEXTMAX 60.Dv NL_TEXTMAX
59characters, including the trailing NUL. 61characters, including the trailing NUL.
60This string is not to be modified by the calling program, 62This string is not to be modified by the calling program.
61but may be overwritten by subsequent calls to 63The string returned by
62.Fn strerror . 64.Fn strerror
65may be overwritten by subsequent calls to
66.Fn strerror
67in any thread.
68The string returned by
69.Fn strerror_l
70may be overwritten by subsequent calls to
71.Fn strerror_l
72in the same thread.
63.Pp 73.Pp
64.Fn strerror_r 74.Fn strerror_r
65is a thread safe version of 75is a thread safe version of
66.Fn strerror 76.Fn strerror
67that places the error message in the specified buffer 77that places the error message in the specified buffer
68.Fa strerrbuf . 78.Fa strerrbuf .
79.Pp
80On
81.Ox ,
82the global locale, the thread-specific locale, and the
83.Fa locale
84argument are ignored.
69.Sh RETURN VALUES 85.Sh RETURN VALUES
70.Fn strerror 86.Fn strerror
71returns a pointer to the error message string. 87and
88.Fn strerror_l
89return a pointer to the error message string.
72If an error occurs, the error code is stored in 90If an error occurs, the error code is stored in
73.Va errno . 91.Va errno .
74.Pp 92.Pp
@@ -77,11 +95,16 @@ returns zero upon successful completion.
77If an error occurs, the error code is stored in 95If an error occurs, the error code is stored in
78.Va errno 96.Va errno
79and the error code is returned. 97and the error code is returned.
80.Sh ERRORS 98.Sh ENVIRONMENT
99On other operating systems, the behaviour of
81.Fn strerror 100.Fn strerror
82and 101and
83.Fn strerror_r 102.Fn strerror_r
84may fail if: 103may depend on the
104.Dv LC_MESSAGES
105.Xr locale 1 .
106.Sh ERRORS
107All these functions may fail if:
85.Bl -tag -width Er 108.Bl -tag -width Er
86.It Bq Er EINVAL 109.It Bq Er EINVAL
87.Fa errnum 110.Fa errnum
@@ -91,7 +114,7 @@ The returned error string will consist of an error message that includes
91.El 114.El
92.Pp 115.Pp
93.Fn strerror_r 116.Fn strerror_r
94may fail if: 117may also fail if:
95.Bl -tag -width Er 118.Bl -tag -width Er
96.It Bq Er ERANGE 119.It Bq Er ERANGE
97The error message is larger than 120The error message is larger than
@@ -101,6 +124,7 @@ The message will be truncated to fit.
101.El 124.El
102.Sh SEE ALSO 125.Sh SEE ALSO
103.Xr intro 2 , 126.Xr intro 2 ,
127.Xr newlocale 3 ,
104.Xr perror 3 , 128.Xr perror 3 ,
105.Xr setlocale 3 129.Xr setlocale 3
106.Sh STANDARDS 130.Sh STANDARDS
@@ -109,15 +133,20 @@ The
109function conforms to 133function conforms to
110.St -isoC-99 . 134.St -isoC-99 .
111The 135The
136.Fn strerror_l
137and
112.Fn strerror_r 138.Fn strerror_r
113function conforms to 139functions conform to
114.St -p1003.1-2008 . 140.St -p1003.1-2008 .
115.Sh HISTORY 141.Sh HISTORY
116The 142The
117.Fn strerror 143.Fn strerror
118function first appeared in 144function has been available since
119.Bx 4.3 Reno . 145.Bx 4.3 Reno ,
120The
121.Fn strerror_r 146.Fn strerror_r
122function first appeared in 147since
123.Ox 3.3 . 148.Ox 3.3 ,
149and
150.Fn strerror_l
151since
152.Ox 6.2 .
diff --git a/src/lib/libc/string/strerror_l.c b/src/lib/libc/string/strerror_l.c
new file mode 100644
index 0000000000..c16be7a0cc
--- /dev/null
+++ b/src/lib/libc/string/strerror_l.c
@@ -0,0 +1,33 @@
1/* $OpenBSD: strerror_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */
2/*
3 * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <limits.h>
19#include <string.h>
20
21#include "thread_private.h"
22
23char *
24strerror_l(int errnum, locale_t locale)
25{
26 static char sel_buf[NL_TEXTMAX];
27 _THREAD_PRIVATE_KEY(strerror_l);
28 char *p = _THREAD_PRIVATE(strerror_l, sel_buf, NULL);
29
30 return p == NULL ? "no buffer available in strerror_l" :
31 strerror_r(errnum, p, sizeof(sel_buf)) ?
32 "strerror_r failure" : p;
33}
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3
index 481f741cb7..1a96c8512e 100644
--- a/src/lib/libc/string/strxfrm.3
+++ b/src/lib/libc/string/strxfrm.3
@@ -1,4 +1,7 @@
1.\" $OpenBSD: strxfrm.3,v 1.11 2017/09/05 03:16:13 schwarze Exp $
2.\"
1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
2.\" All rights reserved. 5.\" All rights reserved.
3.\" 6.\"
4.\" This code is derived from software contributed to Berkeley by 7.\" This code is derived from software contributed to Berkeley by
@@ -29,24 +32,27 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 33.\" SUCH DAMAGE.
31.\" 34.\"
32.\" $OpenBSD: strxfrm.3,v 1.10 2013/06/05 03:39:23 tedu Exp $ 35.Dd $Mdocdate: September 5 2017 $
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt STRXFRM 3 36.Dt STRXFRM 3
36.Os 37.Os
37.Sh NAME 38.Sh NAME
38.Nm strxfrm 39.Nm strxfrm ,
40.Nm strxfrm_l
39.Nd transform a string under locale 41.Nd transform a string under locale
40.Sh SYNOPSIS 42.Sh SYNOPSIS
41.In string.h 43.In string.h
42.Ft size_t 44.Ft size_t
43.Fn strxfrm "char *dst" "const char *src" "size_t n" 45.Fn strxfrm "char *dst" "const char *src" "size_t n"
46.Ft size_t
47.Fn strxfrm_l "char *dst" "const char *src" "size_t n" "locale_t locale"
44.Sh DESCRIPTION 48.Sh DESCRIPTION
45The idea of 49The idea of
46.Fn strxfrm 50.Fn strxfrm
51and
52.Fn strxfrm_l
47is to 53is to
48.Dq un-localize 54.Dq un-localize
49a string: the function transforms 55a string: the functions transform
50.Ar src , 56.Ar src ,
51storing the result in 57storing the result in
52.Ar dst , 58.Ar dst ,
@@ -55,25 +61,42 @@ such that
55on transformed strings returns what 61on transformed strings returns what
56.Xr strcoll 3 62.Xr strcoll 3
57on the original untransformed strings would return. 63on the original untransformed strings would return.
64.Pp
65On
66.Ox ,
67both have the same effect as
68.Xr strlcpy 3 ,
69and the global locale, the thread-specific locale, and the
70.Fa locale
71argument are ignored.
72.Sh ENVIRONMENT
73On other operating systems, the behaviour of
74.Fn strxfrm
75may depend on the
76.Dv LC_CTYPE
77.Xr locale 1 .
58.Sh SEE ALSO 78.Sh SEE ALSO
59.Xr bcmp 3 , 79.Xr newlocale 3 ,
60.Xr memcmp 3 ,
61.Xr setlocale 3 , 80.Xr setlocale 3 ,
62.Xr strcasecmp 3 ,
63.Xr strcmp 3 , 81.Xr strcmp 3 ,
64.Xr strcoll 3 82.Xr strcoll 3 ,
83.Xr strlcpy 3 ,
84.Xr wcsxfrm 3
65.Sh STANDARDS 85.Sh STANDARDS
66The 86The
67.Fn strxfrm 87.Fn strxfrm
68function conforms to 88function conforms to
69.St -ansiC . 89.St -ansiC ,
90and
91.Fn strxfrm_l
92to
93.St -p1003.1-2008 .
70.Sh HISTORY 94.Sh HISTORY
71The 95The
72.Fn strxfrm 96.Fn strxfrm
73function first appeared in 97function has been available since
74.Bx 4.3 Reno . 98.Bx 4.3 Reno ,
75.Sh BUGS 99and
76Since locales are not fully implemented on 100.Fn strxfrm_l
77.Ox , 101since
78.Fn strxfrm 102.Ox 6.2 .
79just returns a copy of the original string.
diff --git a/src/lib/libc/string/strxfrm_l.c b/src/lib/libc/string/strxfrm_l.c
new file mode 100644
index 0000000000..ff77947953
--- /dev/null
+++ b/src/lib/libc/string/strxfrm_l.c
@@ -0,0 +1,14 @@
1/* $OpenBSD: strxfrm_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */
2/*
3 * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>.
4 * Released into the public domain.
5 */
6
7#include <string.h>
8
9size_t
10strxfrm_l(char *dst, const char *src, size_t n,
11 locale_t locale __attribute__((__unused__)))
12{
13 return strxfrm(dst, src, n);
14}
diff --git a/src/lib/libc/string/wcscasecmp.3 b/src/lib/libc/string/wcscasecmp.3
index daf397aece..9db4a829b9 100644
--- a/src/lib/libc/string/wcscasecmp.3
+++ b/src/lib/libc/string/wcscasecmp.3
@@ -1,7 +1,8 @@
1.\" $OpenBSD: wcscasecmp.3,v 1.4 2013/07/16 15:21:11 schwarze Exp $ 1.\" $OpenBSD: wcscasecmp.3,v 1.5 2017/09/05 03:16:14 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1991, 1993 3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5.\" 6.\"
6.\" This code is derived from software contributed to Berkeley by 7.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek. 8.\" Chris Torek.
@@ -31,25 +32,43 @@
31.\" 32.\"
32.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 33.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
33.\" 34.\"
34.Dd $Mdocdate: July 16 2013 $ 35.Dd $Mdocdate: September 5 2017 $
35.Dt WCSCASECMP 3 36.Dt WCSCASECMP 3
36.Os 37.Os
37.Sh NAME 38.Sh NAME
38.Nm wcscasecmp , 39.Nm wcscasecmp ,
39.Nm wcsncasecmp 40.Nm wcscasecmp_l ,
41.Nm wcsncasecmp ,
42.Nm wcsncasecmp_l
40.Nd compare wide strings, ignoring case 43.Nd compare wide strings, ignoring case
41.Sh SYNOPSIS 44.Sh SYNOPSIS
42.In wchar.h 45.In wchar.h
43.Ft int 46.Ft int
44.Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" 47.Fo wcscasecmp
48.Fa "const wchar_t *s1"
49.Fa "const wchar_t *s2"
50.Fc
45.Ft int 51.Ft int
46.Fn wcsncasecmp "const wchar_t *s1" "const wchar_t *s2" "size_t len" 52.Fo wcscasecmp_l
53.Fa "const wchar_t *s1"
54.Fa "const wchar_t *s2"
55.Fa "locale_t locale"
56.Fc
57.Ft int
58.Fo wcsncasecmp
59.Fa "const wchar_t *s1"
60.Fa "const wchar_t *s2"
61.Fa "size_t len"
62.Fc
63.Ft int
64.Fo wcsncasecmp_l
65.Fa "const wchar_t *s1"
66.Fa "const wchar_t *s2"
67.Fa "size_t len"
68.Fa "locale_t locale"
69.Fc
47.Sh DESCRIPTION 70.Sh DESCRIPTION
48The 71These functions compare the wide strings
49.Fn wcscasecmp
50and
51.Fn wcsncasecmp
52functions compare the wide strings
53.Fa s1 72.Fa s1
54and 73and
55.Fa s2 74.Fa s2
@@ -61,28 +80,49 @@ is lexicographically greater than, equal to, or less than
61after translation of each corresponding wide character to lower case. 80after translation of each corresponding wide character to lower case.
62The wide strings themselves are not modified. 81The wide strings themselves are not modified.
63.Pp 82.Pp
83For the translation to lower case,
84.Fn wcscasecmp
85and
86.Fn wcsncasecmp
87use the thread-specific locale as defined with
88.Xr uselocale 3 ,
89falling back to the global locale defined with
90.Xr setlocale 3 .
91.Fn wcscasecmp_l
92and
93.Fn wcsncasecmp_l
94use the
95.Fa locale
96argument instead.
97.Pp
64.Fn wcsncasecmp 98.Fn wcsncasecmp
65compares at most 99and
100.Fn wcsncasecmp_l
101compare at most
66.Fa len 102.Fa len
67wide characters. 103wide characters.
68.Sh SEE ALSO 104.Sh SEE ALSO
105.Xr newlocale 3 ,
106.Xr setlocale 3 ,
69.Xr strcasecmp 3 , 107.Xr strcasecmp 3 ,
70.Xr wcscmp 3 , 108.Xr wcscmp 3 ,
71.Xr wmemcmp 3 109.Xr wmemcmp 3
72.Sh STANDARDS 110.Sh STANDARDS
73The 111These functions conform to
74.Fn wcscasecmp
75and
76.Fn wcsncasecmp
77functions conform to
78.St -p1003.1-2008 . 112.St -p1003.1-2008 .
79.Sh HISTORY 113.Sh HISTORY
80The 114The
81.Fn wcscasecmp 115.Fn wcscasecmp
82and 116and
83.Fn wcsncasecmp 117.Fn wcsncasecmp
84functions first appeared in 118functions have been available since
85.Ox 5.0 . 119.Ox 5.0 ,
120and
121.Fn wcscasecmp_l
122and
123.Fn wcsncasecmp_l
124since
125.Ox 6.2 .
86.Sh AUTHORS 126.Sh AUTHORS
87The 127The
88.Ox 128.Ox
diff --git a/src/lib/libc/string/wcscasecmp_l.c b/src/lib/libc/string/wcscasecmp_l.c
new file mode 100644
index 0000000000..35b99225c1
--- /dev/null
+++ b/src/lib/libc/string/wcscasecmp_l.c
@@ -0,0 +1,63 @@
1/* $OpenBSD: wcscasecmp_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */
2
3/*
4 * Copyright (c) 2011 Marc Espie
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
19 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <wchar.h>
29#include <wctype.h>
30#include "locale/runetype.h"
31
32int
33wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t locale)
34{
35 wchar_t l1, l2;
36
37 while ((l1 = towlower_l(*s1++, locale)) ==
38 (l2 = towlower_l(*s2++, locale))) {
39 if (l1 == 0)
40 return (0);
41 }
42 /* XXX assumes wchar_t = int */
43 return ((rune_t)l1 - (rune_t)l2);
44}
45
46int
47wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t locale)
48{
49 wchar_t l1, l2;
50
51 if (n == 0)
52 return (0);
53 do {
54 if (((l1 = towlower_l(*s1++, locale))) !=
55 (l2 = towlower_l(*s2++, locale))) {
56 /* XXX assumes wchar_t = int */
57 return ((rune_t)l1 - (rune_t)l2);
58 }
59 if (l1 == 0)
60 break;
61 } while (--n != 0);
62 return (0);
63}