diff options
Diffstat (limited to 'src/lib/libc/string')
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 | |||
6 | SRCS+= 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) | ||
23 | OBJS+= memmove.o | ||
24 | memmove.o: bcopy.c | ||
25 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
26 | @${LD} -x -r ${.TARGET} | ||
27 | @mv a.out ${.TARGET} | ||
28 | |||
29 | memmove.po: bcopy.c | ||
30 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
31 | @${LD} -X -r ${.TARGET} | ||
32 | @mv a.out ${.TARGET} | ||
33 | |||
34 | memmove.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) | ||
44 | OBJS+= memcpy.o | ||
45 | memcpy.o: bcopy.c | ||
46 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
47 | @${LD} -x -r ${.TARGET} | ||
48 | @mv a.out ${.TARGET} | ||
49 | |||
50 | memcpy.po: bcopy.c | ||
51 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
52 | @${LD} -X -r ${.TARGET} | ||
53 | @mv a.out ${.TARGET} | ||
54 | |||
55 | memcpy.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) | ||
63 | OBJS+= strchr.o | ||
64 | strchr.o: index.c | ||
65 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
66 | @${LD} -x -r ${.TARGET} | ||
67 | @mv a.out ${.TARGET} | ||
68 | |||
69 | strchr.po: index.c | ||
70 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
71 | @${LD} -X -r ${.TARGET} | ||
72 | @mv a.out ${.TARGET} | ||
73 | |||
74 | strchr.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) | ||
81 | OBJS+= strrchr.o | ||
82 | strrchr.o: rindex.c | ||
83 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
84 | @${LD} -x -r ${.TARGET} | ||
85 | @mv a.out ${.TARGET} | ||
86 | |||
87 | strrchr.po: rindex.c | ||
88 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
89 | @${LD} -X -r ${.TARGET} | ||
90 | @mv a.out ${.TARGET} | ||
91 | |||
92 | strrchr.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 | ||
99 | LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln | ||
100 | |||
101 | memmove.ln: bcopy.c | ||
102 | lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
103 | ${.CURDIR}/string/bcopy.c | ||
104 | |||
105 | memcpy.ln: bcopy.c | ||
106 | lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
107 | ${.CURDIR}/string/bcopy.c | ||
108 | |||
109 | strchr.ln: index.c | ||
110 | lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
111 | ${.CURDIR}/string/index.c | ||
112 | |||
113 | strrchr.ln: rindex.c | ||
114 | lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
115 | ${.CURDIR}/string/rindex.c | ||
116 | |||
117 | MAN+= 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 | |||
123 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | ||
124 | MLINKS+=strcasecmp.3 strncasecmp.3 | ||
125 | MLINKS+=strcat.3 strncat.3 | ||
126 | MLINKS+=strcmp.3 strncmp.3 | ||
127 | MLINKS+=strcpy.3 strncpy.3 | ||
128 | MLINKS+=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) | ||
35 | static 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 | |||
53 | static 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 | |||
74 | char * | ||
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) | ||
35 | static 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 | |||
52 | static 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 | |||
67 | char * | ||
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 | ||
47 | The | ||
48 | .Fn bcmp | ||
49 | function | ||
50 | compares byte string | ||
51 | .Fa b1 | ||
52 | against byte string | ||
53 | .Fa b2 , | ||
54 | returning zero if they are identical, non-zero otherwise. | ||
55 | Both strings are assumed to be | ||
56 | .Fa len | ||
57 | bytes long. | ||
58 | Zero-length strings are always identical. | ||
59 | .Pp | ||
60 | The 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 | ||
68 | A | ||
69 | .Fn bcmp | ||
70 | function 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) | ||
35 | static 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 | */ | ||
47 | int | ||
48 | bcmp(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 | ||
48 | The | ||
49 | .Fn bcopy | ||
50 | function | ||
51 | copies | ||
52 | .Fa len | ||
53 | bytes from string | ||
54 | .Fa src | ||
55 | to string | ||
56 | .Fa dst . | ||
57 | The two strings may overlap. | ||
58 | If | ||
59 | .Fa len | ||
60 | is 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 | ||
68 | A | ||
69 | .Fn bcopy | ||
70 | function 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) | ||
38 | static 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 | */ | ||
47 | typedef 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 | ||
58 | void * | ||
59 | memcpy(dst0, src0, length) | ||
60 | #else | ||
61 | #ifdef MEMMOVE | ||
62 | void * | ||
63 | memmove(dst0, src0, length) | ||
64 | #else | ||
65 | void | ||
66 | bcopy(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 | } | ||
132 | done: | ||
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 | ||
39 | bm_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 | ||
46 | bm_pat * | ||
47 | .br | ||
48 | bm_comp(u_char *pattern, size_t patlen, u_char freq[256]); | ||
49 | .sp | ||
50 | u_char * | ||
51 | .br | ||
52 | bm_exec(bm_pat *pdesc, u_char *text, size_t len); | ||
53 | .sp | ||
54 | void | ||
55 | .br | ||
56 | bm_free(bm_pat *pdesc); | ||
57 | .SH DESCRIPTION | ||
58 | These routines implement an efficient mechanism to find an | ||
59 | occurrence of a byte string within another byte string. | ||
60 | .PP | ||
61 | .I Bm_comp | ||
62 | evaluates the | ||
63 | .I patlen | ||
64 | bytes starting at | ||
65 | .IR pattern , | ||
66 | and returns a pointer to a structure describing them. | ||
67 | The bytes referenced by | ||
68 | .I pattern | ||
69 | may be of any value. | ||
70 | .PP | ||
71 | The search takes advantage of the frequency distribution of the | ||
72 | bytes in the text to be searched. | ||
73 | If specified, | ||
74 | .I freq | ||
75 | should be an array of 256 values, | ||
76 | with higher values indicating that the corresponding character occurs | ||
77 | more frequently. | ||
78 | (A less than optimal frequency distribution can only result in less | ||
79 | than optimal performance, not incorrect results.) | ||
80 | If | ||
81 | .I freq | ||
82 | is NULL, | ||
83 | a system default table is used. | ||
84 | .PP | ||
85 | .I Bm_exec | ||
86 | returns a pointer to the leftmost occurrence of the string given to | ||
87 | .I bm_comp | ||
88 | within | ||
89 | .IR text , | ||
90 | or NULL if none occurs. | ||
91 | The number of bytes in | ||
92 | .I text | ||
93 | must be specified by | ||
94 | .IR len . | ||
95 | .PP | ||
96 | Space allocated for the returned description is discarded | ||
97 | by calling | ||
98 | .I bm_free | ||
99 | with the returned description as an argument. | ||
100 | .PP | ||
101 | The asymptotic speed of | ||
102 | .I bm_exec | ||
103 | is | ||
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" , | ||
111 | Hume and Sunday, | ||
112 | Software Practice and Experience, | ||
113 | Vol. 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) | ||
38 | static 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 | */ | ||
56 | static 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 | |||
91 | bm_pat * | ||
92 | bm_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 | |||
142 | mem: sv_errno = errno; | ||
143 | bm_free(pat); | ||
144 | errno = sv_errno; | ||
145 | return (NULL); | ||
146 | } | ||
147 | |||
148 | void | ||
149 | bm_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 | |||
159 | u_char * | ||
160 | bm_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 | |||
198 | mismatch1: 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 | |||
215 | mismatch2: 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 | ||
71 | These functions operate on variable length strings of bytes. | ||
72 | They do not check for terminating null bytes as the routines | ||
73 | listed in | ||
74 | .Xr string 3 | ||
75 | do. | ||
76 | .Pp | ||
77 | See 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 | ||
89 | The functions | ||
90 | .Fn memchr , | ||
91 | .Fn memcmp , | ||
92 | .Fn memcpy , | ||
93 | .Fn memmove , | ||
94 | and | ||
95 | .Fn memset | ||
96 | conform to | ||
97 | .St -ansiC . | ||
98 | .Sh HISTORY | ||
99 | The functions | ||
100 | .Fn bzero | ||
101 | and | ||
102 | .Fn memccpy | ||
103 | appeared in | ||
104 | .Bx 4.3 ; | ||
105 | the functions | ||
106 | .Fn bcmp , | ||
107 | .Fn bcopy , | ||
108 | appeared 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 | ||
47 | The | ||
48 | .Fn bzero | ||
49 | function | ||
50 | writes | ||
51 | .Fa len | ||
52 | zero bytes to the string | ||
53 | .Fa b . | ||
54 | If | ||
55 | .Fa len | ||
56 | is zero, | ||
57 | .Fn bzero | ||
58 | does nothing. | ||
59 | .Sh SEE ALSO | ||
60 | .Xr memset 3 , | ||
61 | .Xr swab 3 | ||
62 | .Sh HISTORY | ||
63 | A | ||
64 | .Fn bzero | ||
65 | function | ||
66 | appeared 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) | ||
35 | static 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 | */ | ||
47 | void | ||
48 | bzero(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 | ||
47 | The | ||
48 | .Fn ffs | ||
49 | function | ||
50 | finds the first bit set in | ||
51 | .Fa value | ||
52 | and returns the index of that bit. | ||
53 | Bits are numbered starting from 1, starting at the right-most | ||
54 | bit. | ||
55 | A return value of 0 means that the argument was zero. | ||
56 | .Sh SEE ALSO | ||
57 | .Xr bitstring 3 | ||
58 | .Sh HISTORY | ||
59 | The | ||
60 | .Fn ffs | ||
61 | function 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) | ||
35 | static 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 | */ | ||
47 | int | ||
48 | ffs(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 | ||
47 | The | ||
48 | .Fn index | ||
49 | function | ||
50 | locates the first character matching | ||
51 | .Fa c | ||
52 | (converted to a | ||
53 | .Em char ) | ||
54 | in the null-terminated string | ||
55 | .Fa s . | ||
56 | .Sh RETURN VALUES | ||
57 | If the character | ||
58 | .Fa c | ||
59 | is found, a pointer to it is returned; otherwise | ||
60 | .Dv NULL | ||
61 | is returned. | ||
62 | If | ||
63 | .Fa c | ||
64 | is '\e0', | ||
65 | .Fn index | ||
66 | locates 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 | ||
79 | An | ||
80 | .Fn index | ||
81 | function 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) | ||
35 | static 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 | |||
40 | char * | ||
41 | #ifdef STRCHR | ||
42 | strchr(p, ch) | ||
43 | #else | ||
44 | index(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 | ||
47 | The | ||
48 | .Fn memccpy | ||
49 | function | ||
50 | copies bytes from string | ||
51 | .Fa src | ||
52 | to string | ||
53 | .Fa dst . | ||
54 | If the character | ||
55 | .Fa c | ||
56 | (as converted to an unsigned char) occurs in the string | ||
57 | .Fa src , | ||
58 | the copy stops and a pointer to the byte after the copy of | ||
59 | .Fa c | ||
60 | in the string | ||
61 | .Fa dst | ||
62 | is returned. | ||
63 | Otherwise, | ||
64 | .Fa len | ||
65 | bytes 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 | ||
72 | The | ||
73 | .Fn memccpy | ||
74 | function 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 | ||
38 | static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static 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 | |||
46 | void * | ||
47 | memccpy(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 | ||
49 | The | ||
50 | .Fn memchr | ||
51 | function | ||
52 | locates the first occurrence of | ||
53 | .Fa c | ||
54 | (converted to an unsigned char) | ||
55 | in string | ||
56 | .Fa b . | ||
57 | .Sh RETURN VALUES | ||
58 | The | ||
59 | .Fn memchr | ||
60 | function | ||
61 | returns a pointer to the byte located, | ||
62 | or NULL if no such byte exists within | ||
63 | .Fa len | ||
64 | bytes. | ||
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 | ||
77 | The | ||
78 | .Fn memchr | ||
79 | function | ||
80 | conforms 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) | ||
38 | static 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 | |||
43 | void * | ||
44 | memchr(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 | ||
49 | The | ||
50 | .Fn memcmp | ||
51 | function | ||
52 | compares byte string | ||
53 | .Fa b1 | ||
54 | against byte string | ||
55 | .Fa b2 . | ||
56 | Both strings are assumed to be | ||
57 | .Fa len | ||
58 | bytes long. | ||
59 | .Sh RETURN VALUES | ||
60 | The | ||
61 | .Fn memcmp | ||
62 | function | ||
63 | returns zero if the two strings are identical, | ||
64 | otherwise returns the difference between the first two differing bytes | ||
65 | (treated as unsigned char values, so that | ||
66 | .Sq Li \e200 | ||
67 | is greater than | ||
68 | .Sq Li \&\e0 , | ||
69 | for example). | ||
70 | Zero-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 | ||
78 | The | ||
79 | .Fn memcmp | ||
80 | function | ||
81 | conforms 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) | ||
38 | static 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 | */ | ||
46 | int | ||
47 | memcmp(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 | ||
49 | The | ||
50 | .Fn memcpy | ||
51 | function | ||
52 | copies | ||
53 | .Fa len | ||
54 | bytes from string | ||
55 | .Fa src | ||
56 | to string | ||
57 | .Fa dst . | ||
58 | .Sh RETURN VALUES | ||
59 | The | ||
60 | .Fn memcpy | ||
61 | function | ||
62 | returns 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 | ||
70 | The | ||
71 | .Fn memcpy | ||
72 | function | ||
73 | conforms to | ||
74 | .St -ansiC . | ||
75 | .Sh BUGS | ||
76 | In this implementation | ||
77 | .Fn memcpy | ||
78 | is implemented using | ||
79 | .Xr bcopy 3 , | ||
80 | and therefore the strings may overlap. | ||
81 | On other systems, copying overlapping strings may produce surprises. | ||
82 | A 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 | ||
49 | The | ||
50 | .Fn memmove | ||
51 | function | ||
52 | copies | ||
53 | .Fa len | ||
54 | bytes from string | ||
55 | .Fa src | ||
56 | to string | ||
57 | .Fa dst . | ||
58 | The two strings may overlap; | ||
59 | the copy is always done in a non-destructive manner. | ||
60 | .Sh RETURN VALUES | ||
61 | The | ||
62 | .Fn memmove | ||
63 | function 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 | ||
71 | The | ||
72 | .Fn memmove | ||
73 | function | ||
74 | conforms 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 | ||
49 | The | ||
50 | .Fn memset | ||
51 | function | ||
52 | writes | ||
53 | .Fa len | ||
54 | bytes of value | ||
55 | .Fa c | ||
56 | (converted to an unsigned char) to the string | ||
57 | .Fa b . | ||
58 | .Sh RETURN VALUES | ||
59 | The | ||
60 | .Fn memset | ||
61 | function | ||
62 | returns the original value of | ||
63 | .Fa b . | ||
64 | .Sh SEE ALSO | ||
65 | .Xr bzero 3 , | ||
66 | .Xr swab 3 | ||
67 | .Sh STANDARDS | ||
68 | The | ||
69 | .Fn memset | ||
70 | function | ||
71 | conforms 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) | ||
38 | static 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 | |||
43 | void * | ||
44 | memset(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 | ||
47 | The | ||
48 | .Fn rindex | ||
49 | function | ||
50 | locates the last character | ||
51 | matching | ||
52 | .Fa c | ||
53 | (converted to a | ||
54 | .Em char ) | ||
55 | in the null-terminated string | ||
56 | .Fa s . | ||
57 | If the character c is found, a pointer to it is returned; otherwise NULL is returned. | ||
58 | If | ||
59 | .Fa c | ||
60 | is | ||
61 | .Ql \e0 , | ||
62 | .Fn rindex | ||
63 | locates 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 | ||
77 | A | ||
78 | .Fn rindex | ||
79 | function 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) | ||
35 | static 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 | |||
40 | char * | ||
41 | #ifdef STRRCHR | ||
42 | strrchr(p, ch) | ||
43 | #else | ||
44 | rindex(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 | ||
51 | The | ||
52 | .Fn strcasecmp | ||
53 | and | ||
54 | .Fn strncasecmp | ||
55 | functions | ||
56 | compare the null-terminated strings | ||
57 | .Fa s1 | ||
58 | and | ||
59 | .Fa s2 | ||
60 | and return an integer greater than, equal to, or less than 0, | ||
61 | according as | ||
62 | .Fa s1 | ||
63 | is lexicographically greater than, equal to, or less than | ||
64 | .Fa s2 | ||
65 | after translation of each corresponding character to lower-case. | ||
66 | The strings themselves are not modified. | ||
67 | The comparison is done using unsigned characters, so that | ||
68 | .Sq Li \e200 | ||
69 | is greater than | ||
70 | .Ql \e0 . | ||
71 | .Pp | ||
72 | The | ||
73 | .Fn strncasecmp | ||
74 | compares at most | ||
75 | .Fa len | ||
76 | characters. | ||
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 | ||
84 | The | ||
85 | .Fn strcasecmp | ||
86 | and | ||
87 | .Fn strncasecmp | ||
88 | functions 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 | ||
40 | static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; | ||
41 | #else | ||
42 | static 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 | |||
46 | typedef 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 | */ | ||
53 | static 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 | |||
88 | int | ||
89 | strcasecmp(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 | |||
102 | int | ||
103 | strncasecmp(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 | ||
51 | The | ||
52 | .Fn strcat | ||
53 | and | ||
54 | .Fn strncat | ||
55 | functions | ||
56 | append a copy of the null-terminated string | ||
57 | .Fa append | ||
58 | to the end of the null-terminated string | ||
59 | .Fa s , | ||
60 | then add a terminating | ||
61 | .Ql \e0 . | ||
62 | The string | ||
63 | .Fa s | ||
64 | must have sufficient space to hold the result. | ||
65 | .Pp | ||
66 | The | ||
67 | .Fn strncat | ||
68 | function | ||
69 | appends not more than | ||
70 | .Fa count | ||
71 | characters where space for the terminating | ||
72 | .Ql \e0 | ||
73 | should not be included in | ||
74 | .Fa count . | ||
75 | .Sh RETURN VALUES | ||
76 | The | ||
77 | .Fn strcat | ||
78 | and | ||
79 | .Fn strncat | ||
80 | functions | ||
81 | return 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 | ||
90 | The | ||
91 | .Fn strcat | ||
92 | and | ||
93 | .Fn strncat | ||
94 | functions | ||
95 | conform 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) | ||
35 | static 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 | |||
44 | char * | ||
45 | strcat(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 | ||
49 | The | ||
50 | .Fn strchr | ||
51 | function locates the first occurrence of | ||
52 | .Ar c | ||
53 | in the string pointed to by | ||
54 | .Ar s . | ||
55 | The terminating | ||
56 | .Dv NUL | ||
57 | character is considered part of the string. | ||
58 | If | ||
59 | .Fa c | ||
60 | is | ||
61 | .Ql \e0 , | ||
62 | .Fn strchr | ||
63 | locates the terminating | ||
64 | .Ql \e0 . | ||
65 | .Sh RETURN VALUES | ||
66 | The function | ||
67 | .Fn strchr | ||
68 | returns a pointer to the located character, or | ||
69 | .Dv NULL | ||
70 | if 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 | ||
83 | The | ||
84 | .Fn strchr | ||
85 | function | ||
86 | conforms 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 | ||
51 | The | ||
52 | .Fn strcmp | ||
53 | and | ||
54 | .Fn strncmp | ||
55 | functions | ||
56 | lexicographically compare the null-terminated strings | ||
57 | .Fa s1 | ||
58 | and | ||
59 | .Fa s2 . | ||
60 | .Sh RETURN VALUES | ||
61 | The | ||
62 | .Fn strcmp | ||
63 | and | ||
64 | .Fn strncmp | ||
65 | return an integer greater than, equal to, or less than 0, according | ||
66 | as the string | ||
67 | .Fa s1 | ||
68 | is greater than, equal to, or less than the string | ||
69 | .Fa s2 . | ||
70 | The comparison is done using unsigned characters, so that | ||
71 | .Ql \e200 | ||
72 | is greater than | ||
73 | .Ql \e0 . | ||
74 | .Pp | ||
75 | The | ||
76 | .Fn strncmp | ||
77 | compares not more than | ||
78 | .Fa len | ||
79 | characters. | ||
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 | ||
87 | The | ||
88 | .Fn strcmp | ||
89 | and | ||
90 | .Fn strncmp | ||
91 | functions | ||
92 | conform 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) | ||
38 | static 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 | */ | ||
50 | int | ||
51 | strcmp(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 | ||
49 | The | ||
50 | .Fn strcoll | ||
51 | function | ||
52 | lexicographically compares the null-terminated strings | ||
53 | .Fa s1 | ||
54 | and | ||
55 | .Fa s2 | ||
56 | according to the current locale collation | ||
57 | and returns an integer greater than, equal to, or less than 0, | ||
58 | according as | ||
59 | .Fa s1 | ||
60 | is 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 | ||
70 | The | ||
71 | .Fn strcoll | ||
72 | function | ||
73 | conforms 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) | ||
38 | static 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 | */ | ||
46 | int | ||
47 | strcoll(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 | ||
51 | The | ||
52 | .Fn strcpy | ||
53 | and | ||
54 | .Fn strncpy | ||
55 | functions | ||
56 | copy the string | ||
57 | .Fa src | ||
58 | to | ||
59 | .Fa dst | ||
60 | (including the terminating | ||
61 | .Ql \e0 | ||
62 | character). | ||
63 | .Pp | ||
64 | The | ||
65 | .Fn strncpy | ||
66 | copies not more than | ||
67 | .Fa len | ||
68 | characters into | ||
69 | .Fa dst , | ||
70 | appending | ||
71 | .Ql \e0 | ||
72 | characters if | ||
73 | .Fa src | ||
74 | is less than | ||
75 | .Fa len | ||
76 | characters long, and | ||
77 | .Em not | ||
78 | terminating | ||
79 | .Fa dst | ||
80 | if | ||
81 | .Fa src | ||
82 | is more than | ||
83 | .Fa len | ||
84 | characters long. | ||
85 | .Sh RETURN VALUES | ||
86 | The | ||
87 | .Fn strcpy | ||
88 | and | ||
89 | .Fn strncpy | ||
90 | functions | ||
91 | return | ||
92 | .Fa dst . | ||
93 | .Sh EXAMPLES | ||
94 | The following sets | ||
95 | .Dq Li chararray | ||
96 | to | ||
97 | .Dq Li abc\e0\e0\e0 : | ||
98 | .Bd -literal -offset indent | ||
99 | (void)strncpy(chararray, "abc", 6). | ||
100 | .Ed | ||
101 | .Pp | ||
102 | The following sets | ||
103 | .Dq Li chararray | ||
104 | to | ||
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 | ||
115 | The | ||
116 | .Fn strcpy | ||
117 | and | ||
118 | .Fn strncpy | ||
119 | functions | ||
120 | conform 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) | ||
35 | static 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 | |||
44 | char * | ||
45 | strcpy(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 | ||
49 | The | ||
50 | .Fn strcspn | ||
51 | function | ||
52 | spans the initial part of the null-terminated string | ||
53 | .Fa s | ||
54 | as long as the characters from | ||
55 | .Fa s | ||
56 | do not occur in string | ||
57 | .Fa charset | ||
58 | (it | ||
59 | spans the | ||
60 | .Em complement | ||
61 | of | ||
62 | .Fa charset ) . | ||
63 | .Sh RETURN VALUES | ||
64 | The | ||
65 | .Fn strcspn | ||
66 | function | ||
67 | returns 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 | ||
80 | The | ||
81 | .Fn strcspn | ||
82 | function | ||
83 | conforms 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) | ||
38 | static 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 | */ | ||
46 | size_t | ||
47 | strcspn(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 | ||
47 | The | ||
48 | .Fn strdup | ||
49 | function | ||
50 | allocates sufficient memory for a copy | ||
51 | of the string | ||
52 | .Fa str , | ||
53 | does the copy, and returns a pointer to it. | ||
54 | The pointer may subsequently be used as an | ||
55 | argument to the function | ||
56 | .Xr free 3 . | ||
57 | .Pp | ||
58 | If 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 | ||
65 | The | ||
66 | .Fn strdup | ||
67 | function 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 | ||
38 | static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static 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 | |||
50 | char * | ||
51 | strdup(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 | ||
49 | The | ||
50 | .Fn strerror | ||
51 | function returns a pointer to the language-dependent error message | ||
52 | string affiliated with an error number. | ||
53 | .Pp | ||
54 | The array pointed to is not to be modified by the program, but may be | ||
55 | overwritten 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 | ||
62 | The | ||
63 | .Fn strerror | ||
64 | function 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) | ||
35 | static 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 | |||
47 | extern char *__strerror __P((int, char *)); | ||
48 | |||
49 | char * | ||
50 | strerror(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 | ||
104 | The string functions | ||
105 | manipulate strings terminated by a | ||
106 | null byte. | ||
107 | .Pp | ||
108 | See the specific manual pages for more information. | ||
109 | For manipulating variable length generic objects as byte | ||
110 | strings (without the null byte check), see | ||
111 | .Xr bstring 3 . | ||
112 | .Pp | ||
113 | Except as noted in their specific manual pages, | ||
114 | the string functions do not test the destination | ||
115 | for 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 | ||
135 | The | ||
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 , | ||
151 | and | ||
152 | .Fn strtok | ||
153 | functions | ||
154 | conform 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) | ||
31 | static 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 | */ | ||
43 | size_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 | ||
42 | The | ||
43 | .Fn strlcpy | ||
44 | and | ||
45 | .Fn strlcat | ||
46 | functions copy and concatenate strings respectively. They are designed | ||
47 | to be safer, more consistent, and less error prone replacements for | ||
48 | .Xr strncpy 3 | ||
49 | and | ||
50 | .Xr strncat 3 . | ||
51 | Unlike those functions, | ||
52 | .Fn strlcpy | ||
53 | and | ||
54 | .Fn strlcat | ||
55 | take the full size of the buffer (not just the length) and guarantee to | ||
56 | NUL-terminate the result (as long as | ||
57 | .Fa size | ||
58 | is larger than 0). Note that you should include a byte for the NUL in | ||
59 | .Fa size . | ||
60 | .Pp | ||
61 | The | ||
62 | .Fn strlcpy | ||
63 | function copies up to | ||
64 | .Fa size | ||
65 | - 1 characters from the NUL-terminated string | ||
66 | .Fa src | ||
67 | to | ||
68 | .Fa dst , | ||
69 | NUL-terminating the result. | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn strlcat | ||
73 | function appends the NUL-terminated string | ||
74 | .Fa src | ||
75 | to the end of | ||
76 | .Fa dst . | ||
77 | It will append at most | ||
78 | .Fa size | ||
79 | - strlen(dst) - 1 bytes, NUL-terminating the result. | ||
80 | .Sh RETURN VALUES | ||
81 | The | ||
82 | .Fn strlcpy | ||
83 | and | ||
84 | .Fn strlcat | ||
85 | functions return the total length of the string they tried to | ||
86 | create. For | ||
87 | .Fn strlcpy | ||
88 | that means the length of | ||
89 | .Fa src . | ||
90 | For | ||
91 | .Fn strlcat | ||
92 | that means the initial length of | ||
93 | .Fa dst | ||
94 | plus | ||
95 | the length of | ||
96 | .Fa src . | ||
97 | While this may seem somewhat confusing it was done to make | ||
98 | truncation detection simple. | ||
99 | .Sh EXAMPLES | ||
100 | The following code fragment illustrates the simple case: | ||
101 | .Bd -literal -offset indent | ||
102 | char *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 | ||
110 | To detect truncation, perhaps while building a pathname, something | ||
111 | like the following might be used: | ||
112 | .Bd -literal -offset indent | ||
113 | char *dir, *file, pname[MAXPATHNAMELEN]; | ||
114 | |||
115 | .Li ... | ||
116 | |||
117 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
118 | goto toolong; | ||
119 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
120 | goto toolong; | ||
121 | .Ed | ||
122 | .Pp | ||
123 | Since we know how many characters we copied the first time, we can | ||
124 | speed things up a bit by using a copy instead on an append: | ||
125 | .Bd -literal -offset indent | ||
126 | char *dir, *file, pname[MAXPATHNAMELEN]; | ||
127 | size_t n; | ||
128 | |||
129 | .Li ... | ||
130 | |||
131 | n = strlcpy(pname, dir, sizeof(pname)); | ||
132 | if (n >= sizeof(pname)) | ||
133 | goto toolong; | ||
134 | if (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) | ||
31 | static 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 | */ | ||
42 | size_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 | ||
49 | The | ||
50 | .Fn strlen | ||
51 | function | ||
52 | computes the length of the string | ||
53 | .Fa s . | ||
54 | .Sh RETURN VALUES | ||
55 | The | ||
56 | .Fn strlen | ||
57 | function | ||
58 | returns | ||
59 | the number of characters that precede the | ||
60 | terminating | ||
61 | .Dv NUL | ||
62 | character. | ||
63 | .Sh SEE ALSO | ||
64 | .Xr string 3 | ||
65 | .Sh STANDARDS | ||
66 | The | ||
67 | .Fn strlen | ||
68 | function | ||
69 | conforms 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) | ||
35 | static 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 | |||
44 | size_t | ||
45 | strlen(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 | ||
47 | The | ||
48 | .Fn strmode | ||
49 | function | ||
50 | converts a file | ||
51 | .Fa mode | ||
52 | (the type and permission information associated with an inode, see | ||
53 | .Xr stat 2 ) | ||
54 | into a symbolic string which is stored in the location referenced by | ||
55 | .Fa bp . | ||
56 | This stored string is eleven characters in length plus a trailing | ||
57 | .Dv NUL . | ||
58 | .Pp | ||
59 | The 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 \- | ||
63 | regular file | ||
64 | .It b | ||
65 | block special | ||
66 | .It c | ||
67 | character special | ||
68 | .It d | ||
69 | directory | ||
70 | .It l | ||
71 | symbolic link | ||
72 | .It p | ||
73 | fifo | ||
74 | .It s | ||
75 | socket | ||
76 | .It w | ||
77 | whiteout | ||
78 | .It ? | ||
79 | unknown inode type | ||
80 | .El | ||
81 | .Pp | ||
82 | The next nine characters encode three sets of permissions, in three | ||
83 | characters each. | ||
84 | The first three characters are the permissions for the owner of the | ||
85 | file, the second three for the group the file belongs to, and the | ||
86 | third for the ``other'', or default, set of users. | ||
87 | .Pp | ||
88 | Permission checking is done as specifically as possible. | ||
89 | If read permission is denied to the owner of a file in the first set | ||
90 | of permissions, the owner of the file will not be able to read the file. | ||
91 | This is true even if the owner is in the file's group and the group | ||
92 | permissions allow reading or the ``other'' permissions allow reading. | ||
93 | .Pp | ||
94 | If the first character of the three character set is an ``r'', the file is | ||
95 | readable for that set of users; if a dash ``\-'', it is not readable. | ||
96 | .Pp | ||
97 | If the second character of the three character set is a ``w'', the file is | ||
98 | writable for that set of users; if a dash ``\-'', it is not writable. | ||
99 | .Pp | ||
100 | The third character is the first of the following characters that apply: | ||
101 | .Bl -tag -width xxxx | ||
102 | .It S | ||
103 | If the character is part of the owner permissions and the file is not | ||
104 | executable or the directory is not searchable by the owner, and the | ||
105 | set-user-id bit is set. | ||
106 | .It S | ||
107 | If the character is part of the group permissions and the file is not | ||
108 | executable or the directory is not searchable by the group, and the | ||
109 | set-group-id bit is set. | ||
110 | .It T | ||
111 | If the character is part of the other permissions and the file is not | ||
112 | executable or the directory is not searchable by others, and the ``sticky'' | ||
113 | .Pq Dv S_ISVTX | ||
114 | bit is set. | ||
115 | .It s | ||
116 | If the character is part of the owner permissions and the file is | ||
117 | executable or the directory searchable by the owner, and the set-user-id | ||
118 | bit is set. | ||
119 | .It s | ||
120 | If the character is part of the group permissions and the file is | ||
121 | executable or the directory searchable by the group, and the set-group-id | ||
122 | bit is set. | ||
123 | .It t | ||
124 | If the character is part of the other permissions and the file is | ||
125 | executable or the directory searchable by others, and the ``sticky'' | ||
126 | .Pq Dv S_ISVTX | ||
127 | bit is set. | ||
128 | .It x | ||
129 | The file is executable or the directory is searchable. | ||
130 | .It \- | ||
131 | None of the above apply. | ||
132 | .El | ||
133 | .Pp | ||
134 | The last character is a plus sign ``+'' if there are any alternate | ||
135 | or additional access control methods associated with the inode, otherwise | ||
136 | it will be a space. | ||
137 | .Sh RETURN VALUES | ||
138 | The | ||
139 | .Fn strmode | ||
140 | function | ||
141 | always 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 | ||
149 | The | ||
150 | .Fn strmode | ||
151 | function 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) | ||
35 | static 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 | |||
42 | void | ||
43 | strmode(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) | ||
38 | static 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 | */ | ||
47 | char * | ||
48 | strncat(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) | ||
35 | static 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 | |||
44 | int | ||
45 | strncmp(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) | ||
38 | static 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 | */ | ||
47 | char * | ||
48 | strncpy(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 | ||
49 | The | ||
50 | .Fn strpbrk | ||
51 | function | ||
52 | locates in the null-terminated string | ||
53 | .Fa s | ||
54 | the first occurrence of any character in the string | ||
55 | .Fa charset | ||
56 | and returns a pointer to this character. | ||
57 | If no characters from | ||
58 | .Fa charset | ||
59 | occur anywhere in | ||
60 | .Fa s | ||
61 | .Fn strpbrk | ||
62 | returns 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 | ||
75 | The | ||
76 | .Fn strpbrk | ||
77 | function | ||
78 | conforms 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) | ||
35 | static 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 | */ | ||
43 | char * | ||
44 | strpbrk(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 | ||
49 | The | ||
50 | .Fn strrchr | ||
51 | function | ||
52 | locates the last occurrence of | ||
53 | .Fa c | ||
54 | (converted to a char) | ||
55 | in the string | ||
56 | .Fa s . | ||
57 | If | ||
58 | .Fa c | ||
59 | is | ||
60 | .Ql \e0 , | ||
61 | .Fn strrchr | ||
62 | locates the terminating | ||
63 | .Ql \e0 . | ||
64 | .Sh RETURN VALUES | ||
65 | The | ||
66 | .Fn strrchr | ||
67 | function | ||
68 | returns a pointer to the character, | ||
69 | or a null | ||
70 | pointer if | ||
71 | .Fa c | ||
72 | does 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 | ||
86 | The | ||
87 | .Fn strrchr | ||
88 | function | ||
89 | conforms 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 | ||
50 | The | ||
51 | .Fn strsep | ||
52 | function locates, in the string referenced by | ||
53 | .Fa *stringp , | ||
54 | the first occurrence of any character in the string | ||
55 | .Fa delim | ||
56 | (or the terminating | ||
57 | .Ql \e0 | ||
58 | character) and replaces it with a | ||
59 | .Ql \e0 . | ||
60 | The 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 . | ||
63 | The original value of | ||
64 | .Fa *stringp | ||
65 | is returned. | ||
66 | .Pp | ||
67 | An ``empty'' field, i.e. one caused by two adjacent delimiter characters, | ||
68 | can be detected by comparing the location referenced by the pointer returned | ||
69 | in | ||
70 | .Fa *stringp | ||
71 | to | ||
72 | .Ql \e0 . | ||
73 | .Pp | ||
74 | If | ||
75 | .Fa *stringp | ||
76 | is initially | ||
77 | .Dv NULL , | ||
78 | .Fn strsep | ||
79 | returns | ||
80 | .Dv NULL . | ||
81 | .Sh EXAMPLES | ||
82 | The following uses | ||
83 | .Fn strsep | ||
84 | to parse a string, containing tokens delimited by white space, into an | ||
85 | argument vector: | ||
86 | .Bd -literal -offset indent | ||
87 | char **ap, *argv[10], *inputstring; | ||
88 | |||
89 | for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;) | ||
90 | if (**ap != '\e0') | ||
91 | ++ap; | ||
92 | .Ed | ||
93 | .Sh HISTORY | ||
94 | The | ||
95 | .Fn strsep | ||
96 | function | ||
97 | is intended as a replacement for the | ||
98 | .Fn strtok | ||
99 | function. | ||
100 | While the | ||
101 | .Fn strtok | ||
102 | function should be preferred for portability reasons (it conforms to | ||
103 | .St -ansiC ) | ||
104 | it is unable to handle empty fields, i.e. detect fields delimited by | ||
105 | two adjacent delimiter characters, or to be used for more than a single | ||
106 | string at a time. | ||
107 | The | ||
108 | .Fn strsep | ||
109 | function 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 | ||
41 | static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; | ||
42 | #else | ||
43 | static 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 | */ | ||
58 | char * | ||
59 | strsep(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 | ||
49 | The | ||
50 | .Fn strsignal | ||
51 | function returns a pointer to the language-dependent string describing | ||
52 | a signal. | ||
53 | .Pp | ||
54 | The array pointed to is not to be modified by the program, but may be | ||
55 | overwritten 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) | ||
35 | static 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 | |||
41 | extern char *__strsignal __P((int, char *)); | ||
42 | |||
43 | char * | ||
44 | strsignal(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 | ||
49 | The | ||
50 | .Fn strspn | ||
51 | function | ||
52 | spans the initial part of the null-terminated string | ||
53 | .Fa s | ||
54 | as long as the characters from | ||
55 | .Fa s | ||
56 | occur in string | ||
57 | .Fa charset . | ||
58 | .Sh RETURN VALUES | ||
59 | The | ||
60 | .Fn strspn | ||
61 | function | ||
62 | returns 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 | ||
75 | The | ||
76 | .Fn strspn | ||
77 | function | ||
78 | conforms 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) | ||
35 | static 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 | */ | ||
43 | size_t | ||
44 | strspn(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 | */ | ||
54 | cont: | ||
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 | ||
49 | The | ||
50 | .Fn strstr | ||
51 | function | ||
52 | locates the first occurrence of the null-terminated string | ||
53 | .Fa little | ||
54 | in the null-terminated string | ||
55 | .Fa big . | ||
56 | If | ||
57 | .Fa little | ||
58 | is the empty string, | ||
59 | .Fn strstr | ||
60 | returns | ||
61 | .Fa big ; | ||
62 | if | ||
63 | .Fa little | ||
64 | occurs nowhere in | ||
65 | .Fa big , | ||
66 | .Fn strstr | ||
67 | returns NULL; | ||
68 | otherwise | ||
69 | .Fn strstr | ||
70 | returns 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 | ||
84 | The | ||
85 | .Fn strstr | ||
86 | function | ||
87 | conforms 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) | ||
38 | static 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 | */ | ||
46 | char * | ||
47 | strstr(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 | ||
51 | This interface is obsoleted by | ||
52 | .Xr strsep 3 . | ||
53 | .Ef | ||
54 | .Pp | ||
55 | The | ||
56 | .Fn strtok | ||
57 | function | ||
58 | is used to isolate sequential tokens in a null-terminated string, | ||
59 | .Fa str . | ||
60 | These tokens are separated in the string by at least one of the | ||
61 | characters in | ||
62 | .Fa sep . | ||
63 | The first time that | ||
64 | .Fn strtok | ||
65 | is called, | ||
66 | .Fa str | ||
67 | should be specified; subsequent calls, wishing to obtain further tokens | ||
68 | from the same string, should pass a null pointer instead. | ||
69 | The separator string, | ||
70 | .Fa sep , | ||
71 | must be supplied each time, and may change between calls. | ||
72 | .Pp | ||
73 | The | ||
74 | .Fn strtok | ||
75 | function | ||
76 | returns a pointer to the beginning of each subsequent token in the string, | ||
77 | after replacing the separator character itself with a | ||
78 | .Dv NUL | ||
79 | character. | ||
80 | When 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 | ||
93 | The | ||
94 | .Fn strtok | ||
95 | function | ||
96 | conforms to | ||
97 | .St -ansiC . | ||
98 | .Sh BUGS | ||
99 | There is no way to get tokens from multiple strings simultaneously. | ||
100 | .Pp | ||
101 | The System V | ||
102 | .Fn strtok , | ||
103 | if handed a string containing only delimiter characters, | ||
104 | will not alter the next starting point, so that a call to | ||
105 | .Fn strtok | ||
106 | with a different (or empty) delimiter string | ||
107 | may return a | ||
108 | .Pf non- Dv NULL | ||
109 | value. | ||
110 | Since this implementation always alters the next starting point, | ||
111 | such 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) | ||
35 | static 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 | |||
40 | char * | ||
41 | strtok(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 | */ | ||
57 | cont: | ||
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 | ||
49 | The | ||
50 | .Fn strxfrm | ||
51 | function | ||
52 | does something horrible (see | ||
53 | .Tn ANSI | ||
54 | standard). | ||
55 | In 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 | ||
64 | The | ||
65 | .Fn strxfrm | ||
66 | function | ||
67 | conforms 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) | ||
38 | static 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 | */ | ||
48 | size_t | ||
49 | strxfrm(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 | ||
45 | The function | ||
46 | .Fn swab | ||
47 | copies | ||
48 | .Fa len | ||
49 | bytes from the location referenced by | ||
50 | .Fa src | ||
51 | to the location referenced by | ||
52 | .Fa dst , | ||
53 | swapping adjacent bytes. | ||
54 | .Pp | ||
55 | The argument | ||
56 | .Fa len | ||
57 | must be even number. | ||
58 | .Sh SEE ALSO | ||
59 | .Xr bzero 3 , | ||
60 | .Xr memset 3 | ||
61 | .Sh HISTORY | ||
62 | A | ||
63 | .Fn swab | ||
64 | function 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) | ||
38 | static 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 | |||
43 | void | ||
44 | swab(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 | } | ||