summaryrefslogtreecommitdiff
path: root/src/lib/libc/string
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/lib/libc/string
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to '')
-rw-r--r--src/lib/libc/string/Makefile.inc35
-rw-r--r--src/lib/libc/string/bcmp.367
-rw-r--r--src/lib/libc/string/bcmp.c52
-rw-r--r--src/lib/libc/string/bcopy.367
-rw-r--r--src/lib/libc/string/bcopy.c113
-rw-r--r--src/lib/libc/string/bzero.392
-rw-r--r--src/lib/libc/string/bzero.c45
-rw-r--r--src/lib/libc/string/explicit_bzero.c20
-rw-r--r--src/lib/libc/string/ffs.361
-rw-r--r--src/lib/libc/string/ffs.c40
-rw-r--r--src/lib/libc/string/memccpy.381
-rw-r--r--src/lib/libc/string/memccpy.c49
-rw-r--r--src/lib/libc/string/memchr.3102
-rw-r--r--src/lib/libc/string/memchr.c49
-rw-r--r--src/lib/libc/string/memcmp.386
-rw-r--r--src/lib/libc/string/memcmp.c52
-rw-r--r--src/lib/libc/string/memcpy.379
-rw-r--r--src/lib/libc/string/memcpy.c109
-rw-r--r--src/lib/libc/string/memmem.377
-rw-r--r--src/lib/libc/string/memmem.c184
-rw-r--r--src/lib/libc/string/memmove.376
-rw-r--r--src/lib/libc/string/memmove.c113
-rw-r--r--src/lib/libc/string/memrchr.c39
-rw-r--r--src/lib/libc/string/memset.375
-rw-r--r--src/lib/libc/string/memset.c48
-rw-r--r--src/lib/libc/string/stpcpy.3184
-rw-r--r--src/lib/libc/string/stpcpy.c44
-rw-r--r--src/lib/libc/string/stpncpy.c57
-rw-r--r--src/lib/libc/string/strcasecmp.3128
-rw-r--r--src/lib/libc/string/strcasecmp.c107
-rw-r--r--src/lib/libc/string/strcasecmp_l.c21
-rw-r--r--src/lib/libc/string/strcasestr.c61
-rw-r--r--src/lib/libc/string/strcat.376
-rw-r--r--src/lib/libc/string/strcat.c47
-rw-r--r--src/lib/libc/string/strchr.3116
-rw-r--r--src/lib/libc/string/strchr.c46
-rw-r--r--src/lib/libc/string/strcmp.395
-rw-r--r--src/lib/libc/string/strcmp.c48
-rw-r--r--src/lib/libc/string/strcoll.3103
-rw-r--r--src/lib/libc/string/strcoll.c45
-rw-r--r--src/lib/libc/string/strcoll_l.c14
-rw-r--r--src/lib/libc/string/strcpy.382
-rw-r--r--src/lib/libc/string/strcpy.c46
-rw-r--r--src/lib/libc/string/strcspn.3108
-rw-r--r--src/lib/libc/string/strcspn.c59
-rw-r--r--src/lib/libc/string/strdup.3119
-rw-r--r--src/lib/libc/string/strdup.c50
-rw-r--r--src/lib/libc/string/strerror.3154
-rw-r--r--src/lib/libc/string/strerror.c42
-rw-r--r--src/lib/libc/string/strerror_l.c33
-rw-r--r--src/lib/libc/string/strerror_r.c107
-rw-r--r--src/lib/libc/string/strlcat.c56
-rw-r--r--src/lib/libc/string/strlcpy.3195
-rw-r--r--src/lib/libc/string/strlcpy.c51
-rw-r--r--src/lib/libc/string/strlen.3103
-rw-r--r--src/lib/libc/string/strlen.c44
-rw-r--r--src/lib/libc/string/strmode.3153
-rw-r--r--src/lib/libc/string/strmode.c139
-rw-r--r--src/lib/libc/string/strncat.3132
-rw-r--r--src/lib/libc/string/strncat.c58
-rw-r--r--src/lib/libc/string/strncmp.c48
-rw-r--r--src/lib/libc/string/strncpy.3138
-rw-r--r--src/lib/libc/string/strncpy.c59
-rw-r--r--src/lib/libc/string/strndup.c40
-rw-r--r--src/lib/libc/string/strnlen.c33
-rw-r--r--src/lib/libc/string/strpbrk.380
-rw-r--r--src/lib/libc/string/strpbrk.c49
-rw-r--r--src/lib/libc/string/strrchr.3118
-rw-r--r--src/lib/libc/string/strrchr.c48
-rw-r--r--src/lib/libc/string/strsep.3110
-rw-r--r--src/lib/libc/string/strsep.c71
-rw-r--r--src/lib/libc/string/strsignal.378
-rw-r--r--src/lib/libc/string/strsignal.c40
-rw-r--r--src/lib/libc/string/strspn.392
-rw-r--r--src/lib/libc/string/strspn.c52
-rw-r--r--src/lib/libc/string/strstr.3101
-rw-r--r--src/lib/libc/string/strstr.c189
-rw-r--r--src/lib/libc/string/strtok.3169
-rw-r--r--src/lib/libc/string/strtok.c87
-rw-r--r--src/lib/libc/string/strxfrm.3105
-rw-r--r--src/lib/libc/string/strxfrm.c52
-rw-r--r--src/lib/libc/string/strxfrm_l.c14
-rw-r--r--src/lib/libc/string/swab.379
-rw-r--r--src/lib/libc/string/swab.c35
-rw-r--r--src/lib/libc/string/timingsafe_bcmp.387
-rw-r--r--src/lib/libc/string/timingsafe_bcmp.c30
-rw-r--r--src/lib/libc/string/timingsafe_memcmp.c47
-rw-r--r--src/lib/libc/string/wcscasecmp.3134
-rw-r--r--src/lib/libc/string/wcscasecmp.c63
-rw-r--r--src/lib/libc/string/wcscasecmp_l.c63
-rw-r--r--src/lib/libc/string/wcscat.3115
-rw-r--r--src/lib/libc/string/wcscat.c56
-rw-r--r--src/lib/libc/string/wcschr.385
-rw-r--r--src/lib/libc/string/wcschr.c50
-rw-r--r--src/lib/libc/string/wcscmp.392
-rw-r--r--src/lib/libc/string/wcscmp.c52
-rw-r--r--src/lib/libc/string/wcscpy.3129
-rw-r--r--src/lib/libc/string/wcscpy.c52
-rw-r--r--src/lib/libc/string/wcscspn.383
-rw-r--r--src/lib/libc/string/wcscspn.c54
-rw-r--r--src/lib/libc/string/wcsdup.397
-rw-r--r--src/lib/libc/string/wcsdup.c32
-rw-r--r--src/lib/libc/string/wcslcat.c56
-rw-r--r--src/lib/libc/string/wcslcpy.3160
-rw-r--r--src/lib/libc/string/wcslcpy.c51
-rw-r--r--src/lib/libc/string/wcslen.3102
-rw-r--r--src/lib/libc/string/wcslen.c45
-rw-r--r--src/lib/libc/string/wcsncat.c53
-rw-r--r--src/lib/libc/string/wcsncmp.c53
-rw-r--r--src/lib/libc/string/wcsncpy.c51
-rw-r--r--src/lib/libc/string/wcsnlen.c45
-rw-r--r--src/lib/libc/string/wcspbrk.381
-rw-r--r--src/lib/libc/string/wcspbrk.c53
-rw-r--r--src/lib/libc/string/wcsrchr.385
-rw-r--r--src/lib/libc/string/wcsrchr.c50
-rw-r--r--src/lib/libc/string/wcsspn.379
-rw-r--r--src/lib/libc/string/wcsspn.c56
-rw-r--r--src/lib/libc/string/wcsstr.388
-rw-r--r--src/lib/libc/string/wcsstr.c71
-rw-r--r--src/lib/libc/string/wcstok.3151
-rw-r--r--src/lib/libc/string/wcstok.c93
-rw-r--r--src/lib/libc/string/wcswcs.c5
-rw-r--r--src/lib/libc/string/wcswidth.369
-rw-r--r--src/lib/libc/string/wcswidth.c51
-rw-r--r--src/lib/libc/string/wmemchr.381
-rw-r--r--src/lib/libc/string/wmemchr.c47
-rw-r--r--src/lib/libc/string/wmemcmp.378
-rw-r--r--src/lib/libc/string/wmemcmp.c51
-rw-r--r--src/lib/libc/string/wmemcpy.379
-rw-r--r--src/lib/libc/string/wmemcpy.c41
-rw-r--r--src/lib/libc/string/wmemmove.378
-rw-r--r--src/lib/libc/string/wmemmove.c41
-rw-r--r--src/lib/libc/string/wmemset.373
-rw-r--r--src/lib/libc/string/wmemset.c47
134 files changed, 0 insertions, 10106 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc
deleted file mode 100644
index 204ca1b266..0000000000
--- a/src/lib/libc/string/Makefile.inc
+++ /dev/null
@@ -1,35 +0,0 @@
1# $OpenBSD: Makefile.inc,v 1.40 2024/07/14 09:51:18 jca Exp $
2
3# string sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string
5
6SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \
7 strcasecmp.c strcasecmp_l.c strcasestr.c strcoll.c strcoll_l.c \
8 strdup.c strerror.c strerror_l.c strerror_r.c strmode.c \
9 strndup.c strnlen.c strsignal.c strtok.c strxfrm.c strxfrm_l.c \
10 timingsafe_bcmp.c timingsafe_memcmp.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 wcsnlen.c wcspbrk.c wcsrchr.c \
13 wcsspn.c wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c \
14 wmemcpy.c wmemmove.c wmemset.c wcsdup.c wcscasecmp.c wcscasecmp_l.c
15
16# machine-dependent net sources
17# ../arch/ARCH/Makefile.inc must include sources for:
18# bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset()
19# memcpy() memmove() memset() rindex() strcat() strchr()
20# strcmp() strcpy() strcspn() strlen() strlcat() strlcpy()
21# strncat() strncmp() strncpy() strpbrk() strrchr() strsep()
22# strspn() strstr() swab()
23
24.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/string/Makefile.inc"
25
26MAN+= bcmp.3 bcopy.3 bzero.3 ffs.3 memccpy.3 memchr.3 \
27 memcmp.3 memcpy.3 memmem.3 memmove.3 memset.3 stpcpy.3 strcasecmp.3 \
28 strcat.3 strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strdup.3 \
29 strerror.3 strlen.3 strmode.3 strncat.3 strncpy.3 strpbrk.3 \
30 strrchr.3 strsep.3 strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 \
31 swab.3 strlcpy.3 timingsafe_bcmp.3 \
32 wcscasecmp.3 wcscat.3 wcschr.3 wcscmp.3 wcscpy.3 \
33 wcscspn.3 wcsdup.3 wcslcpy.3 wcslen.3 wcspbrk.3 wcsrchr.3 wcsspn.3 \
34 wcsstr.3 wcstok.3 wcswidth.3 wmemchr.3 wmemcmp.3 wmemcpy.3 wmemmove.3 \
35 wmemset.3
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3
deleted file mode 100644
index a3cb1dfb74..0000000000
--- a/src/lib/libc/string/bcmp.3
+++ /dev/null
@@ -1,67 +0,0 @@
1.\" Copyright (c) 1990, 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.\" Chris Torek.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $OpenBSD: bcmp.3,v 1.12 2015/11/24 09:14:35 daniel Exp $
31.\"
32.Dd $Mdocdate: November 24 2015 $
33.Dt BCMP 3
34.Os
35.Sh NAME
36.Nm bcmp
37.Nd compare byte string
38.Sh SYNOPSIS
39.In strings.h
40.Ft int
41.Fn bcmp "const void *b1" "const void *b2" "size_t len"
42.Sh DESCRIPTION
43The
44.Fn bcmp
45function compares byte string
46.Fa b1
47against byte string
48.Fa b2 ,
49returning zero if they are identical, non-zero otherwise.
50Both strings are assumed to be
51.Fa len
52bytes long.
53Zero-length strings are always identical.
54.Pp
55The strings may overlap.
56.Sh SEE ALSO
57.Xr memcmp 3 ,
58.Xr strcasecmp 3 ,
59.Xr strcmp 3 ,
60.Xr strcoll 3 ,
61.Xr strxfrm 3 ,
62.Xr timingsafe_bcmp 3
63.Sh HISTORY
64The
65.Fn bcmp
66function first appeared in
67.Bx 4.2 .
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c
deleted file mode 100644
index 5d446bf096..0000000000
--- a/src/lib/libc/string/bcmp.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: bcmp.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */
2
3/*
4 * Copyright (c) 1987 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34/*
35 * bcmp -- vax cmpc3 instruction
36 */
37int
38bcmp(const void *b1, const void *b2, size_t length)
39{
40 char *p1, *p2;
41
42 if (length == 0)
43 return (0);
44 p1 = (char *)b1;
45 p2 = (char *)b2;
46 do
47 if (*p1++ != *p2++)
48 return (1);
49 while (--length);
50 return (0);
51}
52DEF_WEAK(bcmp);
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3
deleted file mode 100644
index 68c63f92ec..0000000000
--- a/src/lib/libc/string/bcopy.3
+++ /dev/null
@@ -1,67 +0,0 @@
1.\" Copyright (c) 1990, 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.\" Chris Torek.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" $OpenBSD: bcopy.3,v 1.12 2015/11/24 09:14:35 daniel Exp $
32.\"
33.Dd $Mdocdate: November 24 2015 $
34.Dt BCOPY 3
35.Os
36.Sh NAME
37.Nm bcopy
38.Nd copy bytes
39.Sh SYNOPSIS
40.In strings.h
41.Ft void
42.Fn bcopy "const void *src" "void *dst" "size_t len"
43.Sh DESCRIPTION
44The
45.Fn bcopy
46function copies
47.Fa len
48bytes from buffer
49.Fa src
50to buffer
51.Fa dst .
52The two buffers may overlap.
53If
54.Fa len
55is zero, no bytes are copied.
56.Sh SEE ALSO
57.Xr memccpy 3 ,
58.Xr memcpy 3 ,
59.Xr memmove 3 ,
60.Xr strcpy 3 ,
61.Xr strlcpy 3 ,
62.Xr strncpy 3
63.Sh HISTORY
64The
65.Fn bcopy
66function first appeared in
67.Bx 4.2 .
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c
deleted file mode 100644
index ef0d368053..0000000000
--- a/src/lib/libc/string/bcopy.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/* $OpenBSD: bcopy.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * sizeof(word) MUST BE A POWER OF TWO
38 * SO THAT wmask BELOW IS ALL ONES
39 */
40typedef long word; /* "word" used for optimal copy speed */
41
42#define wsize sizeof(word)
43#define wmask (wsize - 1)
44
45/*
46 * Copy a block of memory, handling overlap.
47 */
48void
49bcopy(const void *src0, void *dst0, size_t length)
50{
51 char *dst = dst0;
52 const char *src = src0;
53 size_t t;
54
55 if (length == 0 || dst == src) /* nothing to do */
56 goto done;
57
58 /*
59 * Macros: loop-t-times; and loop-t-times, t>0
60 */
61#define TLOOP(s) if (t) TLOOP1(s)
62#define TLOOP1(s) do { s; } while (--t)
63
64 if ((unsigned long)dst < (unsigned long)src) {
65 /*
66 * Copy forward.
67 */
68 t = (long)src; /* only need low bits */
69 if ((t | (long)dst) & wmask) {
70 /*
71 * Try to align operands. This cannot be done
72 * unless the low bits match.
73 */
74 if ((t ^ (long)dst) & wmask || length < wsize)
75 t = length;
76 else
77 t = wsize - (t & wmask);
78 length -= t;
79 TLOOP1(*dst++ = *src++);
80 }
81 /*
82 * Copy whole words, then mop up any trailing bytes.
83 */
84 t = length / wsize;
85 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
86 t = length & wmask;
87 TLOOP(*dst++ = *src++);
88 } else {
89 /*
90 * Copy backwards. Otherwise essentially the same.
91 * Alignment works as before, except that it takes
92 * (t&wmask) bytes to align, not wsize-(t&wmask).
93 */
94 src += length;
95 dst += length;
96 t = (long)src;
97 if ((t | (long)dst) & wmask) {
98 if ((t ^ (long)dst) & wmask || length <= wsize)
99 t = length;
100 else
101 t &= wmask;
102 length -= t;
103 TLOOP1(*--dst = *--src);
104 }
105 t = length / wsize;
106 TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
107 t = length & wmask;
108 TLOOP(*--dst = *--src);
109 }
110done:
111 return;
112}
113DEF_WEAK(bcopy);
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3
deleted file mode 100644
index 87a23e20bb..0000000000
--- a/src/lib/libc/string/bzero.3
+++ /dev/null
@@ -1,92 +0,0 @@
1.\" Copyright (c) 1990, 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.\" Chris Torek.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $OpenBSD: bzero.3,v 1.13 2017/10/12 15:22:32 schwarze Exp $
31.\"
32.Dd $Mdocdate: October 12 2017 $
33.Dt BZERO 3
34.Os
35.Sh NAME
36.Nm bzero ,
37.Nm explicit_bzero
38.Nd write zeroes to a byte string
39.Sh SYNOPSIS
40.In strings.h
41.Ft void
42.Fn bzero "void *b" "size_t len"
43.In string.h
44.Ft void
45.Fn explicit_bzero "void *b" "size_t len"
46.Sh DESCRIPTION
47The
48.Fn bzero
49function writes
50.Fa len
51zero bytes to the string
52.Fa b .
53If
54.Fa len
55is zero,
56.Fn bzero
57does nothing.
58.Pp
59The
60.Fn explicit_bzero
61variant behaves the same, but will not be removed by a compiler's dead store
62optimization pass, making it useful for clearing sensitive memory such as a
63password.
64.Sh SEE ALSO
65.Xr memset 3 ,
66.Xr swab 3
67.Sh STANDARDS
68The
69.Fn bzero
70function conforms to the X/Open System Interfaces option of the
71.St -p1003.1-2004
72specification.
73It was removed from the standard in
74.St -p1003.1-2008 ,
75which recommends using
76.Xr memset 3
77instead.
78.Pp
79The
80.Fn explicit_bzero
81function is an
82.Ox
83extension.
84.Sh HISTORY
85The
86.Fn bzero
87function first appeared in
88.Bx 4.2 .
89The
90.Fn explicit_bzero
91function first appeared in
92.Ox 5.5 .
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c
deleted file mode 100644
index 5173de26dd..0000000000
--- a/src/lib/libc/string/bzero.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/* $OpenBSD: bzero.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
2
3/*
4 * Copyright (c) 1987 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34/*
35 * bzero -- vax movc5 instruction
36 */
37void
38bzero(void *b, size_t length)
39{
40 char *p;
41
42 for (p = b; length--;)
43 *p++ = '\0';
44}
45DEF_WEAK(bzero);
diff --git a/src/lib/libc/string/explicit_bzero.c b/src/lib/libc/string/explicit_bzero.c
deleted file mode 100644
index 003ea7cc4c..0000000000
--- a/src/lib/libc/string/explicit_bzero.c
+++ /dev/null
@@ -1,20 +0,0 @@
1/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Public domain.
4 * Written by Matthew Dempsky.
5 */
6
7#include <string.h>
8
9__attribute__((weak)) void
10__explicit_bzero_hook(void *buf, size_t len)
11{
12}
13
14void
15explicit_bzero(void *buf, size_t len)
16{
17 memset(buf, 0, len);
18 __explicit_bzero_hook(buf, len);
19}
20DEF_WEAK(explicit_bzero);
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3
deleted file mode 100644
index e78ab99e8f..0000000000
--- a/src/lib/libc/string/ffs.3
+++ /dev/null
@@ -1,61 +0,0 @@
1.\" Copyright (c) 1990, 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.\" Chris Torek.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $OpenBSD: ffs.3,v 1.11 2019/08/30 18:35:03 deraadt Exp $
31.\"
32.Dd $Mdocdate: August 30 2019 $
33.Dt FFS 3
34.Os
35.Sh NAME
36.Nm ffs
37.Nd find first bit set in a bit string
38.Sh SYNOPSIS
39.In strings.h
40.Ft int
41.Fn ffs "int value"
42.Sh DESCRIPTION
43The
44.Fn ffs
45function finds the first bit set in
46.Fa value
47and returns the index of that bit.
48Bits are numbered starting from 1, starting at the rightmost bit.
49A return value of 0 means that the argument was zero.
50.Sh SEE ALSO
51.Xr bit_ffs 3
52.Sh STANDARDS
53The
54.Fn ffs
55function conforms to
56.St -p1003.1-2008 .
57.Sh HISTORY
58The
59.Fn ffs
60function first appeared in
61.Bx 4.2 .
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c
deleted file mode 100644
index 09d6e35eca..0000000000
--- a/src/lib/libc/string/ffs.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/* $OpenBSD: ffs.c,v 1.10 2018/01/18 08:23:44 guenther Exp $ */
2
3/*
4 * Public domain.
5 * Written by Dale Rahn.
6 */
7
8#include <string.h>
9
10/*
11 * ffs -- vax ffs instruction
12 */
13int
14ffs(int mask)
15{
16 int bit;
17 unsigned int r = mask;
18 static const signed char t[16] = {
19 -28, 1, 2, 1,
20 3, 1, 2, 1,
21 4, 1, 2, 1,
22 3, 1, 2, 1
23 };
24
25 bit = 0;
26 if (!(r & 0xffff)) {
27 bit += 16;
28 r >>= 16;
29 }
30 if (!(r & 0xff)) {
31 bit += 8;
32 r >>= 8;
33 }
34 if (!(r & 0xf)) {
35 bit += 4;
36 r >>= 4;
37 }
38
39 return (bit + t[ r & 0xf ]);
40}
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3
deleted file mode 100644
index 49b8ab5d26..0000000000
--- a/src/lib/libc/string/memccpy.3
+++ /dev/null
@@ -1,81 +0,0 @@
1.\" $OpenBSD: memccpy.3,v 1.14 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93
31.\"
32.Dd $Mdocdate: December 11 2024 $
33.Dt MEMCCPY 3
34.Os
35.Sh NAME
36.Nm memccpy
37.Nd copy string until character found
38.Sh SYNOPSIS
39.In string.h
40.Ft void *
41.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
42.Sh DESCRIPTION
43The
44.Fn memccpy
45function copies bytes from string
46.Fa src
47to string
48.Fa dst .
49If the character
50.Fa c
51(as converted to an
52.Vt unsigned char )
53occurs in the string
54.Fa src ,
55the copy stops and a pointer to the byte after the copy of
56.Fa c
57in the string
58.Fa dst
59is returned.
60Otherwise,
61.Fa len
62bytes are copied, and a null pointer is returned.
63.Pp
64If the
65.Fa src
66and
67.Fa dst
68strings overlap, the behavior is undefined.
69.Sh SEE ALSO
70.Xr bcopy 3 ,
71.Xr memcpy 3 ,
72.Xr memmove 3 ,
73.Xr strcpy 3 ,
74.Xr strlcpy 3
75.Sh HISTORY
76The
77.Fn memccpy
78function first appeared in
79.At V
80and was reimplemented for
81.Bx 4.3 .
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c
deleted file mode 100644
index 635061b8cb..0000000000
--- a/src/lib/libc/string/memccpy.c
+++ /dev/null
@@ -1,49 +0,0 @@
1/* $OpenBSD: memccpy.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34void *
35memccpy(void *t, const void *f, int c, size_t n)
36{
37
38 if (n) {
39 unsigned char *tp = t;
40 const unsigned char *fp = f;
41 unsigned char uc = c;
42 do {
43 if ((*tp++ = *fp++) == uc)
44 return (tp);
45 } while (--n != 0);
46 }
47 return (0);
48}
49DEF_WEAK(memccpy);
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3
deleted file mode 100644
index fa5809fa98..0000000000
--- a/src/lib/libc/string/memchr.3
+++ /dev/null
@@ -1,102 +0,0 @@
1.\" $OpenBSD: memchr.3,v 1.14 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt MEMCHR 3
36.Os
37.Sh NAME
38.Nm memchr ,
39.Nm memrchr
40.Nd locate byte in byte string
41.Sh SYNOPSIS
42.In string.h
43.Ft void *
44.Fn memchr "const void *b" "int c" "size_t len"
45.Ft void *
46.Fn memrchr "const void *b" "int c" "size_t len"
47.Sh DESCRIPTION
48The
49.Fn memchr
50function locates the first occurrence of
51.Fa c
52(converted to an
53.Vt unsigned char )
54in string
55.Fa b .
56.Pp
57The
58.Fn memrchr
59function behaves like
60.Fn memchr ,
61except that it locates the last occurrence of
62.Fa c
63in string
64.Fa b .
65.Sh RETURN VALUES
66The
67.Fn memchr
68and
69.Fn memrchr
70functions return a pointer to the byte located, or
71.Dv NULL
72if no such byte exists within
73.Fa len
74bytes.
75.Sh SEE ALSO
76.Xr strchr 3 ,
77.Xr strcspn 3 ,
78.Xr strpbrk 3 ,
79.Xr strrchr 3 ,
80.Xr strsep 3 ,
81.Xr strspn 3 ,
82.Xr strstr 3 ,
83.Xr strtok 3 ,
84.Xr wmemchr 3
85.Sh STANDARDS
86The
87.Fn memchr
88function conforms to
89.St -ansiC .
90.Pp
91The
92.Fn memrchr
93function is an
94.Ox
95extension.
96.Sh HISTORY
97The
98.Fn memchr
99function first appeared in
100.At V
101and was reimplemented for
102.Bx 4.3 .
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c
deleted file mode 100644
index a6a4bd60d0..0000000000
--- a/src/lib/libc/string/memchr.c
+++ /dev/null
@@ -1,49 +0,0 @@
1/* $OpenBSD: memchr.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36void *
37memchr(const void *s, int c, size_t n)
38{
39 if (n != 0) {
40 const unsigned char *p = s;
41
42 do {
43 if (*p++ == (unsigned char)c)
44 return ((void *)(p - 1));
45 } while (--n != 0);
46 }
47 return (NULL);
48}
49DEF_STRONG(memchr);
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3
deleted file mode 100644
index ace8f79255..0000000000
--- a/src/lib/libc/string/memcmp.3
+++ /dev/null
@@ -1,86 +0,0 @@
1.\" $OpenBSD: memcmp.3,v 1.11 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt MEMCMP 3
36.Os
37.Sh NAME
38.Nm memcmp
39.Nd compare byte string
40.Sh SYNOPSIS
41.In string.h
42.Ft int
43.Fn memcmp "const void *b1" "const void *b2" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn memcmp
47function compares byte string
48.Fa b1
49against byte string
50.Fa b2 .
51Both strings are assumed to be
52.Fa len
53bytes long.
54.Sh RETURN VALUES
55The
56.Fn memcmp
57function returns zero if the two strings are identical,
58otherwise returns the difference between the first two differing bytes
59(treated as
60.Vt unsigned char
61values, so that
62.Sq Li \e200
63is greater than
64.Sq Li \&\e0 ,
65for example).
66Zero-length strings are always identical.
67.Sh SEE ALSO
68.Xr bcmp 3 ,
69.Xr strcasecmp 3 ,
70.Xr strcmp 3 ,
71.Xr strcoll 3 ,
72.Xr strxfrm 3 ,
73.Xr timingsafe_memcmp 3 ,
74.Xr wmemcmp 3
75.Sh STANDARDS
76The
77.Fn memcmp
78function conforms to
79.St -ansiC .
80.Sh HISTORY
81The
82.Fn memcmp
83function first appeared in
84.At V
85and was reimplemented for
86.Bx 4.3 .
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c
deleted file mode 100644
index 0df2c54d2a..0000000000
--- a/src/lib/libc/string/memcmp.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: memcmp.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * Compare memory regions.
38 */
39int
40memcmp(const void *s1, const void *s2, size_t n)
41{
42 if (n != 0) {
43 const unsigned char *p1 = s1, *p2 = s2;
44
45 do {
46 if (*p1++ != *p2++)
47 return (*--p1 - *--p2);
48 } while (--n != 0);
49 }
50 return (0);
51}
52DEF_STRONG(memcmp);
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3
deleted file mode 100644
index b093afc919..0000000000
--- a/src/lib/libc/string/memcpy.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" $OpenBSD: memcpy.3,v 1.11 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt MEMCPY 3
36.Os
37.Sh NAME
38.Nm memcpy
39.Nd copy bytes
40.Sh SYNOPSIS
41.In string.h
42.Ft void *
43.Fn memcpy "void *dst" "const void *src" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn memcpy
47function copies
48.Fa len
49bytes from buffer
50.Fa src
51to buffer
52.Fa dst .
53If the two buffers may overlap,
54.Xr memmove 3
55must be used instead.
56.Sh RETURN VALUES
57The
58.Fn memcpy
59function returns the original value of
60.Fa dst .
61.Sh SEE ALSO
62.Xr bcopy 3 ,
63.Xr memccpy 3 ,
64.Xr memmove 3 ,
65.Xr strcpy 3 ,
66.Xr strlcpy 3 ,
67.Xr wmemcpy 3
68.Sh STANDARDS
69The
70.Fn memcpy
71function conforms to
72.St -ansiC .
73.Sh HISTORY
74The
75.Fn memcpy
76function first appeared in
77.At V
78and was reimplemented for
79.Bx 4.3 .
diff --git a/src/lib/libc/string/memcpy.c b/src/lib/libc/string/memcpy.c
deleted file mode 100644
index 19fddc0ab5..0000000000
--- a/src/lib/libc/string/memcpy.c
+++ /dev/null
@@ -1,109 +0,0 @@
1/* $OpenBSD: memcpy.c,v 1.4 2017/11/29 05:13:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35#include <stdlib.h>
36#include <syslog.h>
37
38/*
39 * sizeof(word) MUST BE A POWER OF TWO
40 * SO THAT wmask BELOW IS ALL ONES
41 */
42typedef long word; /* "word" used for optimal copy speed */
43
44#define wsize sizeof(word)
45#define wmask (wsize - 1)
46
47static const char backwards_msg[] = ": backwards memcpy";
48
49/*
50 * Copy a block of memory, not handling overlap.
51 */
52void *
53memcpy(void *dst0, const void *src0, size_t length)
54{
55 char *dst = dst0;
56 const char *src = src0;
57 size_t t;
58
59 if (length == 0 || dst == src) /* nothing to do */
60 goto done;
61
62 if ((dst < src && dst + length > src) ||
63 (src < dst && src + length > dst)) {
64 char buf[1024];
65
66 /* <10> is LOG_CRIT */
67 strlcpy(buf, "<10>", sizeof buf);
68
69 /* Make sure progname does not fill the whole buffer */
70 strlcat(buf, __progname, sizeof(buf) - sizeof backwards_msg);
71 strlcat(buf, backwards_msg, sizeof buf);
72
73 sendsyslog(buf, strlen(buf), LOG_CONS);
74 abort();
75 }
76
77 /*
78 * Macros: loop-t-times; and loop-t-times, t>0
79 */
80#define TLOOP(s) if (t) TLOOP1(s)
81#define TLOOP1(s) do { s; } while (--t)
82
83 /*
84 * Copy forward.
85 */
86 t = (long)src; /* only need low bits */
87 if ((t | (long)dst) & wmask) {
88 /*
89 * Try to align operands. This cannot be done
90 * unless the low bits match.
91 */
92 if ((t ^ (long)dst) & wmask || length < wsize)
93 t = length;
94 else
95 t = wsize - (t & wmask);
96 length -= t;
97 TLOOP1(*dst++ = *src++);
98 }
99 /*
100 * Copy whole words, then mop up any trailing bytes.
101 */
102 t = length / wsize;
103 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
104 t = length & wmask;
105 TLOOP(*dst++ = *src++);
106done:
107 return (dst0);
108}
109DEF_BUILTIN(memcpy);
diff --git a/src/lib/libc/string/memmem.3 b/src/lib/libc/string/memmem.3
deleted file mode 100644
index de62d738de..0000000000
--- a/src/lib/libc/string/memmem.3
+++ /dev/null
@@ -1,77 +0,0 @@
1.\" $OpenBSD: memmem.3,v 1.4 2024/08/03 20:13:23 guenther Exp $
2.\"
3.\" Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
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. The name of the author may not be used to endorse or promote
14.\" products derived from this software without specific prior written
15.\" permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.Dd $Mdocdate: August 3 2024 $
30.Dt MEMMEM 3
31.Os
32.Sh NAME
33.Nm memmem
34.Nd locate a byte substring in a byte string
35.Sh SYNOPSIS
36.In string.h
37.Ft "void *"
38.Fo memmem
39.Fa "const void *big" "size_t big_len"
40.Fa "const void *little" "size_t little_len"
41.Fc
42.Sh DESCRIPTION
43The
44.Fn memmem
45function
46locates the first occurrence of the byte string
47.Fa little
48in the byte string
49.Fa big .
50.Sh RETURN VALUES
51If
52.Fa little
53is zero length,
54.Fa big
55is returned; if
56.Fa little
57occurs nowhere in
58.Fa big ,
59.Dv NULL
60is returned;
61otherwise a pointer to the first character of the first occurrence of
62.Fa little
63is returned.
64.Sh SEE ALSO
65.Xr memchr 3 ,
66.Xr strchr 3 ,
67.Xr strstr 3
68.Sh STANDARDS
69The
70.Fn memmem
71function conforms to
72.St -p1003.1-2024 .
73.Sh HISTORY
74The
75.Fn memmem
76function first appeared in
77.Ox 5.4 .
diff --git a/src/lib/libc/string/memmem.c b/src/lib/libc/string/memmem.c
deleted file mode 100644
index 3b180b4a62..0000000000
--- a/src/lib/libc/string/memmem.c
+++ /dev/null
@@ -1,184 +0,0 @@
1/* $OpenBSD: memmem.c,v 1.5 2020/04/16 12:39:28 claudio Exp $ */
2
3/*
4 * Copyright (c) 2005-2020 Rich Felker, et al.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <string.h>
27#include <stdint.h>
28
29static char *
30twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
31{
32 uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
33 for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++)
34 if (hw == nw) return (char *)h-2;
35 return hw == nw ? (char *)h-2 : 0;
36}
37
38static char *
39threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
40{
41 uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
42 uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
43 for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8)
44 if (hw == nw) return (char *)h-3;
45 return hw == nw ? (char *)h-3 : 0;
46}
47
48static char *
49fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
50{
51 uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
52 uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
53 for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++)
54 if (hw == nw) return (char *)h-4;
55 return hw == nw ? (char *)h-4 : 0;
56}
57
58#define MAX(a,b) ((a)>(b)?(a):(b))
59#define MIN(a,b) ((a)<(b)?(a):(b))
60
61#define BITOP(a,b,op) \
62 ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
63
64/*
65 * Maxime Crochemore and Dominique Perrin, Two-way string-matching,
66 * Journal of the ACM, 38(3):651-675, July 1991.
67 */
68static char *
69twoway_memmem(const unsigned char *h, const unsigned char *z,
70 const unsigned char *n, size_t l)
71{
72 size_t i, ip, jp, k, p, ms, p0, mem, mem0;
73 size_t byteset[32 / sizeof(size_t)] = { 0 };
74 size_t shift[256];
75
76 /* Computing length of needle and fill shift table */
77 for (i=0; i<l; i++)
78 BITOP(byteset, n[i], |=), shift[n[i]] = i+1;
79
80 /* Compute maximal suffix */
81 ip = -1; jp = 0; k = p = 1;
82 while (jp+k<l) {
83 if (n[ip+k] == n[jp+k]) {
84 if (k == p) {
85 jp += p;
86 k = 1;
87 } else k++;
88 } else if (n[ip+k] > n[jp+k]) {
89 jp += k;
90 k = 1;
91 p = jp - ip;
92 } else {
93 ip = jp++;
94 k = p = 1;
95 }
96 }
97 ms = ip;
98 p0 = p;
99
100 /* And with the opposite comparison */
101 ip = -1; jp = 0; k = p = 1;
102 while (jp+k<l) {
103 if (n[ip+k] == n[jp+k]) {
104 if (k == p) {
105 jp += p;
106 k = 1;
107 } else k++;
108 } else if (n[ip+k] < n[jp+k]) {
109 jp += k;
110 k = 1;
111 p = jp - ip;
112 } else {
113 ip = jp++;
114 k = p = 1;
115 }
116 }
117 if (ip+1 > ms+1) ms = ip;
118 else p = p0;
119
120 /* Periodic needle? */
121 if (memcmp(n, n+p, ms+1)) {
122 mem0 = 0;
123 p = MAX(ms, l-ms-1) + 1;
124 } else mem0 = l-p;
125 mem = 0;
126
127 /* Search loop */
128 for (;;) {
129 /* If remainder of haystack is shorter than needle, done */
130 if (z-h < l) return 0;
131
132 /* Check last byte first; advance by shift on mismatch */
133 if (BITOP(byteset, h[l-1], &)) {
134 k = l-shift[h[l-1]];
135 if (k) {
136 if (k < mem) k = mem;
137 h += k;
138 mem = 0;
139 continue;
140 }
141 } else {
142 h += l;
143 mem = 0;
144 continue;
145 }
146
147 /* Compare right half */
148 for (k=MAX(ms+1,mem); k<l && n[k] == h[k]; k++);
149 if (k < l) {
150 h += k-ms;
151 mem = 0;
152 continue;
153 }
154 /* Compare left half */
155 for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--);
156 if (k <= mem) return (char *)h;
157 h += p;
158 mem = mem0;
159 }
160}
161
162void *
163memmem(const void *h0, size_t k, const void *n0, size_t l)
164{
165 const unsigned char *h = h0, *n = n0;
166
167 /* Return immediately on empty needle */
168 if (!l) return (void *)h;
169
170 /* Return immediately when needle is longer than haystack */
171 if (k<l) return 0;
172
173 /* Use faster algorithms for short needles */
174 h = memchr(h0, *n, k);
175 if (!h || l==1) return (void *)h;
176 k -= h - (const unsigned char *)h0;
177 if (k<l) return 0;
178 if (l==2) return twobyte_memmem(h, k, n);
179 if (l==3) return threebyte_memmem(h, k, n);
180 if (l==4) return fourbyte_memmem(h, k, n);
181
182 return twoway_memmem(h, h+k, n, l);
183}
184DEF_WEAK(memmem);
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3
deleted file mode 100644
index 8665e4abcf..0000000000
--- a/src/lib/libc/string/memmove.3
+++ /dev/null
@@ -1,76 +0,0 @@
1.\" $OpenBSD: memmove.3,v 1.9 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt MEMMOVE 3
36.Os
37.Sh NAME
38.Nm memmove
39.Nd copy bytes
40.Sh SYNOPSIS
41.In string.h
42.Ft void *
43.Fn memmove "void *dst" "const void *src" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn memmove
47function copies
48.Fa len
49bytes from buffer
50.Fa src
51to buffer
52.Fa dst .
53The two buffers may overlap;
54the copy is always done in a non-destructive manner.
55.Sh RETURN VALUES
56The
57.Fn memmove
58function returns the original value of
59.Fa dst .
60.Sh SEE ALSO
61.Xr bcopy 3 ,
62.Xr memccpy 3 ,
63.Xr memcpy 3 ,
64.Xr strcpy 3 ,
65.Xr strlcpy 3 ,
66.Xr wmemmove 3
67.Sh STANDARDS
68The
69.Fn memmove
70function conforms to
71.St -ansiC .
72.Sh HISTORY
73The
74.Fn memmove
75function first appeared in
76.Bx 4.3 Reno .
diff --git a/src/lib/libc/string/memmove.c b/src/lib/libc/string/memmove.c
deleted file mode 100644
index 1cd1086ab9..0000000000
--- a/src/lib/libc/string/memmove.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/* $OpenBSD: memmove.c,v 1.3 2017/11/29 05:13:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * sizeof(word) MUST BE A POWER OF TWO
38 * SO THAT wmask BELOW IS ALL ONES
39 */
40typedef long word; /* "word" used for optimal copy speed */
41
42#define wsize sizeof(word)
43#define wmask (wsize - 1)
44
45/*
46 * Copy a block of memory, handling overlap.
47 */
48void *
49memmove(void *dst0, const void *src0, size_t length)
50{
51 char *dst = dst0;
52 const char *src = src0;
53 size_t t;
54
55 if (length == 0 || dst == src) /* nothing to do */
56 goto done;
57
58 /*
59 * Macros: loop-t-times; and loop-t-times, t>0
60 */
61#define TLOOP(s) if (t) TLOOP1(s)
62#define TLOOP1(s) do { s; } while (--t)
63
64 if ((unsigned long)dst < (unsigned long)src) {
65 /*
66 * Copy forward.
67 */
68 t = (long)src; /* only need low bits */
69 if ((t | (long)dst) & wmask) {
70 /*
71 * Try to align operands. This cannot be done
72 * unless the low bits match.
73 */
74 if ((t ^ (long)dst) & wmask || length < wsize)
75 t = length;
76 else
77 t = wsize - (t & wmask);
78 length -= t;
79 TLOOP1(*dst++ = *src++);
80 }
81 /*
82 * Copy whole words, then mop up any trailing bytes.
83 */
84 t = length / wsize;
85 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
86 t = length & wmask;
87 TLOOP(*dst++ = *src++);
88 } else {
89 /*
90 * Copy backwards. Otherwise essentially the same.
91 * Alignment works as before, except that it takes
92 * (t&wmask) bytes to align, not wsize-(t&wmask).
93 */
94 src += length;
95 dst += length;
96 t = (long)src;
97 if ((t | (long)dst) & wmask) {
98 if ((t ^ (long)dst) & wmask || length <= wsize)
99 t = length;
100 else
101 t &= wmask;
102 length -= t;
103 TLOOP1(*--dst = *--src);
104 }
105 t = length / wsize;
106 TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
107 t = length & wmask;
108 TLOOP(*--dst = *--src);
109 }
110done:
111 return (dst0);
112}
113DEF_BUILTIN(memmove);
diff --git a/src/lib/libc/string/memrchr.c b/src/lib/libc/string/memrchr.c
deleted file mode 100644
index e123bc1737..0000000000
--- a/src/lib/libc/string/memrchr.c
+++ /dev/null
@@ -1,39 +0,0 @@
1/* $OpenBSD: memrchr.c,v 1.4 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 2007 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <string.h>
20
21/*
22 * Reverse memchr()
23 * Find the last occurrence of 'c' in the buffer 's' of size 'n'.
24 */
25void *
26memrchr(const void *s, int c, size_t n)
27{
28 const unsigned char *cp;
29
30 if (n != 0) {
31 cp = (unsigned char *)s + n;
32 do {
33 if (*(--cp) == (unsigned char)c)
34 return((void *)cp);
35 } while (--n != 0);
36 }
37 return(NULL);
38}
39DEF_WEAK(memrchr);
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3
deleted file mode 100644
index 34f2ca7888..0000000000
--- a/src/lib/libc/string/memset.3
+++ /dev/null
@@ -1,75 +0,0 @@
1.\" $OpenBSD: memset.3,v 1.10 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt MEMSET 3
36.Os
37.Sh NAME
38.Nm memset
39.Nd write a byte to byte string
40.Sh SYNOPSIS
41.In string.h
42.Ft void *
43.Fn memset "void *b" "int c" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn memset
47function writes
48.Fa len
49bytes of value
50.Fa c
51(converted to an
52.Vt unsigned char )
53to the string
54.Fa b .
55.Sh RETURN VALUES
56The
57.Fn memset
58function returns the original value of
59.Fa b .
60.Sh SEE ALSO
61.Xr bzero 3 ,
62.Xr swab 3 ,
63.Xr wmemset 3
64.Sh STANDARDS
65The
66.Fn memset
67function conforms to
68.St -ansiC .
69.Sh HISTORY
70The
71.Fn memset
72function first appeared in
73.At V
74and was reimplemented for
75.Bx 4.3 .
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c
deleted file mode 100644
index 0c261f0965..0000000000
--- a/src/lib/libc/string/memset.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/* $OpenBSD: memset.c,v 1.8 2017/11/29 05:13:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36void *
37memset(void *dst, int c, size_t n)
38{
39 if (n != 0) {
40 unsigned char *d = dst;
41
42 do
43 *d++ = (unsigned char)c;
44 while (--n != 0);
45 }
46 return (dst);
47}
48DEF_BUILTIN(memset);
diff --git a/src/lib/libc/string/stpcpy.3 b/src/lib/libc/string/stpcpy.3
deleted file mode 100644
index 973eebecdd..0000000000
--- a/src/lib/libc/string/stpcpy.3
+++ /dev/null
@@ -1,184 +0,0 @@
1.\" $OpenBSD: stpcpy.3,v 1.6 2014/02/23 23:09:34 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: February 23 2014 $
35.Dt STPCPY 3
36.Os
37.Sh NAME
38.Nm stpcpy ,
39.Nm stpncpy
40.Nd copy strings
41.Sh SYNOPSIS
42.In string.h
43.Ft char *
44.Fn stpcpy "char *dst" "const char *src"
45.Ft char *
46.Fn stpncpy "char *dst" "const char *src" "size_t len"
47.Sh DESCRIPTION
48The
49.Fn stpcpy
50and
51.Fn stpncpy
52functions copy the string
53.Fa src
54to
55.Fa dst
56(including the terminating
57.Ql \e0
58character).
59.Pp
60The
61.Fn stpncpy
62function copies not more than
63.Fa len
64characters into
65.Fa dst ,
66appending
67.Ql \e0
68characters if
69.Fa src
70is less than
71.Fa len
72characters long, and
73.Em not
74terminating
75.Fa dst
76if the length of
77.Fa src
78is greater than or equal to
79.Fa len .
80.Pp
81If the
82.Fa src
83and
84.Fa dst
85strings overlap, the behavior is undefined.
86.Sh RETURN VALUES
87The
88.Fn stpcpy
89function returns a pointer to the terminating
90.Ql \e0
91character written into
92.Fa dst .
93.Pp
94The
95.Fn stpncpy
96function returns a pointer to the first
97.Ql \e0
98character written into
99.Fa dst ,
100or to
101.Fa &dst[len]
102if the length of
103.Fa src
104is greater than or equal to
105.Fa len .
106.Sh EXAMPLES
107The most common use of
108.Fn stpcpy
109is to build up a string from multiple elements.
110The following example builds up a pathname from
111directory and file components using
112.Fn stpcpy :
113.Bd -literal -offset indent
114char *dir, *file, pname[PATH_MAX];
115
116\&...
117
118if (strlen(dir) + strlen("/") + strlen(file) >= sizeof(pname))
119 goto toolong;
120stpcpy(stpcpy(stpcpy(pname, dir), "/"), file);
121.Ed
122.Pp
123However, the size check required to avoid a buffer overflow is error
124prone since the check can become out of sync with the code that
125performs the copy.
126.Pp
127One might expect that
128.Fn stpncpy
129could be safely used instead, but it suffers from the same defects as
130.Fn strncpy .
131The example below using
132.Fn stpncpy
133is even more prone to error and will not detect when truncation occurs:
134.Bd -literal -offset indent
135char *dir, *file, pname[PATH_MAX];
136char *p1, *p2;
137
138\&...
139
140p1 = stpncpy(pname, dir, sizeof(pname) - 1);
141p2 = stpncpy(p1, "/", sizeof(pname) - 1 - (p1 - pname));
142stpncpy(p2, file, sizeof(pname) - 1 - (p2 - pname));
143pname[sizeof(pname) - 1] = '\e0';
144.Ed
145.Pp
146A safer (and simpler) approach is to use
147.Fn snprintf :
148.Bd -literal -offset indent
149char *dir, *file, pname[PATH_MAX];
150int len;
151
152\&...
153
154len = snprintf(pname, sizeof(pname), "%s/%s", dir, file);
155if (len >= sizeof(pname))
156 goto toolong;
157.Ed
158.Pp
159In most cases, it is better to use
160.Fn snprintf ,
161.Fn strlcpy ,
162or
163.Fn strlcat .
164.Sh SEE ALSO
165.Xr snprintf 3 ,
166.Xr strcpy 3 ,
167.Xr strlcpy 3 ,
168.Xr strncpy 3
169.Sh STANDARDS
170The
171.Fn stpcpy
172and
173.Fn stpncpy
174functions conform to
175.St -p1003.1-2008 .
176.Sh HISTORY
177The function
178.Fn stpcpy
179first appeared in the Lattice C AmigaDOS compiler (1986 or earlier).
180The function
181.Fn stpncpy
182first appeared in the GNU C library version 1.07 (1993).
183Both functions have been available since
184.Ox 5.1 .
diff --git a/src/lib/libc/string/stpcpy.c b/src/lib/libc/string/stpcpy.c
deleted file mode 100644
index 5a86541f08..0000000000
--- a/src/lib/libc/string/stpcpy.c
+++ /dev/null
@@ -1,44 +0,0 @@
1/* $OpenBSD: stpcpy.c,v 1.3 2017/11/28 06:55:49 tb Exp $ */
2
3/*
4 * Copyright (c) 1988 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34#if defined(APIWARN)
35__warn_references(stpcpy,
36 "stpcpy() is dangerous; do not use it");
37#endif
38
39char *
40stpcpy(char *to, const char *from)
41{
42 for (; (*to = *from) != '\0'; ++from, ++to);
43 return(to);
44}
diff --git a/src/lib/libc/string/stpncpy.c b/src/lib/libc/string/stpncpy.c
deleted file mode 100644
index 6bdee5de16..0000000000
--- a/src/lib/libc/string/stpncpy.c
+++ /dev/null
@@ -1,57 +0,0 @@
1/* $OpenBSD: stpncpy.c,v 1.3 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <string.h>
36
37char *
38stpncpy(char *dst, const char *src, size_t n)
39{
40 if (n != 0) {
41 char *d = dst;
42 const char *s = src;
43
44 dst = &dst[n];
45 do {
46 if ((*d++ = *s++) == 0) {
47 dst = d - 1;
48 /* NUL pad the remaining n-1 bytes */
49 while (--n != 0)
50 *d++ = 0;
51 break;
52 }
53 } while (--n != 0);
54 }
55 return (dst);
56}
57DEF_WEAK(stpncpy);
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3
deleted file mode 100644
index bb39df895a..0000000000
--- a/src/lib/libc/string/strcasecmp.3
+++ /dev/null
@@ -1,128 +0,0 @@
1.\" $OpenBSD: strcasecmp.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Chris Torek.
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. 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.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
34.\"
35.Dd $Mdocdate: September 5 2017 $
36.Dt STRCASECMP 3
37.Os
38.Sh NAME
39.Nm strcasecmp ,
40.Nm strcasecmp_l ,
41.Nm strncasecmp ,
42.Nm strncasecmp_l
43.Nd compare strings, ignoring case
44.Sh SYNOPSIS
45.In strings.h
46.Ft int
47.Fo strcasecmp
48.Fa "const char *s1"
49.Fa "const char *s2"
50.Fc
51.Ft int
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
70.Sh DESCRIPTION
71These functions compare the NUL-terminated strings
72.Fa s1
73and
74.Fa s2
75and return an integer greater than, equal to, or less than 0,
76according to whether
77.Fa s1
78is lexicographically greater than, equal to, or less than
79.Fa s2
80after translation of each corresponding character to lower-case.
81The strings themselves are not modified.
82The comparison is done using unsigned characters, so that
83.Sq Li \e200
84is greater than
85.Ql \e0 .
86.Pp
87.Fn strncasecmp
88and
89.Fn strncasecmp_l
90compare at most
91.Fa len
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 .
108.Sh SEE ALSO
109.Xr strcmp 3 ,
110.Xr strcoll 3 ,
111.Xr strxfrm 3 ,
112.Xr wcscasecmp 3
113.Sh STANDARDS
114These functions conform to
115.St -p1003.1-2008 .
116.Sh HISTORY
117The
118.Fn strcasecmp
119and
120.Fn strncasecmp
121functions have been available since
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.c b/src/lib/libc/string/strcasecmp.c
deleted file mode 100644
index edbd638722..0000000000
--- a/src/lib/libc/string/strcasecmp.c
+++ /dev/null
@@ -1,107 +0,0 @@
1/* $OpenBSD: strcasecmp.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
2
3/*
4 * Copyright (c) 1987, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34typedef unsigned char u_char;
35
36/*
37 * This array is designed for mapping upper and lower case letter
38 * together for a case independent comparison. The mappings are
39 * based upon ascii character sequences.
40 */
41static const u_char charmap[] = {
42 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
43 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
44 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
45 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
46 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
47 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
48 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
49 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
50 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
51 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
52 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
53 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
54 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
55 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
56 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
57 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
58 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
59 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
60 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
61 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
62 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
63 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
64 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
65 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
66 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
67 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
68 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
69 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
70 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
71 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
72 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
73 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
74};
75
76int
77strcasecmp(const char *s1, const char *s2)
78{
79 const u_char *cm = charmap;
80 const u_char *us1 = (const u_char *)s1;
81 const u_char *us2 = (const u_char *)s2;
82
83 while (cm[*us1] == cm[*us2++])
84 if (*us1++ == '\0')
85 return (0);
86 return (cm[*us1] - cm[*--us2]);
87}
88DEF_WEAK(strcasecmp);
89
90int
91strncasecmp(const char *s1, const char *s2, size_t n)
92{
93 if (n != 0) {
94 const u_char *cm = charmap;
95 const u_char *us1 = (const u_char *)s1;
96 const u_char *us2 = (const u_char *)s2;
97
98 do {
99 if (cm[*us1] != cm[*us2++])
100 return (cm[*us1] - cm[*--us2]);
101 if (*us1++ == '\0')
102 break;
103 } while (--n != 0);
104 }
105 return (0);
106}
107DEF_WEAK(strncasecmp);
diff --git a/src/lib/libc/string/strcasecmp_l.c b/src/lib/libc/string/strcasecmp_l.c
deleted file mode 100644
index a9543dda11..0000000000
--- a/src/lib/libc/string/strcasecmp_l.c
+++ /dev/null
@@ -1,21 +0,0 @@
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/strcasestr.c b/src/lib/libc/string/strcasestr.c
deleted file mode 100644
index abb3e15549..0000000000
--- a/src/lib/libc/string/strcasestr.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/* $OpenBSD: strcasestr.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
2/* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */
3
4/*-
5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Chris Torek.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <ctype.h>
37#include <string.h>
38
39/*
40 * Find the first occurrence of find in s, ignore case.
41 */
42char *
43strcasestr(const char *s, const char *find)
44{
45 char c, sc;
46 size_t len;
47
48 if ((c = *find++) != 0) {
49 c = (char)tolower((unsigned char)c);
50 len = strlen(find);
51 do {
52 do {
53 if ((sc = *s++) == 0)
54 return (NULL);
55 } while ((char)tolower((unsigned char)sc) != c);
56 } while (strncasecmp(s, find, len) != 0);
57 s--;
58 }
59 return ((char *)s);
60}
61DEF_WEAK(strcasestr);
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3
deleted file mode 100644
index 68da4ed4a5..0000000000
--- a/src/lib/libc/string/strcat.3
+++ /dev/null
@@ -1,76 +0,0 @@
1.\" $OpenBSD: strcat.3,v 1.19 2022/08/01 00:04:46 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: August 1 2022 $
35.Dt STRCAT 3
36.Os
37.Sh NAME
38.Nm strcat
39.Nd concatenate two strings without bounds checking
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strcat "char *dst" "const char *append"
44.Sh DESCRIPTION
45The
46.Fn strcat
47function appends a copy of the NUL-terminated string
48.Fa append
49to the end of the NUL-terminated string
50.Fa dst ,
51then adds a terminating
52.Ql \e0 .
53.Pp
54No bounds checking is performed.
55If the buffer
56.Fa dst
57is not large enough to hold the result,
58subsequent memory will be damaged.
59.Sh RETURN VALUES
60The
61.Fn strcat
62function return the pointer
63.Fa dst .
64.Sh SEE ALSO
65.Xr strlcpy 3 ,
66.Xr wcscat 3 ,
67.Xr wcslcpy 3
68.Sh STANDARDS
69The
70.Fn strcat
71function conforms to
72.St -ansiC .
73.Sh HISTORY
74The
75.Fn strcat
76function first appeared outside of Bell Labs in PWB/UNIX 1.0.
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c
deleted file mode 100644
index 73da22f75d..0000000000
--- a/src/lib/libc/string/strcat.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/* $OpenBSD: strcat.c,v 1.10 2017/11/28 06:55:49 tb Exp $ */
2
3/*
4 * Copyright (c) 1988 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34#if defined(APIWARN)
35__warn_references(strcat,
36 "strcat() is almost always misused, please use strlcat()");
37#endif
38
39char *
40strcat(char *s, const char *append)
41{
42 char *save = s;
43
44 for (; *s; ++s);
45 while ((*s++ = *append++) != '\0');
46 return(save);
47}
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3
deleted file mode 100644
index d1dc67e5ec..0000000000
--- a/src/lib/libc/string/strchr.3
+++ /dev/null
@@ -1,116 +0,0 @@
1.\" $OpenBSD: strchr.3,v 1.14 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRCHR 3
36.Os
37.Sh NAME
38.Nm strchr ,
39.Nm index
40.Nd locate first occurrence of a character in a string
41.Sh SYNOPSIS
42.In string.h
43.Ft char *
44.Fn strchr "const char *s" "int c"
45.In strings.h
46.Ft char *
47.Fn index "const char *s" "int c"
48.Sh DESCRIPTION
49The
50.Fn strchr
51function locates the first occurrence of the character
52.Fa c
53.Pq converted to a char
54in the string
55.Fa s .
56The terminating NUL character is considered part of the string.
57If
58.Fa c
59is
60.Ql \e0 ,
61.Fn strchr
62locates the terminating
63.Ql \e0 .
64.Pp
65The
66.Fn index
67function is an old synonym for
68.Fn strchr .
69.Sh RETURN VALUES
70The
71.Fn strchr
72function returns a pointer to the located character or
73.Dv NULL
74if the character does not appear in the string.
75.Sh EXAMPLES
76After the following call to
77.Fn strchr ,
78.Va p
79will point to the string
80.Qq oobar :
81.Bd -literal -offset indent
82char *p;
83char *s = "foobar";
84
85p = strchr(s, 'o');
86.Ed
87.Sh SEE ALSO
88.Xr memchr 3 ,
89.Xr strcspn 3 ,
90.Xr strpbrk 3 ,
91.Xr strrchr 3 ,
92.Xr strsep 3 ,
93.Xr strspn 3 ,
94.Xr strstr 3 ,
95.Xr strtok 3 ,
96.Xr wcschr 3
97.Sh STANDARDS
98The
99.Fn strchr
100function conforms to
101.St -ansiC .
102.Pp
103The
104.Fn index
105function is deprecated and shouldn't be used in new code.
106.Sh HISTORY
107The
108.Fn index
109function first appeared in
110.At v7 .
111The
112.Fn strchr
113function first appeared in
114.At III
115and was reimplemented for
116.Bx 4.3 .
diff --git a/src/lib/libc/string/strchr.c b/src/lib/libc/string/strchr.c
deleted file mode 100644
index 8bfa7ac3aa..0000000000
--- a/src/lib/libc/string/strchr.c
+++ /dev/null
@@ -1,46 +0,0 @@
1/* $OpenBSD: strchr.c,v 1.4 2018/10/01 06:37:37 martijn Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <string.h>
32
33__weak_alias(index, strchr);
34
35char *
36strchr(const char *p, int ch)
37{
38 for (;; ++p) {
39 if (*p == (char) ch)
40 return((char *)p);
41 if (!*p)
42 return((char *)NULL);
43 }
44 /* NOTREACHED */
45}
46DEF_STRONG(strchr);
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3
deleted file mode 100644
index 4ef341e53e..0000000000
--- a/src/lib/libc/string/strcmp.3
+++ /dev/null
@@ -1,95 +0,0 @@
1.\" $OpenBSD: strcmp.3,v 1.15 2022/08/01 00:04:46 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: August 1 2022 $
35.Dt STRCMP 3
36.Os
37.Sh NAME
38.Nm strcmp ,
39.Nm strncmp
40.Nd compare strings
41.Sh SYNOPSIS
42.In string.h
43.Ft int
44.Fn strcmp "const char *s1" "const char *s2"
45.Ft int
46.Fn strncmp "const char *s1" "const char *s2" "size_t len"
47.Sh DESCRIPTION
48The
49.Fn strcmp
50and
51.Fn strncmp
52functions lexicographically compare the NUL-terminated strings
53.Fa s1
54and
55.Fa s2 .
56The
57.Fn strncmp
58function compares at most
59.Fa len
60characters.
61.Sh RETURN VALUES
62The
63.Fn strcmp
64and
65.Fn strncmp
66functions return an integer greater than, equal to, or less than 0, according
67to whether the string
68.Fa s1
69is greater than, equal to, or less than the string
70.Fa s2 .
71The comparison is done using unsigned characters, so that
72.Ql \e200
73is greater than
74.Ql \e0 .
75.Sh SEE ALSO
76.Xr bcmp 3 ,
77.Xr memcmp 3 ,
78.Xr strcasecmp 3 ,
79.Xr strcoll 3 ,
80.Xr strxfrm 3 ,
81.Xr wcscmp 3
82.Sh STANDARDS
83The
84.Fn strcmp
85and
86.Fn strncmp
87functions conform to
88.St -ansiC .
89.Sh HISTORY
90The
91.Fn strcmp
92function first appeared outside of Bell Labs in PWB/UNIX 1.0.
93.Fn strncmp
94first appeared in
95.At v7 .
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c
deleted file mode 100644
index be175563d4..0000000000
--- a/src/lib/libc/string/strcmp.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/* $OpenBSD: strcmp.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <string.h>
36
37/*
38 * Compare strings.
39 */
40int
41strcmp(const char *s1, const char *s2)
42{
43 while (*s1 == *s2++)
44 if (*s1++ == 0)
45 return (0);
46 return (*(unsigned char *)s1 - *(unsigned char *)--s2);
47}
48DEF_STRONG(strcmp);
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3
deleted file mode 100644
index 9daa6cd93f..0000000000
--- a/src/lib/libc/string/strcoll.3
+++ /dev/null
@@ -1,103 +0,0 @@
1.\" $OpenBSD: strcoll.3,v 1.11 2019/01/18 07:43:36 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Chris Torek and the American National Standards Committee X3,
9.\" on Information Processing Systems.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in the
18.\" documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.Dd $Mdocdate: January 18 2019 $
36.Dt STRCOLL 3
37.Os
38.Sh NAME
39.Nm strcoll ,
40.Nm strcoll_l
41.Nd compare strings according to current collation
42.Sh SYNOPSIS
43.In string.h
44.Ft int
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"
48.Sh DESCRIPTION
49The
50.Fn strcoll
51and
52.Fn strcoll_l
53functions lexicographically compare the NUL-terminated strings
54.Fa s1
55and
56.Fa s2
57according to the current locale collation
58and return an integer greater than, equal to, or less than 0,
59according to whether
60.Fa s1
61is greater than, equal to, or less than
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.
71On other operating systems, results may depend on the
72.Dv LC_CTYPE
73and
74.Dv LC_COLLATE
75locale categories set with
76.Xr setlocale 3 ,
77.Xr uselocale 3 ,
78or
79.Xr newlocale 3 .
80.Sh SEE ALSO
81.Xr newlocale 3 ,
82.Xr setlocale 3 ,
83.Xr strcmp 3 ,
84.Xr strxfrm 3 ,
85.Xr wcscoll 3
86.Sh STANDARDS
87The
88.Fn strcoll
89function conforms to
90.St -ansiC ,
91and
92.Fn strcoll_l
93to
94.St -p1003.1-2008 .
95.Sh HISTORY
96The
97.Fn strcoll
98function has been available since
99.Bx 4.3 Reno ,
100and
101.Fn strcoll_l
102since
103.Ox 6.2 .
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c
deleted file mode 100644
index 47a6ea4f24..0000000000
--- a/src/lib/libc/string/strcoll.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/* $OpenBSD: strcoll.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * Compare strings according to LC_COLLATE category of current locale.
38 */
39int
40strcoll(const char *s1, const char *s2)
41{
42 /* LC_COLLATE is unimplemented, hence always "C" */
43 return (strcmp(s1, s2));
44}
45DEF_STRONG(strcoll);
diff --git a/src/lib/libc/string/strcoll_l.c b/src/lib/libc/string/strcoll_l.c
deleted file mode 100644
index bcd5b0f417..0000000000
--- a/src/lib/libc/string/strcoll_l.c
+++ /dev/null
@@ -1,14 +0,0 @@
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/strcpy.3 b/src/lib/libc/string/strcpy.3
deleted file mode 100644
index 4bf690ba76..0000000000
--- a/src/lib/libc/string/strcpy.3
+++ /dev/null
@@ -1,82 +0,0 @@
1.\" $OpenBSD: strcpy.3,v 1.22 2022/08/01 00:04:46 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: August 1 2022 $
35.Dt STRCPY 3
36.Os
37.Sh NAME
38.Nm strcpy
39.Nd copy a string without bounds checking
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strcpy "char *dst" "const char *src"
44.Sh DESCRIPTION
45The
46.Fn strcpy
47function copies the string
48.Fa src
49(including the terminating
50.Ql \e0
51character) to the buffer
52.Fa dst .
53.Pp
54No bounds checking is performed.
55If the buffer
56.Fa dst
57is not large enough to hold the result,
58subsequent memory will be damaged.
59.Pp
60If the
61.Fa src
62string is inside the
63.Fa dst
64buffer, the behavior is undefined.
65.Sh RETURN VALUES
66The
67.Fn strcpy
68function returns
69.Fa dst .
70.Sh SEE ALSO
71.Xr strlcpy 3 ,
72.Xr wcscpy 3 ,
73.Xr wcslcpy 3
74.Sh STANDARDS
75The
76.Fn strcpy
77function conforms to
78.St -ansiC .
79.Sh HISTORY
80The
81.Fn strcpy
82function first appeared outside of Bell Labs in PWB/UNIX 1.0.
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c
deleted file mode 100644
index 290eefeabf..0000000000
--- a/src/lib/libc/string/strcpy.c
+++ /dev/null
@@ -1,46 +0,0 @@
1/* $OpenBSD: strcpy.c,v 1.10 2017/11/28 06:55:49 tb Exp $ */
2
3/*
4 * Copyright (c) 1988 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34#if defined(APIWARN)
35__warn_references(strcpy,
36 "strcpy() is almost always misused, please use strlcpy()");
37#endif
38
39char *
40strcpy(char *to, const char *from)
41{
42 char *save = to;
43
44 for (; (*to = *from) != '\0'; ++from, ++to);
45 return(save);
46}
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3
deleted file mode 100644
index 91e5c3f1cc..0000000000
--- a/src/lib/libc/string/strcspn.3
+++ /dev/null
@@ -1,108 +0,0 @@
1.\" $OpenBSD: strcspn.3,v 1.12 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRCSPN 3
36.Os
37.Sh NAME
38.Nm strcspn
39.Nd span the complement of a string
40.Sh SYNOPSIS
41.In string.h
42.Ft size_t
43.Fn strcspn "const char *s" "const char *charset"
44.Sh DESCRIPTION
45The
46.Fn strcspn
47function spans the initial part of the NUL-terminated string
48.Fa s
49as long as the characters from
50.Fa s
51do not occur in string
52.Fa charset
53(it spans the
54.Em complement
55of
56.Fa charset ) .
57.Sh RETURN VALUES
58The
59.Fn strcspn
60function returns the number of characters spanned.
61.Sh EXAMPLES
62The following call to
63.Fn strcspn
64will return 3, since the first three characters of string
65.Fa s
66do not occur in string
67.Fa charset :
68.Bd -literal -offset indent
69char *s = "foobar";
70char *charset = "bar";
71size_t span;
72
73span = strcspn(s, charset);
74.Ed
75.Pp
76The following removes the first (if any) newline character from string
77.Fa line .
78This is useful for trimming the newline after a
79.Xr fgets 3
80call.
81.Bd -literal -offset indent
82char line[BUFSIZ];
83
84if (fgets(line, sizeof(line), fp) != NULL)
85 line[strcspn(line, "\en")] = '\e0';
86.Ed
87.Sh SEE ALSO
88.Xr memchr 3 ,
89.Xr strchr 3 ,
90.Xr strpbrk 3 ,
91.Xr strrchr 3 ,
92.Xr strsep 3 ,
93.Xr strspn 3 ,
94.Xr strstr 3 ,
95.Xr strtok 3 ,
96.Xr wcscspn 3
97.Sh STANDARDS
98The
99.Fn strcspn
100function conforms to
101.St -ansiC .
102.Sh HISTORY
103The
104.Fn strcspn
105function first appeared in
106.At III
107and was reimplemented for
108.Bx 4.3 .
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c
deleted file mode 100644
index 3c1f5a4cec..0000000000
--- a/src/lib/libc/string/strcspn.c
+++ /dev/null
@@ -1,59 +0,0 @@
1/* $OpenBSD: strcspn.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * Span the complement of string s2.
38 */
39size_t
40strcspn(const char *s1, const char *s2)
41{
42 const char *p, *spanp;
43 char c, sc;
44
45 /*
46 * Stop as soon as we find any character from s2. Note that there
47 * must be a NUL in s2; it suffices to stop when we find that, too.
48 */
49 for (p = s1;;) {
50 c = *p++;
51 spanp = s2;
52 do {
53 if ((sc = *spanp++) == c)
54 return (p - 1 - s1);
55 } while (sc != 0);
56 }
57 /* NOTREACHED */
58}
59DEF_STRONG(strcspn);
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3
deleted file mode 100644
index 283f3bc0ea..0000000000
--- a/src/lib/libc/string/strdup.3
+++ /dev/null
@@ -1,119 +0,0 @@
1.\" $OpenBSD: strdup.3,v 1.22 2015/12/01 01:32:48 mmcc Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
31.\"
32.Dd $Mdocdate: December 1 2015 $
33.Dt STRDUP 3
34.Os
35.Sh NAME
36.Nm strdup ,
37.Nm strndup
38.Nd save a copy of a string
39.Sh SYNOPSIS
40.In string.h
41.Ft char *
42.Fn strdup "const char *s"
43.Ft char *
44.Fn strndup "const char *s" "size_t maxlen"
45.Sh DESCRIPTION
46The
47.Fn strdup
48function allocates sufficient memory for a copy of the string
49.Fa s ,
50does the copy, and returns a pointer to it.
51The pointer may subsequently be used as an argument to the function
52.Xr free 3 .
53.Pp
54The
55.Fn strndup
56function behaves similarly to
57.Nm strdup
58but only copies up to
59.Fa maxlen
60characters from
61.Fa s .
62The resulting string is always NUL-terminated.
63.Pp
64If the memory allocation fails,
65.Dv NULL
66is returned.
67.Sh EXAMPLES
68The following will point
69.Va p
70to an allocated area of memory containing the NUL-terminated string
71.Qq foobar :
72.Bd -literal -offset indent
73char *p;
74
75p = strdup("foobar");
76if (p == NULL)
77 err(1, NULL);
78.Ed
79.Sh ERRORS
80The
81.Fn strdup
82and
83.Fn strndup
84functions may fail and set the external variable
85.Va errno
86for any of the errors specified for the library function
87.Xr malloc 3 .
88.Sh SEE ALSO
89.Xr free 3 ,
90.Xr malloc 3 ,
91.Xr strcpy 3 ,
92.Xr strlcpy 3 ,
93.Xr strlen 3 ,
94.Xr wcsdup 3
95.Sh STANDARDS
96The
97.Fn strdup
98and
99.Fn strndup
100functions conform to
101.St -p1003.1-2008 .
102.Sh HISTORY
103A
104.Fn strdup
105macro was first used in the
106.Bx 4.1c
107debugger,
108.Sy dbx .
109It was rewritten as a C function for the
110.Bx 4.3
111.Xr inetd 8
112and first appeared in the C library of
113.Bx 4.3 Reno .
114The
115.Fn strndup
116function appeared in glibc 2.0, was reimplemented for
117.Nx 4.0 ,
118and ported to
119.Ox 4.8 .
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c
deleted file mode 100644
index 9aebf399c1..0000000000
--- a/src/lib/libc/string/strdup.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/* $OpenBSD: strdup.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
2
3/*
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/types.h>
33
34#include <stddef.h>
35#include <stdlib.h>
36#include <string.h>
37
38char *
39strdup(const char *str)
40{
41 size_t siz;
42 char *copy;
43
44 siz = strlen(str) + 1;
45 if ((copy = malloc(siz)) == NULL)
46 return(NULL);
47 (void)memcpy(copy, str, siz);
48 return(copy);
49}
50DEF_WEAK(strdup);
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3
deleted file mode 100644
index 6c5b890fa4..0000000000
--- a/src/lib/libc/string/strerror.3
+++ /dev/null
@@ -1,154 +0,0 @@
1.\" $OpenBSD: strerror.3,v 1.16 2019/05/16 13:35:16 schwarze Exp $
2.\"
3.\" Copyright (c) 1980, 1991 Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the American National Standards Committee X3, on Information
9.\" Processing Systems.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in the
18.\" documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.Dd $Mdocdate: May 16 2019 $
36.Dt STRERROR 3
37.Os
38.Sh NAME
39.Nm strerror ,
40.Nm strerror_l ,
41.Nm strerror_r
42.Nd get error message string
43.Sh SYNOPSIS
44.In string.h
45.Ft char *
46.Fn strerror "int errnum"
47.Ft char *
48.Fn strerror_l "int errnum" "locale_t locale"
49.Ft int
50.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen"
51.Sh DESCRIPTION
52These functions map the error number
53.Fa errnum
54to an error message string.
55.Pp
56.Fn strerror
57and
58.Fn strerror_l
59return a string containing a maximum of
60.Dv NL_TEXTMAX
61characters, including the trailing NUL.
62This string is not to be modified by the calling program.
63The string returned by
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.
73.Pp
74.Fn strerror_r
75is a thread safe version of
76.Fn strerror
77that places the error message in the specified buffer
78.Fa strerrbuf .
79.Pp
80On
81.Ox ,
82the global locale, the thread-specific locale, and the
83.Fa locale
84argument are ignored.
85.Sh RETURN VALUES
86.Fn strerror
87and
88.Fn strerror_l
89return a pointer to the error message string.
90If an error occurs, the error code is stored in
91.Va errno .
92.Pp
93.Fn strerror_r
94returns zero upon successful completion.
95If an error occurs, the error code is stored in
96.Va errno
97and the error code is returned.
98.Sh ERRORS
99All these functions may fail if:
100.Bl -tag -width Er
101.It Bq Er EINVAL
102.Fa errnum
103is not a valid error number.
104The returned error string will consist of an error message that includes
105.Fa errnum .
106.El
107.Pp
108.Fn strerror_r
109may also fail if:
110.Bl -tag -width Er
111.It Bq Er ERANGE
112The error message is larger than
113.Fa buflen
114characters.
115The message will be truncated to fit.
116.El
117.Sh SEE ALSO
118.Xr intro 2 ,
119.Xr newlocale 3 ,
120.Xr perror 3 ,
121.Xr setlocale 3
122.Sh STANDARDS
123The
124.Fn strerror
125function conforms to
126.St -isoC-99 .
127The
128.Fn strerror_l
129and
130.Fn strerror_r
131functions conform to
132.St -p1003.1-2008 .
133.Sh HISTORY
134The
135.Fn strerror
136function has been available since
137.Bx 4.3 Reno ,
138.Fn strerror_r
139since
140.Ox 3.3 ,
141and
142.Fn strerror_l
143since
144.Ox 6.2 .
145.Sh CAVEATS
146On systems other than
147.Ox ,
148the
149.Dv LC_MESSAGES
150.Xr locale 1
151category can cause different strings to be returned instead of the
152normal error messages; see CAVEATS in
153.Xr setlocale 3
154for details.
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c
deleted file mode 100644
index c6f05446fd..0000000000
--- a/src/lib/libc/string/strerror.c
+++ /dev/null
@@ -1,42 +0,0 @@
1/* $OpenBSD: strerror.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <string.h>
32#include <limits.h>
33
34char *
35strerror(int num)
36{
37 static char buf[NL_TEXTMAX];
38
39 (void)strerror_r(num, buf, sizeof(buf));
40 return (buf);
41}
42DEF_STRONG(strerror);
diff --git a/src/lib/libc/string/strerror_l.c b/src/lib/libc/string/strerror_l.c
deleted file mode 100644
index c16be7a0cc..0000000000
--- a/src/lib/libc/string/strerror_l.c
+++ /dev/null
@@ -1,33 +0,0 @@
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/strerror_r.c b/src/lib/libc/string/strerror_r.c
deleted file mode 100644
index b45dee12d8..0000000000
--- a/src/lib/libc/string/strerror_r.c
+++ /dev/null
@@ -1,107 +0,0 @@
1/* $OpenBSD: strerror_r.c,v 1.13 2016/10/19 16:26:16 bluhm Exp $ */
2/* Public Domain <marc@snafu.org> */
3
4#include <errno.h>
5#include <limits.h>
6#include <signal.h>
7#include <string.h>
8
9static size_t
10__digits10(unsigned int num)
11{
12 size_t i = 0;
13
14 do {
15 num /= 10;
16 i++;
17 } while (num != 0);
18
19 return i;
20}
21
22static int
23__itoa(int num, int sign, char *buffer, size_t start, size_t end)
24{
25 size_t pos;
26 unsigned int a;
27 int neg;
28
29 if (sign && num < 0) {
30 a = -num;
31 neg = 1;
32 }
33 else {
34 a = num;
35 neg = 0;
36 }
37
38 pos = start + __digits10(a);
39 if (neg)
40 pos++;
41
42 if (pos < end)
43 buffer[pos] = '\0';
44 else
45 return ERANGE;
46 pos--;
47 do {
48 buffer[pos] = (a % 10) + '0';
49 pos--;
50 a /= 10;
51 } while (a != 0);
52 if (neg)
53 buffer[pos] = '-';
54 return 0;
55}
56
57
58static int
59__num2string(int num, int sign, int setid, char *buf, size_t buflen,
60 const char * const list[], size_t max, const char *def)
61{
62 int ret = 0;
63 size_t len;
64
65 if (0 <= num && num < max) {
66 len = strlcpy(buf, list[num], buflen);
67 if (len >= buflen)
68 ret = ERANGE;
69 } else {
70 len = strlcpy(buf, def, buflen);
71 if (len >= buflen)
72 ret = ERANGE;
73 else {
74 ret = __itoa(num, sign, buf, len, buflen);
75 if (ret == 0)
76 ret = EINVAL;
77 }
78 }
79
80 return ret;
81}
82
83#define UPREFIX "Unknown error: "
84
85int
86strerror_r(int errnum, char *strerrbuf, size_t buflen)
87{
88 int ret_errno;
89
90 ret_errno = __num2string(errnum, 1, 1, strerrbuf, buflen,
91 sys_errlist, sys_nerr, UPREFIX);
92
93 if (ret_errno)
94 errno = ret_errno;
95 return (ret_errno);
96}
97DEF_WEAK(strerror_r);
98
99#define USIGPREFIX "Unknown signal: "
100
101char *
102__strsignal(int num, char *buf)
103{
104 __num2string(num, 0, 2, buf, NL_TEXTMAX, sys_siglist, NSIG,
105 USIGPREFIX);
106 return buf;
107}
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c
deleted file mode 100644
index aa3db7ab37..0000000000
--- a/src/lib/libc/string/strlcat.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20#include <string.h>
21
22/*
23 * Appends src to string dst of size dsize (unlike strncat, dsize is the
24 * full size of dst, not space left). At most dsize-1 characters
25 * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
26 * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
27 * If retval >= dsize, truncation occurred.
28 */
29size_t
30strlcat(char *dst, const char *src, size_t dsize)
31{
32 const char *odst = dst;
33 const char *osrc = src;
34 size_t n = dsize;
35 size_t dlen;
36
37 /* Find the end of dst and adjust bytes left but don't go past end. */
38 while (n-- != 0 && *dst != '\0')
39 dst++;
40 dlen = dst - odst;
41 n = dsize - dlen;
42
43 if (n-- == 0)
44 return(dlen + strlen(src));
45 while (*src != '\0') {
46 if (n != 0) {
47 *dst++ = *src;
48 n--;
49 }
50 src++;
51 }
52 *dst = '\0';
53
54 return(dlen + (src - osrc)); /* count does not include NUL */
55}
56DEF_WEAK(strlcat);
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3
deleted file mode 100644
index 4607289883..0000000000
--- a/src/lib/libc/string/strlcpy.3
+++ /dev/null
@@ -1,195 +0,0 @@
1.\" $OpenBSD: strlcpy.3,v 1.28 2024/08/03 20:13:23 guenther Exp $
2.\"
3.\" Copyright (c) 1998, 2000 Todd C. Miller <millert@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.Dd $Mdocdate: August 3 2024 $
18.Dt STRLCPY 3
19.Os
20.Sh NAME
21.Nm strlcpy ,
22.Nm strlcat
23.Nd size-bounded string copying and concatenation
24.Sh SYNOPSIS
25.In string.h
26.Ft size_t
27.Fn strlcpy "char * restrict dst" "const char * restrict src" "size_t dstsize"
28.Ft size_t
29.Fn strlcat "char * restrict dst" "const char * restrict src" "size_t dstsize"
30.Sh DESCRIPTION
31The
32.Fn strlcpy
33and
34.Fn strlcat
35functions copy and concatenate strings with the
36same input parameters and output result as
37.Xr snprintf 3 .
38They are designed to be safer, more consistent, and less error
39prone replacements for the easily misused functions
40.Xr strncpy 3
41and
42.Xr strncat 3 .
43.Pp
44.Fn strlcpy
45and
46.Fn strlcat
47take the full size of the destination buffer and guarantee
48NUL-termination if there is room.
49Note that room for the NUL should be included in
50.Fa dstsize .
51.Pp
52.Fn strlcpy
53copies up to
54.Fa dstsize
55\- 1 characters from the string
56.Fa src
57to
58.Fa dst ,
59NUL-terminating the result if
60.Fa dstsize
61is not 0.
62.Pp
63.Fn strlcat
64appends string
65.Fa src
66to the end of
67.Fa dst .
68It will append at most
69.Fa dstsize
70\- strlen(dst) \- 1 characters.
71It will then NUL-terminate, unless
72.Fa dstsize
73is 0 or the original
74.Fa dst
75string was longer than
76.Fa dstsize
77(in practice this should not happen
78as it means that either
79.Fa dstsize
80is incorrect or that
81.Fa dst
82is not a proper string).
83.Pp
84If the
85.Fa src
86and
87.Fa dst
88strings overlap, the behavior is undefined.
89.Sh RETURN VALUES
90Besides quibbles over the return type
91.Pf ( Va size_t
92versus
93.Va int )
94and signal handler safety
95.Pf ( Xr snprintf 3
96is not entirely safe on some systems), the
97following two are equivalent:
98.Bd -literal -offset indent
99n = strlcpy(dst, src, len);
100n = snprintf(dst, len, "%s", src);
101.Ed
102.Pp
103Like
104.Xr snprintf 3 ,
105the
106.Fn strlcpy
107and
108.Fn strlcat
109functions return the total length of the string they tried to create.
110For
111.Fn strlcpy
112that means the length of
113.Fa src .
114For
115.Fn strlcat
116that means the initial length of
117.Fa dst
118plus
119the length of
120.Fa src .
121.Pp
122If the return value is
123.Cm >=
124.Va dstsize ,
125the output string has been truncated.
126It is the caller's responsibility to handle this.
127.Sh EXAMPLES
128The following code fragment illustrates the simple case:
129.Bd -literal -offset indent
130char *s, *p, buf[BUFSIZ];
131
132\&...
133
134(void)strlcpy(buf, s, sizeof(buf));
135(void)strlcat(buf, p, sizeof(buf));
136.Ed
137.Pp
138To detect truncation, perhaps while building a pathname, something
139like the following might be used:
140.Bd -literal -offset indent
141char *dir, *file, pname[PATH_MAX];
142
143\&...
144
145if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
146 goto toolong;
147if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
148 goto toolong;
149.Ed
150.Pp
151Since it is known how many characters were copied the first time, things
152can be sped up a bit by using a copy instead of an append:
153.Bd -literal -offset indent
154char *dir, *file, pname[PATH_MAX];
155size_t n;
156
157\&...
158
159n = strlcpy(pname, dir, sizeof(pname));
160if (n >= sizeof(pname))
161 goto toolong;
162if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
163 goto toolong;
164.Ed
165.Pp
166However, one may question the validity of such optimizations, as they
167defeat the whole purpose of
168.Fn strlcpy
169and
170.Fn strlcat .
171As a matter of fact, the first version of this manual page got it wrong.
172.Sh SEE ALSO
173.Xr snprintf 3 ,
174.Xr strncat 3 ,
175.Xr strncpy 3 ,
176.Xr wcslcpy 3
177.Sh STANDARDS
178The
179.Fn strlcat
180and
181.Fn strlcpy
182functions conform to
183.St -p1003.1-2024 .
184.Sh HISTORY
185.Fn strlcpy
186and
187.Fn strlcat
188first appeared in
189.Ox 2.4 .
190.Sh AUTHORS
191.Fn strlcpy
192and
193.Fn strlcat
194were created by
195.An Todd C. Miller Aq Mt millert@openbsd.org .
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c
deleted file mode 100644
index 7e3b9aef6f..0000000000
--- a/src/lib/libc/string/strlcpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20#include <string.h>
21
22/*
23 * Copy string src to buffer dst of size dsize. At most dsize-1
24 * chars will be copied. Always NUL terminates (unless dsize == 0).
25 * Returns strlen(src); if retval >= dsize, truncation occurred.
26 */
27size_t
28strlcpy(char *dst, const char *src, size_t dsize)
29{
30 const char *osrc = src;
31 size_t nleft = dsize;
32
33 /* Copy as many bytes as will fit. */
34 if (nleft != 0) {
35 while (--nleft != 0) {
36 if ((*dst++ = *src++) == '\0')
37 break;
38 }
39 }
40
41 /* Not enough room in dst, add NUL and traverse rest of src. */
42 if (nleft == 0) {
43 if (dsize != 0)
44 *dst = '\0'; /* NUL-terminate dst */
45 while (*src++)
46 ;
47 }
48
49 return(src - osrc - 1); /* count does not include NUL */
50}
51DEF_WEAK(strlcpy);
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3
deleted file mode 100644
index 18569d58b9..0000000000
--- a/src/lib/libc/string/strlen.3
+++ /dev/null
@@ -1,103 +0,0 @@
1.\" $OpenBSD: strlen.3,v 1.14 2022/07/31 14:50:32 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: July 31 2022 $
35.Dt STRLEN 3
36.Os
37.Sh NAME
38.Nm strlen ,
39.Nm strnlen
40.Nd find length of a string
41.Sh SYNOPSIS
42.In string.h
43.Ft size_t
44.Fn strlen "const char *s"
45.Ft size_t
46.Fn strnlen "const char *s" "size_t maxlen"
47.Sh DESCRIPTION
48The
49.Fn strlen
50function computes the length of the string
51.Fa s .
52.Pp
53The
54.Fn strnlen
55function computes the length of the string
56.Fa s ,
57up to
58.Fa maxlen
59characters.
60The
61.Fn strnlen
62function will never attempt to address more than
63.Fa maxlen
64characters, making it suitable for use with character arrays that are
65not guaranteed to be NUL-terminated.
66.Sh RETURN VALUES
67The
68.Fn strlen
69function returns the number of characters that precede the terminating
70.Tn NUL
71character.
72.Pp
73The
74.Fn strnlen
75function returns the number of characters that precede the terminating
76.Tn NUL
77or
78.Fa maxlen ,
79whichever is smaller.
80.Sh SEE ALSO
81.Xr wcslen 3
82.Sh STANDARDS
83The
84.Fn strlen
85function conforms to
86.St -ansiC .
87.Pp
88The
89.Fn strlen
90and
91.Fn strnlen
92functions conform to
93.St -p1003.1-2008 .
94.Sh HISTORY
95The
96.Fn strlen
97function first appeared in
98.At v6 .
99The
100.Fn strnlen
101function appeared in glibc 2.0
102and was reimplemented for
103.Ox 4.8 .
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c
deleted file mode 100644
index a5721d3e7f..0000000000
--- a/src/lib/libc/string/strlen.c
+++ /dev/null
@@ -1,44 +0,0 @@
1/* $OpenBSD: strlen.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34size_t
35strlen(const char *str)
36{
37 const char *s;
38
39 for (s = str; *s; ++s)
40 ;
41 return (s - str);
42}
43
44DEF_STRONG(strlen);
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3
deleted file mode 100644
index 8135d30ba1..0000000000
--- a/src/lib/libc/string/strmode.3
+++ /dev/null
@@ -1,153 +0,0 @@
1.\" $OpenBSD: strmode.3,v 1.17 2017/07/05 11:44:35 tb Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
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.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" @(#)strmode.3 8.3 (Berkeley) 7/28/94
31.\"
32.Dd $Mdocdate: July 5 2017 $
33.Dt STRMODE 3
34.Os
35.Sh NAME
36.Nm strmode
37.Nd convert inode status information into a symbolic string
38.Sh SYNOPSIS
39.In string.h
40.Ft void
41.Fn strmode "mode_t mode" "char *bp"
42.Sh DESCRIPTION
43The
44.Fn strmode
45function converts a file
46.Fa mode
47(the type and permission information associated with an inode, see
48.Xr stat 2 )
49into a symbolic string which is stored in the location referenced by
50.Fa bp .
51This stored string is eleven characters in length plus a trailing NUL byte.
52.Pp
53The first character is the inode type, and will be one of the following:
54.Pp
55.Bl -tag -width flag -offset indent -compact
56.It \-
57regular file
58.It b
59block special
60.It c
61character special
62.It d
63directory
64.It l
65symbolic link
66.It p
67FIFO
68.It s
69socket
70.It \&?
71unknown inode type
72.El
73.Pp
74The next nine characters encode three sets of permissions, in three
75characters each.
76The first three characters are the permissions for the owner of the
77file, the second three for the group the file belongs to, and the
78third for the
79.Dq other ,
80or default, set of users.
81.Pp
82Permission checking is done as specifically as possible.
83If read permission is denied to the owner of a file in the first set
84of permissions, the owner of the file will not be able to read the file.
85This is true even if the owner is in the file's group and the group
86permissions allow reading or the
87.Dq other
88permissions allow reading.
89.Pp
90If the first character of the three character set is an
91.Sq r ,
92the file is readable for that set of users; if a dash
93.Pq Ql - ,
94it is not readable.
95.Pp
96If the second character of the three character set is a
97.Sq w ,
98the file is writable for that set of users; if a dash
99.Pq Ql - ,
100it is not writable.
101.Pp
102The third character is the first of the following characters that apply:
103.Bl -tag -width xxxx
104.It S
105If the character is part of the owner permissions and the file is not
106executable or the directory is not searchable by the owner, and the
107set-user-ID bit is set.
108.It S
109If the character is part of the group permissions and the file is not
110executable or the directory is not searchable by the group, and the
111set-group-ID bit is set.
112.It T
113If the character is part of the other permissions and the file is not
114executable or the directory is not searchable by others, and the
115.Dq sticky
116.Pq Dv S_ISVTX
117bit is set.
118.It s
119If the character is part of the owner permissions and the file is
120executable or the directory searchable by the owner, and the set-user-ID
121bit is set.
122.It s
123If the character is part of the group permissions and the file is
124executable or the directory searchable by the group, and the set-group-ID
125bit is set.
126.It t
127If the character is part of the other permissions and the file is
128executable or the directory searchable by others, and the
129.Dq sticky
130.Pq Dv S_ISVTX
131bit is set.
132.It x
133The file is executable or the directory is searchable.
134.It \-
135None of the above apply.
136.El
137.Pp
138The last character is a plus sign
139.Pq Ql +
140if there are any alternate
141or additional access control methods associated with the inode, otherwise
142it will be a space.
143.Sh SEE ALSO
144.Xr chmod 1 ,
145.Xr find 1 ,
146.Xr stat 2 ,
147.Xr getmode 3 ,
148.Xr setmode 3
149.Sh HISTORY
150The
151.Fn strmode
152function first appeared in
153.Bx 4.3 Reno .
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c
deleted file mode 100644
index c57fe74b23..0000000000
--- a/src/lib/libc/string/strmode.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* $OpenBSD: strmode.c,v 1.9 2024/06/23 07:08:26 otto Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <string.h>
34
35void
36strmode(mode_t mode, char *p)
37{
38 /* print type */
39 switch (mode & S_IFMT) {
40 case S_IFDIR: /* directory */
41 *p++ = 'd';
42 break;
43 case S_IFCHR: /* character special */
44 *p++ = 'c';
45 break;
46 case S_IFBLK: /* block special */
47 *p++ = 'b';
48 break;
49 case S_IFREG: /* regular */
50 *p++ = '-';
51 break;
52 case S_IFLNK: /* symbolic link */
53 *p++ = 'l';
54 break;
55 case S_IFSOCK: /* socket */
56 *p++ = 's';
57 break;
58#ifdef S_IFIFO
59 case S_IFIFO: /* fifo */
60 *p++ = 'p';
61 break;
62#endif
63 default: /* unknown */
64 *p++ = '?';
65 break;
66 }
67 /* usr */
68 if (mode & S_IRUSR)
69 *p++ = 'r';
70 else
71 *p++ = '-';
72 if (mode & S_IWUSR)
73 *p++ = 'w';
74 else
75 *p++ = '-';
76 switch (mode & (S_IXUSR | S_ISUID)) {
77 case 0:
78 *p++ = '-';
79 break;
80 case S_IXUSR:
81 *p++ = 'x';
82 break;
83 case S_ISUID:
84 *p++ = 'S';
85 break;
86 case S_IXUSR | S_ISUID:
87 *p++ = 's';
88 break;
89 }
90 /* group */
91 if (mode & S_IRGRP)
92 *p++ = 'r';
93 else
94 *p++ = '-';
95 if (mode & S_IWGRP)
96 *p++ = 'w';
97 else
98 *p++ = '-';
99 switch (mode & (S_IXGRP | S_ISGID)) {
100 case 0:
101 *p++ = '-';
102 break;
103 case S_IXGRP:
104 *p++ = 'x';
105 break;
106 case S_ISGID:
107 *p++ = 'S';
108 break;
109 case S_IXGRP | S_ISGID:
110 *p++ = 's';
111 break;
112 }
113 /* other */
114 if (mode & S_IROTH)
115 *p++ = 'r';
116 else
117 *p++ = '-';
118 if (mode & S_IWOTH)
119 *p++ = 'w';
120 else
121 *p++ = '-';
122 switch (mode & (S_IXOTH | S_ISVTX)) {
123 case 0:
124 *p++ = '-';
125 break;
126 case S_IXOTH:
127 *p++ = 'x';
128 break;
129 case S_ISVTX:
130 *p++ = 'T';
131 break;
132 case S_IXOTH | S_ISVTX:
133 *p++ = 't';
134 break;
135 }
136 *p++ = ' '; /* will be a '+' if ACL's implemented */
137 *p = '\0';
138}
139DEF_WEAK(strmode);
diff --git a/src/lib/libc/string/strncat.3 b/src/lib/libc/string/strncat.3
deleted file mode 100644
index d314a9999a..0000000000
--- a/src/lib/libc/string/strncat.3
+++ /dev/null
@@ -1,132 +0,0 @@
1.\" $OpenBSD: strncat.3,v 1.4 2014/04/19 16:50:46 jmc Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: April 19 2014 $
35.Dt STRNCAT 3
36.Os
37.Sh NAME
38.Nm strncat
39.Nd concatenate a string with part of another
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strncat "char *dst" "const char *append" "size_t count"
44.Sh DESCRIPTION
45The
46.Fn strncat
47function appends not more than
48.Fa count
49characters of the string
50.Fa append
51to the end of the string found in the buffer
52.Fa dst .
53Space for the terminating
54.Ql \e0
55should not be included in
56.Fa count .
57.Pp
58Bounds checking must be performed manually with great care.
59If the buffer
60.Fa dst
61is not large enough to hold the result,
62subsequent memory will be damaged.
63.Sh RETURN VALUES
64The
65.Fn strncat
66function returns the pointer
67.Fa dst .
68.Sh EXAMPLES
69The following example shows how to use
70.Fn strncat
71in conjunction with
72.Xr strncpy 3 :
73.Bd -literal -offset indent
74char buf[BUFSIZ];
75char *base, *suffix;
76
77(void)strncpy(buf, base, sizeof(buf) - 1);
78buf[sizeof(buf) - 1] = '\e0';
79(void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf));
80.Ed
81.Pp
82The above will copy as many characters from
83.Va base
84to
85.Va buf
86as will fit.
87It then appends as many characters from
88.Va suffix
89as will fit.
90If either
91.Va base
92or
93.Va suffix
94are too large, truncation will occur without detection.
95.Pp
96The above example shows dangerous coding patterns, including an
97inability to detect truncation.
98.Fn strncat
99and
100.Fn strncpy
101are dangerously easy to misuse.
102The
103.Xr strlcpy 3
104and
105.Xr strlcat 3
106functions are safer for this kind of operation:
107.Bd -literal -offset indent
108if (strlcpy(buf, base, sizeof(buf)) >= sizeof(buf) ||
109 strlcat(buf, suffix, sizeof(buf)) >= sizeof(buf))
110 goto toolong;
111
112.Ed
113or for greatest portability,
114.Bd -literal -offset indent
115if (snprintf(buf, sizeof(buf), "%s%s",
116 base, suffix) >= sizeof(buf))
117 goto toolong;
118.Ed
119.Sh SEE ALSO
120.Xr strlcpy 3 ,
121.Xr wcscat 3 ,
122.Xr wcslcpy 3
123.Sh STANDARDS
124The
125.Fn strncat
126function conforms to
127.St -ansiC .
128.Sh HISTORY
129The
130.Fn strncat
131function first appeared in
132.At v7 .
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c
deleted file mode 100644
index b3388accf3..0000000000
--- a/src/lib/libc/string/strncat.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/* $OpenBSD: strncat.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes
38 * are written at dst (at most n+1 bytes being appended). Return dst.
39 */
40char *
41strncat(char *dst, const char *src, size_t n)
42{
43 if (n != 0) {
44 char *d = dst;
45 const char *s = src;
46
47 while (*d != 0)
48 d++;
49 do {
50 if ((*d = *s++) == 0)
51 break;
52 d++;
53 } while (--n != 0);
54 *d = 0;
55 }
56 return (dst);
57}
58DEF_STRONG(strncat);
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c
deleted file mode 100644
index 535d2a60fd..0000000000
--- a/src/lib/libc/string/strncmp.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/* $OpenBSD: strncmp.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
2
3/*
4 * Copyright (c) 1989 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34int
35strncmp(const char *s1, const char *s2, size_t n)
36{
37
38 if (n == 0)
39 return (0);
40 do {
41 if (*s1 != *s2++)
42 return (*(unsigned char *)s1 - *(unsigned char *)--s2);
43 if (*s1++ == 0)
44 break;
45 } while (--n != 0);
46 return (0);
47}
48DEF_STRONG(strncmp);
diff --git a/src/lib/libc/string/strncpy.3 b/src/lib/libc/string/strncpy.3
deleted file mode 100644
index 3a68a0bd5b..0000000000
--- a/src/lib/libc/string/strncpy.3
+++ /dev/null
@@ -1,138 +0,0 @@
1.\" $OpenBSD: strncpy.3,v 1.2 2014/04/19 11:30:40 deraadt Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: April 19 2014 $
35.Dt STRNCPY 3
36.Os
37.Sh NAME
38.Nm strncpy
39.Nd copy part of a string to another
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strncpy "char *dst" "const char *src" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn strncpy
47function copies not more than
48.Fa len
49characters from the string
50.Fa src
51to the buffer
52.Fa dst .
53If
54.Fa src
55is less than
56.Fa len
57characters long,
58it fills the remaining buffer with
59.Ql \e0
60characters.
61If the length of
62.Fa src
63is greater than or equal to
64.Fa len ,
65.Fa dst
66will
67.Em not
68be NUL-terminated.
69.Pp
70.Fn strncpy
71.Em only
72NUL terminates the destination string when the length of the source
73string is less than the length parameter.
74.Pp
75If the
76.Fa src
77and
78.Fa dst
79strings overlap, the behavior is undefined.
80.Sh RETURN VALUES
81The
82.Fn strncpy
83function returns
84.Fa dst .
85.Sh EXAMPLES
86The following sets
87.Va chararray
88to
89.Dq abc\e0\e0\e0 :
90.Bd -literal -offset indent
91(void)strncpy(chararray, "abc", 6);
92.Ed
93.Pp
94The following sets
95.Va chararray
96to
97.Dq abcdef ,
98without a NUL-terminator:
99.Bd -literal -offset indent
100(void)strncpy(chararray, "abcdefgh", 6);
101.Ed
102.Pp
103The following sequence copies as many characters from
104.Va input
105to
106.Va buf
107as will fit, and then NUL terminates the result by hand:
108.Bd -literal -offset indent
109char buf[BUFSIZ];
110
111(void)strncpy(buf, input, sizeof(buf) - 1);
112buf[sizeof(buf) - 1] = '\e0';
113.Ed
114.Pp
115By now it is clear that
116.Nm strncpy
117is dangerously easy to misuse.
118The
119.Xr strlcpy 3
120function is safer for this kind of operation:
121.Bd -literal -offset indent
122if (strlcpy(buf, input, sizeof(buf)) >= sizeof(buf))
123 goto toolong;
124.Ed
125.Sh SEE ALSO
126.Xr strlcpy 3 ,
127.Xr wcscpy 3 ,
128.Xr wcslcpy 3
129.Sh STANDARDS
130The
131.Fn strncpy
132function conforms to
133.St -ansiC .
134.Sh HISTORY
135The
136.Fn strncpy
137function first appeared in
138.At v7 .
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c
deleted file mode 100644
index d6d8647fc7..0000000000
--- a/src/lib/libc/string/strncpy.c
+++ /dev/null
@@ -1,59 +0,0 @@
1/* $OpenBSD: strncpy.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <string.h>
36
37/*
38 * Copy src to dst, truncating or null-padding to always copy n bytes.
39 * Return dst.
40 */
41char *
42strncpy(char *dst, const char *src, size_t n)
43{
44 if (n != 0) {
45 char *d = dst;
46 const char *s = src;
47
48 do {
49 if ((*d++ = *s++) == 0) {
50 /* NUL pad the remaining n-1 bytes */
51 while (--n != 0)
52 *d++ = 0;
53 break;
54 }
55 } while (--n != 0);
56 }
57 return (dst);
58}
59DEF_STRONG(strncpy);
diff --git a/src/lib/libc/string/strndup.c b/src/lib/libc/string/strndup.c
deleted file mode 100644
index 499f9a028a..0000000000
--- a/src/lib/libc/string/strndup.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/* $OpenBSD: strndup.c,v 1.3 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 2010 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20
21#include <stddef.h>
22#include <stdlib.h>
23#include <string.h>
24
25char *
26strndup(const char *str, size_t maxlen)
27{
28 char *copy;
29 size_t len;
30
31 len = strnlen(str, maxlen);
32 copy = malloc(len + 1);
33 if (copy != NULL) {
34 (void)memcpy(copy, str, len);
35 copy[len] = '\0';
36 }
37
38 return copy;
39}
40DEF_WEAK(strndup);
diff --git a/src/lib/libc/string/strnlen.c b/src/lib/libc/string/strnlen.c
deleted file mode 100644
index d50a927f28..0000000000
--- a/src/lib/libc/string/strnlen.c
+++ /dev/null
@@ -1,33 +0,0 @@
1/* $OpenBSD: strnlen.c,v 1.9 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 2010 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20
21#include <string.h>
22
23size_t
24strnlen(const char *str, size_t maxlen)
25{
26 const char *cp;
27
28 for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
29 ;
30
31 return (size_t)(cp - str);
32}
33DEF_WEAK(strnlen);
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3
deleted file mode 100644
index 51d2edf5b8..0000000000
--- a/src/lib/libc/string/strpbrk.3
+++ /dev/null
@@ -1,80 +0,0 @@
1.\" $OpenBSD: strpbrk.3,v 1.11 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRPBRK 3
36.Os
37.Sh NAME
38.Nm strpbrk
39.Nd locate multiple characters in string
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strpbrk "const char *s" "const char *charset"
44.Sh DESCRIPTION
45The
46.Fn strpbrk
47function locates in the NUL-terminated string
48.Fa s
49the first occurrence of any character in the string
50.Fa charset
51and returns a pointer to this character.
52If no characters from
53.Fa charset
54occur anywhere in
55.Fa s ,
56.Fn strpbrk
57returns
58.Dv NULL .
59.Sh SEE ALSO
60.Xr memchr 3 ,
61.Xr strchr 3 ,
62.Xr strcspn 3 ,
63.Xr strrchr 3 ,
64.Xr strsep 3 ,
65.Xr strspn 3 ,
66.Xr strstr 3 ,
67.Xr strtok 3 ,
68.Xr wcspbrk 3
69.Sh STANDARDS
70The
71.Fn strpbrk
72function conforms to
73.St -ansiC .
74.Sh HISTORY
75The
76.Fn strpbrk
77function first appeared in
78.At III
79and was reimplemented for
80.Bx 4.3 .
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c
deleted file mode 100644
index 336c22dedd..0000000000
--- a/src/lib/libc/string/strpbrk.c
+++ /dev/null
@@ -1,49 +0,0 @@
1/* $OpenBSD: strpbrk.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Copyright (c) 1985 Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <string.h>
32
33/*
34 * Find the first occurrence in s1 of a character in s2 (excluding NUL).
35 */
36char *
37strpbrk(const char *s1, const char *s2)
38{
39 const char *scanp;
40 int c, sc;
41
42 while ((c = *s1++) != 0) {
43 for (scanp = s2; (sc = *scanp++) != 0;)
44 if (sc == c)
45 return ((char *)(s1 - 1));
46 }
47 return (NULL);
48}
49DEF_STRONG(strpbrk);
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3
deleted file mode 100644
index 231260f7f3..0000000000
--- a/src/lib/libc/string/strrchr.3
+++ /dev/null
@@ -1,118 +0,0 @@
1.\" $OpenBSD: strrchr.3,v 1.13 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRRCHR 3
36.Os
37.Sh NAME
38.Nm strrchr ,
39.Nm rindex
40.Nd locate last occurrence of a character in a string
41.Sh SYNOPSIS
42.In string.h
43.Ft char *
44.Fn strrchr "const char *s" "int c"
45.In strings.h
46.Ft char *
47.Fn rindex "const char *s" "int c"
48.Sh DESCRIPTION
49The
50.Fn strrchr
51function locates the last occurrence of the character
52.Fa c
53.Pq converted to a char
54in the string
55.Fa s .
56The terminating
57.Tn NUL
58character is considered part of the string.
59If
60.Fa c
61is
62.Ql \e0 ,
63.Fn strrchr
64locates the terminating
65.Ql \e0 .
66.Pp
67The
68.Fn rindex
69function is an old synonym for
70.Fn strrchr .
71.Sh RETURN VALUES
72The
73.Fn strrchr
74function returns a pointer to the located character or
75.Dv NULL
76if the character does not appear in the string.
77.Sh EXAMPLES
78After the following call to
79.Fn strrchr ,
80.Va p
81will point to the string
82.Qq obar :
83.Bd -literal -offset indent
84char *p;
85char *s = "foobar";
86
87p = strrchr(s, 'o');
88.Ed
89.Sh SEE ALSO
90.Xr memchr 3 ,
91.Xr strchr 3 ,
92.Xr strcspn 3 ,
93.Xr strpbrk 3 ,
94.Xr strsep 3 ,
95.Xr strspn 3 ,
96.Xr strstr 3 ,
97.Xr strtok 3 ,
98.Xr wcsrchr 3
99.Sh STANDARDS
100The
101.Fn strrchr
102function conforms to
103.St -ansiC .
104.Pp
105The
106.Fn rindex
107function is deprecated and shouldn't be used in new code.
108.Sh HISTORY
109The
110.Fn rindex
111function first appeared in
112.At v7 .
113The
114.Fn strrchr
115function first appeared in
116.At III
117and was reimplemented for
118.Bx 4.3 .
diff --git a/src/lib/libc/string/strrchr.c b/src/lib/libc/string/strrchr.c
deleted file mode 100644
index 848d1ad22e..0000000000
--- a/src/lib/libc/string/strrchr.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/* $OpenBSD: strrchr.c,v 1.4 2018/10/01 06:37:37 martijn Exp $ */
2/*
3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <string.h>
32
33__weak_alias(rindex, strrchr);
34
35char *
36strrchr(const char *p, int ch)
37{
38 char *save;
39
40 for (save = NULL;; ++p) {
41 if (*p == (char) ch)
42 save = (char *)p;
43 if (!*p)
44 return(save);
45 }
46 /* NOTREACHED */
47}
48DEF_STRONG(strrchr);
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3
deleted file mode 100644
index 77053f66d7..0000000000
--- a/src/lib/libc/string/strsep.3
+++ /dev/null
@@ -1,110 +0,0 @@
1.\" $OpenBSD: strsep.3,v 1.14 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. 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.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93
34.\"
35.Dd $Mdocdate: June 5 2013 $
36.Dt STRSEP 3
37.Os
38.Sh NAME
39.Nm strsep
40.Nd separate strings
41.Sh SYNOPSIS
42.In string.h
43.Ft char *
44.Fn strsep "char **stringp" "const char *delim"
45.Sh DESCRIPTION
46The
47.Fn strsep
48function locates, in the string referenced by
49.Fa *stringp ,
50the first occurrence of any character in the string
51.Fa delim
52(or the terminating
53.Ql \e0
54character) and replaces it with a
55.Ql \e0 .
56The location of the next character after the delimiter character
57(or
58.Dv NULL ,
59if the end of the string was reached) is stored in
60.Fa *stringp .
61The original value of
62.Fa *stringp
63is returned.
64.Pp
65An
66.Dq empty
67field, i.e., one caused by two adjacent delimiter characters,
68can be detected by comparing the location referenced by the pointer returned
69by
70.Fn strsep
71to
72.Ql \e0 .
73.Pp
74If
75.Fa *stringp
76is initially
77.Dv NULL ,
78.Fn strsep
79returns
80.Dv NULL .
81.Sh EXAMPLES
82The following uses
83.Fn strsep
84to parse a string, containing tokens delimited by whitespace, into an
85argument vector:
86.Bd -literal -offset indent
87char **ap, *argv[10], *inputstring;
88
89for (ap = argv; ap < &argv[9] &&
90 (*ap = strsep(&inputstring, " \et")) != NULL;) {
91 if (**ap != '\e0')
92 ap++;
93}
94*ap = NULL;
95.Ed
96.Sh HISTORY
97The
98.Fn strsep
99function first appeared in
100.Bx 4.3 Reno .
101It is intended as a replacement for the
102.Xr strtok 3
103function.
104While the
105.Xr strtok 3
106function should be preferred for portability reasons (it conforms to
107.St -ansiC )
108it is unable to handle empty fields, i.e., detect fields delimited by
109two adjacent delimiter characters, or to be used for more than a single
110string at a time.
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c
deleted file mode 100644
index 97c3cbf1f5..0000000000
--- a/src/lib/libc/string/strsep.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/* $OpenBSD: strsep.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
2
3/*-
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <string.h>
33
34/*
35 * Get next token from string *stringp, where tokens are possibly-empty
36 * strings separated by characters from delim.
37 *
38 * Writes NULs into the string at *stringp to end tokens.
39 * delim need not remain constant from call to call.
40 * On return, *stringp points past the last NUL written (if there might
41 * be further tokens), or is NULL (if there are definitely no more tokens).
42 *
43 * If *stringp is NULL, strsep returns NULL.
44 */
45char *
46strsep(char **stringp, const char *delim)
47{
48 char *s;
49 const char *spanp;
50 int c, sc;
51 char *tok;
52
53 if ((s = *stringp) == NULL)
54 return (NULL);
55 for (tok = s;;) {
56 c = *s++;
57 spanp = delim;
58 do {
59 if ((sc = *spanp++) == c) {
60 if (c == 0)
61 s = NULL;
62 else
63 s[-1] = 0;
64 *stringp = s;
65 return (tok);
66 }
67 } while (sc != 0);
68 }
69 /* NOTREACHED */
70}
71DEF_WEAK(strsep);
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3
deleted file mode 100644
index b46be893b5..0000000000
--- a/src/lib/libc/string/strsignal.3
+++ /dev/null
@@ -1,78 +0,0 @@
1.\" Copyright (c) 1980, 1991 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. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" $OpenBSD: strsignal.3,v 1.9 2019/05/16 13:35:16 schwarze Exp $
33.\"
34.Dd $Mdocdate: May 16 2019 $
35.Dt STRSIGNAL 3
36.Os
37.Sh NAME
38.Nm strsignal
39.Nd get signal description string
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strsignal "int sig"
44.Sh DESCRIPTION
45The
46.Fn strsignal
47function returns a pointer to the string describing the signal
48.Fa sig .
49.Pp
50The array pointed to is not to be modified by the program, but may be
51overwritten by subsequent calls to
52.Fn strsignal .
53.Sh SEE ALSO
54.Xr intro 2 ,
55.Xr psignal 3 ,
56.Xr setlocale 3
57.Sh STANDARDS
58The
59.Fn strsignal
60function conforms to
61.St -p1003.1-2008 .
62.Sh HISTORY
63The
64.Fn strsignal
65function first appeared in
66.At V.4
67and was reimplemented for
68.Nx 1.0 .
69.Sh CAVEATS
70On systems other than
71.Ox ,
72the
73.Dv LC_MESSAGES
74.Xr locale 1
75category can cause different strings to be returned instead of the
76normal signal descriptions; see CAVEATS in
77.Xr setlocale 3
78for details.
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c
deleted file mode 100644
index fe2a747943..0000000000
--- a/src/lib/libc/string/strsignal.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright (c) 1988 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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <string.h>
31#include <limits.h>
32
33char *
34strsignal(int sig)
35{
36 static char buf[NL_TEXTMAX];
37
38 return __strsignal(sig, buf);
39}
40DEF_WEAK(strsignal);
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3
deleted file mode 100644
index e677ba15a1..0000000000
--- a/src/lib/libc/string/strspn.3
+++ /dev/null
@@ -1,92 +0,0 @@
1.\" $OpenBSD: strspn.3,v 1.12 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRSPN 3
36.Os
37.Sh NAME
38.Nm strspn
39.Nd span a string
40.Sh SYNOPSIS
41.In string.h
42.Ft size_t
43.Fn strspn "const char *s" "const char *charset"
44.Sh DESCRIPTION
45The
46.Fn strspn
47function spans the initial part of the NUL-terminated string
48.Fa s
49as long as the characters from
50.Fa s
51occur in string
52.Fa charset .
53.Sh RETURN VALUES
54The
55.Fn strspn
56function returns the number of characters spanned.
57.Sh EXAMPLES
58The following call to
59.Fn strspn
60will return 3, since the first three characters of string
61.Fa s
62are part of string
63.Fa charset :
64.Bd -literal -offset indent
65char *s = "foobar";
66char *charset = "of";
67size_t span;
68
69span = strspn(s, charset);
70.Ed
71.Sh SEE ALSO
72.Xr memchr 3 ,
73.Xr strchr 3 ,
74.Xr strcspn 3 ,
75.Xr strpbrk 3 ,
76.Xr strrchr 3 ,
77.Xr strsep 3 ,
78.Xr strstr 3 ,
79.Xr strtok 3 ,
80.Xr wcsspn 3
81.Sh STANDARDS
82The
83.Fn strspn
84function conforms to
85.St -ansiC .
86.Sh HISTORY
87The
88.Fn strspn
89function first appeared in
90.At III
91and was reimplemented for
92.Bx 4.3 .
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c
deleted file mode 100644
index 0ce41cbb49..0000000000
--- a/src/lib/libc/string/strspn.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: strspn.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Copyright (c) 1989 The Regents of the University of California.
4 * All rights reserved.
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 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <string.h>
32
33/*
34 * Span the string s2 (skip characters that are in s2).
35 */
36size_t
37strspn(const char *s1, const char *s2)
38{
39 const char *p = s1, *spanp;
40 char c, sc;
41
42 /*
43 * Skip any characters in s2, excluding the terminating \0.
44 */
45cont:
46 c = *p++;
47 for (spanp = s2; (sc = *spanp++) != 0;)
48 if (sc == c)
49 goto cont;
50 return (p - 1 - s1);
51}
52DEF_STRONG(strspn);
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3
deleted file mode 100644
index 60d2a721a7..0000000000
--- a/src/lib/libc/string/strstr.3
+++ /dev/null
@@ -1,101 +0,0 @@
1.\" $OpenBSD: strstr.3,v 1.13 2016/05/11 17:51:50 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: May 11 2016 $
35.Dt STRSTR 3
36.Os
37.Sh NAME
38.Nm strstr , strcasestr
39.Nd locate a substring in a string
40.Sh SYNOPSIS
41.In string.h
42.Ft char *
43.Fn strstr "const char *big" "const char *little"
44.Ft char *
45.Fn strcasestr "const char *big" "const char *little"
46.Sh DESCRIPTION
47The
48.Fn strstr
49function locates the first occurrence of the NUL-terminated string
50.Fa little
51in the NUL-terminated string
52.Fa big .
53.Pp
54The
55.Fn strcasestr
56function is similar to
57.Fn strstr
58but ignores the case of both strings.
59.Sh RETURN VALUES
60If
61.Fa little
62is an empty string,
63.Fa big
64is returned;
65if
66.Fa little
67occurs nowhere in
68.Fa big ,
69.Dv NULL
70is returned;
71otherwise a pointer to the first character of the first occurrence of
72.Fa little
73is returned.
74.Sh SEE ALSO
75.Xr memchr 3 ,
76.Xr memmem 3 ,
77.Xr strchr 3 ,
78.Xr strcspn 3 ,
79.Xr strpbrk 3 ,
80.Xr strrchr 3 ,
81.Xr strsep 3 ,
82.Xr strspn 3 ,
83.Xr strtok 3 ,
84.Xr wcsstr 3
85.Sh STANDARDS
86The
87.Fn strstr
88function conforms to
89.St -ansiC .
90.Sh HISTORY
91The
92.Fn strstr
93function first appeared in
94.Bx 4.3 Reno .
95The
96.Fn strcasestr
97function appeared in glibc 2.1,
98was reimplemented for
99.Fx 4.5
100and ported to
101.Ox 3.8 .
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c
deleted file mode 100644
index 241a080e7a..0000000000
--- a/src/lib/libc/string/strstr.c
+++ /dev/null
@@ -1,189 +0,0 @@
1/* $OpenBSD: strstr.c,v 1.9 2020/04/16 12:37:52 claudio Exp $ */
2
3/*
4 * Copyright (c) 2005-2018 Rich Felker
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <string.h>
27#include <stdint.h>
28
29static char *
30twobyte_strstr(const unsigned char *h, const unsigned char *n)
31{
32 uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
33 for (h++; *h && hw != nw; hw = hw<<8 | *++h);
34 return *h ? (char *)h-1 : 0;
35}
36
37static char *
38threebyte_strstr(const unsigned char *h, const unsigned char *n)
39{
40 uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
41 uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
42 for (h+=2; *h && hw != nw; hw = (hw|*++h)<<8);
43 return *h ? (char *)h-2 : 0;
44}
45
46static char *
47fourbyte_strstr(const unsigned char *h, const unsigned char *n)
48{
49 uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
50 uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
51 for (h+=3; *h && hw != nw; hw = hw<<8 | *++h);
52 return *h ? (char *)h-3 : 0;
53}
54
55#define MAX(a,b) ((a)>(b)?(a):(b))
56#define MIN(a,b) ((a)<(b)?(a):(b))
57
58#define BITOP(a,b,op) \
59 ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
60
61/*
62 * Maxime Crochemore and Dominique Perrin, Two-way string-matching,
63 * Journal of the ACM, 38(3):651-675, July 1991.
64 */
65static char *
66twoway_strstr(const unsigned char *h, const unsigned char *n)
67{
68 const unsigned char *z;
69 size_t l, ip, jp, k, p, ms, p0, mem, mem0;
70 size_t byteset[32 / sizeof(size_t)] = { 0 };
71 size_t shift[256];
72
73 /* Computing length of needle and fill shift table */
74 for (l=0; n[l] && h[l]; l++)
75 BITOP(byteset, n[l], |=), shift[n[l]] = l+1;
76 if (n[l]) return 0; /* hit the end of h */
77
78 /* Compute maximal suffix */
79 ip = -1; jp = 0; k = p = 1;
80 while (jp+k<l) {
81 if (n[ip+k] == n[jp+k]) {
82 if (k == p) {
83 jp += p;
84 k = 1;
85 } else k++;
86 } else if (n[ip+k] > n[jp+k]) {
87 jp += k;
88 k = 1;
89 p = jp - ip;
90 } else {
91 ip = jp++;
92 k = p = 1;
93 }
94 }
95 ms = ip;
96 p0 = p;
97
98 /* And with the opposite comparison */
99 ip = -1; jp = 0; k = p = 1;
100 while (jp+k<l) {
101 if (n[ip+k] == n[jp+k]) {
102 if (k == p) {
103 jp += p;
104 k = 1;
105 } else k++;
106 } else if (n[ip+k] < n[jp+k]) {
107 jp += k;
108 k = 1;
109 p = jp - ip;
110 } else {
111 ip = jp++;
112 k = p = 1;
113 }
114 }
115 if (ip+1 > ms+1) ms = ip;
116 else p = p0;
117
118 /* Periodic needle? */
119 if (memcmp(n, n+p, ms+1)) {
120 mem0 = 0;
121 p = MAX(ms, l-ms-1) + 1;
122 } else mem0 = l-p;
123 mem = 0;
124
125 /* Initialize incremental end-of-haystack pointer */
126 z = h;
127
128 /* Search loop */
129 for (;;) {
130 /* Update incremental end-of-haystack pointer */
131 if (z-h < l) {
132 /* Fast estimate for MIN(l,63) */
133 size_t grow = l | 63;
134 const unsigned char *z2 = memchr(z, 0, grow);
135 if (z2) {
136 z = z2;
137 if (z-h < l) return 0;
138 } else z += grow;
139 }
140
141 /* Check last byte first; advance by shift on mismatch */
142 if (BITOP(byteset, h[l-1], &)) {
143 k = l-shift[h[l-1]];
144 if (k) {
145 if (k < mem) k = mem;
146 h += k;
147 mem = 0;
148 continue;
149 }
150 } else {
151 h += l;
152 mem = 0;
153 continue;
154 }
155
156 /* Compare right half */
157 for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++);
158 if (n[k]) {
159 h += k-ms;
160 mem = 0;
161 continue;
162 }
163 /* Compare left half */
164 for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--);
165 if (k <= mem) return (char *)h;
166 h += p;
167 mem = mem0;
168 }
169}
170
171char *
172strstr(const char *h, const char *n)
173{
174 /* Return immediately on empty needle */
175 if (!n[0]) return (char *)h;
176
177 /* Use faster algorithms for short needles */
178 h = strchr(h, *n);
179 if (!h || !n[1]) return (char *)h;
180 if (!h[1]) return 0;
181 if (!n[2]) return twobyte_strstr((void *)h, (void *)n);
182 if (!h[2]) return 0;
183 if (!n[3]) return threebyte_strstr((void *)h, (void *)n);
184 if (!h[3]) return 0;
185 if (!n[4]) return fourbyte_strstr((void *)h, (void *)n);
186
187 return twoway_strstr((void *)h, (void *)n);
188}
189DEF_STRONG(strstr);
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3
deleted file mode 100644
index a28f72d6f2..0000000000
--- a/src/lib/libc/string/strtok.3
+++ /dev/null
@@ -1,169 +0,0 @@
1.\" $OpenBSD: strtok.3,v 1.24 2024/12/11 23:28:20 jsg Exp $
2.\"
3.\" Copyright (c) 1988, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the American National Standards Committee X3, on Information
8.\" Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: December 11 2024 $
35.Dt STRTOK 3
36.Os
37.Sh NAME
38.Nm strtok ,
39.Nm strtok_r
40.Nd string token operations
41.Sh SYNOPSIS
42.In string.h
43.Ft char *
44.Fn strtok "char *str" "const char *sep"
45.Ft char *
46.Fn strtok_r "char *str" "const char *sep" "char **last"
47.Sh DESCRIPTION
48.Bf -symbolic
49This interface is obsoleted by
50.Xr strsep 3 .
51.Ef
52.Pp
53The
54.Fn strtok
55function is used to isolate sequential tokens in a NUL-terminated string,
56.Fa str .
57These tokens are separated in the string by at least one of the
58characters in
59.Fa sep .
60The first time that
61.Fn strtok
62is called,
63.Fa str
64should be specified; subsequent calls, wishing to obtain further tokens
65from the same string, should pass a null pointer instead.
66The separator string,
67.Fa sep ,
68must be supplied each time, and may change between calls.
69.Pp
70The
71.Fn strtok_r
72function is a version of
73.Fn strtok
74that takes an explicit context argument and is reentrant.
75.Pp
76Since
77.Fn strtok
78and
79.Fn strtok_r
80modify the string,
81.Fa str
82should not point to an area in the initialized data segment.
83.Sh RETURN VALUES
84The
85.Fn strtok
86and
87.Fn strtok_r
88functions return a pointer to the beginning of each subsequent token
89in the string, after replacing the separator character itself with
90a NUL character.
91When no more tokens remain, a null pointer is returned.
92.Sh EXAMPLES
93The following will construct an array of pointers to each individual word in
94the string
95.Va s :
96.Bd -literal -offset indent
97#define MAXTOKENS 128
98
99char s[512], *p, *tokens[MAXTOKENS];
100char *last;
101int i = 0;
102
103snprintf(s, sizeof(s), "cat dog horse cow");
104
105for ((p = strtok_r(s, " ", &last)); p;
106 (p = strtok_r(NULL, " ", &last))) {
107 if (i < MAXTOKENS - 1)
108 tokens[i++] = p;
109}
110tokens[i] = NULL;
111.Ed
112.Pp
113That is,
114.Li tokens[0]
115will point to
116.Qq cat ,
117.Li tokens[1]
118will point to
119.Qq dog ,
120.Li tokens[2]
121will point to
122.Qq horse ,
123and
124.Li tokens[3]
125will point to
126.Qq cow .
127.Sh SEE ALSO
128.Xr memchr 3 ,
129.Xr strchr 3 ,
130.Xr strcspn 3 ,
131.Xr strpbrk 3 ,
132.Xr strrchr 3 ,
133.Xr strsep 3 ,
134.Xr strspn 3 ,
135.Xr strstr 3 ,
136.Xr wcstok 3
137.Sh STANDARDS
138The
139.Fn strtok
140function conforms to
141.St -ansiC .
142The
143.Fn strtok_r
144function conforms to
145.St -p1003.1-2001 .
146.Sh HISTORY
147The
148.Fn strtok
149function first appeared in
150.At III
151and was reimplemented for
152.Bx 4.3 .
153The
154.Fn strtok_r
155function first appeared in
156.Nx 1.3
157and was reimplemented for
158.Ox 2.7 .
159.Sh BUGS
160The System V
161.Fn strtok ,
162if handed a string containing only delimiter characters,
163will not alter the next starting point, so that a call to
164.Fn strtok
165with a different (or empty) delimiter string
166may return a non-null value.
167Since this implementation always alters the next starting point,
168such a sequence of calls would always return
169.Dv NULL .
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c
deleted file mode 100644
index c5765756fc..0000000000
--- a/src/lib/libc/string/strtok.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright (c) 1988 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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <string.h>
31
32char *
33strtok(char *s, const char *delim)
34{
35 static char *last;
36
37 return strtok_r(s, delim, &last);
38}
39DEF_STRONG(strtok);
40
41char *
42strtok_r(char *s, const char *delim, char **last)
43{
44 const char *spanp;
45 int c, sc;
46 char *tok;
47
48 if (s == NULL && (s = *last) == NULL)
49 return (NULL);
50
51 /*
52 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
53 */
54cont:
55 c = *s++;
56 for (spanp = delim; (sc = *spanp++) != 0;) {
57 if (c == sc)
58 goto cont;
59 }
60
61 if (c == 0) { /* no non-delimiter characters */
62 *last = NULL;
63 return (NULL);
64 }
65 tok = s - 1;
66
67 /*
68 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
69 * Note that delim must have one NUL; we stop if we see that, too.
70 */
71 for (;;) {
72 c = *s++;
73 spanp = delim;
74 do {
75 if ((sc = *spanp++) == c) {
76 if (c == 0)
77 s = NULL;
78 else
79 s[-1] = '\0';
80 *last = s;
81 return (tok);
82 }
83 } while (sc != 0);
84 }
85 /* NOTREACHED */
86}
87DEF_WEAK(strtok_r);
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3
deleted file mode 100644
index dab3673f38..0000000000
--- a/src/lib/libc/string/strxfrm.3
+++ /dev/null
@@ -1,105 +0,0 @@
1.\" $OpenBSD: strxfrm.3,v 1.12 2019/01/18 07:43:36 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Chris Torek and the American National Standards Committee X3,
9.\" on Information Processing Systems.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in the
18.\" documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.Dd $Mdocdate: January 18 2019 $
36.Dt STRXFRM 3
37.Os
38.Sh NAME
39.Nm strxfrm ,
40.Nm strxfrm_l
41.Nd transform a string under locale
42.Sh SYNOPSIS
43.In string.h
44.Ft size_t
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"
48.Sh DESCRIPTION
49The idea of
50.Fn strxfrm
51and
52.Fn strxfrm_l
53is to
54.Dq un-localize
55a string: the functions transform
56.Ar src ,
57storing the result in
58.Ar dst ,
59such that
60.Xr strcmp 3
61on transformed strings returns what
62.Xr strcoll 3
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.
72On other operating systems, the behaviour may depend on the
73.Dv LC_CTYPE
74and
75.Dv LC_COLLATE
76locale categories set with
77.Xr setlocale 3 ,
78.Xr uselocale 3 ,
79or
80.Xr newlocale 3 .
81.Sh SEE ALSO
82.Xr newlocale 3 ,
83.Xr setlocale 3 ,
84.Xr strcmp 3 ,
85.Xr strcoll 3 ,
86.Xr strlcpy 3 ,
87.Xr wcsxfrm 3
88.Sh STANDARDS
89The
90.Fn strxfrm
91function conforms to
92.St -ansiC ,
93and
94.Fn strxfrm_l
95to
96.St -p1003.1-2008 .
97.Sh HISTORY
98The
99.Fn strxfrm
100function has been available since
101.Bx 4.3 Reno ,
102and
103.Fn strxfrm_l
104since
105.Ox 6.2 .
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c
deleted file mode 100644
index 97df097b29..0000000000
--- a/src/lib/libc/string/strxfrm.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: strxfrm.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
2/*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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#include <string.h>
35
36/*
37 * Transform src, storing the result in dst, such that
38 * strcmp() on transformed strings returns what strcoll()
39 * on the original untransformed strings would return.
40 */
41size_t
42strxfrm(char *dst, const char *src, size_t n)
43{
44
45 /*
46 * Since locales are unimplemented, this is just a copy.
47 */
48 if (n == 0)
49 return (strlen(src));
50 return (strlcpy(dst, src, n));
51}
52DEF_STRONG(strxfrm);
diff --git a/src/lib/libc/string/strxfrm_l.c b/src/lib/libc/string/strxfrm_l.c
deleted file mode 100644
index ff77947953..0000000000
--- a/src/lib/libc/string/strxfrm_l.c
+++ /dev/null
@@ -1,14 +0,0 @@
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/swab.3 b/src/lib/libc/string/swab.3
deleted file mode 100644
index 777f2833b6..0000000000
--- a/src/lib/libc/string/swab.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\" may be used to endorse or promote products derived from this software
14.\" without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\" $OpenBSD: swab.3,v 1.10 2022/09/28 20:27:12 jmc Exp $
29.\"
30.Dd $Mdocdate: September 28 2022 $
31.Dt SWAB 3
32.Os
33.Sh NAME
34.Nm swab
35.Nd swap adjacent bytes
36.Sh SYNOPSIS
37.In unistd.h
38.Ft void
39.Fo swab
40.Fa "const void *restrict src"
41.Fa "void *restrict dst"
42.Fa "ssize_t len"
43.Fc
44.Sh DESCRIPTION
45The
46.Fn swab
47function copies
48.Fa len
49bytes from the location referenced by
50.Fa src
51to the location referenced by
52.Fa dst ,
53swapping adjacent bytes.
54.Pp
55If
56.Fa len
57is zero or less,
58.Fn swab
59does nothing.
60If it is odd, what happens to the last byte is unspecified.
61If
62.Fa src
63and
64.Fa dst
65overlap, behaviour is undefined.
66.Sh SEE ALSO
67.Xr bzero 3 ,
68.Xr memset 3
69.Sh STANDARDS
70The
71.Fn swab
72function is compliant with the X/Open System Interfaces option of the
73.St -p1003.1-2008
74specification.
75.Sh HISTORY
76The
77.Fn swab
78function first appeared in
79.At v7 .
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c
deleted file mode 100644
index c7d7d72ce0..0000000000
--- a/src/lib/libc/string/swab.c
+++ /dev/null
@@ -1,35 +0,0 @@
1/* $OpenBSD: swab.c,v 1.9 2014/12/11 23:05:38 tedu Exp $ */
2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@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#include <unistd.h>
18
19void
20swab(const void *__restrict from, void *__restrict to, ssize_t len)
21{
22 const unsigned char *src = from;
23 unsigned char *dst = to;
24 unsigned char t0, t1;
25
26 while (len > 1) {
27 t0 = src[0];
28 t1 = src[1];
29 dst[0] = t1;
30 dst[1] = t0;
31 src += 2;
32 dst += 2;
33 len -= 2;
34 }
35}
diff --git a/src/lib/libc/string/timingsafe_bcmp.3 b/src/lib/libc/string/timingsafe_bcmp.3
deleted file mode 100644
index 00da769157..0000000000
--- a/src/lib/libc/string/timingsafe_bcmp.3
+++ /dev/null
@@ -1,87 +0,0 @@
1.\" $OpenBSD: timingsafe_bcmp.3,v 1.2 2014/06/21 20:22:15 tedu Exp $
2.\"
3.\" Copyright (c) 2014 Google Inc.
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.Dd $Mdocdate: June 21 2014 $
17.Dt TIMINGSAFE_BCMP 3
18.Os
19.Sh NAME
20.Nm timingsafe_bcmp ,
21.Nm timingsafe_memcmp
22.Nd timing-safe byte sequence comparisons
23.Sh SYNOPSIS
24.In string.h
25.Ft int
26.Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len"
27.Ft int
28.Fn timingsafe_memcmp "const void *b1" "const void *b2" "size_t len"
29.Sh DESCRIPTION
30The
31.Fn timingsafe_bcmp
32and
33.Fn timingsafe_memcmp
34functions lexicographically compare the first
35.Fa len
36bytes (each interpreted as an
37.Vt unsigned char )
38pointed to by
39.Fa b1
40and
41.Fa b2 .
42.Pp
43Additionally, their running times are independent of the byte sequences compared,
44making them safe to use for comparing secret values such as cryptographic MACs.
45In contrast,
46.Xr bcmp 3
47and
48.Xr memcmp 3
49may short-circuit after finding the first differing byte.
50.Sh RETURN VALUES
51The
52.Fn timingsafe_bcmp
53function returns 0 or not zero if the byte sequence pointed to by
54.Fa b1
55compares equal to or not equal to (respectively)
56the byte sequence pointed to by
57.Fa b2 .
58.Pp
59The
60.Fn timingsafe_memcmp
61function returns a negative value, 0, or positive value if the byte sequence
62pointed to by
63.Fa b1
64compares less than, equal to, or greater than (respectively)
65the byte sequence pointed to by
66.Fa b2 .
67.Sh SEE ALSO
68.Xr bcmp 3 ,
69.Xr memcmp 3
70.Sh STANDARDS
71The
72.Fn timingsafe_bcmp
73and
74.Fn timingsafe_memcmp
75functions are
76.Ox
77extensions.
78.Sh HISTORY
79The
80.Fn timingsafe_bcmp
81function first appeared in
82.Ox 4.9 .
83.Pp
84The
85.Fn timingsafe_memcmp
86function first appeared in
87.Ox 5.6 .
diff --git a/src/lib/libc/string/timingsafe_bcmp.c b/src/lib/libc/string/timingsafe_bcmp.c
deleted file mode 100644
index 0409ec3244..0000000000
--- a/src/lib/libc/string/timingsafe_bcmp.c
+++ /dev/null
@@ -1,30 +0,0 @@
1/* $OpenBSD: timingsafe_bcmp.c,v 1.3 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Copyright (c) 2010 Damien Miller. All rights reserved.
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 <string.h>
19
20int
21timingsafe_bcmp(const void *b1, const void *b2, size_t n)
22{
23 const unsigned char *p1 = b1, *p2 = b2;
24 int ret = 0;
25
26 for (; n > 0; n--)
27 ret |= *p1++ ^ *p2++;
28 return (ret != 0);
29}
30DEF_WEAK(timingsafe_bcmp);
diff --git a/src/lib/libc/string/timingsafe_memcmp.c b/src/lib/libc/string/timingsafe_memcmp.c
deleted file mode 100644
index 373f8cb197..0000000000
--- a/src/lib/libc/string/timingsafe_memcmp.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/* $OpenBSD: timingsafe_memcmp.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */
2/*
3 * Copyright (c) 2014 Google Inc.
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
21int
22timingsafe_memcmp(const void *b1, const void *b2, size_t len)
23{
24 const unsigned char *p1 = b1, *p2 = b2;
25 size_t i;
26 int res = 0, done = 0;
27
28 for (i = 0; i < len; i++) {
29 /* lt is -1 if p1[i] < p2[i]; else 0. */
30 int lt = (p1[i] - p2[i]) >> CHAR_BIT;
31
32 /* gt is -1 if p1[i] > p2[i]; else 0. */
33 int gt = (p2[i] - p1[i]) >> CHAR_BIT;
34
35 /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */
36 int cmp = lt - gt;
37
38 /* set res = cmp if !done. */
39 res |= cmp & ~done;
40
41 /* set done if p1[i] != p2[i]. */
42 done |= lt | gt;
43 }
44
45 return (res);
46}
47DEF_WEAK(timingsafe_memcmp);
diff --git a/src/lib/libc/string/wcscasecmp.3 b/src/lib/libc/string/wcscasecmp.3
deleted file mode 100644
index 9db4a829b9..0000000000
--- a/src/lib/libc/string/wcscasecmp.3
+++ /dev/null
@@ -1,134 +0,0 @@
1.\" $OpenBSD: wcscasecmp.3,v 1.5 2017/09/05 03:16:14 schwarze Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Chris Torek.
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. 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.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
34.\"
35.Dd $Mdocdate: September 5 2017 $
36.Dt WCSCASECMP 3
37.Os
38.Sh NAME
39.Nm wcscasecmp ,
40.Nm wcscasecmp_l ,
41.Nm wcsncasecmp ,
42.Nm wcsncasecmp_l
43.Nd compare wide strings, ignoring case
44.Sh SYNOPSIS
45.In wchar.h
46.Ft int
47.Fo wcscasecmp
48.Fa "const wchar_t *s1"
49.Fa "const wchar_t *s2"
50.Fc
51.Ft int
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
70.Sh DESCRIPTION
71These functions compare the wide strings
72.Fa s1
73and
74.Fa s2
75and return an integer greater than, equal to, or less than 0,
76according to whether
77.Fa s1
78is lexicographically greater than, equal to, or less than
79.Fa s2
80after translation of each corresponding wide character to lower case.
81The wide strings themselves are not modified.
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
98.Fn wcsncasecmp
99and
100.Fn wcsncasecmp_l
101compare at most
102.Fa len
103wide characters.
104.Sh SEE ALSO
105.Xr newlocale 3 ,
106.Xr setlocale 3 ,
107.Xr strcasecmp 3 ,
108.Xr wcscmp 3 ,
109.Xr wmemcmp 3
110.Sh STANDARDS
111These functions conform to
112.St -p1003.1-2008 .
113.Sh HISTORY
114The
115.Fn wcscasecmp
116and
117.Fn wcsncasecmp
118functions have been available since
119.Ox 5.0 ,
120and
121.Fn wcscasecmp_l
122and
123.Fn wcsncasecmp_l
124since
125.Ox 6.2 .
126.Sh AUTHORS
127The
128.Ox
129versions of
130.Fn wcscasecmp
131and
132.Fn wcsncasecmp
133were implemented by
134.An Marc Espie Aq Mt espie@openbsd.org .
diff --git a/src/lib/libc/string/wcscasecmp.c b/src/lib/libc/string/wcscasecmp.c
deleted file mode 100644
index b122e720fe..0000000000
--- a/src/lib/libc/string/wcscasecmp.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/* $OpenBSD: wcscasecmp.c,v 1.3 2015/09/12 16:23:14 guenther 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(const wchar_t *s1, const wchar_t *s2)
34{
35 wchar_t l1, l2;
36
37 while ((l1 = towlower(*s1++)) == (l2 = towlower(*s2++))) {
38 if (l1 == 0)
39 return (0);
40 }
41 /* XXX assumes wchar_t = int */
42 return ((rune_t)l1 - (rune_t)l2);
43}
44DEF_WEAK(wcscasecmp);
45
46int
47wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
48{
49 wchar_t l1, l2;
50
51 if (n == 0)
52 return (0);
53 do {
54 if (((l1 = towlower(*s1++))) != (l2 = towlower(*s2++))) {
55 /* XXX assumes wchar_t = int */
56 return ((rune_t)l1 - (rune_t)l2);
57 }
58 if (l1 == 0)
59 break;
60 } while (--n != 0);
61 return (0);
62}
63DEF_WEAK(wcsncasecmp);
diff --git a/src/lib/libc/string/wcscasecmp_l.c b/src/lib/libc/string/wcscasecmp_l.c
deleted file mode 100644
index 35b99225c1..0000000000
--- a/src/lib/libc/string/wcscasecmp_l.c
+++ /dev/null
@@ -1,63 +0,0 @@
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}
diff --git a/src/lib/libc/string/wcscat.3 b/src/lib/libc/string/wcscat.3
deleted file mode 100644
index 9b7588cf9e..0000000000
--- a/src/lib/libc/string/wcscat.3
+++ /dev/null
@@ -1,115 +0,0 @@
1.\" $OpenBSD: wcscat.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSCAT 3
36.Os
37.Sh NAME
38.Nm wcscat ,
39.Nm wcsncat
40.Nd concatenate wide strings
41.Sh SYNOPSIS
42.In wchar.h
43.Ft wchar_t *
44.Fn wcscat "wchar_t * restrict s" "const wchar_t * restrict append"
45.Ft wchar_t *
46.Fo wcsncat
47.Fa "wchar_t * restrict s"
48.Fa "const wchar_t * restrict append"
49.Fa "size_t count"
50.Fc
51.Sh DESCRIPTION
52The
53.Fn wcscat
54and
55.Fn wcsncat
56functions append a copy of the wide string
57.Fa append
58to the end of the wide string
59.Fa s ,
60then add a terminating null wide character (L'\e0').
61The wide string
62.Fa s
63must have sufficient space to hold the result.
64.Pp
65The
66.Fn wcsncat
67function appends not more than
68.Fa count
69wide characters where space for the terminating null wide character
70should not be included in
71.Fa count .
72.Sh RETURN VALUES
73The
74.Fn wcscat
75and
76.Fn wcsncat
77functions return the pointer
78.Fa s .
79.Sh SEE ALSO
80.Xr strcat 3 ,
81.Xr strlcpy 3 ,
82.Xr wcscpy 3 ,
83.Xr wcslcpy 3 ,
84.Xr wmemcpy 3 ,
85.Xr wmemmove 3
86.Sh STANDARDS
87The
88.Fn wcscat
89and
90.Fn wcsncat
91functions conform to
92.St -isoC-99
93and were first introduced in
94.St -isoC-amd1 .
95.Sh HISTORY
96The
97.Fn wcscat
98and
99.Fn wcsncat
100functions were ported from
101.Nx
102and first appeared in
103.Ox 3.8 .
104.Sh CAVEATS
105Using the functions
106.Fn wcscat
107and
108.Fn wcsncat
109is very error-prone with respect to buffer overflows;
110see the EXAMPLES section in
111.Xr strcat 3
112for correct usage.
113Using
114.Xr wcslcat 3
115is a better choice in most cases.
diff --git a/src/lib/libc/string/wcscat.c b/src/lib/libc/string/wcscat.c
deleted file mode 100644
index 0525c3cb14..0000000000
--- a/src/lib/libc/string/wcscat.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/* $OpenBSD: wcscat.c,v 1.5 2017/11/28 06:55:49 tb Exp $ */
2/* $NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34#if defined(APIWARN)
35__warn_references(wcscat,
36 "wcscat() is almost always misused, please use wcslcat()");
37#endif
38
39wchar_t *
40wcscat(wchar_t *s1, const wchar_t *s2)
41{
42 wchar_t *p;
43 wchar_t *q;
44 const wchar_t *r;
45
46 p = s1;
47 while (*p)
48 p++;
49 q = p;
50 r = s2;
51 while (*r)
52 *q++ = *r++;
53 *q = '\0';
54 return s1;
55}
56DEF_STRONG(wcscat);
diff --git a/src/lib/libc/string/wcschr.3 b/src/lib/libc/string/wcschr.3
deleted file mode 100644
index bb714b2099..0000000000
--- a/src/lib/libc/string/wcschr.3
+++ /dev/null
@@ -1,85 +0,0 @@
1.\" $OpenBSD: wcschr.3,v 1.4 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSCHR 3
36.Os
37.Sh NAME
38.Nm wcschr
39.Nd locate first occurrence of a wide character in a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wcschr "const wchar_t *s" "wchar_t c"
44.Sh DESCRIPTION
45The
46.Fn wcschr
47function locates the first occurrence of the wide character
48.Fa c
49in the wide string
50.Fa s .
51The terminating null wide character is considered part of the wide string.
52If
53.Fa c
54is the null wide character (L'\e0'),
55.Fn wcschr
56locates the terminating null wide character.
57.Sh RETURN VALUES
58The
59.Fn wcschr
60function returns a pointer to the located wide character or
61.Dv NULL
62if the wide character does not appear in the wide string.
63.Sh SEE ALSO
64.Xr strchr 3 ,
65.Xr wcscspn 3 ,
66.Xr wcspbrk 3 ,
67.Xr wcsrchr 3 ,
68.Xr wcsspn 3 ,
69.Xr wcsstr 3 ,
70.Xr wcstok 3 ,
71.Xr wmemchr 3
72.Sh STANDARDS
73The
74.Fn wcschr
75function conforms to
76.St -isoC-99
77and was first introduced in
78.St -isoC-amd1 .
79.Sh HISTORY
80The
81.Fn wcschr
82function was ported from
83.Nx
84and first appeared in
85.Ox 3.8 .
diff --git a/src/lib/libc/string/wcschr.c b/src/lib/libc/string/wcschr.c
deleted file mode 100644
index 709d4797bb..0000000000
--- a/src/lib/libc/string/wcschr.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/* $OpenBSD: wcschr.c,v 1.6 2015/10/01 02:32:07 guenther Exp $ */
2/* $NetBSD: wcschr.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcschr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wcschr(const wchar_t *s, wchar_t c)
36{
37 const wchar_t *p;
38
39 p = s;
40 for (;;) {
41 if (*p == c) {
42 return (wchar_t *)p;
43 }
44 if (!*p)
45 return NULL;
46 p++;
47 }
48 /* NOTREACHED */
49}
50DEF_STRONG(wcschr);
diff --git a/src/lib/libc/string/wcscmp.3 b/src/lib/libc/string/wcscmp.3
deleted file mode 100644
index 53cd15a1f0..0000000000
--- a/src/lib/libc/string/wcscmp.3
+++ /dev/null
@@ -1,92 +0,0 @@
1.\" $OpenBSD: wcscmp.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSCMP 3
36.Os
37.Sh NAME
38.Nm wcscmp ,
39.Nm wcsncmp
40.Nd compare wide strings
41.Sh SYNOPSIS
42.In wchar.h
43.Ft int
44.Fn wcscmp "const wchar_t *s1" "const wchar_t *s2"
45.Ft int
46.Fn wcsncmp "const wchar_t *s1" "const wchar_t *s2" "size_t len"
47.Sh DESCRIPTION
48The
49.Fn wcscmp
50and
51.Fn wcsncmp
52functions lexicographically compare the wide strings
53.Fa s1
54and
55.Fa s2 .
56The
57.Fn wcsncmp
58function compares at most
59.Fa len
60wide characters.
61.Sh RETURN VALUES
62The
63.Fn wcscmp
64and
65.Fn wcsncmp
66functions return an integer greater than, equal to, or less than 0, according
67to whether the wide string
68.Fa s1
69is greater than, equal to, or less than the wide string
70.Fa s2 .
71.Sh SEE ALSO
72.Xr strcmp 3 ,
73.Xr wcscasecmp 3 ,
74.Xr wmemcmp 3
75.Sh STANDARDS
76The
77.Fn wcscmp
78and
79.Fn wcsncmp
80functions conform to
81.St -isoC-99
82and were first introduced in
83.St -isoC-amd1 .
84.Sh HISTORY
85The
86.Fn wcscmp
87and
88.Fn wcsncmp
89functions were ported from
90.Nx
91and first appeared in
92.Ox 3.8 .
diff --git a/src/lib/libc/string/wcscmp.c b/src/lib/libc/string/wcscmp.c
deleted file mode 100644
index 42d6bca3cc..0000000000
--- a/src/lib/libc/string/wcscmp.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: wcscmp.c,v 1.5 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */
3
4/*-
5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Chris Torek.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <wchar.h>
37#include "locale/runetype.h"
38
39/*
40 * Compare strings.
41 */
42int
43wcscmp(const wchar_t *s1, const wchar_t *s2)
44{
45
46 while (*s1 == *s2++)
47 if (*s1++ == 0)
48 return (0);
49 /* XXX assumes wchar_t = int */
50 return (*(const rune_t *)s1 - *(const rune_t *)--s2);
51}
52DEF_STRONG(wcscmp);
diff --git a/src/lib/libc/string/wcscpy.3 b/src/lib/libc/string/wcscpy.3
deleted file mode 100644
index fcf01b5c57..0000000000
--- a/src/lib/libc/string/wcscpy.3
+++ /dev/null
@@ -1,129 +0,0 @@
1.\" $OpenBSD: wcscpy.3,v 1.5 2016/11/12 08:58:43 jmc Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: November 12 2016 $
35.Dt WCSCPY 3
36.Os
37.Sh NAME
38.Nm wcscpy ,
39.Nm wcsncpy
40.Nd copy wide strings
41.Sh SYNOPSIS
42.In wchar.h
43.Ft wchar_t *
44.Fn wcscpy "wchar_t * restrict dst" "const wchar_t * restrict src"
45.Ft wchar_t *
46.Fo wcsncpy
47.Fa "wchar_t * restrict dst"
48.Fa "const wchar_t * restrict src"
49.Fa "size_t len"
50.Fc
51.Sh DESCRIPTION
52The
53.Fn wcscpy
54and
55.Fn wcsncpy
56functions copy the wide string
57.Fa src
58to
59.Fa dst
60(including the terminating null wide character).
61.Pp
62The
63.Fn wcsncpy
64function copies not more than
65.Fa len
66wide characters to
67.Fa dst ,
68appending null wide characters if the length of
69.Fa src
70is less than
71.Fa len ,
72and
73.Em not
74terminating
75.Fa dst
76if the length of
77.Fa src
78is greater than or equal to
79.Fa len .
80.Pp
81If the
82.Fa src
83and
84.Fa dst
85strings overlap, the behavior is undefined.
86.Sh RETURN VALUES
87The
88.Fn wcscpy
89and
90.Fn wcsncpy
91functions return
92.Fa dst .
93.Sh SEE ALSO
94.Xr strcpy 3 ,
95.Xr strlcpy 3 ,
96.Xr wcscat 3 ,
97.Xr wcslcpy 3 ,
98.Xr wmemcpy 3 ,
99.Xr wmemmove 3
100.Sh STANDARDS
101The
102.Fn wcscpy
103and
104.Fn wcsncpy
105functions conform to
106.St -isoC-99
107and were first introduced in
108.St -isoC-amd1 .
109.Sh HISTORY
110The
111.Fn wcscpy
112and
113.Fn wcsncpy
114functions were ported from
115.Nx
116and first appeared in
117.Ox 3.8 .
118.Sh CAVEATS
119Using the functions
120.Fn wcscpy
121and
122.Fn wcsncpy
123is very error-prone with respect to buffer overflows;
124see the EXAMPLES section in
125.Xr strncpy 3
126for correct usage.
127Using
128.Xr wcslcpy 3
129is a better choice in most cases.
diff --git a/src/lib/libc/string/wcscpy.c b/src/lib/libc/string/wcscpy.c
deleted file mode 100644
index f772752413..0000000000
--- a/src/lib/libc/string/wcscpy.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/* $OpenBSD: wcscpy.c,v 1.5 2017/11/28 06:55:49 tb Exp $ */
2/* $NetBSD: wcscpy.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp
30 */
31
32#include <wchar.h>
33
34#if defined(APIWARN)
35__warn_references(wcscpy,
36 "wcscpy() is almost always misused, please use wcslcpy()");
37#endif
38
39wchar_t *
40wcscpy(wchar_t *s1, const wchar_t *s2)
41{
42 wchar_t *p;
43 const wchar_t *q;
44
45 p = s1;
46 q = s2;
47 while (*q)
48 *p++ = *q++;
49 *p = '\0';
50
51 return s1;
52}
diff --git a/src/lib/libc/string/wcscspn.3 b/src/lib/libc/string/wcscspn.3
deleted file mode 100644
index 520a739202..0000000000
--- a/src/lib/libc/string/wcscspn.3
+++ /dev/null
@@ -1,83 +0,0 @@
1.\" $OpenBSD: wcscspn.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSCSPN 3
36.Os
37.Sh NAME
38.Nm wcscspn
39.Nd span the complement of a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft size_t
43.Fn wcscspn "const wchar_t *s" "const wchar_t *charset"
44.Sh DESCRIPTION
45The
46.Fn wcscspn
47function spans the initial part of the wide string
48.Fa s
49as long as the wide characters from
50.Fa s
51do not occur in string
52.Fa charset
53(it spans the
54.Em complement
55of
56.Fa charset ) .
57.Sh RETURN VALUES
58The
59.Fn wcscspn
60function returns the number of wide characters spanned.
61.Sh SEE ALSO
62.Xr strcspn 3 ,
63.Xr wcschr 3 ,
64.Xr wcspbrk 3 ,
65.Xr wcsrchr 3 ,
66.Xr wcsspn 3 ,
67.Xr wcsstr 3 ,
68.Xr wcstok 3 ,
69.Xr wmemchr 3
70.Sh STANDARDS
71The
72.Fn wcscspn
73function conforms to
74.St -isoC-99
75and was first introduced in
76.St -isoC-amd1 .
77.Sh HISTORY
78The
79.Fn wcscspn
80function was ported from
81.Nx
82and first appeared in
83.Ox 3.8 .
diff --git a/src/lib/libc/string/wcscspn.c b/src/lib/libc/string/wcscspn.c
deleted file mode 100644
index 23e78ab22f..0000000000
--- a/src/lib/libc/string/wcscspn.c
+++ /dev/null
@@ -1,54 +0,0 @@
1/* $OpenBSD: wcscspn.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34size_t
35wcscspn(const wchar_t *s, const wchar_t *set)
36{
37 const wchar_t *p;
38 const wchar_t *q;
39
40 p = s;
41 while (*p) {
42 q = set;
43 while (*q) {
44 if (*p == *q)
45 goto done;
46 q++;
47 }
48 p++;
49 }
50
51done:
52 return (p - s);
53}
54DEF_STRONG(wcscspn);
diff --git a/src/lib/libc/string/wcsdup.3 b/src/lib/libc/string/wcsdup.3
deleted file mode 100644
index 588a2571db..0000000000
--- a/src/lib/libc/string/wcsdup.3
+++ /dev/null
@@ -1,97 +0,0 @@
1.\" $OpenBSD: wcsdup.3,v 1.4 2011/07/25 00:38:53 schwarze Exp $
2.\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
3.\"
4.\" Copyright (c) 1990, 1991, 1993
5.\" The Regents of the University of California. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
32.\"
33.Dd $Mdocdate: July 25 2011 $
34.Dt WCSDUP 3
35.Os
36.Sh NAME
37.Nm wcsdup
38.Nd save a copy of a wide string
39.Sh SYNOPSIS
40.In wchar.h
41.Ft wchar_t *
42.Fn wcsdup "const wchar_t *str"
43.Sh DESCRIPTION
44The
45.Fn wcsdup
46function
47allocates sufficient memory for a copy
48of the wide-character string
49.Fa str ,
50does the copy, and returns a pointer to it.
51The pointer may subsequently be used as an
52argument to the function
53.Xr free 3 .
54.Pp
55If insufficient memory is available,
56.Dv NULL
57is returned.
58.Sh EXAMPLES
59The following will point
60.Va p
61to an allocated area of memory containing the nul-terminated string
62.Qq foobar :
63.Bd -literal -offset indent
64const char *o = "foobar";
65wchar_t *p, b[32];
66size_t blen;
67
68blen = sizeof(b) / sizeof(b[0]);
69if (mbstowcs(b, o, blen) == (size_t)-1)
70 err(1, NULL);
71b[blen - 1] = 0;
72if ((p = wcsdup(b)) == NULL)
73 err(1, NULL);
74.Ed
75.Sh ERRORS
76The
77.Fn wcsdup
78function may fail and set the external variable
79.Va errno
80for any of the errors specified for the library function
81.Xr malloc 3 .
82.Sh SEE ALSO
83.Xr free 3 ,
84.Xr malloc 3 ,
85.Xr strdup 3
86.Sh STANDARDS
87The
88.Fn wcsdup
89function conforms to
90.St -p1003.1-2008 .
91.Sh HISTORY
92The
93.Fn wcsdup
94function was ported from
95.Nx
96and first appeared in
97.Ox 5.0 .
diff --git a/src/lib/libc/string/wcsdup.c b/src/lib/libc/string/wcsdup.c
deleted file mode 100644
index 36f19186ab..0000000000
--- a/src/lib/libc/string/wcsdup.c
+++ /dev/null
@@ -1,32 +0,0 @@
1/* $OpenBSD: wcsdup.c,v 1.3 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $ */
3
4/*
5 * Copyright (C) 2006 Aleksey Cheusov
6 *
7 * This material is provided "as is", with absolutely no warranty expressed
8 * or implied. Any use is at your own risk.
9 *
10 * Permission to use or copy this software for any purpose is hereby granted
11 * without fee. Permission to modify the code and to distribute modified
12 * code is also granted without any restrictions.
13 */
14
15#include <stdlib.h>
16#include <wchar.h>
17
18wchar_t *
19wcsdup(const wchar_t *str)
20{
21 wchar_t *copy;
22 size_t len;
23
24 len = wcslen(str) + 1;
25 copy = reallocarray(NULL, len, sizeof(wchar_t));
26
27 if (!copy)
28 return (NULL);
29
30 return (wmemcpy(copy, str, len));
31}
32DEF_WEAK(wcsdup);
diff --git a/src/lib/libc/string/wcslcat.c b/src/lib/libc/string/wcslcat.c
deleted file mode 100644
index 9949057df4..0000000000
--- a/src/lib/libc/string/wcslcat.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/* $OpenBSD: wcslcat.c,v 1.7 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20#include <wchar.h>
21
22/*
23 * Appends src to string dst of size dsize (unlike strncat, dsize is the
24 * full size of dst, not space left). At most dsize-1 characters
25 * will be copied. Always NUL terminates (unless dsize <= wcslen(dst)).
26 * Returns wcslen(src) + MIN(dsize, wcslen(initial dst)).
27 * If retval >= siz, truncation occurred.
28 */
29size_t
30wcslcat(wchar_t *dst, const wchar_t *src, size_t dsize)
31{
32 const wchar_t *odst = dst;
33 const wchar_t *osrc = src;
34 size_t n = dsize;
35 size_t dlen;
36
37 /* Find the end of dst and adjust bytes left but don't go past end. */
38 while (n-- != 0 && *dst != L'\0')
39 dst++;
40 dlen = dst - odst;
41 n = dsize - dlen;
42
43 if (n-- == 0)
44 return(dlen + wcslen(src));
45 while (*src != L'\0') {
46 if (n != 0) {
47 *dst++ = *src;
48 n--;
49 }
50 src++;
51 }
52 *dst = L'\0';
53
54 return(dlen + (src - osrc)); /* count does not include NUL */
55}
56DEF_WEAK(wcslcat);
diff --git a/src/lib/libc/string/wcslcpy.3 b/src/lib/libc/string/wcslcpy.3
deleted file mode 100644
index d279038079..0000000000
--- a/src/lib/libc/string/wcslcpy.3
+++ /dev/null
@@ -1,160 +0,0 @@
1.\" $OpenBSD: wcslcpy.3,v 1.8 2024/08/07 04:59:45 guenther Exp $
2.\"
3.\" Copyright (c) 1998, 2000 Todd C. Miller <millert@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.Dd $Mdocdate: August 7 2024 $
18.Dt WCSLCPY 3
19.Os
20.Sh NAME
21.Nm wcslcpy ,
22.Nm wcslcat
23.Nd size-bounded wide string copying and concatenation
24.Sh SYNOPSIS
25.In wchar.h
26.Ft size_t
27.Fn wcslcpy "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t size"
28.Ft size_t
29.Fn wcslcat "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t size"
30.Sh DESCRIPTION
31The
32.Fn wcslcpy
33and
34.Fn wcslcat
35functions copy and concatenate wide strings respectively.
36They are designed to be safer, more consistent, and less error prone
37replacements for
38.Xr wcsncpy 3
39and
40.Xr wcsncat 3 .
41Unlike those functions,
42.Fn wcslcpy
43and
44.Fn wcslcat
45take the full size of the buffer (not just the length) and guarantee to
46terminate the result with a null wide character (as long as
47.Fa size
48is larger than 0 or, in the case of
49.Fn wcslcat ,
50as long as there is at least one wide character free in
51.Fa dst ) .
52Note that a wide character for the null wide character should be included in
53.Fa size .
54Also note that
55.Fn wcslcpy
56and
57.Fn wcslcat
58only operate on wide strings that are terminated with a null wide character
59(L'\e0').
60This means that for
61.Fn wcslcpy
62.Fa src
63must be terminated with a null wide character and for
64.Fn wcslcat
65both
66.Fa src
67and
68.Fa dst
69must be terminated with a null wide character.
70.Pp
71The
72.Fn wcslcpy
73function copies up to
74.Fa size
75\(mi 1 wide characters from the wide string
76.Fa src
77to
78.Fa dst ,
79terminating the result with a null wide character.
80.Pp
81The
82.Fn wcslcat
83function appends the wide string
84.Fa src
85to the end of
86.Fa dst .
87It will append at most
88.Fa size
89\(mi wcslen(dst) \(mi 1 wide characters, terminating the result with a null
90wide character.
91.Pp
92If the
93.Fa src
94and
95.Fa dst
96strings overlap, the behavior is undefined.
97.Sh RETURN VALUES
98The
99.Fn wcslcpy
100and
101.Fn wcslcat
102functions return the total length of the wide string they tried to create.
103For
104.Fn wcslcpy
105that means the length of
106.Fa src .
107For
108.Fn wcslcat
109that means the initial length of
110.Fa dst
111plus
112the length of
113.Fa src .
114While this may seem somewhat confusing, it was done to make
115truncation detection simple.
116.Pp
117Note, however, that if
118.Fn wcslcat
119traverses
120.Fa size
121wide characters without finding a null wide character, the length of the
122string is considered to be
123.Fa size
124and the destination wide string will not be terminated with a null wide
125character (since there was no space for it).
126This keeps
127.Fn wcslcat
128from running off the end of a wide string.
129In practice this should not happen (as it means that either
130.Fa size
131is incorrect or that
132.Fa dst
133is not terminated with a null wide character).
134The check exists to prevent potential security problems in incorrect code.
135.Sh SEE ALSO
136.Xr strlcpy 3 ,
137.Xr swprintf 3 ,
138.Xr wcsncat 3 ,
139.Xr wcsncpy 3
140.Sh STANDARDS
141The
142.Fn wcslcpy
143and
144.Fn wcslcat
145functions conform to
146.St -p1003.1-2024 .
147.Sh HISTORY
148The
149.Fn wcslcpy
150and
151.Fn wcslcat
152functions first appeared in
153.Ox 3.8 .
154.Sh AUTHORS
155The
156.Fn wcslcpy
157and
158.Fn wcslcat
159functions are based on code by
160.An Todd C. Miller Aq Mt millert@openbsd.org .
diff --git a/src/lib/libc/string/wcslcpy.c b/src/lib/libc/string/wcslcpy.c
deleted file mode 100644
index 9c433c83dc..0000000000
--- a/src/lib/libc/string/wcslcpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* $OpenBSD: wcslcpy.c,v 1.8 2019/01/25 00:19:25 millert Exp $ */
2
3/*
4 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20#include <wchar.h>
21
22/*
23 * Copy string src to buffer dst of size dsize. At most dsize-1
24 * chars will be copied. Always NUL terminates (unless dsize == 0).
25 * Returns wcslen(src); if retval >= dsize, truncation occurred.
26 */
27size_t
28wcslcpy(wchar_t *dst, const wchar_t *src, size_t dsize)
29{
30 const wchar_t *osrc = src;
31 size_t nleft = dsize;
32
33 /* Copy as many bytes as will fit. */
34 if (nleft != 0) {
35 while (--nleft != 0) {
36 if ((*dst++ = *src++) == L'\0')
37 break;
38 }
39 }
40
41 /* Not enough room in dst, add NUL and traverse rest of src. */
42 if (nleft == 0) {
43 if (dsize != 0)
44 *dst = L'\0'; /* NUL-terminate dst */
45 while (*src++)
46 ;
47 }
48
49 return(src - osrc - 1); /* count does not include NUL */
50}
51DEF_WEAK(wcslcpy);
diff --git a/src/lib/libc/string/wcslen.3 b/src/lib/libc/string/wcslen.3
deleted file mode 100644
index b6d9aafc41..0000000000
--- a/src/lib/libc/string/wcslen.3
+++ /dev/null
@@ -1,102 +0,0 @@
1.\" $OpenBSD: wcslen.3,v 1.4 2024/07/14 09:51:18 jca Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: July 14 2024 $
35.Dt WCSLEN 3
36.Os
37.Sh NAME
38.Nm wcslen ,
39.Nm wcsnlen
40.Nd find length of a wide string
41.Sh SYNOPSIS
42.In wchar.h
43.Ft size_t
44.Fn wcslen "const wchar_t *s"
45.Ft size_t
46.Fn wcsnlen "const wchar_t *s" "size_t maxlen"
47.Sh DESCRIPTION
48The
49.Fn wcslen
50function computes the length of the wide string
51.Fa s .
52The
53.Fn wcsnlen
54function computes the length of the wide string
55.Fa s ,
56up to
57.Fa maxlen
58wide characters.
59The
60.Fn wcsnlen
61function will never attempt to address more than
62.Fa maxlen
63wide characters, making it suitable for use with wide character arrays
64that are not guaranteed to be NUL-terminated.
65.Sh RETURN VALUES
66The
67.Fn wcslen
68function returns the number of wide characters that precede the terminating
69null wide character.
70.Pp
71The
72.Fn wcsnlen
73function returns the number of wide characters that precede the terminating
74null wide character
75or
76.Fa maxlen ,
77whichever is smaller.
78.Sh SEE ALSO
79.Xr strlen 3 ,
80.Xr wcswidth 3
81.Sh STANDARDS
82The
83.Fn wcslen
84function conforms to
85.St -isoC-99
86and was first introduced in
87.St -isoC-amd1 .
88The
89.Fn wcsnlen
90function conforms to
91.St -p1003.1-2008 .
92.Sh HISTORY
93The
94.Fn wcslen
95function was ported from
96.Nx
97and first appeared in
98.Ox 3.8 .
99The
100.Fn wcsnlen
101function first appeared in
102.Ox 7.6 .
diff --git a/src/lib/libc/string/wcslen.c b/src/lib/libc/string/wcslen.c
deleted file mode 100644
index 16d4bba128..0000000000
--- a/src/lib/libc/string/wcslen.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/* $OpenBSD: wcslen.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34size_t
35wcslen(const wchar_t *s)
36{
37 const wchar_t *p;
38
39 p = s;
40 while (*p)
41 p++;
42
43 return p - s;
44}
45DEF_STRONG(wcslen);
diff --git a/src/lib/libc/string/wcsncat.c b/src/lib/libc/string/wcsncat.c
deleted file mode 100644
index 2b4b9f0d49..0000000000
--- a/src/lib/libc/string/wcsncat.c
+++ /dev/null
@@ -1,53 +0,0 @@
1/* $OpenBSD: wcsncat.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcsncat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wcsncat(wchar_t *s1, const wchar_t *s2, size_t n)
36{
37 wchar_t *p;
38 wchar_t *q;
39 const wchar_t *r;
40
41 p = s1;
42 while (*p)
43 p++;
44 q = p;
45 r = s2;
46 while (*r && n) {
47 *q++ = *r++;
48 n--;
49 }
50 *q = '\0';
51 return s1;
52}
53DEF_STRONG(wcsncat);
diff --git a/src/lib/libc/string/wcsncmp.c b/src/lib/libc/string/wcsncmp.c
deleted file mode 100644
index bdaab33e4c..0000000000
--- a/src/lib/libc/string/wcsncmp.c
+++ /dev/null
@@ -1,53 +0,0 @@
1/* $OpenBSD: wcsncmp.c,v 1.5 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */
3
4/*
5 * Copyright (c) 1989, 1993
6 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <wchar.h>
34#include "locale/runetype.h"
35
36int
37wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
38{
39
40 if (n == 0)
41 return (0);
42 do {
43 if (*s1 != *s2++) {
44 /* XXX assumes wchar_t = int */
45 return (*(const rune_t *)s1 -
46 *(const rune_t *)--s2);
47 }
48 if (*s1++ == 0)
49 break;
50 } while (--n != 0);
51 return (0);
52}
53DEF_STRONG(wcsncmp);
diff --git a/src/lib/libc/string/wcsncpy.c b/src/lib/libc/string/wcsncpy.c
deleted file mode 100644
index 1be482b114..0000000000
--- a/src/lib/libc/string/wcsncpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* $OpenBSD: wcsncpy.c,v 1.5 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcsncpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcsncpy.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wcsncpy(wchar_t *s1, const wchar_t *s2, size_t n)
36{
37 wchar_t *p;
38
39 p = s1;
40 while (n && *s2) {
41 *p++ = *s2++;
42 n--;
43 }
44 while (n) {
45 *p++ = L'\0';
46 n--;
47 }
48
49 return s1;
50}
51DEF_STRONG(wcsncpy);
diff --git a/src/lib/libc/string/wcsnlen.c b/src/lib/libc/string/wcsnlen.c
deleted file mode 100644
index eb1d08e85b..0000000000
--- a/src/lib/libc/string/wcsnlen.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/* $OpenBSD: wcsnlen.c,v 1.1 2024/07/14 09:51:18 jca Exp $ */
2/* $NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34size_t
35wcsnlen(const wchar_t *s, size_t maxlen)
36{
37 const wchar_t *p;
38
39 p = s;
40 while (maxlen-- && *p)
41 p++;
42
43 return p - s;
44}
45
diff --git a/src/lib/libc/string/wcspbrk.3 b/src/lib/libc/string/wcspbrk.3
deleted file mode 100644
index 602bfdc3d6..0000000000
--- a/src/lib/libc/string/wcspbrk.3
+++ /dev/null
@@ -1,81 +0,0 @@
1.\" $OpenBSD: wcspbrk.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSPBRK 3
36.Os
37.Sh NAME
38.Nm wcspbrk
39.Nd locate multiple wide characters in a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wcspbrk "const wchar_t *s" "const wchar_t *charset"
44.Sh DESCRIPTION
45The
46.Fn wcspbrk
47function locates in the wide string
48.Fa s
49the first occurrence of any wide character in the wide string
50.Fa charset
51and returns a pointer to this wide character.
52If no wide characters from
53.Fa charset
54occur anywhere in
55.Fa s ,
56.Fn wcspbrk
57returns
58.Dv NULL .
59.Sh SEE ALSO
60.Xr strpbrk 3 ,
61.Xr wcschr 3 ,
62.Xr wcscspn 3 ,
63.Xr wcsrchr 3 ,
64.Xr wcsspn 3 ,
65.Xr wcsstr 3 ,
66.Xr wcstok 3 ,
67.Xr wmemchr 3
68.Sh STANDARDS
69The
70.Fn wcspbrk
71function conforms to
72.St -isoC-99
73and was first introduced in
74.St -isoC-amd1 .
75.Sh HISTORY
76The
77.Fn wcspbrk
78function was ported from
79.Nx
80and first appeared in
81.Ox 3.8 .
diff --git a/src/lib/libc/string/wcspbrk.c b/src/lib/libc/string/wcspbrk.c
deleted file mode 100644
index f398fd92ab..0000000000
--- a/src/lib/libc/string/wcspbrk.c
+++ /dev/null
@@ -1,53 +0,0 @@
1/* $OpenBSD: wcspbrk.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
2/* $NetBSD: wcspbrk.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wcspbrk(const wchar_t *s, const wchar_t *set)
36{
37 const wchar_t *p;
38 const wchar_t *q;
39
40 p = s;
41 while (*p) {
42 q = set;
43 while (*q) {
44 if (*p == *q) {
45 return (wchar_t *)p;
46 }
47 q++;
48 }
49 p++;
50 }
51 return NULL;
52}
53DEF_STRONG(wcspbrk);
diff --git a/src/lib/libc/string/wcsrchr.3 b/src/lib/libc/string/wcsrchr.3
deleted file mode 100644
index d4a2e7cf78..0000000000
--- a/src/lib/libc/string/wcsrchr.3
+++ /dev/null
@@ -1,85 +0,0 @@
1.\" $OpenBSD: wcsrchr.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSRCHR 3
36.Os
37.Sh NAME
38.Nm wcsrchr
39.Nd locate last occurrence of a wide character in a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wcsrchr "const wchar_t *s" "wchar_t c"
44.Sh DESCRIPTION
45The
46.Fn wcsrchr
47function locates the last occurrence of the wide character
48.Fa c
49in the wide string
50.Fa s .
51The terminating null wide character is considered part of the wide string.
52If
53.Fa c
54is the null wide character (L'\e0'),
55.Fn wcsrchr
56locates the terminating null wide character.
57.Sh RETURN VALUES
58The
59.Fn wcsrchr
60function returns a pointer to the located wide character or
61.Dv NULL
62if the wide character does not appear in the wide string.
63.Sh SEE ALSO
64.Xr strrchr 3 ,
65.Xr wcschr 3 ,
66.Xr wcscspn 3 ,
67.Xr wcspbrk 3 ,
68.Xr wcsspn 3 ,
69.Xr wcsstr 3 ,
70.Xr wcstok 3 ,
71.Xr wmemchr 3
72.Sh STANDARDS
73The
74.Fn wcsrchr
75function conforms to
76.St -isoC-99
77and was first introduced in
78.St -isoC-amd1 .
79.Sh HISTORY
80The
81.Fn wcsrchr
82function was ported from
83.Nx
84and first appeared in
85.Ox 3.8 .
diff --git a/src/lib/libc/string/wcsrchr.c b/src/lib/libc/string/wcsrchr.c
deleted file mode 100644
index aa936de508..0000000000
--- a/src/lib/libc/string/wcsrchr.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/* $OpenBSD: wcsrchr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
2/* $NetBSD: wcsrchr.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcsrchr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wcsrchr(const wchar_t *s, wchar_t c)
36{
37 const wchar_t *p;
38
39 p = s;
40 while (*p)
41 p++;
42 while (s <= p) {
43 if (*p == c) {
44 return (wchar_t *)p;
45 }
46 p--;
47 }
48 return NULL;
49}
50DEF_STRONG(wcsrchr);
diff --git a/src/lib/libc/string/wcsspn.3 b/src/lib/libc/string/wcsspn.3
deleted file mode 100644
index 3be82344dd..0000000000
--- a/src/lib/libc/string/wcsspn.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" $OpenBSD: wcsspn.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSSPN 3
36.Os
37.Sh NAME
38.Nm wcsspn
39.Nd span a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft size_t
43.Fn wcsspn "const wchar_t *s" "const wchar_t *charset"
44.Sh DESCRIPTION
45The
46.Fn wcsspn
47function spans the initial part of the wide string
48.Fa s
49as long as the wide characters from
50.Fa s
51occur in the wide string
52.Fa charset .
53.Sh RETURN VALUES
54The
55.Fn wcsspn
56function returns the number of wide characters spanned.
57.Sh SEE ALSO
58.Xr strspn 3 ,
59.Xr wcschr 3 ,
60.Xr wcscspn 3 ,
61.Xr wcspbrk 3 ,
62.Xr wcsrchr 3 ,
63.Xr wcsstr 3 ,
64.Xr wcstok 3 ,
65.Xr wmemchr 3
66.Sh STANDARDS
67The
68.Fn wcsspn
69function conforms to
70.St -isoC-99
71and was first introduced in
72.St -isoC-amd1 .
73.Sh HISTORY
74The
75.Fn wcsspn
76function was ported from
77.Nx
78and first appeared in
79.Ox 3.8 .
diff --git a/src/lib/libc/string/wcsspn.c b/src/lib/libc/string/wcsspn.c
deleted file mode 100644
index a3f28e3a49..0000000000
--- a/src/lib/libc/string/wcsspn.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/* $OpenBSD: wcsspn.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $ */
3
4/*-
5 * Copyright (c)1999,2001 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $Citrus: xpg4dl/FreeBSD/lib/libc/string/wcsspn.c,v 1.3 2001/09/21 16:06:43 yamt Exp $
30 */
31
32#include <wchar.h>
33
34size_t
35wcsspn(const wchar_t *s, const wchar_t *set)
36{
37 const wchar_t *p;
38 const wchar_t *q;
39
40 p = s;
41 while (*p) {
42 q = set;
43 while (*q) {
44 if (*p == *q)
45 break;
46 q++;
47 }
48 if (!*q)
49 goto done;
50 p++;
51 }
52
53done:
54 return (p - s);
55}
56DEF_STRONG(wcsspn);
diff --git a/src/lib/libc/string/wcsstr.3 b/src/lib/libc/string/wcsstr.3
deleted file mode 100644
index 203a76ded3..0000000000
--- a/src/lib/libc/string/wcsstr.3
+++ /dev/null
@@ -1,88 +0,0 @@
1.\" $OpenBSD: wcsstr.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WCSSTR 3
36.Os
37.Sh NAME
38.Nm wcsstr
39.Nd locate a wide substring in a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wcsstr "const wchar_t *big" "const wchar_t *little"
44.Sh DESCRIPTION
45The
46.Fn wcsstr
47function locates the first occurrence of the wide string
48.Fa little
49in the wide string
50.Fa big .
51.Pp
52If
53.Fa little
54is an empty wide string,
55.Fa big
56is returned;
57if
58.Fa little
59occurs nowhere in
60.Fa big ,
61.Dv NULL
62is returned;
63otherwise a pointer to the first wide character of the first occurrence of
64.Fa little
65is returned.
66.Sh SEE ALSO
67.Xr strstr 3 ,
68.Xr wcschr 3 ,
69.Xr wcscspn 3 ,
70.Xr wcspbrk 3 ,
71.Xr wcsrchr 3 ,
72.Xr wcsspn 3 ,
73.Xr wcstok 3 ,
74.Xr wmemchr 3
75.Sh STANDARDS
76The
77.Fn wcsstr
78function conforms to
79.St -isoC-99
80and was first introduced in
81.St -isoC-amd1 .
82.Sh HISTORY
83The
84.Fn wcsstr
85function was ported from
86.Nx
87and first appeared in
88.Ox 3.8 .
diff --git a/src/lib/libc/string/wcsstr.c b/src/lib/libc/string/wcsstr.c
deleted file mode 100644
index 6a7b0dac4a..0000000000
--- a/src/lib/libc/string/wcsstr.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/* $OpenBSD: wcsstr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
2/* $NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35#ifdef WCSWCS
36wcswcs(const wchar_t *big, const wchar_t *little)
37#else
38wcsstr(const wchar_t *big, const wchar_t *little)
39#endif
40{
41 const wchar_t *p;
42 const wchar_t *q;
43 const wchar_t *r;
44
45 if (!*little) {
46 return (wchar_t *)big;
47 }
48 if (wcslen(big) < wcslen(little))
49 return NULL;
50
51 p = big;
52 q = little;
53 while (*p) {
54 q = little;
55 r = p;
56 while (*q) {
57 if (*r != *q)
58 break;
59 q++;
60 r++;
61 }
62 if (!*q) {
63 return (wchar_t *)p;
64 }
65 p++;
66 }
67 return NULL;
68}
69#ifndef WCSWCS
70DEF_STRONG(wcsstr);
71#endif
diff --git a/src/lib/libc/string/wcstok.3 b/src/lib/libc/string/wcstok.3
deleted file mode 100644
index 33ba1318a1..0000000000
--- a/src/lib/libc/string/wcstok.3
+++ /dev/null
@@ -1,151 +0,0 @@
1.\" $OpenBSD: wcstok.3,v 1.7 2011/07/25 00:38:53 schwarze Exp $
2.\"
3.\" $NetBSD: wcstok.3,v 1.3 2003/09/08 17:54:33 wiz Exp $
4.\"
5.\" Copyright (c) 1998 Softweyr LLC. All rights reserved.
6.\"
7.\" strtok_r, from Berkeley strtok
8.\" Oct 13, 1998 by Wes Peters <wes@softweyr.com>
9.\"
10.\" Copyright (c) 1988, 1991, 1993
11.\" The Regents of the University of California. All rights reserved.
12.\"
13.\" This code is derived from software contributed to Berkeley by
14.\" the American National Standards Committee X3, on Information
15.\" Processing Systems.
16.\"
17.\" Redistribution and use in source and binary forms, with or without
18.\" modification, are permitted provided that the following conditions
19.\" are met:
20.\"
21.\" 1. Redistributions of source code must retain the above copyright
22.\" notices, this list of conditions and the following disclaimer.
23.\"
24.\" 2. Redistributions in binary form must reproduce the above
25.\" copyright notices, this list of conditions and the following
26.\" disclaimer in the documentation and/or other materials provided
27.\" with the distribution.
28.\"
29.\" 3. All advertising materials mentioning features or use of this
30.\" software must display the following acknowledgement:
31.\"
32.\" This product includes software developed by Softweyr LLC, the
33.\" University of California, Berkeley, and its contributors.
34.\"
35.\" 4. Neither the name of Softweyr LLC, the University nor the names
36.\" of its contributors may be used to endorse or promote products
37.\" derived from this software without specific prior written
38.\" permission.
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND
41.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
42.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44.\" DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR
45.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52.\" SUCH DAMAGE.
53.\"
54.\" Original version ID:
55.\" FreeBSD: src/lib/libc/string/wcstok.3,v 1.4 2002/10/15 09:49:54 tjr Exp
56.\"
57.Dd $Mdocdate: July 25 2011 $
58.Dt WCSTOK 3
59.Os
60.Sh NAME
61.Nm wcstok
62.Nd split wide-character string into tokens
63.Sh SYNOPSIS
64.In wchar.h
65.Ft wchar_t *
66.Fn wcstok "wchar_t * restrict str" "const wchar_t * restrict sep" "wchar_t ** restrict last"
67.Sh DESCRIPTION
68The
69.Fn wcstok
70function
71is used to isolate sequential tokens in a NUL-terminated wide-character
72string,
73.Fa str .
74These tokens are separated in the string by at least one of the
75characters in
76.Fa sep .
77The first time that
78.Fn wcstok
79is called,
80.Fa str
81should be specified; subsequent calls, wishing to obtain further tokens
82from the same string, should pass a null pointer instead.
83The separator string,
84.Fa sep ,
85must be supplied each time, and may change between calls.
86The context pointer
87.Fa last
88must be provided on each call.
89.Pp
90The
91.Fn wcstok
92function is the wide-character counterpart of the
93.Xr strtok_r 3
94function.
95.Pp
96Since
97.Fn wcstok
98modifies the string,
99.Fa str
100should not point to an area in the initialized data segment.
101.Sh RETURN VALUES
102The
103.Fn wcstok
104function
105returns a pointer to the beginning of each subsequent token in the string,
106after replacing the token itself with a NUL wide character (L'\e0').
107When no more tokens remain, a null pointer is returned.
108.Sh EXAMPLES
109The following code fragment splits a wide-character string on
110.Tn ASCII
111space, tab, and newline characters and writes the tokens to
112standard output:
113.Bd -literal -offset indent
114const wchar_t *seps = L" \et\en";
115wchar_t *last, *tok, text[] = L" \enone\ettwo\et\etthree \en";
116
117for (tok = wcstok(text, seps, &last); tok != NULL;
118 tok = wcstok(NULL, seps, &last))
119 wprintf(L"%ls\en", tok);
120.Ed
121.Sh SEE ALSO
122.Xr strtok 3 ,
123.Xr wcschr 3 ,
124.Xr wcscspn 3 ,
125.Xr wcspbrk 3 ,
126.Xr wcsrchr 3 ,
127.Xr wcsspn 3 ,
128.Xr wcsstr 3 ,
129.Xr wmemchr 3
130.Sh STANDARDS
131The
132.Fn wcstok
133function
134conforms to
135.St -isoC-99 .
136.Sh HISTORY
137The
138.Fn wcstok
139function was ported from
140.Nx
141and first appeared in
142.Ox 3.8 .
143.Pp
144Some early implementations of
145.Fn wcstok
146omit the
147context pointer argument,
148.Fa last ,
149and maintain state across calls in a static variable like
150.Xr strtok 3
151does.
diff --git a/src/lib/libc/string/wcstok.c b/src/lib/libc/string/wcstok.c
deleted file mode 100644
index bc1ac3e8cb..0000000000
--- a/src/lib/libc/string/wcstok.c
+++ /dev/null
@@ -1,93 +0,0 @@
1/* $OpenBSD: wcstok.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */
2/* $NetBSD: wcstok.c,v 1.3 2003/07/10 08:50:48 tshiozak Exp $ */
3
4/*-
5 * Copyright (c) 1998 Softweyr LLC. All rights reserved.
6 *
7 * strtok_r, from Berkeley strtok
8 * Oct 13, 1998 by Wes Peters <wes@softweyr.com>
9 *
10 * Copyright (c) 1988, 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notices, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notices, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by Softweyr LLC, the
24 * University of California, Berkeley, and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE
33 * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
35 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Original version ID:
42 * FreeBSD: src/lib/libc/string/wcstok.c,v 1.1 2002/09/07 08:16:57 tjr Exp
43 */
44
45#include <wchar.h>
46
47wchar_t *
48wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim,
49 wchar_t ** __restrict last)
50{
51 const wchar_t *spanp;
52 wchar_t c, sc;
53 wchar_t *tok;
54
55 if (s == NULL && (s = *last) == NULL)
56 return (NULL);
57
58 /*
59 * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of).
60 */
61cont:
62 c = *s++;
63 for (spanp = delim; (sc = *spanp++) != L'\0';) {
64 if (c == sc)
65 goto cont;
66 }
67
68 if (c == L'\0') { /* no non-delimiter characters */
69 *last = NULL;
70 return (NULL);
71 }
72 tok = s - 1;
73
74 /*
75 * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of).
76 * Note that delim must have one NUL; we stop if we see that, too.
77 */
78 for (;;) {
79 c = *s++;
80 spanp = delim;
81 do {
82 if ((sc = *spanp++) == c) {
83 if (c == L'\0')
84 s = NULL;
85 else
86 s[-1] = L'\0';
87 *last = s;
88 return (tok);
89 }
90 } while (sc != L'\0');
91 }
92 /* NOTREACHED */
93}
diff --git a/src/lib/libc/string/wcswcs.c b/src/lib/libc/string/wcswcs.c
deleted file mode 100644
index bd35605547..0000000000
--- a/src/lib/libc/string/wcswcs.c
+++ /dev/null
@@ -1,5 +0,0 @@
1/* $OpenBSD: wcswcs.c,v 1.1 2005/04/13 16:35:58 espie Exp $ */
2/* $NetBSD: wcswcs.c,v 1.1 2003/03/05 20:18:17 tshiozak Exp $ */
3
4#define WCSWCS
5#include "wcsstr.c"
diff --git a/src/lib/libc/string/wcswidth.3 b/src/lib/libc/string/wcswidth.3
deleted file mode 100644
index a2a5b2df86..0000000000
--- a/src/lib/libc/string/wcswidth.3
+++ /dev/null
@@ -1,69 +0,0 @@
1.\" $OpenBSD: wcswidth.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $
2.\"
3.\" Copyright (c) 2002 Tim J. Robbins
4.\" All rights reserved.
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd $Mdocdate: July 25 2011 $
28.Dt WCSWIDTH 3
29.Os
30.Sh NAME
31.Nm wcswidth
32.Nd number of column positions in wide-character string
33.Sh SYNOPSIS
34.In wchar.h
35.Ft int
36.Fn wcswidth "const wchar_t *pwcs" "size_t n"
37.Sh DESCRIPTION
38The
39.Fn wcswidth
40function determines the number of column positions required for the first
41.Fa n
42characters of
43.Fa pwcs ,
44or until a null wide character (L'\e0') is encountered.
45.Sh RETURN VALUES
46The
47.Fn wcswidth
48function returns 0 if
49.Fa pwcs
50is an empty string (L""),
51\-1 if a non-printing wide character is encountered,
52otherwise it returns the number of column positions occupied.
53.Sh SEE ALSO
54.Xr iswprint 3 ,
55.Xr strlen 3 ,
56.Xr wcslen 3 ,
57.Xr wcwidth 3
58.Sh STANDARDS
59The
60.Fn wcswidth
61function conforms to
62.St -p1003.1-2001 .
63.Sh HISTORY
64The
65.Fn wcswidth
66function was ported from
67.Nx
68and first appeared in
69.Ox 3.8 .
diff --git a/src/lib/libc/string/wcswidth.c b/src/lib/libc/string/wcswidth.c
deleted file mode 100644
index 9f003f96c7..0000000000
--- a/src/lib/libc/string/wcswidth.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* $OpenBSD: wcswidth.c,v 1.5 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30 */
31
32#include <wchar.h>
33
34int
35wcswidth(const wchar_t *s, size_t n)
36{
37 int w, q;
38
39 w = 0;
40 while (n && *s) {
41 q = wcwidth(*s);
42 if (q == -1)
43 return (-1);
44 w += q;
45 s++;
46 n--;
47 }
48
49 return w;
50}
51DEF_WEAK(wcswidth);
diff --git a/src/lib/libc/string/wmemchr.3 b/src/lib/libc/string/wmemchr.3
deleted file mode 100644
index 17fbc9dbc5..0000000000
--- a/src/lib/libc/string/wmemchr.3
+++ /dev/null
@@ -1,81 +0,0 @@
1.\" $OpenBSD: wmemchr.3,v 1.10 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WMEMCHR 3
36.Os
37.Sh NAME
38.Nm wmemchr
39.Nd locate wide character in wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wmemchr "const wchar_t *b" "wchar_t c" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn wmemchr
47function locates the first occurrence of
48.Fa c
49in wide string
50.Fa b .
51.Sh RETURN VALUES
52The
53.Fn wmemchr
54function returns a pointer to the wide character located, or
55.Dv NULL
56if no such wide character exists within
57.Fa len
58wide characters.
59.Sh SEE ALSO
60.Xr memchr 3 ,
61.Xr wcschr 3 ,
62.Xr wcscspn 3 ,
63.Xr wcspbrk 3 ,
64.Xr wcsrchr 3 ,
65.Xr wcsspn 3 ,
66.Xr wcsstr 3 ,
67.Xr wcstok 3
68.Sh STANDARDS
69The
70.Fn wmemchr
71function conforms to
72.St -isoC-99
73and was first introduced in
74.St -isoC-amd1 .
75.Sh HISTORY
76The
77.Fn wmemchr
78function was ported from
79.Nx
80and first appeared in
81.Ox 3.8 .
diff --git a/src/lib/libc/string/wmemchr.c b/src/lib/libc/string/wmemchr.c
deleted file mode 100644
index 556a0b35cc..0000000000
--- a/src/lib/libc/string/wmemchr.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/* $OpenBSD: wmemchr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
2/* $NetBSD: wmemchr.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wmemchr(const wchar_t *s, wchar_t c, size_t n)
36{
37 size_t i;
38
39 for (i = 0; i < n; i++) {
40 if (*s == c) {
41 return (wchar_t *)s;
42 }
43 s++;
44 }
45 return NULL;
46}
47DEF_STRONG(wmemchr);
diff --git a/src/lib/libc/string/wmemcmp.3 b/src/lib/libc/string/wmemcmp.3
deleted file mode 100644
index bd8ddfd120..0000000000
--- a/src/lib/libc/string/wmemcmp.3
+++ /dev/null
@@ -1,78 +0,0 @@
1.\" $OpenBSD: wmemcmp.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WMEMCMP 3
36.Os
37.Sh NAME
38.Nm wmemcmp
39.Nd compare wide strings
40.Sh SYNOPSIS
41.In wchar.h
42.Ft int
43.Fn wmemcmp "const wchar_t *s1" "const wchar_t *s2" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn wmemcmp
47function compares the wide string
48.Fa s1
49against the wide string
50.Fa s2 .
51Both wide strings are assumed to be
52.Fa len
53wide characters long.
54.Sh RETURN VALUES
55The
56.Fn wmemcmp
57function returns zero if the two wide strings are identical,
58otherwise the difference between the first two differing wide characters is
59returned.
60Zero-length wide strings are always identical.
61.Sh SEE ALSO
62.Xr memcmp 3 ,
63.Xr wcscasecmp 3 ,
64.Xr wcscmp 3
65.Sh STANDARDS
66The
67.Fn wmemcmp
68function conforms to
69.St -isoC-99
70and was first introduced in
71.St -isoC-amd1 .
72.Sh HISTORY
73The
74.Fn wmemcmp
75function was ported from
76.Nx
77and first appeared in
78.Ox 3.8 .
diff --git a/src/lib/libc/string/wmemcmp.c b/src/lib/libc/string/wmemcmp.c
deleted file mode 100644
index 46617e29cf..0000000000
--- a/src/lib/libc/string/wmemcmp.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/* $OpenBSD: wmemcmp.c,v 1.5 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp
30 */
31
32#include <wchar.h>
33#include "locale/runetype.h"
34
35int
36wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)
37{
38 size_t i;
39
40 for (i = 0; i < n; i++) {
41 if (*s1 != *s2) {
42 /* wchar might be unsigned */
43 return *(const rune_t *)s1 >
44 *(const rune_t *)s2 ? 1 : -1;
45 }
46 s1++;
47 s2++;
48 }
49 return 0;
50}
51DEF_STRONG(wmemcmp);
diff --git a/src/lib/libc/string/wmemcpy.3 b/src/lib/libc/string/wmemcpy.3
deleted file mode 100644
index 2a6d528a1a..0000000000
--- a/src/lib/libc/string/wmemcpy.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" $OpenBSD: wmemcpy.3,v 1.5 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WMEMCPY 3
36.Os
37.Sh NAME
38.Nm wmemcpy
39.Nd copy wide characters
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wmemcpy "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn wmemcpy
47function copies
48.Fa len
49wide characters from buffer
50.Fa src
51to buffer
52.Fa dst .
53If the two buffers may overlap,
54.Xr wmemmove 3
55must be used instead.
56.Sh RETURN VALUES
57The
58.Fn wmemcpy
59function returns the original value of
60.Fa dst .
61.Sh SEE ALSO
62.Xr memcpy 3 ,
63.Xr wcscpy 3 ,
64.Xr wcslcpy 3 ,
65.Xr wmemmove 3
66.Sh STANDARDS
67The
68.Fn wmemcpy
69function conforms to
70.St -isoC-99
71and was first introduced in
72.St -isoC-amd1 .
73.Sh HISTORY
74The
75.Fn wmemcpy
76function was ported from
77.Nx
78and first appeared in
79.Ox 3.8 .
diff --git a/src/lib/libc/string/wmemcpy.c b/src/lib/libc/string/wmemcpy.c
deleted file mode 100644
index cf02ab9d56..0000000000
--- a/src/lib/libc/string/wmemcpy.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/* $OpenBSD: wmemcpy.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp
30 */
31
32#include <string.h>
33#include <wchar.h>
34
35wchar_t *
36wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
37{
38
39 return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t));
40}
41DEF_STRONG(wmemcpy);
diff --git a/src/lib/libc/string/wmemmove.3 b/src/lib/libc/string/wmemmove.3
deleted file mode 100644
index 46942e7928..0000000000
--- a/src/lib/libc/string/wmemmove.3
+++ /dev/null
@@ -1,78 +0,0 @@
1.\" $OpenBSD: wmemmove.3,v 1.3 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WMEMMOVE 3
36.Os
37.Sh NAME
38.Nm wmemmove
39.Nd copy wide characters
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wmemmove "wchar_t *dst" "const wchar_t *src" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn wmemmove
47function copies
48.Fa len
49wide characters from buffer
50.Fa src
51to buffer
52.Fa dst .
53The two buffers may overlap;
54the copy is always done in a non-destructive manner.
55.Sh RETURN VALUES
56The
57.Fn wmemmove
58function returns the original value of
59.Fa dst .
60.Sh SEE ALSO
61.Xr memmove 3 ,
62.Xr wcscpy 3 ,
63.Xr wcslcpy 3 ,
64.Xr wmemcpy 3
65.Sh STANDARDS
66The
67.Fn wmemmove
68function conforms to
69.St -isoC-99
70and was first introduced in
71.St -isoC-amd1 .
72.Sh HISTORY
73The
74.Fn wmemmove
75function was ported from
76.Nx
77and first appeared in
78.Ox 3.8 .
diff --git a/src/lib/libc/string/wmemmove.c b/src/lib/libc/string/wmemmove.c
deleted file mode 100644
index 8bf8011064..0000000000
--- a/src/lib/libc/string/wmemmove.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/* $OpenBSD: wmemmove.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wmemmove.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp
30 */
31
32#include <string.h>
33#include <wchar.h>
34
35wchar_t *
36wmemmove(wchar_t *d, const wchar_t *s, size_t n)
37{
38
39 return (wchar_t *)memmove(d, s, n * sizeof(wchar_t));
40}
41DEF_STRONG(wmemmove);
diff --git a/src/lib/libc/string/wmemset.3 b/src/lib/libc/string/wmemset.3
deleted file mode 100644
index 2655d68bcb..0000000000
--- a/src/lib/libc/string/wmemset.3
+++ /dev/null
@@ -1,73 +0,0 @@
1.\" $OpenBSD: wmemset.3,v 1.4 2013/06/05 03:39:23 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in the
17.\" documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: June 5 2013 $
35.Dt WMEMSET 3
36.Os
37.Sh NAME
38.Nm wmemset
39.Nd write a wide string
40.Sh SYNOPSIS
41.In wchar.h
42.Ft wchar_t *
43.Fn wmemset "wchar_t *s" "wchar_t c" "size_t len"
44.Sh DESCRIPTION
45The
46.Fn wmemset
47function writes
48.Fa len
49wide characters of value
50.Fa c
51to the wide string
52.Fa s .
53.Sh RETURN VALUES
54The
55.Fn wmemset
56function returns the original value of
57.Fa s .
58.Sh SEE ALSO
59.Xr memset 3
60.Sh STANDARDS
61The
62.Fn wmemset
63function conforms to
64.St -isoC-99
65and was first introduced in
66.St -isoC-amd1 .
67.Sh HISTORY
68The
69.Fn wmemset
70function was ported from
71.Nx
72and first appeared in
73.Ox 3.8 .
diff --git a/src/lib/libc/string/wmemset.c b/src/lib/libc/string/wmemset.c
deleted file mode 100644
index a2d3295170..0000000000
--- a/src/lib/libc/string/wmemset.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/* $OpenBSD: wmemset.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
2/* $NetBSD: wmemset.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3
4/*-
5 * Copyright (c)1999 Citrus Project,
6 * All rights reserved.
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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp
30 */
31
32#include <wchar.h>
33
34wchar_t *
35wmemset(wchar_t *s, wchar_t c, size_t n)
36{
37 size_t i;
38 wchar_t *p;
39
40 p = s;
41 for (i = 0; i < n; i++) {
42 *p = c;
43 p++;
44 }
45 return s;
46}
47DEF_STRONG(wmemset);