summaryrefslogtreecommitdiff
path: root/src/lib/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string')
-rw-r--r--src/lib/libc/string/Makefile.inc128
-rw-r--r--src/lib/libc/string/__strerror.c111
-rw-r--r--src/lib/libc/string/__strsignal.c104
-rw-r--r--src/lib/libc/string/bcmp.371
-rw-r--r--src/lib/libc/string/bcmp.c63
-rw-r--r--src/lib/libc/string/bcopy.371
-rw-r--r--src/lib/libc/string/bcopy.c138
-rw-r--r--src/lib/libc/string/bm.3113
-rw-r--r--src/lib/libc/string/bm.c219
-rw-r--r--src/lib/libc/string/bstring.3109
-rw-r--r--src/lib/libc/string/bzero.367
-rw-r--r--src/lib/libc/string/bzero.c56
-rw-r--r--src/lib/libc/string/ffs.362
-rw-r--r--src/lib/libc/string/ffs.c58
-rw-r--r--src/lib/libc/string/index.382
-rw-r--r--src/lib/libc/string/index.c55
-rw-r--r--src/lib/libc/string/memccpy.375
-rw-r--r--src/lib/libc/string/memccpy.c64
-rw-r--r--src/lib/libc/string/memchr.381
-rw-r--r--src/lib/libc/string/memchr.c58
-rw-r--r--src/lib/libc/string/memcmp.382
-rw-r--r--src/lib/libc/string/memcmp.c60
-rw-r--r--src/lib/libc/string/memcpy.383
-rw-r--r--src/lib/libc/string/memmove.375
-rw-r--r--src/lib/libc/string/memset.372
-rw-r--r--src/lib/libc/string/memset.c58
-rw-r--r--src/lib/libc/string/rindex.380
-rw-r--r--src/lib/libc/string/rindex.c57
-rw-r--r--src/lib/libc/string/strcasecmp.389
-rw-r--r--src/lib/libc/string/strcasecmp.c120
-rw-r--r--src/lib/libc/string/strcat.396
-rw-r--r--src/lib/libc/string/strcat.c54
-rw-r--r--src/lib/libc/string/strchr.387
-rw-r--r--src/lib/libc/string/strcmp.393
-rw-r--r--src/lib/libc/string/strcmp.c58
-rw-r--r--src/lib/libc/string/strcoll.374
-rw-r--r--src/lib/libc/string/strcoll.c52
-rw-r--r--src/lib/libc/string/strcpy.3121
-rw-r--r--src/lib/libc/string/strcpy.c53
-rw-r--r--src/lib/libc/string/strcspn.384
-rw-r--r--src/lib/libc/string/strcspn.c67
-rw-r--r--src/lib/libc/string/strdup.368
-rw-r--r--src/lib/libc/string/strdup.c62
-rw-r--r--src/lib/libc/string/strerror.365
-rw-r--r--src/lib/libc/string/strerror.c55
-rw-r--r--src/lib/libc/string/string.3155
-rw-r--r--src/lib/libc/string/strlcat.c71
-rw-r--r--src/lib/libc/string/strlcpy.3140
-rw-r--r--src/lib/libc/string/strlcpy.c63
-rw-r--r--src/lib/libc/string/strlen.370
-rw-r--r--src/lib/libc/string/strlen.c53
-rw-r--r--src/lib/libc/string/strmode.3152
-rw-r--r--src/lib/libc/string/strmode.c152
-rw-r--r--src/lib/libc/string/strncat.c67
-rw-r--r--src/lib/libc/string/strncmp.c59
-rw-r--r--src/lib/libc/string/strncpy.c67
-rw-r--r--src/lib/libc/string/strpbrk.379
-rw-r--r--src/lib/libc/string/strpbrk.c56
-rw-r--r--src/lib/libc/string/strrchr.390
-rw-r--r--src/lib/libc/string/strsep.3110
-rw-r--r--src/lib/libc/string/strsep.c85
-rw-r--r--src/lib/libc/string/strsignal.360
-rw-r--r--src/lib/libc/string/strsignal.c49
-rw-r--r--src/lib/libc/string/strspn.379
-rw-r--r--src/lib/libc/string/strspn.c60
-rw-r--r--src/lib/libc/string/strstr.388
-rw-r--r--src/lib/libc/string/strstr.c64
-rw-r--r--src/lib/libc/string/strtok.3112
-rw-r--r--src/lib/libc/string/strtok.c89
-rw-r--r--src/lib/libc/string/strxfrm.368
-rw-r--r--src/lib/libc/string/strxfrm.c73
-rw-r--r--src/lib/libc/string/swab.365
-rw-r--r--src/lib/libc/string/swab.c65
73 files changed, 5991 insertions, 0 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc
new file mode 100644
index 0000000000..076db78945
--- /dev/null
+++ b/src/lib/libc/string/Makefile.inc
@@ -0,0 +1,128 @@
1# $OpenBSD: Makefile.inc,v 1.5 1998/07/01 01:29:44 millert Exp $
2
3# string sources
4.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string
5
6SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \
7 strlcat.c strlcpy.c strmode.c strsignal.c strtok.c strxfrm.c \
8 __strerror.c __strsignal.c
9
10# machine-dependent net sources
11# m-d Makefile.inc must include sources for:
12# bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset()
13# rindex() strcat() strcmp() strcpy() strcspn() strlen()
14# strncat() strncmp() strncpy() strpbrk() strsep()
15# strspn() strstr() swav()
16# m-d Makefile.inc may include sources for:
17# memcpy() memmove() strchr() strrchr()
18
19.include "${.CURDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc"
20
21# if no machine specific memmove(3), build one out of bcopy(3).
22.if empty(SRCS:Mmemmove.S)
23OBJS+= memmove.o
24memmove.o: bcopy.c
25 ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
26 @${LD} -x -r ${.TARGET}
27 @mv a.out ${.TARGET}
28
29memmove.po: bcopy.c
30 ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
31 @${LD} -X -r ${.TARGET}
32 @mv a.out ${.TARGET}
33
34memmove.so: bcopy.c
35 ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \
36 -o ${.TARGET}
37.endif
38
39# if no machine specific memcpy(3), build one out of bcopy(3).
40# if there is a machine specific memmove(3), we'll assume it aliases
41# memcpy(3).
42.if empty(SRCS:Mmemcpy.S)
43.if empty(SRCS:Mmemmove.S)
44OBJS+= memcpy.o
45memcpy.o: bcopy.c
46 ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
47 @${LD} -x -r ${.TARGET}
48 @mv a.out ${.TARGET}
49
50memcpy.po: bcopy.c
51 ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
52 @${LD} -X -r ${.TARGET}
53 @mv a.out ${.TARGET}
54
55memcpy.so: bcopy.c
56 ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \
57 -o ${.TARGET}
58.endif
59.endif
60
61# if no machine specific strchr(3), build one out of index(3).
62.if empty(SRCS:Mstrchr.S)
63OBJS+= strchr.o
64strchr.o: index.c
65 ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
66 @${LD} -x -r ${.TARGET}
67 @mv a.out ${.TARGET}
68
69strchr.po: index.c
70 ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
71 @${LD} -X -r ${.TARGET}
72 @mv a.out ${.TARGET}
73
74strchr.so: index.c
75 ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \
76 -o ${.TARGET}
77.endif
78
79# if no machine specific strrchr(3), build one out of rindex(3).
80.if empty(SRCS:Mstrrchr.S)
81OBJS+= strrchr.o
82strrchr.o: rindex.c
83 ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
84 @${LD} -x -r ${.TARGET}
85 @mv a.out ${.TARGET}
86
87strrchr.po: rindex.c
88 ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
89 @${LD} -X -r ${.TARGET}
90 @mv a.out ${.TARGET}
91
92strrchr.so: rindex.c
93 ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \
94 -o ${.TARGET}
95.endif
96
97# build .ln files for memmove, memcpy, strchr and strrchr always from
98# bcopy, index, and rindex
99LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln
100
101memmove.ln: bcopy.c
102 lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
103 ${.CURDIR}/string/bcopy.c
104
105memcpy.ln: bcopy.c
106 lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
107 ${.CURDIR}/string/bcopy.c
108
109strchr.ln: index.c
110 lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
111 ${.CURDIR}/string/index.c
112
113strrchr.ln: rindex.c
114 lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
115 ${.CURDIR}/string/rindex.c
116
117MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \
118 memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \
119 strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 \
120 string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \
121 strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3
122
123MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3
124MLINKS+=strcasecmp.3 strncasecmp.3
125MLINKS+=strcat.3 strncat.3
126MLINKS+=strcmp.3 strncmp.3
127MLINKS+=strcpy.3 strncpy.3
128MLINKS+=strlcpy.3 strlcat.3
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c
new file mode 100644
index 0000000000..9c023f8a53
--- /dev/null
+++ b/src/lib/libc/string/__strerror.c
@@ -0,0 +1,111 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifdef NLS
39#define catclose _catclose
40#define catgets _catgets
41#define catopen _catopen
42#include <nl_types.h>
43#endif
44
45#define sys_errlist _sys_errlist
46#define sys_nerr _sys_nerr
47
48#include <errno.h>
49#include <limits.h>
50#include <stdio.h>
51#include <string.h>
52
53static char *itoa(num)
54 int num;
55{
56 static char buffer[11];
57 char *p;
58
59 p = buffer + 4;
60 while (num >= 10) {
61 *--p = (num % 10) + '0';
62 num /= 10;
63 }
64 *p = (num % 10) + '0';
65 return p;
66}
67
68/*
69 * Since perror() is not allowed to change the contents of strerror()'s
70 * static buffer, both functions supply their own buffers to the
71 * internal function __strerror().
72 */
73
74char *
75__strerror(num, buf)
76 int num;
77 char *buf;
78{
79#define UPREFIX "Unknown error: "
80 register unsigned int errnum;
81
82#ifdef NLS
83 nl_catd catd;
84 catd = catopen("libc", 0);
85#endif
86
87 errnum = num; /* convert to unsigned */
88 if (errnum < sys_nerr) {
89#ifdef NLS
90 strncpy(buf, catgets(catd, 1, errnum,
91 (char *)sys_errlist[errnum]), NL_TEXTMAX-1);
92 buf[NL_TEXTMAX - 1] = '\0';
93#else
94 return(sys_errlist[errnum]);
95#endif
96 } else {
97#ifdef NLS
98 strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1);
99 buf[NL_TEXTMAX - 1] = '\0';
100#else
101 strcpy(buf, UPREFIX);
102#endif
103 strncat(buf, itoa(errnum), NL_TEXTMAX-strlen(buf)-1);
104 }
105
106#ifdef NLS
107 catclose(catd);
108#endif
109
110 return buf;
111}
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c
new file mode 100644
index 0000000000..ae0df72cd3
--- /dev/null
+++ b/src/lib/libc/string/__strsignal.c
@@ -0,0 +1,104 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: __strsignal.c,v 1.5 1996/09/25 13:19:01 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifdef NLS
39#define catclose _catclose
40#define catgets _catgets
41#define catopen _catopen
42#include <nl_types.h>
43#endif
44
45#define sys_siglist _sys_siglist
46
47#include <stdio.h>
48#include <limits.h>
49#include <signal.h>
50#include <string.h>
51
52static char *itoa(num)
53 int num;
54{
55 static char buffer[11];
56 char *p;
57
58 p = buffer + 4;
59 while (num >= 10) {
60 *--p = (num % 10) + '0';
61 num /= 10;
62 }
63 *p = (num % 10) + '0';
64 return p;
65}
66
67char *
68__strsignal(num, buf)
69 int num;
70 char *buf;
71{
72#define UPREFIX "Unknown signal: "
73 register unsigned int signum;
74
75#ifdef NLS
76 nl_catd catd ;
77 catd = catopen("libc", 0);
78#endif
79
80 signum = num; /* convert to unsigned */
81 if (signum < NSIG) {
82#ifdef NLS
83 strncpy(buf, catgets(catd, 2, signum,
84 (char *)sys_siglist[signum]), NL_TEXTMAX-1);
85 buf[NL_TEXTMAX-1] = '\0';
86#else
87 return((char *)sys_siglist[signum]);
88#endif
89 } else {
90#ifdef NLS
91 strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1);
92 buf[NL_TEXTMAX-1] = '\0';
93#else
94 strcpy(buf, UPREFIX);
95#endif
96 strncat(buf, itoa(signum), NL_TEXTMAX-strlen(buf)-1);
97 }
98
99#ifdef NLS
100 catclose(catd);
101#endif
102
103 return buf;
104}
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3
new file mode 100644
index 0000000000..9234b5739d
--- /dev/null
+++ b/src/lib/libc/string/bcmp.3
@@ -0,0 +1,71 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: bcmp.3,v 1.2 1996/08/19 08:33:56 tholo Exp $
35.\"
36.Dd April 19, 1991
37.Dt BCMP 3
38.Os BSD 4.2
39.Sh NAME
40.Nm bcmp
41.Nd compare byte string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft int
45.Fn bcmp "const void *b1" "const void *b2" "size_t len"
46.Sh DESCRIPTION
47The
48.Fn bcmp
49function
50compares byte string
51.Fa b1
52against byte string
53.Fa b2 ,
54returning zero if they are identical, non-zero otherwise.
55Both strings are assumed to be
56.Fa len
57bytes long.
58Zero-length strings are always identical.
59.Pp
60The strings may overlap.
61.Sh SEE ALSO
62.Xr memcmp 3 ,
63.Xr strcasecmp 3 ,
64.Xr strcmp 3 ,
65.Xr strcoll 3 ,
66.Xr strxfrm 3
67.Sh HISTORY
68A
69.Fn bcmp
70function first appeared in
71.Bx 4.2 .
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c
new file mode 100644
index 0000000000..4ed00975a4
--- /dev/null
+++ b/src/lib/libc/string/bcmp.c
@@ -0,0 +1,63 @@
1/*
2 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: bcmp.c,v 1.4 1996/08/19 08:33:57 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44/*
45 * bcmp -- vax cmpc3 instruction
46 */
47int
48bcmp(b1, b2, length)
49 const void *b1, *b2;
50 register size_t length;
51{
52 register char *p1, *p2;
53
54 if (length == 0)
55 return(0);
56 p1 = (char *)b1;
57 p2 = (char *)b2;
58 do
59 if (*p1++ != *p2++)
60 break;
61 while (--length);
62 return(length);
63}
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3
new file mode 100644
index 0000000000..4e841562e0
--- /dev/null
+++ b/src/lib/libc/string/bcopy.3
@@ -0,0 +1,71 @@
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. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by the University of
18.\" California, Berkeley and its contributors.
19.\" 4. 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.\" $OpenBSD: bcopy.3,v 1.2 1996/08/19 08:33:57 tholo Exp $
36.\"
37.Dd April 19, 1991
38.Dt BCOPY 3
39.Os BSD 4.2
40.Sh NAME
41.Nm bcopy
42.Nd copy byte string
43.Sh SYNOPSIS
44.Fd #include <string.h>
45.Ft void
46.Fn bcopy "const void *src" "void *dst" "size_t len"
47.Sh DESCRIPTION
48The
49.Fn bcopy
50function
51copies
52.Fa len
53bytes from string
54.Fa src
55to string
56.Fa dst .
57The two strings may overlap.
58If
59.Fa len
60is zero, no bytes are copied.
61.Sh SEE ALSO
62.Xr memccpy 3 ,
63.Xr memcpy 3 ,
64.Xr memmove 3 ,
65.Xr strcpy 3 ,
66.Xr strncpy 3
67.Sh HISTORY
68A
69.Fn bcopy
70function appeared in
71.Bx 4.2 .
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c
new file mode 100644
index 0000000000..023a3b2db2
--- /dev/null
+++ b/src/lib/libc/string/bcopy.c
@@ -0,0 +1,138 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: bcopy.c,v 1.2 1996/08/19 08:33:58 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * sizeof(word) MUST BE A POWER OF TWO
45 * SO THAT wmask BELOW IS ALL ONES
46 */
47typedef long word; /* "word" used for optimal copy speed */
48
49#define wsize sizeof(word)
50#define wmask (wsize - 1)
51
52/*
53 * Copy a block of memory, handling overlap.
54 * This is the routine that actually implements
55 * (the portable versions of) bcopy, memcpy, and memmove.
56 */
57#ifdef MEMCOPY
58void *
59memcpy(dst0, src0, length)
60#else
61#ifdef MEMMOVE
62void *
63memmove(dst0, src0, length)
64#else
65void
66bcopy(src0, dst0, length)
67#endif
68#endif
69 void *dst0;
70 const void *src0;
71 register size_t length;
72{
73 register char *dst = dst0;
74 register const char *src = src0;
75 register size_t t;
76
77 if (length == 0 || dst == src) /* nothing to do */
78 goto done;
79
80 /*
81 * Macros: loop-t-times; and loop-t-times, t>0
82 */
83#define TLOOP(s) if (t) TLOOP1(s)
84#define TLOOP1(s) do { s; } while (--t)
85
86 if ((unsigned long)dst < (unsigned long)src) {
87 /*
88 * Copy forward.
89 */
90 t = (long)src; /* only need low bits */
91 if ((t | (long)dst) & wmask) {
92 /*
93 * Try to align operands. This cannot be done
94 * unless the low bits match.
95 */
96 if ((t ^ (long)dst) & wmask || length < wsize)
97 t = length;
98 else
99 t = wsize - (t & wmask);
100 length -= t;
101 TLOOP1(*dst++ = *src++);
102 }
103 /*
104 * Copy whole words, then mop up any trailing bytes.
105 */
106 t = length / wsize;
107 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
108 t = length & wmask;
109 TLOOP(*dst++ = *src++);
110 } else {
111 /*
112 * Copy backwards. Otherwise essentially the same.
113 * Alignment works as before, except that it takes
114 * (t&wmask) bytes to align, not wsize-(t&wmask).
115 */
116 src += length;
117 dst += length;
118 t = (long)src;
119 if ((t | (long)dst) & wmask) {
120 if ((t ^ (long)dst) & wmask || length <= wsize)
121 t = length;
122 else
123 t &= wmask;
124 length -= t;
125 TLOOP1(*--dst = *--src);
126 }
127 t = length / wsize;
128 TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
129 t = length & wmask;
130 TLOOP(*--dst = *--src);
131 }
132done:
133#if defined(MEMCOPY) || defined(MEMMOVE)
134 return (dst0);
135#else
136 return;
137#endif
138}
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3
new file mode 100644
index 0000000000..c942930163
--- /dev/null
+++ b/src/lib/libc/string/bm.3
@@ -0,0 +1,113 @@
1.\" Copyright (c) 1994
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Andrew Hume of AT&T Bell Laboratories.
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. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by the University of
18.\" California, Berkeley and its contributors.
19.\" 4. 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.\" $OpenBSD: bm.3,v 1.2 1996/08/19 08:33:58 tholo Exp $
36.\"
37.TH BM 3
38.SH NAME
39bm_comp, bm_exec, bm_free \- Boyer-Moore string search
40.SH SYNOPSIS
41.ft B
42#include <sys/types.h>
43.br
44#include <bm.h>
45.sp
46bm_pat *
47.br
48bm_comp(u_char *pattern, size_t patlen, u_char freq[256]);
49.sp
50u_char *
51.br
52bm_exec(bm_pat *pdesc, u_char *text, size_t len);
53.sp
54void
55.br
56bm_free(bm_pat *pdesc);
57.SH DESCRIPTION
58These routines implement an efficient mechanism to find an
59occurrence of a byte string within another byte string.
60.PP
61.I Bm_comp
62evaluates the
63.I patlen
64bytes starting at
65.IR pattern ,
66and returns a pointer to a structure describing them.
67The bytes referenced by
68.I pattern
69may be of any value.
70.PP
71The search takes advantage of the frequency distribution of the
72bytes in the text to be searched.
73If specified,
74.I freq
75should be an array of 256 values,
76with higher values indicating that the corresponding character occurs
77more frequently.
78(A less than optimal frequency distribution can only result in less
79than optimal performance, not incorrect results.)
80If
81.I freq
82is NULL,
83a system default table is used.
84.PP
85.I Bm_exec
86returns a pointer to the leftmost occurrence of the string given to
87.I bm_comp
88within
89.IR text ,
90or NULL if none occurs.
91The number of bytes in
92.I text
93must be specified by
94.IR len .
95.PP
96Space allocated for the returned description is discarded
97by calling
98.I bm_free
99with the returned description as an argument.
100.PP
101The asymptotic speed of
102.I bm_exec
103is
104.RI O( len / patlen ).
105.PP
106.SH "SEE ALSO"
107.IR regexp (3),
108.IR strstr (3)
109.sp
110.IR "Fast String Searching" ,
111Hume and Sunday,
112Software Practice and Experience,
113Vol. 21, 11 (November 1991) pp. 1221-48.
diff --git a/src/lib/libc/string/bm.c b/src/lib/libc/string/bm.c
new file mode 100644
index 0000000000..b191d340f6
--- /dev/null
+++ b/src/lib/libc/string/bm.c
@@ -0,0 +1,219 @@
1/*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Andrew Hume of AT&T Bell Laboratories.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: bm.c,v 1.3 1996/08/19 08:33:59 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <sys/types.h>
42
43#include <bm.h>
44#include <errno.h>
45#include <stdlib.h>
46#include <string.h>
47
48/*
49 * XXX
50 * The default frequency table starts at 99 and counts down. The default
51 * table should probably be oriented toward text, and will necessarily be
52 * locale specific. This one is for English. It was derived from the
53 * OSF/1 and 4.4BSD formatted and unformatted manual pages, and about 100Mb
54 * of email and random text. Change it if you can find something better.
55 */
56static u_char const freq_def[256] = {
57 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 77, 90, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0,
61 99, 28, 42, 27, 16, 14, 20, 51,
62 66, 65, 59, 24, 75, 76, 84, 56,
63 72, 74, 64, 55, 54, 47, 41, 37,
64 44, 61, 70, 43, 23, 53, 49, 22,
65 33, 58, 40, 46, 45, 57, 60, 26,
66 30, 63, 21, 12, 32, 50, 38, 39,
67 34, 11, 48, 67, 62, 35, 15, 29,
68 71, 18, 9, 17, 25, 13, 10, 52,
69 36, 95, 78, 86, 87, 98, 82, 80,
70 88, 94, 19, 68, 89, 83, 93, 96,
71 81, 7, 91, 92, 97, 85, 69, 73,
72 31, 79, 8, 5, 4, 6, 3, 0,
73 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0,
89};
90
91bm_pat *
92bm_comp(pb, len, freq)
93 u_char const *pb;
94 size_t len;
95 u_char const *freq;
96{
97 register u_char const *pe, *p;
98 register size_t *d, r;
99 register int j;
100 int sv_errno;
101 bm_pat *pat;
102
103 if (len == 0) {
104 errno = EINVAL;
105 return (NULL);
106 }
107 if ((pat = malloc(sizeof(*pat))) == NULL)
108 return (NULL);
109 pat->pat = NULL;
110 pat->delta = NULL;
111
112 pat->patlen = len; /* copy pattern */
113 if ((pat->pat = malloc(pat->patlen)) == NULL)
114 goto mem;
115 memcpy(pat->pat, pb, pat->patlen);
116 /* get skip delta */
117 if ((pat->delta = malloc(256 * sizeof(*d))) == NULL)
118 goto mem;
119 for (j = 0, d = pat->delta; j < 256; j++)
120 d[j] = pat->patlen;
121 for (pe = pb + pat->patlen - 1; pb <= pe; pb++)
122 d[*pb] = pe - pb;
123
124 if (freq == NULL) /* default freq table */
125 freq = freq_def;
126 r = 0; /* get guard */
127 for (pb = pat->pat, pe = pb + pat->patlen - 1; pb < pe; pb++)
128 if (freq[*pb] < freq[pat->pat[r]])
129 r = pb - pat->pat;
130 pat->rarec = pat->pat[r];
131 pat->rareoff = r - (pat->patlen - 1);
132
133 /* get md2 shift */
134 for (pe = pat->pat + pat->patlen - 1, p = pe - 1; p >= pat->pat; p--)
135 if (*p == *pe)
136 break;
137
138 /* *p is first leftward reoccurrence of *pe */
139 pat->md2 = pe - p;
140 return (pat);
141
142mem: sv_errno = errno;
143 bm_free(pat);
144 errno = sv_errno;
145 return (NULL);
146}
147
148void
149bm_free(pat)
150 bm_pat *pat;
151{
152 if (pat->pat != NULL)
153 free(pat->pat);
154 if (pat->delta != NULL)
155 free(pat->delta);
156 free(pat);
157}
158
159u_char *
160bm_exec(pat, base, n)
161 bm_pat *pat;
162 u_char *base;
163 size_t n;
164{
165 register u_char *e, *ep, *p, *q, *s;
166 register size_t *d0, k, md2, n1, ro;
167 register int rc;
168
169 if (n == 0)
170 return (NULL);
171
172 d0 = pat->delta;
173 n1 = pat->patlen - 1;
174 md2 = pat->md2;
175 ro = pat->rareoff;
176 rc = pat->rarec;
177 ep = pat->pat + pat->patlen - 1;
178 s = base + (pat->patlen - 1);
179
180 /* fast loop up to n - 3 * patlen */
181 e = base + n - 3 * pat->patlen;
182 while (s < e) {
183 k = d0[*s]; /* ufast skip loop */
184 while (k) {
185 k = d0[*(s += k)];
186 k = d0[*(s += k)];
187 }
188 if (s >= e)
189 break;
190 if (s[ro] != rc) /* guard test */
191 goto mismatch1;
192 /* fwd match */
193 for (p = pat->pat, q = s - n1; p < ep;)
194 if (*q++ != *p++)
195 goto mismatch1;
196 return (s - n1);
197
198mismatch1: s += md2; /* md2 shift */
199 }
200
201 /* slow loop up to end */
202 e = base + n;
203 while (s < e) {
204 s += d0[*s]; /* step */
205 if (s >= e)
206 break;
207 if (s[ro] != rc) /* guard test */
208 goto mismatch2;
209 /* fwd match */
210 for (p = pat->pat, q = s - n1; p <= ep;)
211 if (*q++ != *p++)
212 goto mismatch2;
213 return (s - n1);
214
215mismatch2: s += md2; /* md2 shift */
216 }
217
218 return (NULL);
219}
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3
new file mode 100644
index 0000000000..b553fd0beb
--- /dev/null
+++ b/src/lib/libc/string/bstring.3
@@ -0,0 +1,109 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: bstring.3,v 1.2 1996/08/19 08:33:59 tholo Exp $
35.\"
36.Dd April 19, 1991
37.Dt BSTRING 3
38.Os
39.Sh NAME
40.Nm bcmp ,
41.Nm bcopy ,
42.Nm bzero ,
43.Nm memccpy ,
44.Nm memchr ,
45.Nm memcmp ,
46.Nm memcpy ,
47.Nm memmove,
48.Nm memset
49.Nd byte string operations
50.Sh SYNOPSIS
51.Fd #include <string.h>
52.Ft int
53.Fn bcmp "const void *b1" "const void *b2" "size_t len"
54.Ft void
55.Fn bcopy "const void *src" "void *dst" "size_t len"
56.Ft void
57.Fn bzero "void *b" "size_t len"
58.Ft void *
59.Fn memchr "const void *b" "int c" "size_t len"
60.Ft int
61.Fn memcmp "const void *b1" "const void *b2" "size_t len"
62.Ft void *
63.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
64.Ft void *
65.Fn memcpy "void *dst" "const void *src" "size_t len"
66.Ft void *
67.Fn memmove "void *dst" "const void *src" "size_t len"
68.Ft void *
69.Fn memset "void *b" "int c" "size_t len"
70.Sh DESCRIPTION
71These functions operate on variable length strings of bytes.
72They do not check for terminating null bytes as the routines
73listed in
74.Xr string 3
75do.
76.Pp
77See the specific manual pages for more information.
78.Sh SEE ALSO
79.Xr bcmp 3 ,
80.Xr bcopy 3 ,
81.Xr bzero 3 ,
82.Xr memccpy 3 ,
83.Xr memchr 3 ,
84.Xr memcmp 3 ,
85.Xr memcpy 3 ,
86.Xr memmove 3 ,
87.Xr memset 3
88.Sh STANDARDS
89The functions
90.Fn memchr ,
91.Fn memcmp ,
92.Fn memcpy ,
93.Fn memmove ,
94and
95.Fn memset
96conform to
97.St -ansiC .
98.Sh HISTORY
99The functions
100.Fn bzero
101and
102.Fn memccpy
103appeared in
104.Bx 4.3 ;
105the functions
106.Fn bcmp ,
107.Fn bcopy ,
108appeared in
109.Bx 4.2 .
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3
new file mode 100644
index 0000000000..a8e55a63c1
--- /dev/null
+++ b/src/lib/libc/string/bzero.3
@@ -0,0 +1,67 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: bzero.3,v 1.2 1996/08/19 08:34:00 tholo Exp $
35.\"
36.Dd April 19, 1991
37.Dt BZERO 3
38.Os BSD 4.3
39.Sh NAME
40.Nm bzero
41.Nd write zeroes to a byte string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft void
45.Fn bzero "void *b" "size_t len"
46.Sh DESCRIPTION
47The
48.Fn bzero
49function
50writes
51.Fa len
52zero bytes to the string
53.Fa b .
54If
55.Fa len
56is zero,
57.Fn bzero
58does nothing.
59.Sh SEE ALSO
60.Xr memset 3 ,
61.Xr swab 3
62.Sh HISTORY
63A
64.Fn bzero
65function
66appeared in
67.Bx 4.3 .
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c
new file mode 100644
index 0000000000..3e660a307f
--- /dev/null
+++ b/src/lib/libc/string/bzero.c
@@ -0,0 +1,56 @@
1/*
2 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: bzero.c,v 1.3 1996/08/19 08:34:00 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44/*
45 * bzero -- vax movc5 instruction
46 */
47void
48bzero(b, length)
49 void *b;
50 register size_t length;
51{
52 register char *p;
53
54 for (p = b; length--;)
55 *p++ = '\0';
56}
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3
new file mode 100644
index 0000000000..9ef08aef8e
--- /dev/null
+++ b/src/lib/libc/string/ffs.3
@@ -0,0 +1,62 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: ffs.3,v 1.2 1996/08/19 08:34:01 tholo Exp $
35.\"
36.Dd April 19, 1991
37.Dt FFS 3
38.Os
39.Sh NAME
40.Nm ffs
41.Nd find first bit set in a bit string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft int
45.Fn ffs "int value"
46.Sh DESCRIPTION
47The
48.Fn ffs
49function
50finds the first bit set in
51.Fa value
52and returns the index of that bit.
53Bits are numbered starting from 1, starting at the right-most
54bit.
55A return value of 0 means that the argument was zero.
56.Sh SEE ALSO
57.Xr bitstring 3
58.Sh HISTORY
59The
60.Fn ffs
61function appeared in
62.Bx 4.3 .
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c
new file mode 100644
index 0000000000..a0767e50ad
--- /dev/null
+++ b/src/lib/libc/string/ffs.c
@@ -0,0 +1,58 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: ffs.c,v 1.3 1996/08/19 08:34:01 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44/*
45 * ffs -- vax ffs instruction
46 */
47int
48ffs(mask)
49 register int mask;
50{
51 register int bit;
52
53 if (mask == 0)
54 return(0);
55 for (bit = 1; !(mask & 1); bit++)
56 mask >>= 1;
57 return(bit);
58}
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/index.3
new file mode 100644
index 0000000000..d236a73a48
--- /dev/null
+++ b/src/lib/libc/string/index.3
@@ -0,0 +1,82 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: index.3,v 1.4 1997/12/30 01:09:49 deraadt Exp $
35.\"
36.Dd April 19, 1991
37.Dt INDEX 3
38.Os
39.Sh NAME
40.Nm index
41.Nd locate character in string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft char *
45.Fn index "const char *s" "int c"
46.Sh DESCRIPTION
47The
48.Fn index
49function
50locates the first character matching
51.Fa c
52(converted to a
53.Em char )
54in the null-terminated string
55.Fa s .
56.Sh RETURN VALUES
57If the character
58.Fa c
59is found, a pointer to it is returned; otherwise
60.Dv NULL
61is returned.
62If
63.Fa c
64is '\e0',
65.Fn index
66locates the terminating '\e0'.
67.Sh SEE ALSO
68.Xr memchr 3 ,
69.Xr rindex 3 ,
70.Xr strchr 3 ,
71.Xr strcspn 3 ,
72.Xr strpbrk 3 ,
73.Xr strrchr 3 ,
74.Xr strsep 3 ,
75.Xr strspn 3 ,
76.Xr strstr 3 ,
77.Xr strtok 3
78.Sh HISTORY
79An
80.Fn index
81function appeared in
82.At v6 .
diff --git a/src/lib/libc/string/index.c b/src/lib/libc/string/index.c
new file mode 100644
index 0000000000..86c4e75f12
--- /dev/null
+++ b/src/lib/libc/string/index.c
@@ -0,0 +1,55 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: index.c,v 1.2 1996/08/19 08:34:02 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39
40char *
41#ifdef STRCHR
42strchr(p, ch)
43#else
44index(p, ch)
45#endif
46 register const char *p, ch;
47{
48 for (;; ++p) {
49 if (*p == ch)
50 return((char *)p);
51 if (!*p)
52 return((char *)NULL);
53 }
54 /* NOTREACHED */
55}
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3
new file mode 100644
index 0000000000..c2e15b1405
--- /dev/null
+++ b/src/lib/libc/string/memccpy.3
@@ -0,0 +1,75 @@
1.\" $OpenBSD: memccpy.3,v 1.4 1998/06/15 17:55:09 mickey 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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93
35.\"
36.Dd June 9, 1993
37.Dt MEMCCPY 3
38.Os
39.Sh NAME
40.Nm memccpy
41.Nd copy string until character found
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft void *
45.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
46.Sh DESCRIPTION
47The
48.Fn memccpy
49function
50copies bytes from string
51.Fa src
52to string
53.Fa dst .
54If the character
55.Fa c
56(as converted to an unsigned char) occurs in the string
57.Fa src ,
58the copy stops and a pointer to the byte after the copy of
59.Fa c
60in the string
61.Fa dst
62is returned.
63Otherwise,
64.Fa len
65bytes are copied, and a NULL pointer is returned.
66.Sh SEE ALSO
67.Xr bcopy 3 ,
68.Xr memcpy 3 ,
69.Xr memmove 3 ,
70.Xr strcpy 3
71.Sh HISTORY
72The
73.Fn memccpy
74function first appeared in
75.Bx 4.4 .
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c
new file mode 100644
index 0000000000..020e6e5679
--- /dev/null
+++ b/src/lib/libc/string/memccpy.c
@@ -0,0 +1,64 @@
1/* $OpenBSD: memccpy.c,v 1.3 1997/08/20 04:09:39 millert 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. 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#if defined(LIBC_SCCS) && !defined(lint)
37#if 0
38static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93";
39#else
40static char *rcsid = "$OpenBSD: memccpy.c,v 1.3 1997/08/20 04:09:39 millert Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */
43
44#include <string.h>
45
46void *
47memccpy(t, f, c, n)
48 void *t;
49 const void *f;
50 int c;
51 register size_t n;
52{
53
54 if (n) {
55 register unsigned char *tp = t;
56 register const unsigned char *fp = f;
57 register unsigned char uc = c;
58 do {
59 if ((*tp++ = *fp++) == uc)
60 return (tp);
61 } while (--n != 0);
62 }
63 return (0);
64}
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3
new file mode 100644
index 0000000000..56a2aee9ce
--- /dev/null
+++ b/src/lib/libc/string/memchr.3
@@ -0,0 +1,81 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: memchr.3,v 1.2 1996/08/19 08:34:04 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt MEMCHR 3
40.Os
41.Sh NAME
42.Nm memchr
43.Nd locate byte in byte string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft void *
47.Fn memchr "const void *b" "int c" "size_t len"
48.Sh DESCRIPTION
49The
50.Fn memchr
51function
52locates the first occurrence of
53.Fa c
54(converted to an unsigned char)
55in string
56.Fa b .
57.Sh RETURN VALUES
58The
59.Fn memchr
60function
61returns a pointer to the byte located,
62or NULL if no such byte exists within
63.Fa len
64bytes.
65.Sh SEE ALSO
66.Xr index 3 ,
67.Xr rindex 3 ,
68.Xr strchr 3 ,
69.Xr strcspn 3 ,
70.Xr strpbrk 3 ,
71.Xr strrchr 3 ,
72.Xr strsep 3 ,
73.Xr strspn 3 ,
74.Xr strstr 3 ,
75.Xr strtok 3
76.Sh STANDARDS
77The
78.Fn memchr
79function
80conforms to
81.St -ansiC .
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c
new file mode 100644
index 0000000000..2ebb5dab32
--- /dev/null
+++ b/src/lib/libc/string/memchr.c
@@ -0,0 +1,58 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: memchr.c,v 1.2 1996/08/19 08:34:04 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43void *
44memchr(s, c, n)
45 const void *s;
46 register unsigned char c;
47 register size_t n;
48{
49 if (n != 0) {
50 register const unsigned char *p = s;
51
52 do {
53 if (*p++ == c)
54 return ((void *)(p - 1));
55 } while (--n != 0);
56 }
57 return (NULL);
58}
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3
new file mode 100644
index 0000000000..34c5f60861
--- /dev/null
+++ b/src/lib/libc/string/memcmp.3
@@ -0,0 +1,82 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: memcmp.3,v 1.3 1996/12/10 09:06:11 deraadt Exp $
37.\"
38.Dd June 29, 1991
39.Dt MEMCMP 3
40.Os
41.Sh NAME
42.Nm memcmp
43.Nd compare byte string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft int
47.Fn memcmp "const void *b1" "const void *b2" "size_t len"
48.Sh DESCRIPTION
49The
50.Fn memcmp
51function
52compares byte string
53.Fa b1
54against byte string
55.Fa b2 .
56Both strings are assumed to be
57.Fa len
58bytes long.
59.Sh RETURN VALUES
60The
61.Fn memcmp
62function
63returns zero if the two strings are identical,
64otherwise returns the difference between the first two differing bytes
65(treated as unsigned char values, so that
66.Sq Li \e200
67is greater than
68.Sq Li \&\e0 ,
69for example).
70Zero-length strings are always identical.
71.Sh SEE ALSO
72.Xr bcmp 3 ,
73.Xr strcasecmp 3 ,
74.Xr strcmp 3 ,
75.Xr strcoll 3 ,
76.Xr strxfrm 3
77.Sh STANDARDS
78The
79.Fn memcmp
80function
81conforms to
82.St -ansiC .
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c
new file mode 100644
index 0000000000..5ce33e2998
--- /dev/null
+++ b/src/lib/libc/string/memcmp.c
@@ -0,0 +1,60 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Compare memory regions.
45 */
46int
47memcmp(s1, s2, n)
48 const void *s1, *s2;
49 size_t n;
50{
51 if (n != 0) {
52 register const unsigned char *p1 = s1, *p2 = s2;
53
54 do {
55 if (*p1++ != *p2++)
56 return (*--p1 - *--p2);
57 } while (--n != 0);
58 }
59 return (0);
60}
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3
new file mode 100644
index 0000000000..75eb00b2d5
--- /dev/null
+++ b/src/lib/libc/string/memcpy.3
@@ -0,0 +1,83 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: memcpy.3,v 1.2 1996/08/19 08:34:06 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt MEMCPY 3
40.Os
41.Sh NAME
42.Nm memcpy
43.Nd copy byte string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft void *
47.Fn memcpy "void *dst" "const void *src" "size_t len"
48.Sh DESCRIPTION
49The
50.Fn memcpy
51function
52copies
53.Fa len
54bytes from string
55.Fa src
56to string
57.Fa dst .
58.Sh RETURN VALUES
59The
60.Fn memcpy
61function
62returns the original value of
63.Fa dst .
64.Sh SEE ALSO
65.Xr bcopy 3 ,
66.Xr memccpy 3 ,
67.Xr memmove 3 ,
68.Xr strcpy 3
69.Sh STANDARDS
70The
71.Fn memcpy
72function
73conforms to
74.St -ansiC .
75.Sh BUGS
76In this implementation
77.Fn memcpy
78is implemented using
79.Xr bcopy 3 ,
80and therefore the strings may overlap.
81On other systems, copying overlapping strings may produce surprises.
82A simpler solution is to not use
83.Fn memcpy .
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3
new file mode 100644
index 0000000000..95f6b7596c
--- /dev/null
+++ b/src/lib/libc/string/memmove.3
@@ -0,0 +1,75 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: memmove.3,v 1.2 1996/08/19 08:34:07 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt MEMMOVE 3
40.Os
41.Sh NAME
42.Nm memmove
43.Nd copy byte string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft void *
47.Fn memmove "void *dst" "const void *src" "size_t len"
48.Sh DESCRIPTION
49The
50.Fn memmove
51function
52copies
53.Fa len
54bytes from string
55.Fa src
56to string
57.Fa dst .
58The two strings may overlap;
59the copy is always done in a non-destructive manner.
60.Sh RETURN VALUES
61The
62.Fn memmove
63function returns the original value of
64.Fa dst .
65.Sh SEE ALSO
66.Xr bcopy 3 ,
67.Xr memccpy 3 ,
68.Xr memcpy 3 ,
69.Xr strcpy 3
70.Sh STANDARDS
71The
72.Fn memmove
73function
74conforms to
75.St -ansiC .
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3
new file mode 100644
index 0000000000..e1d8583732
--- /dev/null
+++ b/src/lib/libc/string/memset.3
@@ -0,0 +1,72 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: memset.3,v 1.3 1997/08/24 21:56:45 deraadt Exp $
37.\"
38.Dd June 29, 1991
39.Dt MEMSET 3
40.Os
41.Sh NAME
42.Nm memset
43.Nd write a byte to byte string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft void *
47.Fn memset "void *b" "int c" "size_t len"
48.Sh DESCRIPTION
49The
50.Fn memset
51function
52writes
53.Fa len
54bytes of value
55.Fa c
56(converted to an unsigned char) to the string
57.Fa b .
58.Sh RETURN VALUES
59The
60.Fn memset
61function
62returns the original value of
63.Fa b .
64.Sh SEE ALSO
65.Xr bzero 3 ,
66.Xr swab 3
67.Sh STANDARDS
68The
69.Fn memset
70function
71conforms to
72.St -ansiC .
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c
new file mode 100644
index 0000000000..c3373a21a9
--- /dev/null
+++ b/src/lib/libc/string/memset.c
@@ -0,0 +1,58 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: memset.c,v 1.2 1996/08/19 08:34:07 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43void *
44memset(dst, c, n)
45 void *dst;
46 register int c;
47 register size_t n;
48{
49
50 if (n != 0) {
51 register char *d = dst;
52
53 do
54 *d++ = c;
55 while (--n != 0);
56 }
57 return (dst);
58}
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/rindex.3
new file mode 100644
index 0000000000..db7f8e1cd8
--- /dev/null
+++ b/src/lib/libc/string/rindex.3
@@ -0,0 +1,80 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: rindex.3,v 1.3 1997/12/30 01:09:49 deraadt Exp $
35.\"
36.Dd April 19, 1991
37.Dt RINDEX 3
38.Os
39.Sh NAME
40.Nm rindex
41.Nd locate character in string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft char *
45.Fn rindex "const char *s" "int c"
46.Sh DESCRIPTION
47The
48.Fn rindex
49function
50locates the last character
51matching
52.Fa c
53(converted to a
54.Em char )
55in the null-terminated string
56.Fa s .
57If the character c is found, a pointer to it is returned; otherwise NULL is returned.
58If
59.Fa c
60is
61.Ql \e0 ,
62.Fn rindex
63locates the terminating
64.Ql \e0 .
65.Sh SEE ALSO
66.Xr index 3 ,
67.Xr memchr 3 ,
68.Xr strchr 3 ,
69.Xr strcspn 3 ,
70.Xr strpbrk 3 ,
71.Xr strrchr 3 ,
72.Xr strsep 3 ,
73.Xr strspn 3 ,
74.Xr strstr 3 ,
75.Xr strtok 3
76.Sh HISTORY
77A
78.Fn rindex
79function appeared in
80.At v6 .
diff --git a/src/lib/libc/string/rindex.c b/src/lib/libc/string/rindex.c
new file mode 100644
index 0000000000..f18553f667
--- /dev/null
+++ b/src/lib/libc/string/rindex.c
@@ -0,0 +1,57 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: rindex.c,v 1.2 1996/08/19 08:34:08 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39
40char *
41#ifdef STRRCHR
42strrchr(p, ch)
43#else
44rindex(p, ch)
45#endif
46 register const char *p, ch;
47{
48 register char *save;
49
50 for (save = NULL;; ++p) {
51 if (*p == ch)
52 save = (char *)p;
53 if (!*p)
54 return(save);
55 }
56 /* NOTREACHED */
57}
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3
new file mode 100644
index 0000000000..52a13055ee
--- /dev/null
+++ b/src/lib/libc/string/strcasecmp.3
@@ -0,0 +1,89 @@
1.\" $OpenBSD: strcasecmp.3,v 1.4 1998/06/15 17:55:11 mickey 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.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
37.\"
38.Dd June 9, 1993
39.Dt STRCASECMP 3
40.Os
41.Sh NAME
42.Nm strcasecmp
43.Nd compare strings, ignoring case
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft int
47.Fn strcasecmp "const char *s1" "const char *s2"
48.Ft int
49.Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
50.Sh DESCRIPTION
51The
52.Fn strcasecmp
53and
54.Fn strncasecmp
55functions
56compare the null-terminated strings
57.Fa s1
58and
59.Fa s2
60and return an integer greater than, equal to, or less than 0,
61according as
62.Fa s1
63is lexicographically greater than, equal to, or less than
64.Fa s2
65after translation of each corresponding character to lower-case.
66The strings themselves are not modified.
67The comparison is done using unsigned characters, so that
68.Sq Li \e200
69is greater than
70.Ql \e0 .
71.Pp
72The
73.Fn strncasecmp
74compares at most
75.Fa len
76characters.
77.Sh SEE ALSO
78.Xr bcmp 3 ,
79.Xr memcmp 3 ,
80.Xr strcmp 3 ,
81.Xr strcoll 3 ,
82.Xr strxfrm 3
83.Sh HISTORY
84The
85.Fn strcasecmp
86and
87.Fn strncasecmp
88functions first appeared in
89.Bx 4.4 .
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c
new file mode 100644
index 0000000000..1f487524aa
--- /dev/null
+++ b/src/lib/libc/string/strcasecmp.c
@@ -0,0 +1,120 @@
1/* $OpenBSD: strcasecmp.c,v 1.3 1997/08/20 04:13:57 millert 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. 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 <string.h>
37
38#if defined(LIBC_SCCS) && !defined(lint)
39#if 0
40static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93";
41#else
42static char *rcsid = "$OpenBSD: strcasecmp.c,v 1.3 1997/08/20 04:13:57 millert Exp $";
43#endif
44#endif /* LIBC_SCCS and not lint */
45
46typedef unsigned char u_char;
47
48/*
49 * This array is designed for mapping upper and lower case letter
50 * together for a case independent comparison. The mappings are
51 * based upon ascii character sequences.
52 */
53static const u_char charmap[] = {
54 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
55 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
56 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
57 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
58 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
59 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
60 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
61 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
62 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
63 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
64 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
65 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
66 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
67 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
68 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
69 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
70 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
71 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
72 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
73 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
74 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
75 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
76 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
77 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
78 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
79 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
80 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
81 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
82 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
83 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
84 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
85 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
86};
87
88int
89strcasecmp(s1, s2)
90 const char *s1, *s2;
91{
92 register const u_char *cm = charmap,
93 *us1 = (const u_char *)s1,
94 *us2 = (const u_char *)s2;
95
96 while (cm[*us1] == cm[*us2++])
97 if (*us1++ == '\0')
98 return (0);
99 return (cm[*us1] - cm[*--us2]);
100}
101
102int
103strncasecmp(s1, s2, n)
104 const char *s1, *s2;
105 register size_t n;
106{
107 if (n != 0) {
108 register const u_char *cm = charmap,
109 *us1 = (const u_char *)s1,
110 *us2 = (const u_char *)s2;
111
112 do {
113 if (cm[*us1] != cm[*us2++])
114 return (cm[*us1] - cm[*--us2]);
115 if (*us1++ == '\0')
116 break;
117 } while (--n != 0);
118 }
119 return (0);
120}
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3
new file mode 100644
index 0000000000..686afd3f2e
--- /dev/null
+++ b/src/lib/libc/string/strcat.3
@@ -0,0 +1,96 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strcat.3,v 1.3 1997/07/09 00:19:53 millert Exp $
37.\"
38.Dd July 8, 1997
39.Dt STRCAT 3
40.Os
41.Sh NAME
42.Nm strcat
43.Nd concatenate strings
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strcat "char *s" "const char *append"
48.Ft char *
49.Fn strncat "char *s" "const char *append" "size_t count"
50.Sh DESCRIPTION
51The
52.Fn strcat
53and
54.Fn strncat
55functions
56append a copy of the null-terminated string
57.Fa append
58to the end of the null-terminated string
59.Fa s ,
60then add a terminating
61.Ql \e0 .
62The string
63.Fa s
64must have sufficient space to hold the result.
65.Pp
66The
67.Fn strncat
68function
69appends not more than
70.Fa count
71characters where space for the terminating
72.Ql \e0
73should not be included in
74.Fa count .
75.Sh RETURN VALUES
76The
77.Fn strcat
78and
79.Fn strncat
80functions
81return the pointer
82.Fa s .
83.Sh SEE ALSO
84.Xr bcopy 3 ,
85.Xr memccpy 3 ,
86.Xr memcpy 3 ,
87.Xr memmove 3 ,
88.Xr strcpy 3
89.Sh STANDARDS
90The
91.Fn strcat
92and
93.Fn strncat
94functions
95conform to
96.St -ansiC .
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c
new file mode 100644
index 0000000000..374a2b7464
--- /dev/null
+++ b/src/lib/libc/string/strcat.c
@@ -0,0 +1,54 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strcat.c,v 1.4 1996/08/19 08:34:10 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44char *
45strcat(s, append)
46 register char *s;
47 register const char *append;
48{
49 char *save = s;
50
51 for (; *s; ++s);
52 while ((*s++ = *append++) != '\0');
53 return(save);
54}
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3
new file mode 100644
index 0000000000..c3bc2f8817
--- /dev/null
+++ b/src/lib/libc/string/strchr.3
@@ -0,0 +1,87 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strchr.3,v 1.3 1997/12/29 22:31:50 deraadt Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRCHR 3
40.Os
41.Sh NAME
42.Nm strchr
43.Nd locate character in string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strchr "const char *s" "int c"
48.Sh DESCRIPTION
49The
50.Fn strchr
51function locates the first occurrence of
52.Ar c
53in the string pointed to by
54.Ar s .
55The terminating
56.Dv NUL
57character is considered part of the string.
58If
59.Fa c
60is
61.Ql \e0 ,
62.Fn strchr
63locates the terminating
64.Ql \e0 .
65.Sh RETURN VALUES
66The function
67.Fn strchr
68returns a pointer to the located character, or
69.Dv NULL
70if the character does not appear in the string.
71.Sh SEE ALSO
72.Xr index 3 ,
73.Xr memchr 3 ,
74.Xr rindex 3 ,
75.Xr strcspn 3 ,
76.Xr strpbrk 3 ,
77.Xr strrchr 3 ,
78.Xr strsep 3 ,
79.Xr strspn 3 ,
80.Xr strstr 3 ,
81.Xr strtok 3
82.Sh STANDARDS
83The
84.Fn strchr
85function
86conforms to
87.St -ansiC .
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3
new file mode 100644
index 0000000000..91e51d68fc
--- /dev/null
+++ b/src/lib/libc/string/strcmp.3
@@ -0,0 +1,93 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strcmp.3,v 1.2 1996/08/19 08:34:11 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRCMP 3
40.Os
41.Sh NAME
42.Nm strcmp
43.Nd compare strings
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft int
47.Fn strcmp "const char *s1" "const char *s2"
48.Ft int
49.Fn strncmp "const char *s1" "const char *s2" "size_t len"
50.Sh DESCRIPTION
51The
52.Fn strcmp
53and
54.Fn strncmp
55functions
56lexicographically compare the null-terminated strings
57.Fa s1
58and
59.Fa s2 .
60.Sh RETURN VALUES
61The
62.Fn strcmp
63and
64.Fn strncmp
65return an integer greater than, equal to, or less than 0, according
66as the string
67.Fa s1
68is greater than, equal to, or less than the string
69.Fa s2 .
70The comparison is done using unsigned characters, so that
71.Ql \e200
72is greater than
73.Ql \e0 .
74.Pp
75The
76.Fn strncmp
77compares not more than
78.Fa len
79characters.
80.Sh SEE ALSO
81.Xr bcmp 3 ,
82.Xr memcmp 3 ,
83.Xr strcasecmp 3 ,
84.Xr strcoll 3 ,
85.Xr strxfrm 3
86.Sh STANDARDS
87The
88.Fn strcmp
89and
90.Fn strncmp
91functions
92conform to
93.St -ansiC .
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c
new file mode 100644
index 0000000000..9a5b208323
--- /dev/null
+++ b/src/lib/libc/string/strcmp.c
@@ -0,0 +1,58 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strcmp.c,v 1.3 1996/08/19 08:34:12 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#ifndef _KERNEL
42#include <string.h>
43#else
44#include <lib/libkern/libkern.h>
45#endif
46
47/*
48 * Compare strings.
49 */
50int
51strcmp(s1, s2)
52 register const char *s1, *s2;
53{
54 while (*s1 == *s2++)
55 if (*s1++ == 0)
56 return (0);
57 return (*(unsigned char *)s1 - *(unsigned char *)--s2);
58}
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3
new file mode 100644
index 0000000000..20af998885
--- /dev/null
+++ b/src/lib/libc/string/strcoll.3
@@ -0,0 +1,74 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strcoll.3,v 1.2 1996/08/19 08:34:12 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRCOLL 3
40.Os
41.Sh NAME
42.Nm strcoll
43.Nd compare strings according to current collation
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft int
47.Fn strcoll "const char *s1" "const char *s2"
48.Sh DESCRIPTION
49The
50.Fn strcoll
51function
52lexicographically compares the null-terminated strings
53.Fa s1
54and
55.Fa s2
56according to the current locale collation
57and returns an integer greater than, equal to, or less than 0,
58according as
59.Fa s1
60is greater than, equal to, or less than
61.Fa s2 .
62.Sh SEE ALSO
63.Xr bcmp 3 ,
64.Xr memcmp 3 ,
65.Xr setlocale 3 ,
66.Xr strcasecmp 3 ,
67.Xr strcmp 3 ,
68.Xr strxfrm 3
69.Sh STANDARDS
70The
71.Fn strcoll
72function
73conforms to
74.St -ansiC .
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c
new file mode 100644
index 0000000000..dca0b10d25
--- /dev/null
+++ b/src/lib/libc/string/strcoll.c
@@ -0,0 +1,52 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strcoll.c,v 1.2 1996/08/19 08:34:13 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Compare strings according to LC_COLLATE category of current locale.
45 */
46int
47strcoll(s1, s2)
48 const char *s1, *s2;
49{
50 /* LC_COLLATE is unimplemented, hence always "C" */
51 return (strcmp(s1, s2));
52}
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3
new file mode 100644
index 0000000000..33da6e619e
--- /dev/null
+++ b/src/lib/libc/string/strcpy.3
@@ -0,0 +1,121 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strcpy.3,v 1.2 1996/08/19 08:34:13 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRCPY 3
40.Os BSD 4
41.Sh NAME
42.Nm strcpy
43.Nd copy strings
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strcpy "char *dst" "const char *src"
48.Ft char *
49.Fn strncpy "char *dst" "const char *src" "size_t len"
50.Sh DESCRIPTION
51The
52.Fn strcpy
53and
54.Fn strncpy
55functions
56copy the string
57.Fa src
58to
59.Fa dst
60(including the terminating
61.Ql \e0
62character).
63.Pp
64The
65.Fn strncpy
66copies not more than
67.Fa len
68characters into
69.Fa dst ,
70appending
71.Ql \e0
72characters if
73.Fa src
74is less than
75.Fa len
76characters long, and
77.Em not
78terminating
79.Fa dst
80if
81.Fa src
82is more than
83.Fa len
84characters long.
85.Sh RETURN VALUES
86The
87.Fn strcpy
88and
89.Fn strncpy
90functions
91return
92.Fa dst .
93.Sh EXAMPLES
94The following sets
95.Dq Li chararray
96to
97.Dq Li abc\e0\e0\e0 :
98.Bd -literal -offset indent
99(void)strncpy(chararray, "abc", 6).
100.Ed
101.Pp
102The following sets
103.Dq Li chararray
104to
105.Dq Li abcdef :
106.Bd -literal -offset indent
107(void)strncpy(chararray, "abcdefgh", 6);
108.Ed
109.Sh SEE ALSO
110.Xr bcopy 3 ,
111.Xr memccpy 3 ,
112.Xr memcpy 3 ,
113.Xr memmove 3
114.Sh STANDARDS
115The
116.Fn strcpy
117and
118.Fn strncpy
119functions
120conform to
121.St -ansiC .
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c
new file mode 100644
index 0000000000..76b063fc10
--- /dev/null
+++ b/src/lib/libc/string/strcpy.c
@@ -0,0 +1,53 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strcpy.c,v 1.4 1996/08/19 08:34:14 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44char *
45strcpy(to, from)
46 register char *to;
47 register const char *from;
48{
49 char *save = to;
50
51 for (; (*to = *from) != '\0'; ++from, ++to);
52 return(save);
53}
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3
new file mode 100644
index 0000000000..93c6d8f84c
--- /dev/null
+++ b/src/lib/libc/string/strcspn.3
@@ -0,0 +1,84 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strcspn.3,v 1.2 1996/08/19 08:34:14 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRCSPN 3
40.Os
41.Sh NAME
42.Nm strcspn
43.Nd span the complement of a string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft size_t
47.Fn strcspn "const char *s" "const char *charset"
48.Sh DESCRIPTION
49The
50.Fn strcspn
51function
52spans the initial part of the null-terminated string
53.Fa s
54as long as the characters from
55.Fa s
56do not occur in string
57.Fa charset
58(it
59spans the
60.Em complement
61of
62.Fa charset ) .
63.Sh RETURN VALUES
64The
65.Fn strcspn
66function
67returns the number of characters spanned.
68.Sh SEE ALSO
69.Xr index 3 ,
70.Xr memchr 3 ,
71.Xr rindex 3 ,
72.Xr strchr 3 ,
73.Xr strpbrk 3 ,
74.Xr strrchr 3 ,
75.Xr strsep 3 ,
76.Xr strspn 3 ,
77.Xr strstr 3 ,
78.Xr strtok 3
79.Sh STANDARDS
80The
81.Fn strcspn
82function
83conforms to
84.St -ansiC .
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c
new file mode 100644
index 0000000000..f7261564a7
--- /dev/null
+++ b/src/lib/libc/string/strcspn.c
@@ -0,0 +1,67 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strcspn.c,v 1.2 1996/08/19 08:34:15 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Span the complement of string s2.
45 */
46size_t
47strcspn(s1, s2)
48 const char *s1;
49 register const char *s2;
50{
51 register const char *p, *spanp;
52 register char c, sc;
53
54 /*
55 * Stop as soon as we find any character from s2. Note that there
56 * must be a NUL in s2; it suffices to stop when we find that, too.
57 */
58 for (p = s1;;) {
59 c = *p++;
60 spanp = s2;
61 do {
62 if ((sc = *spanp++) == c)
63 return (p - 1 - s1);
64 } while (sc != 0);
65 }
66 /* NOTREACHED */
67}
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3
new file mode 100644
index 0000000000..6abbba57cb
--- /dev/null
+++ b/src/lib/libc/string/strdup.3
@@ -0,0 +1,68 @@
1.\" $OpenBSD: strdup.3,v 1.6 1998/08/19 05:51:14 pjanzen 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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
35.\"
36.Dd June 9, 1993
37.Dt STRDUP 3
38.Os
39.Sh NAME
40.Nm strdup
41.Nd save a copy of a string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft char *
45.Fn strdup "const char *str"
46.Sh DESCRIPTION
47The
48.Fn strdup
49function
50allocates sufficient memory for a copy
51of the string
52.Fa str ,
53does the copy, and returns a pointer to it.
54The pointer may subsequently be used as an
55argument to the function
56.Xr free 3 .
57.Pp
58If insufficient memory is available, NULL is returned.
59.Sh SEE ALSO
60.Xr free 3 ,
61.Xr malloc 3 ,
62.Xr strcpy 3 ,
63.Xr strlen 3
64.Sh HISTORY
65The
66.Fn strdup
67function first appeared in
68.Bx 4.4 .
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c
new file mode 100644
index 0000000000..be7f7ad094
--- /dev/null
+++ b/src/lib/libc/string/strdup.c
@@ -0,0 +1,62 @@
1/* $OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. 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#if defined(LIBC_SCCS) && !defined(lint)
37#if 0
38static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
39#else
40static char *rcsid = "$OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */
43
44#include <sys/types.h>
45
46#include <stddef.h>
47#include <stdlib.h>
48#include <string.h>
49
50char *
51strdup(str)
52 const char *str;
53{
54 size_t siz;
55 char *copy;
56
57 siz = strlen(str) + 1;
58 if ((copy = malloc(siz)) == NULL)
59 return(NULL);
60 (void)memcpy(copy, str, siz);
61 return(copy);
62}
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3
new file mode 100644
index 0000000000..487c2b0e9f
--- /dev/null
+++ b/src/lib/libc/string/strerror.3
@@ -0,0 +1,65 @@
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. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strerror.3,v 1.2 1996/08/19 08:34:16 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRERROR 3
40.Os BSD 4
41.Sh NAME
42.Nm strerror
43.Nd get error message string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strerror "int errnum"
48.Sh DESCRIPTION
49The
50.Fn strerror
51function returns a pointer to the language-dependent error message
52string affiliated with an error number.
53.Pp
54The array pointed to is not to be modified by the program, but may be
55overwritten by subsequent calls to
56.Fn strerror .
57.Sh SEE ALSO
58.Xr intro 2 ,
59.Xr perror 3 ,
60.Xr setlocale 3
61.Sh STANDARDS
62The
63.Fn strerror
64function conforms to
65.St -ansiC .
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c
new file mode 100644
index 0000000000..0e2690c3dd
--- /dev/null
+++ b/src/lib/libc/string/strerror.c
@@ -0,0 +1,55 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strerror.c,v 1.2 1996/08/19 08:34:17 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39#include <limits.h>
40
41/*
42 * Since perror() is not allowed to change the contents of strerror()'s
43 * static buffer, both functions supply their own buffers to the
44 * internal function __strerror().
45 */
46
47extern char *__strerror __P((int, char *));
48
49char *
50strerror(num)
51 int num;
52{
53 static char buf[NL_TEXTMAX];
54 return __strerror(num, buf);
55}
diff --git a/src/lib/libc/string/string.3 b/src/lib/libc/string/string.3
new file mode 100644
index 0000000000..323d4f3040
--- /dev/null
+++ b/src/lib/libc/string/string.3
@@ -0,0 +1,155 @@
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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" $OpenBSD: string.3,v 1.3 1998/09/06 22:23:18 aaron Exp $
35.\"
36.Dd April 19, 1991
37.Dt STRING 3
38.Os BSD 4
39.Sh NAME
40.Nm strcat ,
41.Nm strncat ,
42.Nm strchr ,
43.Nm strrchr ,
44.Nm strcmp ,
45.Nm strncmp ,
46.Nm strcasecmp,
47.Nm strncasecmp ,
48.Nm strcpy ,
49.Nm strncpy ,
50.Nm strerror ,
51.Nm strlen ,
52.Nm strpbrk ,
53.Nm strsep,
54.Nm strspn ,
55.Nm strcspn ,
56.Nm strstr ,
57.Nm strtok ,
58.Nm index ,
59.Nm rindex
60.Nd string specific functions
61.Sh SYNOPSIS
62.Fd #include <string.h>
63.Ft char *
64.Fn strcat "char *s" "const char * append"
65.Ft char *
66.Fn strncat "char *s" "const char *append" "size_t count"
67.Ft char *
68.Fn strchr "const char *s" "int c"
69.Ft char *
70.Fn strrchr "const char *s" "int c"
71.Ft int
72.Fn strcmp "const char *s1" "const char *s2"
73.Ft int
74.Fn strncmp "const char *s1" "const char *s2" "size_t count"
75.Ft int
76.Fn strcasecmp "const char *s1" "const char *s2"
77.Ft int
78.Fn strncasecmp "const char *s1" "const char *s2" "size_t count"
79.Ft char *
80.Fn strcpy "char *dst" "const char *src"
81.Ft char *
82.Fn strncpy "char *dst" "const char *src" "size_t count"
83.Ft char *
84.Fn strerror "int errno"
85.Ft size_t
86.Fn strlen "const char *s"
87.Ft char *
88.Fn strpbrk "const char *s" "const char *charset"
89.Ft char *
90.Fn strsep "char **stringp" "const char *delim"
91.Ft size_t
92.Fn strspn "const char *s" "const char *charset"
93.Ft size_t
94.Fn strcspn "const char *s" "const char *charset"
95.Ft char *
96.Fn strstr "const char *big" "const char *little"
97.Ft char *
98.Fn strtok "char *s" "const char *delim"
99.Ft char *
100.Fn index "const char *s" "int c"
101.Ft char *
102.Fn rindex "const char *s" "int c"
103.Sh DESCRIPTION
104The string functions
105manipulate strings terminated by a
106null byte.
107.Pp
108See the specific manual pages for more information.
109For manipulating variable length generic objects as byte
110strings (without the null byte check), see
111.Xr bstring 3 .
112.Pp
113Except as noted in their specific manual pages,
114the string functions do not test the destination
115for size limitations.
116.Sh SEE ALSO
117.Xr index 3 ,
118.Xr strcat 3 ,
119.Xr strchr 3 ,
120.Xr strrchr 3 ,
121.Xr strcmp 3 ,
122.Xr strcasecmp 3 ,
123.Xr strcpy 3 ,
124.Xr strerror 3 ,
125.Xr strlen 3 ,
126.Xr strpbrk 3 ,
127.Xr strsep 3 ,
128.Xr strspn 3 ,
129.Xr strcspn 3 ,
130.Xr strstr 3 ,
131.Xr strtok 3 ,
132.Xr rindex 3
133.Xr bstring 3
134.Sh STANDARDS
135The
136.Fn strcat ,
137.Fn strncat ,
138.Fn strchr ,
139.Fn strrchr ,
140.Fn strcmp ,
141.Fn strncmp ,
142.Fn strcpy ,
143.Fn strncpy ,
144.Fn strerror ,
145.Fn strlen ,
146.Fn strpbrk ,
147.Fn strsep ,
148.Fn strspn ,
149.Fn strcspn ,
150.Fn strstr ,
151and
152.Fn strtok
153functions
154conform to
155.St -ansiC .
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c
new file mode 100644
index 0000000000..2e8c56926e
--- /dev/null
+++ b/src/lib/libc/string/strlcat.c
@@ -0,0 +1,71 @@
1/* $OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $ */
2
3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
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. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31static char *rcsid = "$OpenBSD: strlcat.c,v 1.1 1998/07/01 01:29:45 millert Exp $";
32#endif /* LIBC_SCCS and not lint */
33
34#include <sys/types.h>
35#include <string.h>
36
37/*
38 * Appends src to string dst of size siz (unlike strncat, siz is the
39 * full size of dst, not space left). At most siz-1 characters
40 * will be copied. Always NUL terminates (unless siz == 0).
41 * Returns strlen(src); if retval >= siz, truncation occurred.
42 */
43size_t strlcat(dst, src, siz)
44 char *dst;
45 const char *src;
46 size_t siz;
47{
48 register char *d = dst;
49 register const char *s = src;
50 register size_t n = siz;
51 size_t dlen;
52
53 /* Find the end of dst and adjust bytes left */
54 while (*d != '\0' && n != 0)
55 d++;
56 dlen = d - dst;
57 n -= dlen;
58
59 if (n == 0)
60 return(dlen + strlen(s));
61 while (*s != '\0') {
62 if (n != 1) {
63 *d++ = *s;
64 n--;
65 }
66 s++;
67 }
68 *d = '\0';
69
70 return(dlen + (s - src)); /* count does not include NUL */
71}
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3
new file mode 100644
index 0000000000..5ce444d6fa
--- /dev/null
+++ b/src/lib/libc/string/strlcpy.3
@@ -0,0 +1,140 @@
1.\" $OpenBSD: strlcpy.3,v 1.2 1998/07/06 19:17:21 millert Exp $
2.\"
3.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
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. The name of the author may not be used to endorse or promote products
15.\" derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.Dd June 22, 1998
29.Dt STRLCPY 3
30.Os
31.Sh NAME
32.Nm strlcpy,
33.Nm strlcat
34.Nd size-bounded string copying and concatenation
35.Sh SYNOPSIS
36.Fd #include <string.h>
37.Ft size_t
38.Fn strlcpy "char *dst" "const char *src" "size_t size"
39.Ft size_t
40.Fn strlcat "char *dst" "const char *src" "size_t size"
41.Sh DESCRIPTION
42The
43.Fn strlcpy
44and
45.Fn strlcat
46functions copy and concatenate strings respectively. They are designed
47to be safer, more consistent, and less error prone replacements for
48.Xr strncpy 3
49and
50.Xr strncat 3 .
51Unlike those functions,
52.Fn strlcpy
53and
54.Fn strlcat
55take the full size of the buffer (not just the length) and guarantee to
56NUL-terminate the result (as long as
57.Fa size
58is larger than 0). Note that you should include a byte for the NUL in
59.Fa size .
60.Pp
61The
62.Fn strlcpy
63function copies up to
64.Fa size
65- 1 characters from the NUL-terminated string
66.Fa src
67to
68.Fa dst ,
69NUL-terminating the result.
70.Pp
71The
72.Fn strlcat
73function appends the NUL-terminated string
74.Fa src
75to the end of
76.Fa dst .
77It will append at most
78.Fa size
79- strlen(dst) - 1 bytes, NUL-terminating the result.
80.Sh RETURN VALUES
81The
82.Fn strlcpy
83and
84.Fn strlcat
85functions return the total length of the string they tried to
86create. For
87.Fn strlcpy
88that means the length of
89.Fa src .
90For
91.Fn strlcat
92that means the initial length of
93.Fa dst
94plus
95the length of
96.Fa src .
97While this may seem somewhat confusing it was done to make
98truncation detection simple.
99.Sh EXAMPLES
100The following code fragment illustrates the simple case:
101.Bd -literal -offset indent
102char *s, *p, buf[BUFSIZ];
103
104.Li ...
105
106(void)strlcpy(buf, s, sizeof(buf));
107(void)strlcat(buf, p, sizeof(buf));
108.Ed
109.Pp
110To detect truncation, perhaps while building a pathname, something
111like the following might be used:
112.Bd -literal -offset indent
113char *dir, *file, pname[MAXPATHNAMELEN];
114
115.Li ...
116
117if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
118 goto toolong;
119if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
120 goto toolong;
121.Ed
122.Pp
123Since we know how many characters we copied the first time, we can
124speed things up a bit by using a copy instead on an append:
125.Bd -literal -offset indent
126char *dir, *file, pname[MAXPATHNAMELEN];
127size_t n;
128
129.Li ...
130
131n = strlcpy(pname, dir, sizeof(pname));
132if (n >= sizeof(pname))
133 goto toolong;
134if (strlcpy(pname + n, file, sizeof(pname)) >= sizeof(pname) - n)
135 goto toolong;
136.Ed
137.Sh SEE ALSO
138.Xr snprintf 3 ,
139.Xr strncpy 3 ,
140.Xr strncat 3
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c
new file mode 100644
index 0000000000..1a60445599
--- /dev/null
+++ b/src/lib/libc/string/strlcpy.c
@@ -0,0 +1,63 @@
1/* $OpenBSD: strlcpy.c,v 1.1 1998/07/01 01:29:45 millert Exp $ */
2
3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
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. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31static char *rcsid = "$OpenBSD: strlcpy.c,v 1.1 1998/07/01 01:29:45 millert Exp $";
32#endif /* LIBC_SCCS and not lint */
33
34#include <sys/types.h>
35#include <string.h>
36
37/*
38 * Copy src to string dst of size siz. At most siz-1 characters
39 * will be copied. Always NUL terminates (unless siz == 0).
40 * Returns strlen(src); if retval >= siz, truncation occurred.
41 */
42size_t strlcpy(dst, src, siz)
43 char *dst;
44 char *src;
45 size_t siz;
46{
47 register char *d = dst;
48 register const char *s = src;
49 register size_t n = siz;
50
51 if (n == 0)
52 return(strlen(s));
53 while (*s != '\0') {
54 if (n != 1) {
55 *d++ = *s;
56 n--;
57 }
58 s++;
59 }
60 *d = '\0';
61
62 return(s - src); /* count does not include NUL */
63}
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3
new file mode 100644
index 0000000000..99e7dd19c3
--- /dev/null
+++ b/src/lib/libc/string/strlen.3
@@ -0,0 +1,70 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strlen.3,v 1.2 1996/08/19 08:34:19 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRLEN 3
40.Os
41.Sh NAME
42.Nm strlen
43.Nd find length of string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft size_t
47.Fn strlen "const char *s"
48.Sh DESCRIPTION
49The
50.Fn strlen
51function
52computes the length of the string
53.Fa s .
54.Sh RETURN VALUES
55The
56.Fn strlen
57function
58returns
59the number of characters that precede the
60terminating
61.Dv NUL
62character.
63.Sh SEE ALSO
64.Xr string 3
65.Sh STANDARDS
66The
67.Fn strlen
68function
69conforms to
70.St -ansiC .
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c
new file mode 100644
index 0000000000..332d5766f9
--- /dev/null
+++ b/src/lib/libc/string/strlen.c
@@ -0,0 +1,53 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strlen.c,v 1.3 1996/08/19 08:34:19 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44size_t
45strlen(str)
46 const char *str;
47{
48 register const char *s;
49
50 for (s = str; *s; ++s);
51 return(s - str);
52}
53
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3
new file mode 100644
index 0000000000..3db953704d
--- /dev/null
+++ b/src/lib/libc/string/strmode.3
@@ -0,0 +1,152 @@
1.\" $OpenBSD: strmode.3,v 1.6 1998/06/15 17:55:13 mickey 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. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. 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.\" @(#)strmode.3 8.3 (Berkeley) 7/28/94
35.\"
36.Dd July 28, 1994
37.Dt STRMODE 3
38.Os
39.Sh NAME
40.Nm strmode
41.Nd convert inode status information into a symbolic string
42.Sh SYNOPSIS
43.Fd #include <string.h>
44.Ft void
45.Fn strmode "mode_t mode" "char *bp"
46.Sh DESCRIPTION
47The
48.Fn strmode
49function
50converts a file
51.Fa mode
52(the type and permission information associated with an inode, see
53.Xr stat 2 )
54into a symbolic string which is stored in the location referenced by
55.Fa bp .
56This stored string is eleven characters in length plus a trailing
57.Dv NUL .
58.Pp
59The first character is the inode type, and will be one of the following:
60.Pp
61.Bl -tag -width flag -offset indent -compact
62.It \-
63regular file
64.It b
65block special
66.It c
67character special
68.It d
69directory
70.It l
71symbolic link
72.It p
73fifo
74.It s
75socket
76.It w
77whiteout
78.It ?
79unknown inode type
80.El
81.Pp
82The next nine characters encode three sets of permissions, in three
83characters each.
84The first three characters are the permissions for the owner of the
85file, the second three for the group the file belongs to, and the
86third for the ``other'', or default, set of users.
87.Pp
88Permission checking is done as specifically as possible.
89If read permission is denied to the owner of a file in the first set
90of permissions, the owner of the file will not be able to read the file.
91This is true even if the owner is in the file's group and the group
92permissions allow reading or the ``other'' permissions allow reading.
93.Pp
94If the first character of the three character set is an ``r'', the file is
95readable for that set of users; if a dash ``\-'', it is not readable.
96.Pp
97If the second character of the three character set is a ``w'', the file is
98writable for that set of users; if a dash ``\-'', it is not writable.
99.Pp
100The third character is the first of the following characters that apply:
101.Bl -tag -width xxxx
102.It S
103If the character is part of the owner permissions and the file is not
104executable or the directory is not searchable by the owner, and the
105set-user-id bit is set.
106.It S
107If the character is part of the group permissions and the file is not
108executable or the directory is not searchable by the group, and the
109set-group-id bit is set.
110.It T
111If the character is part of the other permissions and the file is not
112executable or the directory is not searchable by others, and the ``sticky''
113.Pq Dv S_ISVTX
114bit is set.
115.It s
116If the character is part of the owner permissions and the file is
117executable or the directory searchable by the owner, and the set-user-id
118bit is set.
119.It s
120If the character is part of the group permissions and the file is
121executable or the directory searchable by the group, and the set-group-id
122bit is set.
123.It t
124If the character is part of the other permissions and the file is
125executable or the directory searchable by others, and the ``sticky''
126.Pq Dv S_ISVTX
127bit is set.
128.It x
129The file is executable or the directory is searchable.
130.It \-
131None of the above apply.
132.El
133.Pp
134The last character is a plus sign ``+'' if there are any alternate
135or additional access control methods associated with the inode, otherwise
136it will be a space.
137.Sh RETURN VALUES
138The
139.Fn strmode
140function
141always returns 0.
142.Sh SEE ALSO
143.Xr chmod 1 ,
144.Xr find 1 ,
145.Xr stat 2 ,
146.Xr getmode 3 ,
147.Xr setmode 3
148.Sh HISTORY
149The
150.Fn strmode
151function first appeared in
152.Bx 4.4 .
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c
new file mode 100644
index 0000000000..5e7f15e857
--- /dev/null
+++ b/src/lib/libc/string/strmode.c
@@ -0,0 +1,152 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <string.h>
41
42void
43strmode(mode, p)
44 register mode_t mode;
45 register char *p;
46{
47 /* print type */
48 switch (mode & S_IFMT) {
49 case S_IFDIR: /* directory */
50 *p++ = 'd';
51 break;
52 case S_IFCHR: /* character special */
53 *p++ = 'c';
54 break;
55 case S_IFBLK: /* block special */
56 *p++ = 'b';
57 break;
58 case S_IFREG: /* regular */
59 *p++ = '-';
60 break;
61 case S_IFLNK: /* symbolic link */
62 *p++ = 'l';
63 break;
64 case S_IFSOCK: /* socket */
65 *p++ = 's';
66 break;
67#ifdef S_IFIFO
68 case S_IFIFO: /* fifo */
69 *p++ = 'p';
70 break;
71#endif
72#ifdef S_IFWHT
73 case S_IFWHT: /* whiteout */
74 *p++ = 'w';
75 break;
76#endif
77 default: /* unknown */
78 *p++ = '?';
79 break;
80 }
81 /* usr */
82 if (mode & S_IRUSR)
83 *p++ = 'r';
84 else
85 *p++ = '-';
86 if (mode & S_IWUSR)
87 *p++ = 'w';
88 else
89 *p++ = '-';
90 switch (mode & (S_IXUSR | S_ISUID)) {
91 case 0:
92 *p++ = '-';
93 break;
94 case S_IXUSR:
95 *p++ = 'x';
96 break;
97 case S_ISUID:
98 *p++ = 'S';
99 break;
100 case S_IXUSR | S_ISUID:
101 *p++ = 's';
102 break;
103 }
104 /* group */
105 if (mode & S_IRGRP)
106 *p++ = 'r';
107 else
108 *p++ = '-';
109 if (mode & S_IWGRP)
110 *p++ = 'w';
111 else
112 *p++ = '-';
113 switch (mode & (S_IXGRP | S_ISGID)) {
114 case 0:
115 *p++ = '-';
116 break;
117 case S_IXGRP:
118 *p++ = 'x';
119 break;
120 case S_ISGID:
121 *p++ = 'S';
122 break;
123 case S_IXGRP | S_ISGID:
124 *p++ = 's';
125 break;
126 }
127 /* other */
128 if (mode & S_IROTH)
129 *p++ = 'r';
130 else
131 *p++ = '-';
132 if (mode & S_IWOTH)
133 *p++ = 'w';
134 else
135 *p++ = '-';
136 switch (mode & (S_IXOTH | S_ISVTX)) {
137 case 0:
138 *p++ = '-';
139 break;
140 case S_IXOTH:
141 *p++ = 'x';
142 break;
143 case S_ISVTX:
144 *p++ = 'T';
145 break;
146 case S_IXOTH | S_ISVTX:
147 *p++ = 't';
148 break;
149 }
150 *p++ = ' '; /* will be a '+' if ACL's implemented */
151 *p = '\0';
152}
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c
new file mode 100644
index 0000000000..27ae2ba324
--- /dev/null
+++ b/src/lib/libc/string/strncat.c
@@ -0,0 +1,67 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strncat.c,v 1.2 1996/08/19 08:34:21 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes
45 * are written at dst (at most n+1 bytes being appended). Return dst.
46 */
47char *
48strncat(dst, src, n)
49 char *dst;
50 const char *src;
51 register size_t n;
52{
53 if (n != 0) {
54 register char *d = dst;
55 register const char *s = src;
56
57 while (*d != 0)
58 d++;
59 do {
60 if ((*d = *s++) == 0)
61 break;
62 d++;
63 } while (--n != 0);
64 *d = 0;
65 }
66 return (dst);
67}
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c
new file mode 100644
index 0000000000..0224957f8b
--- /dev/null
+++ b/src/lib/libc/string/strncmp.c
@@ -0,0 +1,59 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strncmp.c,v 1.3 1996/08/19 08:34:21 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#ifndef _KERNEL
39#include <string.h>
40#else
41#include <lib/libkern/libkern.h>
42#endif
43
44int
45strncmp(s1, s2, n)
46 register const char *s1, *s2;
47 register size_t n;
48{
49
50 if (n == 0)
51 return (0);
52 do {
53 if (*s1 != *s2++)
54 return (*(unsigned char *)s1 - *(unsigned char *)--s2);
55 if (*s1++ == 0)
56 break;
57 } while (--n != 0);
58 return (0);
59}
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c
new file mode 100644
index 0000000000..01bc8a872e
--- /dev/null
+++ b/src/lib/libc/string/strncpy.c
@@ -0,0 +1,67 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strncpy.c,v 1.2 1996/08/19 08:34:22 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Copy src to dst, truncating or null-padding to always copy n bytes.
45 * Return dst.
46 */
47char *
48strncpy(dst, src, n)
49 char *dst;
50 const char *src;
51 register size_t n;
52{
53 if (n != 0) {
54 register char *d = dst;
55 register const char *s = src;
56
57 do {
58 if ((*d++ = *s++) == 0) {
59 /* NUL pad the remaining n-1 bytes */
60 while (--n != 0)
61 *d++ = 0;
62 break;
63 }
64 } while (--n != 0);
65 }
66 return (dst);
67}
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3
new file mode 100644
index 0000000000..5876f560a9
--- /dev/null
+++ b/src/lib/libc/string/strpbrk.3
@@ -0,0 +1,79 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strpbrk.3,v 1.2 1996/08/19 08:34:22 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRPBRK 3
40.Os
41.Sh NAME
42.Nm strpbrk
43.Nd locate multiple characters in string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strpbrk "const char *s" "const char *charset"
48.Sh DESCRIPTION
49The
50.Fn strpbrk
51function
52locates in the null-terminated string
53.Fa s
54the first occurrence of any character in the string
55.Fa charset
56and returns a pointer to this character.
57If no characters from
58.Fa charset
59occur anywhere in
60.Fa s
61.Fn strpbrk
62returns NULL.
63.Sh SEE ALSO
64.Xr index 3 ,
65.Xr memchr 3 ,
66.Xr rindex 3 ,
67.Xr strchr 3 ,
68.Xr strcspn 3 ,
69.Xr strrchr 3 ,
70.Xr strsep 3 ,
71.Xr strspn 3 ,
72.Xr strstr 3 ,
73.Xr strtok 3
74.Sh STANDARDS
75The
76.Fn strpbrk
77function
78conforms to
79.St -ansiC .
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c
new file mode 100644
index 0000000000..748a3a8c94
--- /dev/null
+++ b/src/lib/libc/string/strpbrk.c
@@ -0,0 +1,56 @@
1/*
2 * Copyright (c) 1985 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strpbrk.c,v 1.2 1996/08/19 08:34:23 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39
40/*
41 * Find the first occurrence in s1 of a character in s2 (excluding NUL).
42 */
43char *
44strpbrk(s1, s2)
45 register const char *s1, *s2;
46{
47 register const char *scanp;
48 register int c, sc;
49
50 while ((c = *s1++) != 0) {
51 for (scanp = s2; (sc = *scanp++) != 0;)
52 if (sc == c)
53 return ((char *)(s1 - 1));
54 }
55 return (NULL);
56}
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3
new file mode 100644
index 0000000000..6dd00d32fb
--- /dev/null
+++ b/src/lib/libc/string/strrchr.3
@@ -0,0 +1,90 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strrchr.3,v 1.2 1996/08/19 08:34:23 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRRCHR 3
40.Os
41.Sh NAME
42.Nm strrchr
43.Nd locate character in string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strrchr "const char *s" "int c"
48.Sh DESCRIPTION
49The
50.Fn strrchr
51function
52locates the last occurrence of
53.Fa c
54(converted to a char)
55in the string
56.Fa s .
57If
58.Fa c
59is
60.Ql \e0 ,
61.Fn strrchr
62locates the terminating
63.Ql \e0 .
64.Sh RETURN VALUES
65The
66.Fn strrchr
67function
68returns a pointer to the character,
69or a null
70pointer if
71.Fa c
72does not occur anywhere in
73.Fa s .
74.Sh SEE ALSO
75.Xr index 3 ,
76.Xr memchr 3 ,
77.Xr rindex 3 ,
78.Xr strchr 3 ,
79.Xr strcspn 3 ,
80.Xr strpbrk 3 ,
81.Xr strsep 3 ,
82.Xr strspn 3 ,
83.Xr strstr 3 ,
84.Xr strtok 3
85.Sh STANDARDS
86The
87.Fn strrchr
88function
89conforms to
90.St -ansiC .
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3
new file mode 100644
index 0000000000..5af262a074
--- /dev/null
+++ b/src/lib/libc/string/strsep.3
@@ -0,0 +1,110 @@
1.\" $OpenBSD: strsep.3,v 1.4 1998/06/15 17:55:14 mickey 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. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93
38.\"
39.Dd June 9, 1993
40.Dt STRSEP 3
41.Os
42.Sh NAME
43.Nm strsep
44.Nd separate strings
45.Sh SYNOPSIS
46.Fd #include <string.h>
47.Ft char *
48.Fn strsep "char **stringp" "char *delim"
49.Sh DESCRIPTION
50The
51.Fn strsep
52function locates, in the string referenced by
53.Fa *stringp ,
54the first occurrence of any character in the string
55.Fa delim
56(or the terminating
57.Ql \e0
58character) and replaces it with a
59.Ql \e0 .
60The location of the next character after the delimiter character
61(or NULL, if the end of the string was reached) is stored in
62.Fa *stringp .
63The original value of
64.Fa *stringp
65is returned.
66.Pp
67An ``empty'' field, i.e. one caused by two adjacent delimiter characters,
68can be detected by comparing the location referenced by the pointer returned
69in
70.Fa *stringp
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 white space, into an
85argument vector:
86.Bd -literal -offset indent
87char **ap, *argv[10], *inputstring;
88
89for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;)
90 if (**ap != '\e0')
91 ++ap;
92.Ed
93.Sh HISTORY
94The
95.Fn strsep
96function
97is intended as a replacement for the
98.Fn strtok
99function.
100While the
101.Fn strtok
102function should be preferred for portability reasons (it conforms to
103.St -ansiC )
104it is unable to handle empty fields, i.e. detect fields delimited by
105two adjacent delimiter characters, or to be used for more than a single
106string at a time.
107The
108.Fn strsep
109function first appeared in
110.Bx 4.4 .
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c
new file mode 100644
index 0000000000..b69b715fc5
--- /dev/null
+++ b/src/lib/libc/string/strsep.c
@@ -0,0 +1,85 @@
1/* $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. 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 <string.h>
37#include <stdio.h>
38
39#if defined(LIBC_SCCS) && !defined(lint)
40#if 0
41static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
42#else
43static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $";
44#endif
45#endif /* LIBC_SCCS and not lint */
46
47/*
48 * Get next token from string *stringp, where tokens are possibly-empty
49 * strings separated by characters from delim.
50 *
51 * Writes NULs into the string at *stringp to end tokens.
52 * delim need not remain constant from call to call.
53 * On return, *stringp points past the last NUL written (if there might
54 * be further tokens), or is NULL (if there are definitely no more tokens).
55 *
56 * If *stringp is NULL, strsep returns NULL.
57 */
58char *
59strsep(stringp, delim)
60 register char **stringp;
61 register const char *delim;
62{
63 register char *s;
64 register const char *spanp;
65 register int c, sc;
66 char *tok;
67
68 if ((s = *stringp) == NULL)
69 return (NULL);
70 for (tok = s;;) {
71 c = *s++;
72 spanp = delim;
73 do {
74 if ((sc = *spanp++) == c) {
75 if (c == 0)
76 s = NULL;
77 else
78 s[-1] = 0;
79 *stringp = s;
80 return (tok);
81 }
82 } while (sc != 0);
83 }
84 /* NOTREACHED */
85}
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3
new file mode 100644
index 0000000000..42e433c259
--- /dev/null
+++ b/src/lib/libc/string/strsignal.3
@@ -0,0 +1,60 @@
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. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strsignal.3,v 1.2 1996/08/19 08:34:25 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRSIGNAL 3
40.Os BSD 4
41.Sh NAME
42.Nm strsignal
43.Nd get signal description string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strsignal "int sig"
48.Sh DESCRIPTION
49The
50.Fn strsignal
51function returns a pointer to the language-dependent string describing
52a signal.
53.Pp
54The array pointed to is not to be modified by the program, but may be
55overwritten by subsequent calls to
56.Fn strsignal .
57.Sh SEE ALSO
58.Xr intro 2 ,
59.Xr psignal 3 ,
60.Xr setlocale 3
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c
new file mode 100644
index 0000000000..cf03af5963
--- /dev/null
+++ b/src/lib/libc/string/strsignal.c
@@ -0,0 +1,49 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strsignal.c,v 1.2 1996/08/19 08:34:25 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39#include <limits.h>
40
41extern char *__strsignal __P((int, char *));
42
43char *
44strsignal(sig)
45 int sig;
46{
47 static char buf[NL_TEXTMAX];
48 return __strsignal(sig, buf);
49}
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3
new file mode 100644
index 0000000000..7d15470dee
--- /dev/null
+++ b/src/lib/libc/string/strspn.3
@@ -0,0 +1,79 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strspn.3,v 1.3 1996/08/19 08:34:25 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRSPN 3
40.Os
41.Sh NAME
42.Nm strspn
43.Nd span a string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft size_t
47.Fn strspn "const char *s" "const char *charset"
48.Sh DESCRIPTION
49The
50.Fn strspn
51function
52spans the initial part of the null-terminated string
53.Fa s
54as long as the characters from
55.Fa s
56occur in string
57.Fa charset .
58.Sh RETURN VALUES
59The
60.Fn strspn
61function
62returns the number of characters spanned.
63.Sh SEE ALSO
64.Xr index 3 ,
65.Xr memchr 3 ,
66.Xr rindex 3 ,
67.Xr strchr 3 ,
68.Xr strcspn 3 ,
69.Xr strpbrk 3 ,
70.Xr strrchr 3 ,
71.Xr strsep 3 ,
72.Xr strstr 3 ,
73.Xr strtok 3
74.Sh STANDARDS
75The
76.Fn strspn
77function
78conforms to
79.St -ansiC .
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c
new file mode 100644
index 0000000000..41940f9190
--- /dev/null
+++ b/src/lib/libc/string/strspn.c
@@ -0,0 +1,60 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strspn.c,v 1.2 1996/08/19 08:34:26 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39
40/*
41 * Span the string s2 (skip characters that are in s2).
42 */
43size_t
44strspn(s1, s2)
45 const char *s1;
46 register const char *s2;
47{
48 register const char *p = s1, *spanp;
49 register char c, sc;
50
51 /*
52 * Skip any characters in s2, excluding the terminating \0.
53 */
54cont:
55 c = *p++;
56 for (spanp = s2; (sc = *spanp++) != 0;)
57 if (sc == c)
58 goto cont;
59 return (p - 1 - s1);
60}
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3
new file mode 100644
index 0000000000..fa455b426a
--- /dev/null
+++ b/src/lib/libc/string/strstr.3
@@ -0,0 +1,88 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strstr.3,v 1.2 1996/08/19 08:34:26 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRSTR 3
40.Os
41.Sh NAME
42.Nm strstr
43.Nd locate a substring in a string
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft char *
47.Fn strstr "const char *big" "const char *little"
48.Sh DESCRIPTION
49The
50.Fn strstr
51function
52locates the first occurrence of the null-terminated string
53.Fa little
54in the null-terminated string
55.Fa big .
56If
57.Fa little
58is the empty string,
59.Fn strstr
60returns
61.Fa big ;
62if
63.Fa little
64occurs nowhere in
65.Fa big ,
66.Fn strstr
67returns NULL;
68otherwise
69.Fn strstr
70returns a pointer to the first character of the first occurrence of
71.Fa little .
72.Sh SEE ALSO
73.Xr index 3 ,
74.Xr memchr 3 ,
75.Xr rindex 3 ,
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 strtok 3
83.Sh STANDARDS
84The
85.Fn strstr
86function
87conforms to
88.St -ansiC .
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c
new file mode 100644
index 0000000000..763c7e29d7
--- /dev/null
+++ b/src/lib/libc/string/strstr.c
@@ -0,0 +1,64 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strstr.c,v 1.2 1996/08/19 08:34:27 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Find the first occurrence of find in s.
45 */
46char *
47strstr(s, find)
48 register const char *s, *find;
49{
50 register char c, sc;
51 register size_t len;
52
53 if ((c = *find++) != 0) {
54 len = strlen(find);
55 do {
56 do {
57 if ((sc = *s++) == 0)
58 return (NULL);
59 } while (sc != c);
60 } while (strncmp(s, find, len) != 0);
61 s--;
62 }
63 return ((char *)s);
64}
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3
new file mode 100644
index 0000000000..876e0eb515
--- /dev/null
+++ b/src/lib/libc/string/strtok.3
@@ -0,0 +1,112 @@
1.\" Copyright (c) 1988, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strtok.3,v 1.3 1998/04/28 07:36:55 deraadt Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRTOK 3
40.Os BSD 3
41.Sh NAME
42.Nm strtok ,
43.Nm strsep
44.Nd string token operations
45.Sh SYNOPSIS
46.Fd #include <string.h>
47.Ft char *
48.Fn strtok "char *str" "const char *sep"
49.Sh DESCRIPTION
50.Bf -symbolic
51This interface is obsoleted by
52.Xr strsep 3 .
53.Ef
54.Pp
55The
56.Fn strtok
57function
58is used to isolate sequential tokens in a null-terminated string,
59.Fa str .
60These tokens are separated in the string by at least one of the
61characters in
62.Fa sep .
63The first time that
64.Fn strtok
65is called,
66.Fa str
67should be specified; subsequent calls, wishing to obtain further tokens
68from the same string, should pass a null pointer instead.
69The separator string,
70.Fa sep ,
71must be supplied each time, and may change between calls.
72.Pp
73The
74.Fn strtok
75function
76returns a pointer to the beginning of each subsequent token in the string,
77after replacing the separator character itself with a
78.Dv NUL
79character.
80When no more tokens remain, a null pointer is returned.
81.Sh SEE ALSO
82.Xr index 3 ,
83.Xr memchr 3 ,
84.Xr rindex 3 ,
85.Xr strchr 3 ,
86.Xr strcspn 3 ,
87.Xr strpbrk 3 ,
88.Xr strrchr 3 ,
89.Xr strsep 3 ,
90.Xr strspn 3 ,
91.Xr strstr 3
92.Sh STANDARDS
93The
94.Fn strtok
95function
96conforms to
97.St -ansiC .
98.Sh BUGS
99There is no way to get tokens from multiple strings simultaneously.
100.Pp
101The System V
102.Fn strtok ,
103if handed a string containing only delimiter characters,
104will not alter the next starting point, so that a call to
105.Fn strtok
106with a different (or empty) delimiter string
107may return a
108.Pf non- Dv NULL
109value.
110Since this implementation always alters the next starting point,
111such a sequence of calls would always return
112.Dv NULL .
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c
new file mode 100644
index 0000000000..2fce04c3ad
--- /dev/null
+++ b/src/lib/libc/string/strtok.c
@@ -0,0 +1,89 @@
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strtok.c,v 1.2 1996/08/19 08:34:28 tholo Exp $";
36#endif /* LIBC_SCCS and not lint */
37
38#include <string.h>
39
40char *
41strtok(s, delim)
42 register char *s;
43 register const char *delim;
44{
45 register char *spanp;
46 register int c, sc;
47 char *tok;
48 static char *last;
49
50
51 if (s == NULL && (s = last) == NULL)
52 return (NULL);
53
54 /*
55 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
56 */
57cont:
58 c = *s++;
59 for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
60 if (c == sc)
61 goto cont;
62 }
63
64 if (c == 0) { /* no non-delimiter characters */
65 last = NULL;
66 return (NULL);
67 }
68 tok = s - 1;
69
70 /*
71 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
72 * Note that delim must have one NUL; we stop if we see that, too.
73 */
74 for (;;) {
75 c = *s++;
76 spanp = (char *)delim;
77 do {
78 if ((sc = *spanp++) == c) {
79 if (c == 0)
80 s = NULL;
81 else
82 s[-1] = 0;
83 last = s;
84 return (tok);
85 }
86 } while (sc != 0);
87 }
88 /* NOTREACHED */
89}
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3
new file mode 100644
index 0000000000..3ebdd42c29
--- /dev/null
+++ b/src/lib/libc/string/strxfrm.3
@@ -0,0 +1,68 @@
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\" $OpenBSD: strxfrm.3,v 1.2 1996/08/19 08:34:28 tholo Exp $
37.\"
38.Dd June 29, 1991
39.Dt STRXFRM 3
40.Os
41.Sh NAME
42.Nm strxfrm
43.Nd transform a string under locale
44.Sh SYNOPSIS
45.Fd #include <string.h>
46.Ft size_t
47.Fn strxfrm "char *dst" "const char *src" "size_t n"
48.Sh DESCRIPTION
49The
50.Fn strxfrm
51function
52does something horrible (see
53.Tn ANSI
54standard).
55In this implementation it just copies.
56.Sh SEE ALSO
57.Xr bcmp 3 ,
58.Xr memcmp 3 ,
59.\" .Xr setlocale 3 ,
60.Xr strcasecmp 3 ,
61.Xr strcmp 3 ,
62.Xr strcoll 3
63.Sh STANDARDS
64The
65.Fn strxfrm
66function
67conforms to
68.St -ansiC .
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c
new file mode 100644
index 0000000000..6b258edecc
--- /dev/null
+++ b/src/lib/libc/string/strxfrm.c
@@ -0,0 +1,73 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strxfrm.c,v 1.2 1996/08/19 08:34:29 tholo Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <string.h>
42
43/*
44 * Transform src, storing the result in dst, such that
45 * strcmp() on transformed strings returns what strcoll()
46 * on the original untransformed strings would return.
47 */
48size_t
49strxfrm(dst, src, n)
50 register char *dst;
51 register const char *src;
52 register size_t n;
53{
54 register size_t r = 0;
55 register int c;
56
57 /*
58 * Since locales are unimplemented, this is just a copy.
59 */
60 if (n != 0) {
61 while ((c = *src++) != 0) {
62 r++;
63 if (--n == 0) {
64 while (*src++ != 0)
65 r++;
66 break;
67 }
68 *dst++ = c;
69 }
70 *dst = 0;
71 }
72 return (r);
73}
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3
new file mode 100644
index 0000000000..d1bfc358fb
--- /dev/null
+++ b/src/lib/libc/string/swab.3
@@ -0,0 +1,65 @@
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. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. 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: swab.3,v 1.3 1998/02/10 02:19:48 deraadt Exp $
33.\"
34.Dd May 1, 1991
35.Dt SWAB 3
36.Os
37.Sh NAME
38.Nm swab
39.Nd swap adjacent bytes
40.Sh SYNOPSIS
41.Fd #include <unistd.h>
42.Ft void
43.Fn swab "const void *src" "void *dst" "size_t len"
44.Sh DESCRIPTION
45The function
46.Fn swab
47copies
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
55The argument
56.Fa len
57must be even number.
58.Sh SEE ALSO
59.Xr bzero 3 ,
60.Xr memset 3
61.Sh HISTORY
62A
63.Fn swab
64function appeared in
65.At v7 .
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c
new file mode 100644
index 0000000000..311cf13a53
--- /dev/null
+++ b/src/lib/libc/string/swab.c
@@ -0,0 +1,65 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Jeffrey Mogul.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: swab.c,v 1.3 1998/02/10 02:19:48 deraadt Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <unistd.h>
42
43void
44swab(from, to, len)
45 const void *from;
46 void *to;
47 size_t len;
48{
49 register unsigned long temp;
50 register int n;
51 register char *fp, *tp;
52
53 n = (len >> 1) + 1;
54 fp = (char *)from;
55 tp = (char *)to;
56#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp
57 /* round to multiple of 8 */
58 while ((--n) & 07)
59 STEP;
60 n >>= 3;
61 while (--n >= 0) {
62 STEP; STEP; STEP; STEP;
63 STEP; STEP; STEP; STEP;
64 }
65}