diff options
author | schwarze <> | 2017-09-05 03:16:14 +0000 |
---|---|---|
committer | schwarze <> | 2017-09-05 03:16:14 +0000 |
commit | f63c4fd91b8483c7d4364046fd6ef2d2679dd63a (patch) | |
tree | d7f851bfa426cf869a3a3aec05ffba386b6f2ce5 | |
parent | c1d0fec9b838e4df93e396d54f1e4b9a41f7401a (diff) | |
download | openbsd-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.inc | 10 | ||||
-rw-r--r-- | src/lib/libc/string/strcasecmp.3 | 76 | ||||
-rw-r--r-- | src/lib/libc/string/strcasecmp_l.c | 21 | ||||
-rw-r--r-- | src/lib/libc/string/strcoll.3 | 53 | ||||
-rw-r--r-- | src/lib/libc/string/strcoll_l.c | 14 | ||||
-rw-r--r-- | src/lib/libc/string/strerror.3 | 75 | ||||
-rw-r--r-- | src/lib/libc/string/strerror_l.c | 33 | ||||
-rw-r--r-- | src/lib/libc/string/strxfrm.3 | 57 | ||||
-rw-r--r-- | src/lib/libc/string/strxfrm_l.c | 14 | ||||
-rw-r--r-- | src/lib/libc/string/wcscasecmp.3 | 76 | ||||
-rw-r--r-- | src/lib/libc/string/wcscasecmp_l.c | 63 |
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 | ||
6 | SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \ | 6 | SRCS+= 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 |
48 | The | 71 | These functions compare the NUL-terminated strings |
49 | .Fn strcasecmp | ||
50 | and | ||
51 | .Fn strncasecmp | ||
52 | functions compare the NUL-terminated strings | ||
53 | .Fa s1 | 72 | .Fa s1 |
54 | and | 73 | and |
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 |
69 | compares at most | 88 | and |
89 | .Fn strncasecmp_l | ||
90 | compare at most | ||
70 | .Fa len | 91 | .Fa len |
71 | characters. | 92 | characters. |
93 | .Pp | ||
94 | On | ||
95 | .Ox , | ||
96 | these functions always use the C locale and ignore | ||
97 | the global locale, the thread-specific locale, and the | ||
98 | .Fa locale | ||
99 | argument. | ||
100 | .Sh ENVIRONMENT | ||
101 | On other operating systems, the behaviour of | ||
102 | .Fn strcasecmp | ||
103 | and | ||
104 | .Fn strncasecmp | ||
105 | may 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 |
80 | The | 114 | These functions conform to |
81 | .Fn strcasecmp | ||
82 | and | ||
83 | .Fn strncasecmp | ||
84 | functions conform to | ||
85 | .St -p1003.1-2008 . | 115 | .St -p1003.1-2008 . |
86 | .Sh HISTORY | 116 | .Sh HISTORY |
87 | The | 117 | The |
88 | .Fn strcasecmp | 118 | .Fn strcasecmp |
89 | and | 119 | and |
90 | .Fn strncasecmp | 120 | .Fn strncasecmp |
91 | functions first appeared in | 121 | functions have been available since |
92 | .Bx 4.3 Tahoe . | 122 | .Bx 4.3 Tahoe , |
123 | and | ||
124 | .Fn strcasecmp_l | ||
125 | and | ||
126 | .Fn strncasecmp_l | ||
127 | since | ||
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 | |||
9 | int | ||
10 | strcasecmp_l(const char *s1, const char *s2, | ||
11 | locale_t locale __attribute__((__unused__))) | ||
12 | { | ||
13 | return strcasecmp(s1, s2); | ||
14 | } | ||
15 | |||
16 | int | ||
17 | strncasecmp_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 |
45 | The | 49 | The |
46 | .Fn strcoll | 50 | .Fn strcoll |
47 | function lexicographically compares the NUL-terminated strings | 51 | and |
52 | .Fn strcoll_l | ||
53 | functions lexicographically compare the NUL-terminated strings | ||
48 | .Fa s1 | 54 | .Fa s1 |
49 | and | 55 | and |
50 | .Fa s2 | 56 | .Fa s2 |
51 | according to the current locale collation | 57 | according to the current locale collation |
52 | and returns an integer greater than, equal to, or less than 0, | 58 | and return an integer greater than, equal to, or less than 0, |
53 | according to whether | 59 | according to whether |
54 | .Fa s1 | 60 | .Fa s1 |
55 | is greater than, equal to, or less than | 61 | is greater than, equal to, or less than |
56 | .Fa s2 . | 62 | .Fa s2 . |
63 | .Pp | ||
64 | On | ||
65 | .Ox , | ||
66 | they have the same effect as | ||
67 | .Xr strcmp 3 , | ||
68 | and the global locale, the thread-specific locale, and the | ||
69 | .Fa locale | ||
70 | argument are ignored. | ||
71 | .Sh ENVIRONMENT | ||
72 | On other operating systems, the behaviour of | ||
73 | .Fn strcoll | ||
74 | may 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 |
65 | The | 84 | The |
66 | .Fn strcoll | 85 | .Fn strcoll |
67 | function conforms to | 86 | function conforms to |
68 | .St -ansiC . | 87 | .St -ansiC , |
88 | and | ||
89 | .Fn strcoll_l | ||
90 | to | ||
91 | .St -p1003.1-2008 . | ||
69 | .Sh HISTORY | 92 | .Sh HISTORY |
70 | The | 93 | The |
71 | .Fn strcoll | 94 | .Fn strcoll |
72 | function first appeared in | 95 | function has been available since |
73 | .Bx 4.3 Reno . | 96 | .Bx 4.3 Reno , |
97 | and | ||
98 | .Fn strcoll_l | ||
99 | since | ||
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 | |||
9 | int | ||
10 | strcoll_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 |
48 | The | 52 | These functions map the error number |
49 | .Fn strerror | ||
50 | and | ||
51 | .Fn strerror_r | ||
52 | functions map the error number | ||
53 | .Fa errnum | 53 | .Fa errnum |
54 | to a language-dependent error message string. | 54 | to an error message string. |
55 | .Pp | 55 | .Pp |
56 | .Fn strerror | 56 | .Fn strerror |
57 | returns a string containing a maximum of | 57 | and |
58 | .Fn strerror_l | ||
59 | return a string containing a maximum of | ||
58 | .Dv NL_TEXTMAX | 60 | .Dv NL_TEXTMAX |
59 | characters, including the trailing NUL. | 61 | characters, including the trailing NUL. |
60 | This string is not to be modified by the calling program, | 62 | This string is not to be modified by the calling program. |
61 | but may be overwritten by subsequent calls to | 63 | The string returned by |
62 | .Fn strerror . | 64 | .Fn strerror |
65 | may be overwritten by subsequent calls to | ||
66 | .Fn strerror | ||
67 | in any thread. | ||
68 | The string returned by | ||
69 | .Fn strerror_l | ||
70 | may be overwritten by subsequent calls to | ||
71 | .Fn strerror_l | ||
72 | in the same thread. | ||
63 | .Pp | 73 | .Pp |
64 | .Fn strerror_r | 74 | .Fn strerror_r |
65 | is a thread safe version of | 75 | is a thread safe version of |
66 | .Fn strerror | 76 | .Fn strerror |
67 | that places the error message in the specified buffer | 77 | that places the error message in the specified buffer |
68 | .Fa strerrbuf . | 78 | .Fa strerrbuf . |
79 | .Pp | ||
80 | On | ||
81 | .Ox , | ||
82 | the global locale, the thread-specific locale, and the | ||
83 | .Fa locale | ||
84 | argument are ignored. | ||
69 | .Sh RETURN VALUES | 85 | .Sh RETURN VALUES |
70 | .Fn strerror | 86 | .Fn strerror |
71 | returns a pointer to the error message string. | 87 | and |
88 | .Fn strerror_l | ||
89 | return a pointer to the error message string. | ||
72 | If an error occurs, the error code is stored in | 90 | If 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. | |||
77 | If an error occurs, the error code is stored in | 95 | If an error occurs, the error code is stored in |
78 | .Va errno | 96 | .Va errno |
79 | and the error code is returned. | 97 | and the error code is returned. |
80 | .Sh ERRORS | 98 | .Sh ENVIRONMENT |
99 | On other operating systems, the behaviour of | ||
81 | .Fn strerror | 100 | .Fn strerror |
82 | and | 101 | and |
83 | .Fn strerror_r | 102 | .Fn strerror_r |
84 | may fail if: | 103 | may depend on the |
104 | .Dv LC_MESSAGES | ||
105 | .Xr locale 1 . | ||
106 | .Sh ERRORS | ||
107 | All 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 |
94 | may fail if: | 117 | may also fail if: |
95 | .Bl -tag -width Er | 118 | .Bl -tag -width Er |
96 | .It Bq Er ERANGE | 119 | .It Bq Er ERANGE |
97 | The error message is larger than | 120 | The 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 | |||
109 | function conforms to | 133 | function conforms to |
110 | .St -isoC-99 . | 134 | .St -isoC-99 . |
111 | The | 135 | The |
136 | .Fn strerror_l | ||
137 | and | ||
112 | .Fn strerror_r | 138 | .Fn strerror_r |
113 | function conforms to | 139 | functions conform to |
114 | .St -p1003.1-2008 . | 140 | .St -p1003.1-2008 . |
115 | .Sh HISTORY | 141 | .Sh HISTORY |
116 | The | 142 | The |
117 | .Fn strerror | 143 | .Fn strerror |
118 | function first appeared in | 144 | function has been available since |
119 | .Bx 4.3 Reno . | 145 | .Bx 4.3 Reno , |
120 | The | ||
121 | .Fn strerror_r | 146 | .Fn strerror_r |
122 | function first appeared in | 147 | since |
123 | .Ox 3.3 . | 148 | .Ox 3.3 , |
149 | and | ||
150 | .Fn strerror_l | ||
151 | since | ||
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 | |||
23 | char * | ||
24 | strerror_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 |
45 | The idea of | 49 | The idea of |
46 | .Fn strxfrm | 50 | .Fn strxfrm |
51 | and | ||
52 | .Fn strxfrm_l | ||
47 | is to | 53 | is to |
48 | .Dq un-localize | 54 | .Dq un-localize |
49 | a string: the function transforms | 55 | a string: the functions transform |
50 | .Ar src , | 56 | .Ar src , |
51 | storing the result in | 57 | storing the result in |
52 | .Ar dst , | 58 | .Ar dst , |
@@ -55,25 +61,42 @@ such that | |||
55 | on transformed strings returns what | 61 | on transformed strings returns what |
56 | .Xr strcoll 3 | 62 | .Xr strcoll 3 |
57 | on the original untransformed strings would return. | 63 | on the original untransformed strings would return. |
64 | .Pp | ||
65 | On | ||
66 | .Ox , | ||
67 | both have the same effect as | ||
68 | .Xr strlcpy 3 , | ||
69 | and the global locale, the thread-specific locale, and the | ||
70 | .Fa locale | ||
71 | argument are ignored. | ||
72 | .Sh ENVIRONMENT | ||
73 | On other operating systems, the behaviour of | ||
74 | .Fn strxfrm | ||
75 | may 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 |
66 | The | 86 | The |
67 | .Fn strxfrm | 87 | .Fn strxfrm |
68 | function conforms to | 88 | function conforms to |
69 | .St -ansiC . | 89 | .St -ansiC , |
90 | and | ||
91 | .Fn strxfrm_l | ||
92 | to | ||
93 | .St -p1003.1-2008 . | ||
70 | .Sh HISTORY | 94 | .Sh HISTORY |
71 | The | 95 | The |
72 | .Fn strxfrm | 96 | .Fn strxfrm |
73 | function first appeared in | 97 | function has been available since |
74 | .Bx 4.3 Reno . | 98 | .Bx 4.3 Reno , |
75 | .Sh BUGS | 99 | and |
76 | Since locales are not fully implemented on | 100 | .Fn strxfrm_l |
77 | .Ox , | 101 | since |
78 | .Fn strxfrm | 102 | .Ox 6.2 . |
79 | just 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 | |||
9 | size_t | ||
10 | strxfrm_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 |
48 | The | 71 | These functions compare the wide strings |
49 | .Fn wcscasecmp | ||
50 | and | ||
51 | .Fn wcsncasecmp | ||
52 | functions compare the wide strings | ||
53 | .Fa s1 | 72 | .Fa s1 |
54 | and | 73 | and |
55 | .Fa s2 | 74 | .Fa s2 |
@@ -61,28 +80,49 @@ is lexicographically greater than, equal to, or less than | |||
61 | after translation of each corresponding wide character to lower case. | 80 | after translation of each corresponding wide character to lower case. |
62 | The wide strings themselves are not modified. | 81 | The wide strings themselves are not modified. |
63 | .Pp | 82 | .Pp |
83 | For the translation to lower case, | ||
84 | .Fn wcscasecmp | ||
85 | and | ||
86 | .Fn wcsncasecmp | ||
87 | use the thread-specific locale as defined with | ||
88 | .Xr uselocale 3 , | ||
89 | falling back to the global locale defined with | ||
90 | .Xr setlocale 3 . | ||
91 | .Fn wcscasecmp_l | ||
92 | and | ||
93 | .Fn wcsncasecmp_l | ||
94 | use the | ||
95 | .Fa locale | ||
96 | argument instead. | ||
97 | .Pp | ||
64 | .Fn wcsncasecmp | 98 | .Fn wcsncasecmp |
65 | compares at most | 99 | and |
100 | .Fn wcsncasecmp_l | ||
101 | compare at most | ||
66 | .Fa len | 102 | .Fa len |
67 | wide characters. | 103 | wide 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 |
73 | The | 111 | These functions conform to |
74 | .Fn wcscasecmp | ||
75 | and | ||
76 | .Fn wcsncasecmp | ||
77 | functions conform to | ||
78 | .St -p1003.1-2008 . | 112 | .St -p1003.1-2008 . |
79 | .Sh HISTORY | 113 | .Sh HISTORY |
80 | The | 114 | The |
81 | .Fn wcscasecmp | 115 | .Fn wcscasecmp |
82 | and | 116 | and |
83 | .Fn wcsncasecmp | 117 | .Fn wcsncasecmp |
84 | functions first appeared in | 118 | functions have been available since |
85 | .Ox 5.0 . | 119 | .Ox 5.0 , |
120 | and | ||
121 | .Fn wcscasecmp_l | ||
122 | and | ||
123 | .Fn wcsncasecmp_l | ||
124 | since | ||
125 | .Ox 6.2 . | ||
86 | .Sh AUTHORS | 126 | .Sh AUTHORS |
87 | The | 127 | The |
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 | |||
32 | int | ||
33 | wcscasecmp_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 | |||
46 | int | ||
47 | wcsncasecmp_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 | } | ||