diff options
Diffstat (limited to '')
72 files changed, 6138 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..2b7ce63a63 --- /dev/null +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -0,0 +1,108 @@ | |||
1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 | ||
2 | # $Id: Makefile.inc,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
3 | |||
4 | # string sources | ||
5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string | ||
6 | |||
7 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | ||
8 | strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ | ||
9 | __strerror.c __strsignal.c | ||
10 | |||
11 | # machine-dependent net sources | ||
12 | # m-d Makefile.inc must include sources for: | ||
13 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() | ||
14 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() | ||
15 | # strncat() strncmp() strncpy() strpbrk() strsep() | ||
16 | # strspn() strstr() swav() | ||
17 | # m-d Makefile.inc may include sources for: | ||
18 | # memcpy() memmove() strchr() strrchr() | ||
19 | |||
20 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" | ||
21 | |||
22 | # if no machine specific memmove(3), build one out of bcopy(3). | ||
23 | .if empty(SRCS:Mmemmove.S) | ||
24 | OBJS+= memmove.o | ||
25 | memmove.o: bcopy.c | ||
26 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
27 | @${LD} -x -r ${.TARGET} | ||
28 | @mv a.out ${.TARGET} | ||
29 | |||
30 | memmove.po: bcopy.c | ||
31 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
32 | @${LD} -X -r ${.TARGET} | ||
33 | @mv a.out ${.TARGET} | ||
34 | |||
35 | memmove.so: bcopy.c | ||
36 | ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | ||
37 | -o ${.TARGET} | ||
38 | .endif | ||
39 | |||
40 | # if no machine specific memcpy(3), build one out of bcopy(3). | ||
41 | # if there is a machine specific memmove(3), we'll assume it aliases | ||
42 | # memcpy(3). | ||
43 | .if empty(SRCS:Mmemcpy.S) | ||
44 | .if empty(SRCS:Mmemmove.S) | ||
45 | OBJS+= memcpy.o | ||
46 | memcpy.o: bcopy.c | ||
47 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
48 | @${LD} -x -r ${.TARGET} | ||
49 | @mv a.out ${.TARGET} | ||
50 | |||
51 | memcpy.po: bcopy.c | ||
52 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
53 | @${LD} -X -r ${.TARGET} | ||
54 | @mv a.out ${.TARGET} | ||
55 | |||
56 | memcpy.so: bcopy.c | ||
57 | ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | ||
58 | -o ${.TARGET} | ||
59 | .endif | ||
60 | .endif | ||
61 | |||
62 | # if no machine specific strchr(3), build one out of index(3). | ||
63 | .if empty(SRCS:Mstrchr.S) | ||
64 | OBJS+= strchr.o | ||
65 | strchr.o: index.c | ||
66 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
67 | @${LD} -x -r ${.TARGET} | ||
68 | @mv a.out ${.TARGET} | ||
69 | |||
70 | strchr.po: index.c | ||
71 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
72 | @${LD} -X -r ${.TARGET} | ||
73 | @mv a.out ${.TARGET} | ||
74 | |||
75 | strchr.so: index.c | ||
76 | ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | ||
77 | -o ${.TARGET} | ||
78 | .endif | ||
79 | |||
80 | # if no machine specific strrchr(3), build one out of rindex(3). | ||
81 | .if empty(SRCS:Mstrrchr.S) | ||
82 | OBJS+= strrchr.o | ||
83 | strrchr.o: rindex.c | ||
84 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
85 | @${LD} -x -r ${.TARGET} | ||
86 | @mv a.out ${.TARGET} | ||
87 | |||
88 | strrchr.po: rindex.c | ||
89 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | ||
90 | @${LD} -X -r ${.TARGET} | ||
91 | @mv a.out ${.TARGET} | ||
92 | |||
93 | strrchr.so: rindex.c | ||
94 | ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | ||
95 | -o ${.TARGET} | ||
96 | .endif | ||
97 | |||
98 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ | ||
99 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ | ||
100 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 strftime.3 \ | ||
101 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ | ||
102 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 | ||
103 | |||
104 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | ||
105 | MLINKS+=strcasecmp.3 strncasecmp.3 | ||
106 | MLINKS+=strcat.3 strncat.3 | ||
107 | MLINKS+=strcmp.3 strncmp.3 | ||
108 | MLINKS+=strcpy.3 strncpy.3 | ||
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c new file mode 100644 index 0000000000..cd604906db --- /dev/null +++ b/src/lib/libc/string/__strerror.c | |||
@@ -0,0 +1,92 @@ | |||
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 *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | ||
36 | static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #ifdef NLS | ||
40 | #define catclose _catclose | ||
41 | #define catgets _catgets | ||
42 | #define catopen _catopen | ||
43 | #include <nl_types.h> | ||
44 | #endif | ||
45 | |||
46 | #define sys_errlist _sys_errlist | ||
47 | #define sys_nerr _sys_nerr | ||
48 | |||
49 | #include <stdio.h> | ||
50 | #include <string.h> | ||
51 | |||
52 | /* | ||
53 | * Since perror() is not allowed to change the contents of strerror()'s | ||
54 | * static buffer, both functions supply their own buffers to the | ||
55 | * internal function __strerror(). | ||
56 | */ | ||
57 | |||
58 | char * | ||
59 | __strerror(num, buf) | ||
60 | int num; | ||
61 | char *buf; | ||
62 | { | ||
63 | #define UPREFIX "Unknown error: %u" | ||
64 | register unsigned int errnum; | ||
65 | |||
66 | #ifdef NLS | ||
67 | nl_catd catd ; | ||
68 | catd = catopen("libc", 0); | ||
69 | #endif | ||
70 | |||
71 | errnum = num; /* convert to unsigned */ | ||
72 | if (errnum < sys_nerr) { | ||
73 | #ifdef NLS | ||
74 | strcpy(buf, catgets(catd, 1, errnum, | ||
75 | (char *)sys_errlist[errnum])); | ||
76 | #else | ||
77 | return(sys_errlist[errnum]); | ||
78 | #endif | ||
79 | } else { | ||
80 | #ifdef NLS | ||
81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | ||
82 | #else | ||
83 | sprintf(buf, UPREFIX, errnum); | ||
84 | #endif | ||
85 | } | ||
86 | |||
87 | #ifdef NLS | ||
88 | catclose(catd); | ||
89 | #endif | ||
90 | |||
91 | return buf; | ||
92 | } | ||
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c new file mode 100644 index 0000000000..1937e2d608 --- /dev/null +++ b/src/lib/libc/string/__strsignal.c | |||
@@ -0,0 +1,86 @@ | |||
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 *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | ||
36 | static char *rcsid = "$Id: __strsignal.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #ifdef NLS | ||
40 | #define catclose _catclose | ||
41 | #define catgets _catgets | ||
42 | #define catopen _catopen | ||
43 | #include <nl_types.h> | ||
44 | #endif | ||
45 | |||
46 | #define sys_siglist _sys_siglist | ||
47 | |||
48 | #include <stdio.h> | ||
49 | #include <signal.h> | ||
50 | #include <string.h> | ||
51 | |||
52 | char * | ||
53 | __strsignal(num, buf) | ||
54 | int num; | ||
55 | char *buf; | ||
56 | { | ||
57 | #define UPREFIX "Unknown signal: %u" | ||
58 | register unsigned int signum; | ||
59 | |||
60 | #ifdef NLS | ||
61 | nl_catd catd ; | ||
62 | catd = catopen("libc", 0); | ||
63 | #endif | ||
64 | |||
65 | signum = num; /* convert to unsigned */ | ||
66 | if (signum < NSIG) { | ||
67 | #ifdef NLS | ||
68 | strcpy(buf, catgets(catd, 2, signum, | ||
69 | (char *)sys_siglist[signum])); | ||
70 | #else | ||
71 | return((char *)sys_siglist[signum]); | ||
72 | #endif | ||
73 | } else { | ||
74 | #ifdef NLS | ||
75 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); | ||
76 | #else | ||
77 | sprintf(buf, UPREFIX, signum); | ||
78 | #endif | ||
79 | } | ||
80 | |||
81 | #ifdef NLS | ||
82 | catclose(catd); | ||
83 | #endif | ||
84 | |||
85 | return buf; | ||
86 | } | ||
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3 new file mode 100644 index 0000000000..118c55c579 --- /dev/null +++ b/src/lib/libc/string/bcmp.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. | ||
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 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | ||
35 | .\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt BCMP 3 | ||
39 | .Os BSD 4.2 | ||
40 | .Sh NAME | ||
41 | .Nm bcmp | ||
42 | .Nd compare byte string | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft int | ||
46 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn bcmp | ||
50 | function | ||
51 | compares byte string | ||
52 | .Fa b1 | ||
53 | against byte string | ||
54 | .Fa b2 , | ||
55 | returning zero if they are identical, non-zero otherwise. | ||
56 | Both strings are assumed to be | ||
57 | .Fa len | ||
58 | bytes long. | ||
59 | Zero-length strings are always identical. | ||
60 | .Pp | ||
61 | The strings may overlap. | ||
62 | .Sh SEE ALSO | ||
63 | .Xr memcmp 3 , | ||
64 | .Xr strcasecmp 3 , | ||
65 | .Xr strcmp 3 , | ||
66 | .Xr strcoll 3 , | ||
67 | .Xr strxfrm 3 | ||
68 | .Sh HISTORY | ||
69 | A | ||
70 | .Fn bcmp | ||
71 | function first appeared in | ||
72 | .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..2cc38baee3 --- /dev/null +++ b/src/lib/libc/string/bcmp.c | |||
@@ -0,0 +1,59 @@ | |||
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 *sccsid = "from: @(#)bcmp.c 5.6 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: bcmp.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * bcmp -- vax cmpc3 instruction | ||
43 | */ | ||
44 | bcmp(b1, b2, length) | ||
45 | const void *b1, *b2; | ||
46 | register size_t length; | ||
47 | { | ||
48 | register char *p1, *p2; | ||
49 | |||
50 | if (length == 0) | ||
51 | return(0); | ||
52 | p1 = (char *)b1; | ||
53 | p2 = (char *)b2; | ||
54 | do | ||
55 | if (*p1++ != *p2++) | ||
56 | break; | ||
57 | while (--length); | ||
58 | return(length); | ||
59 | } | ||
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3 new file mode 100644 index 0000000000..6db3812caf --- /dev/null +++ b/src/lib/libc/string/bcopy.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. | ||
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 | .\" from: @(#)bcopy.3 5.3 (Berkeley) 4/19/91 | ||
36 | .\" $Id: bcopy.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | ||
38 | .Dd April 19, 1991 | ||
39 | .Dt BCOPY 3 | ||
40 | .Os BSD 4.2 | ||
41 | .Sh NAME | ||
42 | .Nm bcopy | ||
43 | .Nd copy byte string | ||
44 | .Sh SYNOPSIS | ||
45 | .Fd #include <string.h> | ||
46 | .Ft void | ||
47 | .Fn bcopy "const void *src" "void *dst" "size_t len" | ||
48 | .Sh DESCRIPTION | ||
49 | The | ||
50 | .Fn bcopy | ||
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 | If | ||
60 | .Fa len | ||
61 | is zero, no bytes are copied. | ||
62 | .Sh SEE ALSO | ||
63 | .Xr memccpy 3 , | ||
64 | .Xr memcpy 3 , | ||
65 | .Xr memmove 3 , | ||
66 | .Xr strcpy 3 , | ||
67 | .Xr strncpy 3 | ||
68 | .Sh HISTORY | ||
69 | A | ||
70 | .Fn bcopy | ||
71 | function appeared in | ||
72 | .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..92feed66ea --- /dev/null +++ b/src/lib/libc/string/bcopy.c | |||
@@ -0,0 +1,139 @@ | |||
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 *sccsid = "from: @(#)bcopy.c 5.11 (Berkeley) 6/21/91";*/ | ||
39 | static char *rcsid = "$Id: bcopy.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * sizeof(word) MUST BE A POWER OF TWO | ||
46 | * SO THAT wmask BELOW IS ALL ONES | ||
47 | */ | ||
48 | typedef long word; /* "word" used for optimal copy speed */ | ||
49 | |||
50 | #define wsize sizeof(word) | ||
51 | #define wmask (wsize - 1) | ||
52 | |||
53 | /* | ||
54 | * Copy a block of memory, handling overlap. | ||
55 | * This is the routine that actually implements | ||
56 | * (the portable versions of) bcopy, memcpy, and memmove. | ||
57 | */ | ||
58 | #ifdef MEMCOPY | ||
59 | void * | ||
60 | memcpy(dst0, src0, length) | ||
61 | #else | ||
62 | #ifdef MEMMOVE | ||
63 | void * | ||
64 | memmove(dst0, src0, length) | ||
65 | #else | ||
66 | void | ||
67 | bcopy(src0, dst0, length) | ||
68 | #endif | ||
69 | #endif | ||
70 | void *dst0; | ||
71 | const void *src0; | ||
72 | register size_t length; | ||
73 | { | ||
74 | register char *dst = dst0; | ||
75 | register const char *src = src0; | ||
76 | register size_t t; | ||
77 | |||
78 | if (length == 0 || dst == src) /* nothing to do */ | ||
79 | goto done; | ||
80 | |||
81 | /* | ||
82 | * Macros: loop-t-times; and loop-t-times, t>0 | ||
83 | */ | ||
84 | #define TLOOP(s) if (t) TLOOP1(s) | ||
85 | #define TLOOP1(s) do { s; } while (--t) | ||
86 | |||
87 | if ((unsigned long)dst < (unsigned long)src) { | ||
88 | /* | ||
89 | * Copy forward. | ||
90 | */ | ||
91 | t = (long)src; /* only need low bits */ | ||
92 | if ((t | (long)dst) & wmask) { | ||
93 | /* | ||
94 | * Try to align operands. This cannot be done | ||
95 | * unless the low bits match. | ||
96 | */ | ||
97 | if ((t ^ (long)dst) & wmask || length < wsize) | ||
98 | t = length; | ||
99 | else | ||
100 | t = wsize - (t & wmask); | ||
101 | length -= t; | ||
102 | TLOOP1(*dst++ = *src++); | ||
103 | } | ||
104 | /* | ||
105 | * Copy whole words, then mop up any trailing bytes. | ||
106 | */ | ||
107 | t = length / wsize; | ||
108 | TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); | ||
109 | t = length & wmask; | ||
110 | TLOOP(*dst++ = *src++); | ||
111 | } else { | ||
112 | /* | ||
113 | * Copy backwards. Otherwise essentially the same. | ||
114 | * Alignment works as before, except that it takes | ||
115 | * (t&wmask) bytes to align, not wsize-(t&wmask). | ||
116 | */ | ||
117 | src += length; | ||
118 | dst += length; | ||
119 | t = (long)src; | ||
120 | if ((t | (long)dst) & wmask) { | ||
121 | if ((t ^ (long)dst) & wmask || length <= wsize) | ||
122 | t = length; | ||
123 | else | ||
124 | t &= wmask; | ||
125 | length -= t; | ||
126 | TLOOP1(*--dst = *--src); | ||
127 | } | ||
128 | t = length / wsize; | ||
129 | TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); | ||
130 | t = length & wmask; | ||
131 | TLOOP(*--dst = *--src); | ||
132 | } | ||
133 | done: | ||
134 | #if defined(MEMCOPY) || defined(MEMMOVE) | ||
135 | return (dst0); | ||
136 | #else | ||
137 | return; | ||
138 | #endif | ||
139 | } | ||
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 new file mode 100644 index 0000000000..2264a6a1c4 --- /dev/null +++ b/src/lib/libc/string/bm.3 | |||
@@ -0,0 +1,114 @@ | |||
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 | .\" from: @(#)bm.3 8.4 (Berkeley) 6/21/94 | ||
36 | .\" $Id: bm.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | ||
38 | .TH BM 3 | ||
39 | .SH NAME | ||
40 | bm_comp, bm_exec, bm_free \- Boyer-Moore string search | ||
41 | .SH SYNOPSIS | ||
42 | .ft B | ||
43 | #include <sys/types.h> | ||
44 | .br | ||
45 | #include <bm.h> | ||
46 | .sp | ||
47 | bm_pat * | ||
48 | .br | ||
49 | bm_comp(u_char *pattern, size_t patlen, u_char freq[256]); | ||
50 | .sp | ||
51 | u_char * | ||
52 | .br | ||
53 | bm_exec(bm_pat *pdesc, u_char *text, size_t len); | ||
54 | .sp | ||
55 | void | ||
56 | .br | ||
57 | bm_free(bm_pat *pdesc); | ||
58 | .SH DESCRIPTION | ||
59 | These routines implement an efficient mechanism to find an | ||
60 | occurrence of a byte string within another byte string. | ||
61 | .PP | ||
62 | .I Bm_comp | ||
63 | evaluates the | ||
64 | .I patlen | ||
65 | bytes starting at | ||
66 | .IR pattern , | ||
67 | and returns a pointer to a structure describing them. | ||
68 | The bytes referenced by | ||
69 | .I pattern | ||
70 | may be of any value. | ||
71 | .PP | ||
72 | The search takes advantage of the frequency distribution of the | ||
73 | bytes in the text to be searched. | ||
74 | If specified, | ||
75 | .I freq | ||
76 | should be an array of 256 values, | ||
77 | with higher values indicating that the corresponding character occurs | ||
78 | more frequently. | ||
79 | (A less than optimal frequency distribution can only result in less | ||
80 | than optimal performance, not incorrect results.) | ||
81 | If | ||
82 | .I freq | ||
83 | is NULL, | ||
84 | a system default table is used. | ||
85 | .PP | ||
86 | .I Bm_exec | ||
87 | returns a pointer to the leftmost occurrence of the string given to | ||
88 | .I bm_comp | ||
89 | within | ||
90 | .IR text , | ||
91 | or NULL if none occurs. | ||
92 | The number of bytes in | ||
93 | .I text | ||
94 | must be specified by | ||
95 | .IR len . | ||
96 | .PP | ||
97 | Space allocated for the returned description is discarded | ||
98 | by calling | ||
99 | .I bm_free | ||
100 | with the returned description as an argument. | ||
101 | .PP | ||
102 | The asymptotic speed of | ||
103 | .I bm_exec | ||
104 | is | ||
105 | .RI O( len / patlen ). | ||
106 | .PP | ||
107 | .SH "SEE ALSO" | ||
108 | .IR regexp (3), | ||
109 | .IR strstr (3) | ||
110 | .sp | ||
111 | .IR "Fast String Searching" , | ||
112 | Hume and Sunday, | ||
113 | Software Practice and Experience, | ||
114 | 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..68eac22ecc --- /dev/null +++ b/src/lib/libc/string/bm.c | |||
@@ -0,0 +1,220 @@ | |||
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 | #ifndef lint | ||
38 | /* from: static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94"; */ | ||
39 | static char *rcsid = "$Id: bm.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
40 | #endif /* not lint */ | ||
41 | |||
42 | #include <sys/types.h> | ||
43 | |||
44 | #include <bm.h> | ||
45 | #include <errno.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | |||
49 | /* | ||
50 | * XXX | ||
51 | * The default frequency table starts at 99 and counts down. The default | ||
52 | * table should probably be oriented toward text, and will necessarily be | ||
53 | * locale specific. This one is for English. It was derived from the | ||
54 | * OSF/1 and 4.4BSD formatted and unformatted manual pages, and about 100Mb | ||
55 | * of email and random text. Change it if you can find something better. | ||
56 | */ | ||
57 | static u_char const freq_def[256] = { | ||
58 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
59 | 0, 77, 90, 0, 0, 0, 0, 0, | ||
60 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
61 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
62 | 99, 28, 42, 27, 16, 14, 20, 51, | ||
63 | 66, 65, 59, 24, 75, 76, 84, 56, | ||
64 | 72, 74, 64, 55, 54, 47, 41, 37, | ||
65 | 44, 61, 70, 43, 23, 53, 49, 22, | ||
66 | 33, 58, 40, 46, 45, 57, 60, 26, | ||
67 | 30, 63, 21, 12, 32, 50, 38, 39, | ||
68 | 34, 11, 48, 67, 62, 35, 15, 29, | ||
69 | 71, 18, 9, 17, 25, 13, 10, 52, | ||
70 | 36, 95, 78, 86, 87, 98, 82, 80, | ||
71 | 88, 94, 19, 68, 89, 83, 93, 96, | ||
72 | 81, 7, 91, 92, 97, 85, 69, 73, | ||
73 | 31, 79, 8, 5, 4, 6, 3, 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 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
90 | }; | ||
91 | |||
92 | bm_pat * | ||
93 | bm_comp(pb, len, freq) | ||
94 | u_char const *pb; | ||
95 | size_t len; | ||
96 | u_char const *freq; | ||
97 | { | ||
98 | register u_char const *pe, *p; | ||
99 | register size_t *d, r; | ||
100 | register int j; | ||
101 | int sv_errno; | ||
102 | bm_pat *pat; | ||
103 | |||
104 | if (len == 0) { | ||
105 | errno = EINVAL; | ||
106 | return (NULL); | ||
107 | } | ||
108 | if ((pat = malloc(sizeof(*pat))) == NULL) | ||
109 | return (NULL); | ||
110 | pat->pat = NULL; | ||
111 | pat->delta = NULL; | ||
112 | |||
113 | pat->patlen = len; /* copy pattern */ | ||
114 | if ((pat->pat = malloc(pat->patlen)) == NULL) | ||
115 | goto mem; | ||
116 | memcpy(pat->pat, pb, pat->patlen); | ||
117 | /* get skip delta */ | ||
118 | if ((pat->delta = malloc(256 * sizeof(*d))) == NULL) | ||
119 | goto mem; | ||
120 | for (j = 0, d = pat->delta; j < 256; j++) | ||
121 | d[j] = pat->patlen; | ||
122 | for (pe = pb + pat->patlen - 1; pb <= pe; pb++) | ||
123 | d[*pb] = pe - pb; | ||
124 | |||
125 | if (freq == NULL) /* default freq table */ | ||
126 | freq = freq_def; | ||
127 | r = 0; /* get guard */ | ||
128 | for (pb = pat->pat, pe = pb + pat->patlen - 1; pb < pe; pb++) | ||
129 | if (freq[*pb] < freq[pat->pat[r]]) | ||
130 | r = pb - pat->pat; | ||
131 | pat->rarec = pat->pat[r]; | ||
132 | pat->rareoff = r - (pat->patlen - 1); | ||
133 | |||
134 | /* get md2 shift */ | ||
135 | for (pe = pat->pat + pat->patlen - 1, p = pe - 1; p >= pat->pat; p--) | ||
136 | if (*p == *pe) | ||
137 | break; | ||
138 | |||
139 | /* *p is first leftward reoccurrence of *pe */ | ||
140 | pat->md2 = pe - p; | ||
141 | return (pat); | ||
142 | |||
143 | mem: sv_errno = errno; | ||
144 | bm_free(pat); | ||
145 | errno = sv_errno; | ||
146 | return (NULL); | ||
147 | } | ||
148 | |||
149 | void | ||
150 | bm_free(pat) | ||
151 | bm_pat *pat; | ||
152 | { | ||
153 | if (pat->pat != NULL) | ||
154 | free(pat->pat); | ||
155 | if (pat->delta != NULL) | ||
156 | free(pat->delta); | ||
157 | free(pat); | ||
158 | } | ||
159 | |||
160 | u_char * | ||
161 | bm_exec(pat, base, n) | ||
162 | bm_pat *pat; | ||
163 | u_char *base; | ||
164 | size_t n; | ||
165 | { | ||
166 | register u_char *e, *ep, *p, *q, *s; | ||
167 | register size_t *d0, k, md2, n1, ro; | ||
168 | register int rc; | ||
169 | |||
170 | if (n == 0) | ||
171 | return (NULL); | ||
172 | |||
173 | d0 = pat->delta; | ||
174 | n1 = pat->patlen - 1; | ||
175 | md2 = pat->md2; | ||
176 | ro = pat->rareoff; | ||
177 | rc = pat->rarec; | ||
178 | ep = pat->pat + pat->patlen - 1; | ||
179 | s = base + (pat->patlen - 1); | ||
180 | |||
181 | /* fast loop up to n - 3 * patlen */ | ||
182 | e = base + n - 3 * pat->patlen; | ||
183 | while (s < e) { | ||
184 | k = d0[*s]; /* ufast skip loop */ | ||
185 | while (k) { | ||
186 | k = d0[*(s += k)]; | ||
187 | k = d0[*(s += k)]; | ||
188 | } | ||
189 | if (s >= e) | ||
190 | break; | ||
191 | if (s[ro] != rc) /* guard test */ | ||
192 | goto mismatch1; | ||
193 | /* fwd match */ | ||
194 | for (p = pat->pat, q = s - n1; p < ep;) | ||
195 | if (*q++ != *p++) | ||
196 | goto mismatch1; | ||
197 | return (s - n1); | ||
198 | |||
199 | mismatch1: s += md2; /* md2 shift */ | ||
200 | } | ||
201 | |||
202 | /* slow loop up to end */ | ||
203 | e = base + n; | ||
204 | while (s < e) { | ||
205 | s += d0[*s]; /* step */ | ||
206 | if (s >= e) | ||
207 | break; | ||
208 | if (s[ro] != rc) /* guard test */ | ||
209 | goto mismatch2; | ||
210 | /* fwd match */ | ||
211 | for (p = pat->pat, q = s - n1; p <= ep;) | ||
212 | if (*q++ != *p++) | ||
213 | goto mismatch2; | ||
214 | return (s - n1); | ||
215 | |||
216 | mismatch2: s += md2; /* md2 shift */ | ||
217 | } | ||
218 | |||
219 | return (NULL); | ||
220 | } | ||
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3 new file mode 100644 index 0000000000..12fcfb0cc1 --- /dev/null +++ b/src/lib/libc/string/bstring.3 | |||
@@ -0,0 +1,110 @@ | |||
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 | .\" from: @(#)bstring.3 6.8 (Berkeley) 4/19/91 | ||
35 | .\" $Id: bstring.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt BSTRING 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm bcmp , | ||
42 | .Nm bcopy , | ||
43 | .Nm bzero , | ||
44 | .Nm memccpy , | ||
45 | .Nm memchr , | ||
46 | .Nm memcmp , | ||
47 | .Nm memcpy , | ||
48 | .Nm memmove, | ||
49 | .Nm memset | ||
50 | .Nd byte string operations | ||
51 | .Sh SYNOPSIS | ||
52 | .Fd #include <string.h> | ||
53 | .Ft int | ||
54 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" | ||
55 | .Ft void | ||
56 | .Fn bcopy "const void *src" "void *dst" "size_t len" | ||
57 | .Ft void | ||
58 | .Fn bzero "void *b" "size_t len" | ||
59 | .Ft void * | ||
60 | .Fn memchr "const void *b" "int c" "size_t len" | ||
61 | .Ft int | ||
62 | .Fn memcmp "const void *b1" "const void *b2" "size_t len" | ||
63 | .Ft void * | ||
64 | .Fn memccpy "void *dst" "const void *src" "int c" "size_t len" | ||
65 | .Ft void * | ||
66 | .Fn memcpy "void *dst" "const void *src" "size_t len" | ||
67 | .Ft void * | ||
68 | .Fn memmove "void *dst" "const void *src" "size_t len" | ||
69 | .Ft void * | ||
70 | .Fn memset "void *b" "int c" "size_t len" | ||
71 | .Sh DESCRIPTION | ||
72 | These functions operate on variable length strings of bytes. | ||
73 | They do not check for terminating null bytes as the routines | ||
74 | listed in | ||
75 | .Xr string 3 | ||
76 | do. | ||
77 | .Pp | ||
78 | See the specific manual pages for more information. | ||
79 | .Sh SEE ALSO | ||
80 | .Xr bcmp 3 , | ||
81 | .Xr bcopy 3 , | ||
82 | .Xr bzero 3 , | ||
83 | .Xr memccpy 3 , | ||
84 | .Xr memchr 3 , | ||
85 | .Xr memcmp 3 , | ||
86 | .Xr memcpy 3 , | ||
87 | .Xr memmove 3 , | ||
88 | .Xr memset 3 | ||
89 | .Sh STANDARDS | ||
90 | The functions | ||
91 | .Fn memchr , | ||
92 | .Fn memcmp , | ||
93 | .Fn memcpy , | ||
94 | .Fn memmove , | ||
95 | and | ||
96 | .Fn memset | ||
97 | conform to | ||
98 | .St -ansiC . | ||
99 | .Sh HISTORY | ||
100 | The functions | ||
101 | .Fn bzero | ||
102 | and | ||
103 | .Fn memccpy | ||
104 | appeared in | ||
105 | .Bx 4.3 ; | ||
106 | the functions | ||
107 | .Fn bcmp , | ||
108 | .Fn bcopy , | ||
109 | appeared in | ||
110 | .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..4f0141e051 --- /dev/null +++ b/src/lib/libc/string/bzero.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. | ||
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 | .\" from: @(#)bzero.3 5.3 (Berkeley) 4/19/91 | ||
35 | .\" $Id: bzero.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt BZERO 3 | ||
39 | .Os BSD 4.3 | ||
40 | .Sh NAME | ||
41 | .Nm bzero | ||
42 | .Nd write zeroes to a byte string | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft void | ||
46 | .Fn bzero "void *b" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn bzero | ||
50 | function | ||
51 | writes | ||
52 | .Fa len | ||
53 | zero bytes to the string | ||
54 | .Fa b . | ||
55 | If | ||
56 | .Fa len | ||
57 | is zero, | ||
58 | .Fn bzero | ||
59 | does nothing. | ||
60 | .Sh SEE ALSO | ||
61 | .Xr memset 3 , | ||
62 | .Xr swab 3 | ||
63 | .Sh HISTORY | ||
64 | A | ||
65 | .Fn bzero | ||
66 | function | ||
67 | appeared in | ||
68 | .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..4865e396ef --- /dev/null +++ b/src/lib/libc/string/bzero.c | |||
@@ -0,0 +1,53 @@ | |||
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 *sccsid = "from: @(#)bzero.c 5.7 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: bzero.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * bzero -- vax movc5 instruction | ||
43 | */ | ||
44 | void | ||
45 | bzero(b, length) | ||
46 | void *b; | ||
47 | register size_t length; | ||
48 | { | ||
49 | register char *p; | ||
50 | |||
51 | for (p = b; length--;) | ||
52 | *p++ = '\0'; | ||
53 | } | ||
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 new file mode 100644 index 0000000000..6464bea2b1 --- /dev/null +++ b/src/lib/libc/string/ffs.3 | |||
@@ -0,0 +1,63 @@ | |||
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 | .\" from: @(#)ffs.3 5.3 (Berkeley) 4/19/91 | ||
35 | .\" $Id: ffs.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt FFS 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm ffs | ||
42 | .Nd find first bit set in a bit string | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft int | ||
46 | .Fn ffs "int value" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn ffs | ||
50 | function | ||
51 | finds the first bit set in | ||
52 | .Fa value | ||
53 | and returns the index of that bit. | ||
54 | Bits are numbered starting from 1, starting at the right-most | ||
55 | bit. | ||
56 | A return value of 0 means that the argument was zero. | ||
57 | .Sh SEE ALSO | ||
58 | .Xr bitstring 3 | ||
59 | .Sh HISTORY | ||
60 | The | ||
61 | .Fn ffs | ||
62 | function appeared in | ||
63 | .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..42bc87ddea --- /dev/null +++ b/src/lib/libc/string/ffs.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 *sccsid = "from: @(#)ffs.c 5.4 (Berkeley) 5/17/90";*/ | ||
36 | static char *rcsid = "$Id: ffs.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * ffs -- vax ffs instruction | ||
43 | */ | ||
44 | int | ||
45 | ffs(mask) | ||
46 | register int mask; | ||
47 | { | ||
48 | register int bit; | ||
49 | |||
50 | if (mask == 0) | ||
51 | return(0); | ||
52 | for (bit = 1; !(mask & 1); bit++) | ||
53 | mask >>= 1; | ||
54 | return(bit); | ||
55 | } | ||
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/index.3 new file mode 100644 index 0000000000..847b03628b --- /dev/null +++ b/src/lib/libc/string/index.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. | ||
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 | .\" from: @(#)index.3 5.3 (Berkeley) 4/19/91 | ||
35 | .\" $Id: index.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt INDEX 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm index | ||
42 | .Nd locate character in string | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft char * | ||
46 | .Fn index "const char *s" "int c" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn index | ||
50 | function | ||
51 | locates the first character matching | ||
52 | .Fa c | ||
53 | (converted to a | ||
54 | .Em char ) | ||
55 | in the null-terminated string | ||
56 | .Fa s . | ||
57 | .Sh RETURN VALUES | ||
58 | The character | ||
59 | .Fa c | ||
60 | is returned if it is found; otherwise | ||
61 | .Dv NULL | ||
62 | is returned. | ||
63 | If | ||
64 | .Fa c | ||
65 | is '\e0', | ||
66 | .Fn index | ||
67 | locates the terminating '\e0'. | ||
68 | .Sh SEE ALSO | ||
69 | .Xr memchr 3 , | ||
70 | .Xr rindex 3 , | ||
71 | .Xr strchr 3 , | ||
72 | .Xr strcspn 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 HISTORY | ||
80 | A | ||
81 | .Fn index | ||
82 | function appeared in | ||
83 | .At v6 . | ||
diff --git a/src/lib/libc/string/index.c b/src/lib/libc/string/index.c new file mode 100644 index 0000000000..3d9c05f961 --- /dev/null +++ b/src/lib/libc/string/index.c | |||
@@ -0,0 +1,56 @@ | |||
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 *sccsid = "from: @(#)index.c 5.7 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: index.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | char * | ||
42 | #ifdef STRCHR | ||
43 | strchr(p, ch) | ||
44 | #else | ||
45 | index(p, ch) | ||
46 | #endif | ||
47 | register const char *p, ch; | ||
48 | { | ||
49 | for (;; ++p) { | ||
50 | if (*p == ch) | ||
51 | return((char *)p); | ||
52 | if (!*p) | ||
53 | return((char *)NULL); | ||
54 | } | ||
55 | /* NOTREACHED */ | ||
56 | } | ||
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3 new file mode 100644 index 0000000000..61df704028 --- /dev/null +++ b/src/lib/libc/string/memccpy.3 | |||
@@ -0,0 +1,73 @@ | |||
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 | .\" from: @(#)memccpy.3 5.4 (Berkeley) 4/19/91 | ||
33 | .\" $Id: memccpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
34 | .\" | ||
35 | .Dd April 19, 1991 | ||
36 | .Dt MEMCCPY 3 | ||
37 | .Os | ||
38 | .Sh NAME | ||
39 | .Nm memccpy | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <string.h> | ||
42 | .Ft void * | ||
43 | .Fn memccpy "void *dst" "const void *src" "int c" "size_t len" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn memccpy | ||
47 | function | ||
48 | copies bytes from string | ||
49 | .Fa src | ||
50 | to string | ||
51 | .Fa dst . | ||
52 | If the character | ||
53 | .Fa c | ||
54 | (as converted to an unsigned char) occurs in the string | ||
55 | .Fa src , | ||
56 | the copy stops and a pointer to the byte after the copy of | ||
57 | .Fa c | ||
58 | in the string | ||
59 | .Fa dst | ||
60 | is returned. | ||
61 | Otherwise, | ||
62 | .Fa len | ||
63 | bytes are copied, and a NULL pointer is returned. | ||
64 | .Sh SEE ALSO | ||
65 | .Xr bcopy 3 , | ||
66 | .Xr memcpy 3 , | ||
67 | .Xr memmove 3 , | ||
68 | .Xr strcpy 3 | ||
69 | .Sh HISTORY | ||
70 | The | ||
71 | .Fn memccpy | ||
72 | function is | ||
73 | .Ud . | ||
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c new file mode 100644 index 0000000000..3a1d7bcca1 --- /dev/null +++ b/src/lib/libc/string/memccpy.c | |||
@@ -0,0 +1,59 @@ | |||
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 *sccsid = "from: @(#)memccpy.c 5.8 (Berkeley) 5/30/91";*/ | ||
36 | static char *rcsid = "$Id: memccpy.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | void * | ||
42 | memccpy(t, f, c, n) | ||
43 | void *t; | ||
44 | const void *f; | ||
45 | int c; | ||
46 | register size_t n; | ||
47 | { | ||
48 | |||
49 | if (n) { | ||
50 | register unsigned char *tp = t; | ||
51 | register const unsigned char *fp = f; | ||
52 | register unsigned char uc = c; | ||
53 | do { | ||
54 | if ((*tp++ = *fp++) == uc) | ||
55 | return (tp); | ||
56 | } while (--n != 0); | ||
57 | } | ||
58 | return (0); | ||
59 | } | ||
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3 new file mode 100644 index 0000000000..265711e3b5 --- /dev/null +++ b/src/lib/libc/string/memchr.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 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCHR 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm memchr | ||
44 | .Nd locate byte in byte string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft void * | ||
48 | .Fn memchr "const void *b" "int c" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn memchr | ||
52 | function | ||
53 | locates the first occurrence of | ||
54 | .Fa c | ||
55 | (converted to an unsigned char) | ||
56 | in string | ||
57 | .Fa b . | ||
58 | .Sh RETURN VALUES | ||
59 | The | ||
60 | .Fn memchr | ||
61 | function | ||
62 | returns a pointer to the byte located, | ||
63 | or NULL if no such byte exists within | ||
64 | .Fa len | ||
65 | bytes. | ||
66 | .Sh SEE ALSO | ||
67 | .Xr index 3 , | ||
68 | .Xr rindex 3 , | ||
69 | .Xr strchr 3 , | ||
70 | .Xr strcspn 3 , | ||
71 | .Xr strpbrk 3 , | ||
72 | .Xr strrchr 3 , | ||
73 | .Xr strsep 3 , | ||
74 | .Xr strspn 3 , | ||
75 | .Xr strstr 3 , | ||
76 | .Xr strtok 3 | ||
77 | .Sh STANDARDS | ||
78 | The | ||
79 | .Fn memchr | ||
80 | function | ||
81 | conforms to | ||
82 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c new file mode 100644 index 0000000000..61652c6bb1 --- /dev/null +++ b/src/lib/libc/string/memchr.c | |||
@@ -0,0 +1,59 @@ | |||
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 *sccsid = "from: @(#)memchr.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: memchr.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | void * | ||
45 | memchr(s, c, n) | ||
46 | const void *s; | ||
47 | register unsigned char c; | ||
48 | register size_t n; | ||
49 | { | ||
50 | if (n != 0) { | ||
51 | register const unsigned char *p = s; | ||
52 | |||
53 | do { | ||
54 | if (*p++ == c) | ||
55 | return ((void *)(p - 1)); | ||
56 | } while (--n != 0); | ||
57 | } | ||
58 | return (NULL); | ||
59 | } | ||
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3 new file mode 100644 index 0000000000..13901c1009 --- /dev/null +++ b/src/lib/libc/string/memcmp.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 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | ||
37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCMP 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm memcmp | ||
44 | .Nd compare byte string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft int | ||
48 | .Fn memcmp "const void *b1" "const void *b2" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn memcmp | ||
52 | function | ||
53 | compares byte string | ||
54 | .Fa b1 | ||
55 | against byte string | ||
56 | .Fa b2 . | ||
57 | Both strings are assumed to be | ||
58 | .Fa len | ||
59 | bytes long. | ||
60 | .Sh RETURN VALUES | ||
61 | The | ||
62 | .Fn memcmp | ||
63 | function | ||
64 | returns zero if the the two strings are identical, | ||
65 | otherwise returns the difference between the first two differing bytes | ||
66 | (treated as unsigned char values, so that | ||
67 | .Sq Li \e200 | ||
68 | is greater than | ||
69 | .Sq Li \&\e0 , | ||
70 | for example). | ||
71 | Zero-length strings are always identical. | ||
72 | .Sh SEE ALSO | ||
73 | .Xr bcmp 3 , | ||
74 | .Xr strcasecmp 3 , | ||
75 | .Xr strcmp 3 , | ||
76 | .Xr strcoll 3 , | ||
77 | .Xr strxfrm 3 | ||
78 | .Sh STANDARDS | ||
79 | The | ||
80 | .Fn memcmp | ||
81 | function | ||
82 | conforms to | ||
83 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c new file mode 100644 index 0000000000..23d2ab2393 --- /dev/null +++ b/src/lib/libc/string/memcmp.c | |||
@@ -0,0 +1,61 @@ | |||
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 *sccsid = "from: @(#)memcmp.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: memcmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Compare memory regions. | ||
46 | */ | ||
47 | int | ||
48 | memcmp(s1, s2, n) | ||
49 | const void *s1, *s2; | ||
50 | size_t n; | ||
51 | { | ||
52 | if (n != 0) { | ||
53 | register const unsigned char *p1 = s1, *p2 = s2; | ||
54 | |||
55 | do { | ||
56 | if (*p1++ != *p2++) | ||
57 | return (*--p1 - *--p2); | ||
58 | } while (--n != 0); | ||
59 | } | ||
60 | return (0); | ||
61 | } | ||
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3 new file mode 100644 index 0000000000..3f4bb643c9 --- /dev/null +++ b/src/lib/libc/string/memcpy.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 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | ||
37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCPY 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm memcpy | ||
44 | .Nd copy byte string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft void * | ||
48 | .Fn memcpy "void *dst" "const void *src" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn memcpy | ||
52 | function | ||
53 | copies | ||
54 | .Fa len | ||
55 | bytes from string | ||
56 | .Fa src | ||
57 | to string | ||
58 | .Fa dst . | ||
59 | .Sh RETURN VALUES | ||
60 | The | ||
61 | .Fn memcpy | ||
62 | function | ||
63 | returns the original value of | ||
64 | .Fa dst . | ||
65 | .Sh SEE ALSO | ||
66 | .Xr bcopy 3 , | ||
67 | .Xr memccpy 3 , | ||
68 | .Xr memmove 3 , | ||
69 | .Xr strcpy 3 | ||
70 | .Sh STANDARDS | ||
71 | The | ||
72 | .Fn memcpy | ||
73 | function | ||
74 | conforms to | ||
75 | .St -ansiC . | ||
76 | .Sh BUGS | ||
77 | In this implementation | ||
78 | .Fn memcpy | ||
79 | is implemented using | ||
80 | .Xr bcopy 3 , | ||
81 | and therefore the strings may overlap. | ||
82 | On other systems, copying overlapping strings may produce surprises. | ||
83 | A simpler solution is to not use | ||
84 | .Fn memcpy . | ||
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 new file mode 100644 index 0000000000..24422e7971 --- /dev/null +++ b/src/lib/libc/string/memmove.3 | |||
@@ -0,0 +1,76 @@ | |||
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 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | ||
37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMMOVE 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm memmove | ||
44 | .Nd copy byte string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft void * | ||
48 | .Fn memmove "void *dst" "const void *src" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn memmove | ||
52 | function | ||
53 | copies | ||
54 | .Fa len | ||
55 | bytes from string | ||
56 | .Fa src | ||
57 | to string | ||
58 | .Fa dst . | ||
59 | The two strings may overlap; | ||
60 | the copy is always done in a non-destructive manner. | ||
61 | .Sh RETURN VALUES | ||
62 | The | ||
63 | .Fn memmove | ||
64 | function returns the original value of | ||
65 | .Fa dst . | ||
66 | .Sh SEE ALSO | ||
67 | .Xr bcopy 3 , | ||
68 | .Xr memccpy 3 , | ||
69 | .Xr memcpy 3 , | ||
70 | .Xr strcpy 3 | ||
71 | .Sh STANDARDS | ||
72 | The | ||
73 | .Fn memmove | ||
74 | function | ||
75 | conforms to | ||
76 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3 new file mode 100644 index 0000000000..1afc052182 --- /dev/null +++ b/src/lib/libc/string/memset.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 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 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMSET 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm memset | ||
44 | .Nd write a byte to byte string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft void * | ||
48 | .Fn memset "void *b" "int c" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn memset | ||
52 | function | ||
53 | writes | ||
54 | .Fa len | ||
55 | bytes of value | ||
56 | .Fa c | ||
57 | (converted to an unsigned char) to the string | ||
58 | .Fa b . | ||
59 | .Sh SEE ALSO | ||
60 | .Xr bzero 3 , | ||
61 | .Xr swab 3 | ||
62 | .Sh STANDARDS | ||
63 | The | ||
64 | .Fn memset | ||
65 | function | ||
66 | conforms to | ||
67 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c new file mode 100644 index 0000000000..117de2e80b --- /dev/null +++ b/src/lib/libc/string/memset.c | |||
@@ -0,0 +1,59 @@ | |||
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 *sccsid = "from: @(#)memset.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: memset.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | void * | ||
45 | memset(dst, c, n) | ||
46 | void *dst; | ||
47 | register int c; | ||
48 | register size_t n; | ||
49 | { | ||
50 | |||
51 | if (n != 0) { | ||
52 | register char *d = dst; | ||
53 | |||
54 | do | ||
55 | *d++ = c; | ||
56 | while (--n != 0); | ||
57 | } | ||
58 | return (dst); | ||
59 | } | ||
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/rindex.3 new file mode 100644 index 0000000000..b13b3513e0 --- /dev/null +++ b/src/lib/libc/string/rindex.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. | ||
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 | .\" from: @(#)rindex.3 5.2 (Berkeley) 4/19/91 | ||
35 | .\" $Id: rindex.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt RINDEX 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm rindex | ||
42 | .Nd locate character in string | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft char * | ||
46 | .Fn rindex "const char *s" "int c" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn rindex | ||
50 | function | ||
51 | locates the last character | ||
52 | matching | ||
53 | .Fa c | ||
54 | (converted to a | ||
55 | .Em char ) | ||
56 | in the null-terminated string | ||
57 | .Fa s . | ||
58 | The character c is returned if it is found; otherwise NULL is returned. | ||
59 | If | ||
60 | .Fa c | ||
61 | is | ||
62 | .Ql \e0 , | ||
63 | .Fn rindex | ||
64 | locates the terminating | ||
65 | .Ql \e0 . | ||
66 | .Sh SEE ALSO | ||
67 | .Xr index 3 , | ||
68 | .Xr memchr 3 , | ||
69 | .Xr strchr 3 , | ||
70 | .Xr strcspn 3 , | ||
71 | .Xr strpbrk 3 , | ||
72 | .Xr strrchr 3 , | ||
73 | .Xr strsep 3 , | ||
74 | .Xr strspn 3 , | ||
75 | .Xr strstr 3 , | ||
76 | .Xr strtok 3 | ||
77 | .Sh HISTORY | ||
78 | A | ||
79 | .Fn rindex | ||
80 | function appeared in | ||
81 | .At v6 . | ||
diff --git a/src/lib/libc/string/rindex.c b/src/lib/libc/string/rindex.c new file mode 100644 index 0000000000..1b84c92072 --- /dev/null +++ b/src/lib/libc/string/rindex.c | |||
@@ -0,0 +1,58 @@ | |||
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 *sccsid = "from: @(#)rindex.c 5.9 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: rindex.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | char * | ||
42 | #ifdef STRRCHR | ||
43 | strrchr(p, ch) | ||
44 | #else | ||
45 | rindex(p, ch) | ||
46 | #endif | ||
47 | register const char *p, ch; | ||
48 | { | ||
49 | register char *save; | ||
50 | |||
51 | for (save = NULL;; ++p) { | ||
52 | if (*p == ch) | ||
53 | save = (char *)p; | ||
54 | if (!*p) | ||
55 | return(save); | ||
56 | } | ||
57 | /* NOTREACHED */ | ||
58 | } | ||
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 new file mode 100644 index 0000000000..46e9010e4f --- /dev/null +++ b/src/lib/libc/string/strcasecmp.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. | ||
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 | .\" from: @(#)strcasecmp.3 5.4 (Berkeley) 4/19/91 | ||
35 | .\" $Id: strcasecmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt STRCASECMP 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm strcasecmp | ||
42 | .Nd compare strings, ignoring case | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft int | ||
46 | .Fn strcasecmp "const char *s1" "const char *s2" | ||
47 | .Ft int | ||
48 | .Fn strncasecmp "const char *s1" "const char *s2" "size_t len" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strcasecmp | ||
52 | and | ||
53 | .Fn strncasecmp | ||
54 | functions | ||
55 | compare the null-terminated strings | ||
56 | .Fa s1 | ||
57 | and | ||
58 | .Fa s2 | ||
59 | and return an integer greater than, equal to, or less than 0, | ||
60 | according as | ||
61 | .Fa s1 | ||
62 | is lexicographically greater than, equal to, or less than | ||
63 | .Fa s2 | ||
64 | after translation of each corresponding character to lower-case. | ||
65 | The strings themselves are not modified. | ||
66 | The comparison is done using unsigned characters, so that | ||
67 | .Sq Li \e200 | ||
68 | is greater than | ||
69 | .Ql \e0 . | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn strncasecmp | ||
73 | compares at most | ||
74 | .Fa len | ||
75 | characters. | ||
76 | .Sh SEE ALSO | ||
77 | .Xr bcmp 3 , | ||
78 | .Xr memcmp 3 , | ||
79 | .Xr strcmp 3 , | ||
80 | .Xr strcoll 3 , | ||
81 | .Xr strxfrm 3 | ||
82 | .Sh HISTORY | ||
83 | The | ||
84 | .Fn strcasecmp | ||
85 | and | ||
86 | .Fn strncasecmp | ||
87 | functions are | ||
88 | .Ud . | ||
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c new file mode 100644 index 0000000000..79bd0081e3 --- /dev/null +++ b/src/lib/libc/string/strcasecmp.c | |||
@@ -0,0 +1,115 @@ | |||
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 const char sccsid[] = "from: @(#)strcasecmp.c 5.10 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strcasecmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | typedef unsigned char u_char; | ||
42 | |||
43 | /* | ||
44 | * This array is designed for mapping upper and lower case letter | ||
45 | * together for a case independent comparison. The mappings are | ||
46 | * based upon ascii character sequences. | ||
47 | */ | ||
48 | static const u_char charmap[] = { | ||
49 | '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', | ||
50 | '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', | ||
51 | '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', | ||
52 | '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', | ||
53 | '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', | ||
54 | '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', | ||
55 | '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', | ||
56 | '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', | ||
57 | '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', | ||
58 | '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', | ||
59 | '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', | ||
60 | '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', | ||
61 | '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', | ||
62 | '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', | ||
63 | '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', | ||
64 | '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', | ||
65 | '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', | ||
66 | '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', | ||
67 | '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', | ||
68 | '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', | ||
69 | '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', | ||
70 | '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', | ||
71 | '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', | ||
72 | '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', | ||
73 | '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', | ||
74 | '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', | ||
75 | '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', | ||
76 | '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', | ||
77 | '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', | ||
78 | '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', | ||
79 | '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', | ||
80 | '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', | ||
81 | }; | ||
82 | |||
83 | int | ||
84 | strcasecmp(s1, s2) | ||
85 | const char *s1, *s2; | ||
86 | { | ||
87 | register const u_char *cm = charmap, | ||
88 | *us1 = (const u_char *)s1, | ||
89 | *us2 = (const u_char *)s2; | ||
90 | |||
91 | while (cm[*us1] == cm[*us2++]) | ||
92 | if (*us1++ == '\0') | ||
93 | return (0); | ||
94 | return (cm[*us1] - cm[*--us2]); | ||
95 | } | ||
96 | |||
97 | int | ||
98 | strncasecmp(s1, s2, n) | ||
99 | const char *s1, *s2; | ||
100 | register size_t n; | ||
101 | { | ||
102 | if (n != 0) { | ||
103 | register const u_char *cm = charmap, | ||
104 | *us1 = (const u_char *)s1, | ||
105 | *us2 = (const u_char *)s2; | ||
106 | |||
107 | do { | ||
108 | if (cm[*us1] != cm[*us2++]) | ||
109 | return (cm[*us1] - cm[*--us2]); | ||
110 | if (*us1++ == '\0') | ||
111 | break; | ||
112 | } while (--n != 0); | ||
113 | } | ||
114 | return (0); | ||
115 | } | ||
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 new file mode 100644 index 0000000000..5357d65754 --- /dev/null +++ b/src/lib/libc/string/strcat.3 | |||
@@ -0,0 +1,94 @@ | |||
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 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCAT 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strcat | ||
44 | .Nd concatenate strings | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strcat "char *s" "const char *append" | ||
49 | .Ft char * | ||
50 | .Fn strncat "char *s" "const char *append" "size_t count" | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn strcat | ||
54 | and | ||
55 | .Fn strncat | ||
56 | functions | ||
57 | append a copy of the null-terminated string | ||
58 | .Fa append | ||
59 | to the end of the null-terminated string | ||
60 | .Fa s , | ||
61 | then add a terminating | ||
62 | .Ql \e0 . | ||
63 | The string | ||
64 | .Fa s | ||
65 | must have sufficient space to hold the result. | ||
66 | .Pp | ||
67 | The | ||
68 | .Fn strncat | ||
69 | function | ||
70 | appends not more than | ||
71 | .Fa count | ||
72 | characters. | ||
73 | .Sh RETURN VALUES | ||
74 | The | ||
75 | .Fn strcat | ||
76 | and | ||
77 | .Fn strncat | ||
78 | functions | ||
79 | return the pointer | ||
80 | .Fa s . | ||
81 | .Sh SEE ALSO | ||
82 | .Xr bcopy 3 , | ||
83 | .Xr memccpy 3 , | ||
84 | .Xr memcpy 3 , | ||
85 | .Xr memmove 3 , | ||
86 | .Xr strcpy 3 | ||
87 | .Sh STANDARDS | ||
88 | The | ||
89 | .Fn strcat | ||
90 | and | ||
91 | .Fn strncat | ||
92 | functions | ||
93 | conform to | ||
94 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c new file mode 100644 index 0000000000..e741b84f03 --- /dev/null +++ b/src/lib/libc/string/strcat.c | |||
@@ -0,0 +1,51 @@ | |||
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 *sccsid = "from: @(#)strcat.c 5.6 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strcat.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | char * | ||
42 | strcat(s, append) | ||
43 | register char *s; | ||
44 | register const char *append; | ||
45 | { | ||
46 | char *save = s; | ||
47 | |||
48 | for (; *s; ++s); | ||
49 | while (*s++ = *append++); | ||
50 | return(save); | ||
51 | } | ||
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3 new file mode 100644 index 0000000000..18b50301f3 --- /dev/null +++ b/src/lib/libc/string/strchr.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 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCHR 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strchr | ||
44 | .Nd locate character in string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strchr "const char *s" "int c" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strchr | ||
52 | function locates the first occurrence of | ||
53 | .Ar c | ||
54 | in the string pointed to by | ||
55 | .Ar s . | ||
56 | The terminating | ||
57 | .Dv NULL | ||
58 | character is considered part of the string. | ||
59 | If | ||
60 | .Fa c | ||
61 | is | ||
62 | .Ql \e0 , | ||
63 | .Fn strchr | ||
64 | locates the terminating | ||
65 | .Ql \e0 . | ||
66 | .Sh RETURN VALUES | ||
67 | The function | ||
68 | .Fn strchr | ||
69 | returns a pointer to the located character, or | ||
70 | .Dv NULL | ||
71 | if the character does not appear in the string. | ||
72 | .Sh SEE ALSO | ||
73 | .Xr index 3 , | ||
74 | .Xr memchr 3 , | ||
75 | .Xr rindex 3 , | ||
76 | .Xr strcspn 3 , | ||
77 | .Xr strpbrk 3 , | ||
78 | .Xr strrchr 3 , | ||
79 | .Xr strsep 3 , | ||
80 | .Xr strspn 3 , | ||
81 | .Xr strstr 3 , | ||
82 | .Xr strtok 3 | ||
83 | .Sh STANDARDS | ||
84 | The | ||
85 | .Fn strchr | ||
86 | function | ||
87 | conforms to | ||
88 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 new file mode 100644 index 0000000000..fecaa85410 --- /dev/null +++ b/src/lib/libc/string/strcmp.3 | |||
@@ -0,0 +1,94 @@ | |||
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 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCMP 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strcmp | ||
44 | .Nd compare strings | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft int | ||
48 | .Fn strcmp "const char *s1" "const char *s2" | ||
49 | .Ft int | ||
50 | .Fn strncmp "const char *s1" "const char *s2" "size_t len" | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn strcmp | ||
54 | and | ||
55 | .Fn strncmp | ||
56 | functions | ||
57 | lexicographically compare the null-terminated strings | ||
58 | .Fa s1 | ||
59 | and | ||
60 | .Fa s2 . | ||
61 | .Sh RETURN VALUES | ||
62 | The | ||
63 | .Fn strcmp | ||
64 | and | ||
65 | .Fn strncmp | ||
66 | return an integer greater than, equal to, or less than 0, according | ||
67 | as the string | ||
68 | .Fa s1 | ||
69 | is greater than, equal to, or less than the string | ||
70 | .Fa s2 . | ||
71 | The comparison is done using unsigned characters, so that | ||
72 | .Ql \e200 | ||
73 | is greater than | ||
74 | .Ql \e0 . | ||
75 | .Pp | ||
76 | The | ||
77 | .Fn strncmp | ||
78 | compares not more than | ||
79 | .Fa len | ||
80 | characters. | ||
81 | .Sh SEE ALSO | ||
82 | .Xr bcmp 3 , | ||
83 | .Xr memcmp 3 , | ||
84 | .Xr strcasecmp 3 , | ||
85 | .Xr strcoll 3 , | ||
86 | .Xr strxfrm 3 | ||
87 | .Sh STANDARDS | ||
88 | The | ||
89 | .Fn strcmp | ||
90 | and | ||
91 | .Fn strncmp | ||
92 | functions | ||
93 | conform to | ||
94 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c new file mode 100644 index 0000000000..ae19e2e26e --- /dev/null +++ b/src/lib/libc/string/strcmp.c | |||
@@ -0,0 +1,55 @@ | |||
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 *sccsid = "from: @(#)strcmp.c 5.5 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strcmp.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Compare strings. | ||
46 | */ | ||
47 | int | ||
48 | strcmp(s1, s2) | ||
49 | register const char *s1, *s2; | ||
50 | { | ||
51 | while (*s1 == *s2++) | ||
52 | if (*s1++ == 0) | ||
53 | return (0); | ||
54 | return (*(unsigned char *)s1 - *(unsigned char *)--s2); | ||
55 | } | ||
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3 new file mode 100644 index 0000000000..12f73f98f2 --- /dev/null +++ b/src/lib/libc/string/strcoll.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 | .\" from: @(#)strcoll.3 5.6 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strcoll.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCOLL 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strcoll | ||
44 | .Nd compare strings according to current collation | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft int | ||
48 | .Fn strcoll "const char *s1" "const char *s2" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strcoll | ||
52 | function | ||
53 | lexicographically compares the null-terminated strings | ||
54 | .Fa s1 | ||
55 | and | ||
56 | .Fa s2 | ||
57 | according to the current locale collation | ||
58 | and returns an integer greater than, equal to, or less than 0, | ||
59 | according as | ||
60 | .Fa s1 | ||
61 | is greater than, equal to, or less than | ||
62 | .Fa s2 . | ||
63 | .Sh SEE ALSO | ||
64 | .Xr bcmp 3 , | ||
65 | .Xr memcmp 3 , | ||
66 | .Xr setlocale 3 , | ||
67 | .Xr strcasecmp 3 , | ||
68 | .Xr strcmp 3 , | ||
69 | .Xr strxfrm 3 | ||
70 | .Sh STANDARDS | ||
71 | The | ||
72 | .Fn strcoll | ||
73 | function | ||
74 | conforms to | ||
75 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c new file mode 100644 index 0000000000..86c742cba9 --- /dev/null +++ b/src/lib/libc/string/strcoll.c | |||
@@ -0,0 +1,53 @@ | |||
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 *sccsid = "from: @(#)strcoll.c 5.2 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strcoll.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Compare strings according to LC_COLLATE category of current locale. | ||
46 | */ | ||
47 | int | ||
48 | strcoll(s1, s2) | ||
49 | const char *s1, *s2; | ||
50 | { | ||
51 | /* LC_COLLATE is unimplemented, hence always "C" */ | ||
52 | return (strcmp(s1, s2)); | ||
53 | } | ||
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 new file mode 100644 index 0000000000..1ca12c2707 --- /dev/null +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -0,0 +1,122 @@ | |||
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 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCPY 3 | ||
41 | .Os BSD 4 | ||
42 | .Sh NAME | ||
43 | .Nm strcpy | ||
44 | .Nd copy strings | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strcpy "char *dst" "const char *src" | ||
49 | .Ft char * | ||
50 | .Fn strncpy "char *dst" "const char *src" "size_t len" | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn strcpy | ||
54 | and | ||
55 | .Fn strncpy | ||
56 | functions | ||
57 | copy the string | ||
58 | .Fa src | ||
59 | to | ||
60 | .Fa dst | ||
61 | (including the terminating | ||
62 | .Ql \e0 | ||
63 | character). | ||
64 | .Pp | ||
65 | The | ||
66 | .Fn strncpy | ||
67 | copies not more than | ||
68 | .Fa len | ||
69 | characters into | ||
70 | .Fa dst , | ||
71 | appending | ||
72 | .Ql \e0 | ||
73 | characters if | ||
74 | .Fa src | ||
75 | is less than | ||
76 | .Fa len | ||
77 | characters long, and | ||
78 | .Em not | ||
79 | terminating | ||
80 | .Fa dst | ||
81 | if | ||
82 | .Fa src | ||
83 | is more than | ||
84 | .Fa len | ||
85 | characters long. | ||
86 | .Sh RETURN VALUES | ||
87 | The | ||
88 | .Fn strcpy | ||
89 | and | ||
90 | .Fn strncpy | ||
91 | functions | ||
92 | return | ||
93 | .Fa dst . | ||
94 | .Sh EXAMPLES | ||
95 | The following sets | ||
96 | .Dq Li chararray | ||
97 | to | ||
98 | .Dq Li abc\e0\e0\e0 : | ||
99 | .Bd -literal -offset indent | ||
100 | (void)strncpy(chararray, "abc", 6). | ||
101 | .Ed | ||
102 | .Pp | ||
103 | The following sets | ||
104 | .Dq Li chararray | ||
105 | to | ||
106 | .Dq Li abcdef : | ||
107 | .Bd -literal -offset indent | ||
108 | (void)strncpy(chararray, "abcdefgh", 6); | ||
109 | .Ed | ||
110 | .Sh SEE ALSO | ||
111 | .Xr bcopy 3 , | ||
112 | .Xr memccpy 3 , | ||
113 | .Xr memcpy 3 , | ||
114 | .Xr memmove 3 | ||
115 | .Sh STANDARDS | ||
116 | The | ||
117 | .Fn strcpy | ||
118 | and | ||
119 | .Fn strncpy | ||
120 | functions | ||
121 | conform to | ||
122 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c new file mode 100644 index 0000000000..669bfde23e --- /dev/null +++ b/src/lib/libc/string/strcpy.c | |||
@@ -0,0 +1,50 @@ | |||
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 *sccsid = "from: @(#)strcpy.c 5.7 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strcpy.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | char * | ||
42 | strcpy(to, from) | ||
43 | register char *to; | ||
44 | register const char *from; | ||
45 | { | ||
46 | char *save = to; | ||
47 | |||
48 | for (; *to = *from; ++from, ++to); | ||
49 | return(save); | ||
50 | } | ||
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3 new file mode 100644 index 0000000000..cc9e5c2fe3 --- /dev/null +++ b/src/lib/libc/string/strcspn.3 | |||
@@ -0,0 +1,85 @@ | |||
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 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCSPN 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strcspn | ||
44 | .Nd span the complement of a string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft size_t | ||
48 | .Fn strcspn "const char *s" "const char *charset" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strcspn | ||
52 | function | ||
53 | spans the initial part of the null-terminated string | ||
54 | .Fa s | ||
55 | as long as the characters from | ||
56 | .Fa s | ||
57 | do not occur in string | ||
58 | .Fa charset | ||
59 | (it | ||
60 | spans the | ||
61 | .Em complement | ||
62 | of | ||
63 | .Fa charset ) . | ||
64 | .Sh RETURN VALUES | ||
65 | The | ||
66 | .Fn strcspn | ||
67 | function | ||
68 | returns the number of characters spanned. | ||
69 | .Sh SEE ALSO | ||
70 | .Xr index 3 , | ||
71 | .Xr memchr 3 , | ||
72 | .Xr rindex 3 , | ||
73 | .Xr strchr 3 , | ||
74 | .Xr strpbrk 3 , | ||
75 | .Xr strrchr 3 , | ||
76 | .Xr strsep 3 , | ||
77 | .Xr strspn 3 , | ||
78 | .Xr strstr 3 , | ||
79 | .Xr strtok 3 | ||
80 | .Sh STANDARDS | ||
81 | The | ||
82 | .Fn strcspn | ||
83 | function | ||
84 | conforms to | ||
85 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c new file mode 100644 index 0000000000..acb4d2a3af --- /dev/null +++ b/src/lib/libc/string/strcspn.c | |||
@@ -0,0 +1,68 @@ | |||
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 *sccsid = "from: @(#)strcspn.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strcspn.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Span the complement of string s2. | ||
46 | */ | ||
47 | size_t | ||
48 | strcspn(s1, s2) | ||
49 | const char *s1; | ||
50 | register const char *s2; | ||
51 | { | ||
52 | register const char *p, *spanp; | ||
53 | register char c, sc; | ||
54 | |||
55 | /* | ||
56 | * Stop as soon as we find any character from s2. Note that there | ||
57 | * must be a NUL in s2; it suffices to stop when we find that, too. | ||
58 | */ | ||
59 | for (p = s1;;) { | ||
60 | c = *p++; | ||
61 | spanp = s2; | ||
62 | do { | ||
63 | if ((sc = *spanp++) == c) | ||
64 | return (p - 1 - s1); | ||
65 | } while (sc != 0); | ||
66 | } | ||
67 | /* NOTREACHED */ | ||
68 | } | ||
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 new file mode 100644 index 0000000000..925cbf3d46 --- /dev/null +++ b/src/lib/libc/string/strdup.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 | .\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 | ||
33 | .\" $Id: strdup.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | ||
35 | .Dd April 19, 1991 | ||
36 | .Dt STRDUP 3 | ||
37 | .Os | ||
38 | .Sh NAME | ||
39 | .Nm strdup | ||
40 | .Nd save a copy of a string | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <string.h> | ||
43 | .Ft char * | ||
44 | .Fn strdup "const char *str" | ||
45 | .Sh DESCRIPTION | ||
46 | The | ||
47 | .Fn strdup | ||
48 | function | ||
49 | allocates sufficient memory for a copy | ||
50 | of the string | ||
51 | .Fa str , | ||
52 | does the copy, and returns a pointer to it. | ||
53 | The pointer may subsequently be used as an | ||
54 | argument to the function | ||
55 | .Xr free 3 . | ||
56 | .Sh SEE ALSO | ||
57 | .Xr free 3 , | ||
58 | .Xr malloc 3 , | ||
59 | .Xt strcpy 3 , | ||
60 | .Xt strlen 3 | ||
61 | .Sh HISTORY | ||
62 | The | ||
63 | .Fn strdup | ||
64 | function | ||
65 | .Ud . | ||
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c new file mode 100644 index 0000000000..27ede44110 --- /dev/null +++ b/src/lib/libc/string/strdup.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1988 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 *sccsid = "from: @(#)strdup.c 5.4 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strdup.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | |||
42 | char * | ||
43 | strdup(str) | ||
44 | const char *str; | ||
45 | { | ||
46 | size_t len; | ||
47 | char *copy; | ||
48 | |||
49 | len = strlen(str) + 1; | ||
50 | if (!(copy = malloc(len))) | ||
51 | return((char *)NULL); | ||
52 | memcpy(copy, str, len); | ||
53 | return(copy); | ||
54 | } | ||
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 new file mode 100644 index 0000000000..c9d8504dbb --- /dev/null +++ b/src/lib/libc/string/strerror.3 | |||
@@ -0,0 +1,66 @@ | |||
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 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strerror.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRERROR 3 | ||
41 | .Os BSD 4 | ||
42 | .Sh NAME | ||
43 | .Nm strerror | ||
44 | .Nd get error message string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strerror "int errnum" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strerror | ||
52 | function returns a pointer to the language-dependent error message | ||
53 | string affiliated with an error number. | ||
54 | .Pp | ||
55 | The array pointed to is not to be modified by the program, but may be | ||
56 | overwritten by subsequent calls to | ||
57 | .Fn strerror . | ||
58 | .Sh SEE ALSO | ||
59 | .Xr intro 2 , | ||
60 | .Xr perror 3 , | ||
61 | .Xr setlocale 3 | ||
62 | .Sh STANDARDS | ||
63 | The | ||
64 | .Fn strerror | ||
65 | function conforms to | ||
66 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c new file mode 100644 index 0000000000..c3f5ab5d98 --- /dev/null +++ b/src/lib/libc/string/strerror.c | |||
@@ -0,0 +1,56 @@ | |||
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 *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | ||
36 | static char *rcsid = "$Id: strerror.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <limits.h> | ||
41 | |||
42 | /* | ||
43 | * Since perror() is not allowed to change the contents of strerror()'s | ||
44 | * static buffer, both functions supply their own buffers to the | ||
45 | * internal function __strerror(). | ||
46 | */ | ||
47 | |||
48 | extern char *__strerror __P((int, char *)); | ||
49 | |||
50 | char * | ||
51 | strerror(num) | ||
52 | int num; | ||
53 | { | ||
54 | static char buf[NL_TEXTMAX]; | ||
55 | return __strerror(num, buf); | ||
56 | } | ||
diff --git a/src/lib/libc/string/strftime.3 b/src/lib/libc/string/strftime.3 new file mode 100644 index 0000000000..f14db4bb13 --- /dev/null +++ b/src/lib/libc/string/strftime.3 | |||
@@ -0,0 +1,202 @@ | |||
1 | .\" Copyright (c) 1989, 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 | .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strftime.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRFTIME 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strftime | ||
44 | .Nd format date and time | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <time.h> | ||
47 | .Ft size_t | ||
48 | .Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strftime | ||
52 | function formats the information from | ||
53 | .Fa timeptr | ||
54 | into the buffer | ||
55 | .Fa buf | ||
56 | according to the string pointed to by | ||
57 | .Fa format . | ||
58 | .Pp | ||
59 | The | ||
60 | .Fa format | ||
61 | string consists of zero or more conversion specifications and | ||
62 | ordinary characters. | ||
63 | All ordinary characters are copied directly into the buffer. | ||
64 | A conversion specification consists of a percent sign | ||
65 | .Ql % | ||
66 | and one other character. | ||
67 | .Pp | ||
68 | No more than | ||
69 | .Fa maxsize | ||
70 | characters will be placed into the array. | ||
71 | If the total number of resulting characters, including the terminating | ||
72 | null character, is not more than | ||
73 | .Fa maxsize , | ||
74 | .Fn strftime | ||
75 | returns the number of characters in the array, not counting the | ||
76 | terminating null. | ||
77 | Otherwise, zero is returned. | ||
78 | .Pp | ||
79 | Each conversion specification is replaced by the characters as | ||
80 | follows which are then copied into the buffer. | ||
81 | .Bl -tag -width "xxxx" | ||
82 | .It Cm \&%A | ||
83 | is replaced by the locale's full weekday name. | ||
84 | .It Cm %a | ||
85 | is replaced by the locale's abbreviated weekday name. | ||
86 | .It Cm \&%B | ||
87 | is replaced by the locale's full month name. | ||
88 | .It Cm \&%b No or Cm \&%h | ||
89 | is replaced by the locale's abbreviated month name. | ||
90 | .It Cm \&%C | ||
91 | is replaced by the century (a year divided by 100 and truncated to an integer) | ||
92 | as a decimal number (00-99). | ||
93 | .It Cm \&%c | ||
94 | is replaced by the locale's appropriate date and time representation. | ||
95 | .It Cm \&%D | ||
96 | is replaced by the date in the format | ||
97 | .Dq Li %m/%d/%y . | ||
98 | .It Cm \&%d | ||
99 | is replaced by the day of the month as a decimal number (01-31). | ||
100 | .It Cm \&%e | ||
101 | is replaced by the day of month as a decimal number (1-31); | ||
102 | single digits are preceded by a blank. | ||
103 | .It Cm \&%H | ||
104 | is replaced by the hour (24-hour clock) as a decimal number (00-23). | ||
105 | .It Cm \&%I | ||
106 | is replaced by the hour (12-hour clock) as a decimal number (01-12). | ||
107 | .It Cm \&%j | ||
108 | is replaced by the day of the year as a decimal number (001-366). | ||
109 | .It Cm \&%k | ||
110 | is replaced by the hour (24-hour clock) as a decimal number (0-23); | ||
111 | single digits are preceded by a blank. | ||
112 | .It Cm \&%l | ||
113 | is replaced by the hour (12-hour clock) as a decimal number (1-12); | ||
114 | single digits are preceded by a blank. | ||
115 | .It Cm \&%M | ||
116 | is replaced by the minute as a decimal number (00-59). | ||
117 | .It Cm %m | ||
118 | is replaced by the month as a decimal number (01-12). | ||
119 | .It Cm %n | ||
120 | is replaced by a newline. | ||
121 | .It Cm %p | ||
122 | is replaced by the locale's equivalent of either | ||
123 | .Dq Tn AM | ||
124 | or | ||
125 | .Dq Tn PM . | ||
126 | .It Cm \&%R | ||
127 | is replaced by the time in the format | ||
128 | .Dq Li %H:%M . | ||
129 | .It Cm \&%r | ||
130 | is replaced by the locale's representation of 12-hour clock time | ||
131 | using AM/PM notation. | ||
132 | .It Cm \&%T | ||
133 | is replaced by the time in the format | ||
134 | .Dq Li %H:%M:%S . | ||
135 | .It Cm \&%t | ||
136 | is replaced by a tab. | ||
137 | .It Cm \&%S | ||
138 | is replaced by the second as a decimal number (00-60). | ||
139 | .It Cm %s | ||
140 | is replaced by the number of seconds since the Epoch, UCT (see | ||
141 | .Xr mktime 3 ) . | ||
142 | .It Cm \&%U | ||
143 | is replaced by the week number of the year (Sunday as the first day of | ||
144 | the week) as a decimal number (00-53). | ||
145 | .It Cm \&%u | ||
146 | is replaced by the weekday (Monday as the first day of the week) | ||
147 | as a decimal number (1-7). | ||
148 | .It Cm \&%V | ||
149 | is replaced by the week number of the year (Monday as the first day of | ||
150 | the week) as a decimal number (01-53). If the week containing January | ||
151 | 1 has four or more days in the new year, then it is week 1; otherwise | ||
152 | it is week 53 of the previous year, and the next week is week 1. | ||
153 | .It Cm \&%W | ||
154 | is replaced by the week number of the year (Monday as the first day of | ||
155 | the week) as a decimal number (00-53). | ||
156 | .It Cm \&%w | ||
157 | is replaced by the weekday (Sunday as the first day of the week) | ||
158 | as a decimal number (0-6). | ||
159 | .It Cm \&%X | ||
160 | is replaced by the locale's appropriate date representation. | ||
161 | .It Cm \&%x | ||
162 | is replaced by the locale's appropriate time representation. | ||
163 | .It Cm \&%Y | ||
164 | is replaced by the year with century as a decimal number. | ||
165 | .It Cm \&%y | ||
166 | is replaced by the year without century as a decimal number (00-99). | ||
167 | .It Cm \&%Z | ||
168 | is replaced by the time zone name. | ||
169 | .It Cm %% | ||
170 | is replaced by | ||
171 | .Ql % . | ||
172 | .El | ||
173 | .Sh SEE ALSO | ||
174 | .Xr date 1 , | ||
175 | .Xr ctime 3 , | ||
176 | .Xr printf 1 , | ||
177 | .Xr printf 3 | ||
178 | .Sh STANDARDS | ||
179 | The | ||
180 | .Fn strftime | ||
181 | function | ||
182 | conforms to | ||
183 | .St -ansiC . | ||
184 | The | ||
185 | .Ql \&%C , | ||
186 | .Ql \&%D , | ||
187 | .Ql \&%e , | ||
188 | .Ql \&%h , | ||
189 | .Ql \&%k , | ||
190 | .Ql \&%l , | ||
191 | .Ql \&%n , | ||
192 | .Ql \&%r , | ||
193 | .Ql \&%R , | ||
194 | .Ql \&%s . | ||
195 | .Ql \&%t , | ||
196 | .Ql \&%T , | ||
197 | .Ql \&%u , | ||
198 | and | ||
199 | .Ql \&%V | ||
200 | conversion specifications are extensions. | ||
201 | .Sh BUGS | ||
202 | There is no conversion specification for the phase of the moon. | ||
diff --git a/src/lib/libc/string/strftime.c b/src/lib/libc/string/strftime.c new file mode 100644 index 0000000000..fffa9ecbb0 --- /dev/null +++ b/src/lib/libc/string/strftime.c | |||
@@ -0,0 +1,317 @@ | |||
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 *sccsid = "from: @(#)strftime.c 5.11 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strftime.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <sys/localedef.h> | ||
40 | #include <locale.h> | ||
41 | #include <string.h> | ||
42 | #include <tzfile.h> | ||
43 | #include <time.h> | ||
44 | |||
45 | static size_t gsize; | ||
46 | static char *pt; | ||
47 | static int _add(), _conv(), _secs(); | ||
48 | static size_t _fmt(); | ||
49 | |||
50 | size_t | ||
51 | strftime(s, maxsize, format, t) | ||
52 | char *s; | ||
53 | size_t maxsize; | ||
54 | const char *format; | ||
55 | const struct tm *t; | ||
56 | { | ||
57 | tzset(); | ||
58 | |||
59 | pt = s; | ||
60 | if ((gsize = maxsize) < 1) | ||
61 | return(0); | ||
62 | if (_fmt(format, t)) { | ||
63 | *pt = '\0'; | ||
64 | return(maxsize - gsize); | ||
65 | } | ||
66 | return(0); | ||
67 | } | ||
68 | |||
69 | #define SUN_WEEK(t) (((t)->tm_yday + 7 - \ | ||
70 | ((t)->tm_wday)) / 7) | ||
71 | #define MON_WEEK(t) (((t)->tm_yday + 7 - \ | ||
72 | ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7) | ||
73 | static size_t | ||
74 | _fmt(format, t) | ||
75 | register char *format; | ||
76 | struct tm *t; | ||
77 | { | ||
78 | for (; *format; ++format) { | ||
79 | if (*format == '%') { | ||
80 | ++format; | ||
81 | if (*format == 'E') { | ||
82 | /* Alternate Era */ | ||
83 | ++format; | ||
84 | } else if (*format == 'O') { | ||
85 | /* Alternate numeric symbols */ | ||
86 | ++format; | ||
87 | } | ||
88 | switch(*format) { | ||
89 | case '\0': | ||
90 | --format; | ||
91 | break; | ||
92 | case 'A': | ||
93 | if (t->tm_wday < 0 || t->tm_wday > 6) | ||
94 | return(0); | ||
95 | if (!_add(_CurrentTimeLocale->day[t->tm_wday])) | ||
96 | return(0); | ||
97 | continue; | ||
98 | case 'a': | ||
99 | if (t->tm_wday < 0 || t->tm_wday > 6) | ||
100 | return(0); | ||
101 | if (!_add(_CurrentTimeLocale->abday[t->tm_wday])) | ||
102 | return(0); | ||
103 | continue; | ||
104 | case 'B': | ||
105 | if (t->tm_mon < 0 || t->tm_mon > 11) | ||
106 | return(0); | ||
107 | if (!_add(_CurrentTimeLocale->mon[t->tm_mon])) | ||
108 | return(0); | ||
109 | continue; | ||
110 | case 'b': | ||
111 | case 'h': | ||
112 | if (t->tm_mon < 0 || t->tm_mon > 11) | ||
113 | return(0); | ||
114 | if (!_add(_CurrentTimeLocale->abmon[t->tm_mon])) | ||
115 | return(0); | ||
116 | continue; | ||
117 | case 'C': | ||
118 | if (!_conv((t->tm_year + TM_YEAR_BASE) / 100, | ||
119 | 2, '0')) | ||
120 | return(0); | ||
121 | continue; | ||
122 | case 'c': | ||
123 | if (!_fmt(_CurrentTimeLocale->d_t_fmt, t)) | ||
124 | return(0); | ||
125 | continue; | ||
126 | case 'D': | ||
127 | if (!_fmt("%m/%d/%y", t)) | ||
128 | return(0); | ||
129 | continue; | ||
130 | case 'd': | ||
131 | if (!_conv(t->tm_mday, 2, '0')) | ||
132 | return(0); | ||
133 | continue; | ||
134 | case 'e': | ||
135 | if (!_conv(t->tm_mday, 2, ' ')) | ||
136 | return(0); | ||
137 | continue; | ||
138 | case 'H': | ||
139 | if (!_conv(t->tm_hour, 2, '0')) | ||
140 | return(0); | ||
141 | continue; | ||
142 | case 'I': | ||
143 | if (!_conv(t->tm_hour % 12 ? | ||
144 | t->tm_hour % 12 : 12, 2, '0')) | ||
145 | return(0); | ||
146 | continue; | ||
147 | case 'j': | ||
148 | if (!_conv(t->tm_yday + 1, 3, '0')) | ||
149 | return(0); | ||
150 | continue; | ||
151 | case 'k': | ||
152 | if (!_conv(t->tm_hour, 2, ' ')) | ||
153 | return(0); | ||
154 | continue; | ||
155 | case 'l': | ||
156 | if (!_conv(t->tm_hour % 12 ? | ||
157 | t->tm_hour % 12: 12, 2, ' ')) | ||
158 | return(0); | ||
159 | continue; | ||
160 | case 'M': | ||
161 | if (!_conv(t->tm_min, 2, '0')) | ||
162 | return(0); | ||
163 | continue; | ||
164 | case 'm': | ||
165 | if (!_conv(t->tm_mon + 1, 2, '0')) | ||
166 | return(0); | ||
167 | continue; | ||
168 | case 'n': | ||
169 | if (!_add("\n")) | ||
170 | return(0); | ||
171 | continue; | ||
172 | case 'p': | ||
173 | if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour >= 12])) | ||
174 | return(0); | ||
175 | continue; | ||
176 | case 'R': | ||
177 | if (!_fmt("%H:%M", t)) | ||
178 | return(0); | ||
179 | continue; | ||
180 | case 'r': | ||
181 | if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t)) | ||
182 | return(0); | ||
183 | continue; | ||
184 | case 'S': | ||
185 | if (!_conv(t->tm_sec, 2, '0')) | ||
186 | return(0); | ||
187 | continue; | ||
188 | case 's': | ||
189 | if (!_secs(t)) | ||
190 | return(0); | ||
191 | continue; | ||
192 | case 'T': | ||
193 | if (!_fmt("%H:%M:%S", t)) | ||
194 | return(0); | ||
195 | continue; | ||
196 | case 't': | ||
197 | if (!_add("\t")) | ||
198 | return(0); | ||
199 | continue; | ||
200 | case 'U': | ||
201 | if (!_conv(SUN_WEEK(t), 2, '0')) | ||
202 | return(0); | ||
203 | continue; | ||
204 | case 'u': | ||
205 | if (!_conv(t->tm_wday ? t->tm_wday : 7, 2, '0')) | ||
206 | return(0); | ||
207 | continue; | ||
208 | case 'V': | ||
209 | { | ||
210 | /* ISO 8601 Week Of Year: | ||
211 | If the week (Monday - Sunday) containing | ||
212 | January 1 has four or more days in the new | ||
213 | year, then it is week 1; otherwise it is | ||
214 | week 53 of the previous year and the next | ||
215 | week is week one. */ | ||
216 | |||
217 | int week = MON_WEEK(t); | ||
218 | |||
219 | if (((t->tm_yday + 7 - (t->tm_wday + 1)) % 7) >= 4) { | ||
220 | week++; | ||
221 | } else if (week == 0) { | ||
222 | week = 53; | ||
223 | } | ||
224 | |||
225 | if (!_conv(week, 2, '0')) | ||
226 | return(0); | ||
227 | continue; | ||
228 | } | ||
229 | case 'W': | ||
230 | if (!_conv(MON_WEEK(t), 2, '0')) | ||
231 | return(0); | ||
232 | continue; | ||
233 | case 'w': | ||
234 | if (!_conv(t->tm_wday, 1, '0')) | ||
235 | return(0); | ||
236 | continue; | ||
237 | case 'x': | ||
238 | if (!_fmt(_CurrentTimeLocale->d_fmt, t)) | ||
239 | return(0); | ||
240 | continue; | ||
241 | case 'X': | ||
242 | if (!_fmt(_CurrentTimeLocale->t_fmt, t)) | ||
243 | return(0); | ||
244 | continue; | ||
245 | case 'y': | ||
246 | if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, | ||
247 | 2, '0')) | ||
248 | return(0); | ||
249 | continue; | ||
250 | case 'Y': | ||
251 | if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0')) | ||
252 | return(0); | ||
253 | continue; | ||
254 | case 'Z': | ||
255 | if (t->tm_zone && !_add(t->tm_zone)) | ||
256 | return(0); | ||
257 | continue; | ||
258 | case '%': | ||
259 | /* | ||
260 | * X311J/88-090 (4.12.3.5): if conversion char is | ||
261 | * undefined, behavior is undefined. Print out the | ||
262 | * character itself as printf(3) does. | ||
263 | */ | ||
264 | default: | ||
265 | break; | ||
266 | } | ||
267 | } | ||
268 | if (!gsize--) | ||
269 | return(0); | ||
270 | *pt++ = *format; | ||
271 | } | ||
272 | return(gsize); | ||
273 | } | ||
274 | |||
275 | static | ||
276 | _secs(t) | ||
277 | struct tm *t; | ||
278 | { | ||
279 | static char buf[15]; | ||
280 | register time_t s; | ||
281 | register char *p; | ||
282 | struct tm tmp; | ||
283 | |||
284 | /* Make a copy, mktime(3) modifies the tm struct. */ | ||
285 | tmp = *t; | ||
286 | s = mktime(&tmp); | ||
287 | for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10) | ||
288 | *p-- = s % 10 + '0'; | ||
289 | return(_add(++p)); | ||
290 | } | ||
291 | |||
292 | static | ||
293 | _conv(n, digits, pad) | ||
294 | int n, digits; | ||
295 | char pad; | ||
296 | { | ||
297 | static char buf[10]; | ||
298 | register char *p; | ||
299 | |||
300 | for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits) | ||
301 | *p-- = n % 10 + '0'; | ||
302 | while (p > buf && digits-- > 0) | ||
303 | *p-- = pad; | ||
304 | return(_add(++p)); | ||
305 | } | ||
306 | |||
307 | static | ||
308 | _add(str) | ||
309 | register char *str; | ||
310 | { | ||
311 | for (;; ++pt, --gsize) { | ||
312 | if (!gsize) | ||
313 | return(0); | ||
314 | if (!(*pt = *str++)) | ||
315 | return(1); | ||
316 | } | ||
317 | } | ||
diff --git a/src/lib/libc/string/string.3 b/src/lib/libc/string/string.3 new file mode 100644 index 0000000000..aaf97e0321 --- /dev/null +++ b/src/lib/libc/string/string.3 | |||
@@ -0,0 +1,156 @@ | |||
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 | .\" from: @(#)string.3 6.9 (Berkeley) 4/19/91 | ||
35 | .\" $Id: string.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt STRING 3 | ||
39 | .Os BSD 4 | ||
40 | .Sh NAME | ||
41 | .Nm strcat , | ||
42 | .Nm strncat , | ||
43 | .Nm strchr , | ||
44 | .Nm strrchr , | ||
45 | .Nm strcmp , | ||
46 | .Nm strncmp , | ||
47 | .Nm strcasecmp, | ||
48 | .Nm strncasecmp , | ||
49 | .Nm strcpy , | ||
50 | .Nm strncpy , | ||
51 | .Nm strerror , | ||
52 | .Nm strlen , | ||
53 | .Nm strpbrk , | ||
54 | .Nm strsep, | ||
55 | .Nm strspn , | ||
56 | .Nm strcspn , | ||
57 | .Nm strstr , | ||
58 | .Nm strtok , | ||
59 | .Nm index , | ||
60 | .Nm rindex | ||
61 | .Nd string specific functions | ||
62 | .Sh SYNOPSIS | ||
63 | .Fd #include <string.h> | ||
64 | .Ft char * | ||
65 | .Fn strcat "char *s" "const char * append" | ||
66 | .Ft char * | ||
67 | .Fn strncat "char *s" "const char *append" "size_t count" | ||
68 | .Ft char * | ||
69 | .Fn strchr "const char *s" "int c" | ||
70 | .Ft char * | ||
71 | .Fn strrchr "const char *s" "int c" | ||
72 | .Ft int | ||
73 | .Fn strcmp "const char *s1" "const char *s2" | ||
74 | .Ft int | ||
75 | .Fn strncmp "const char *s1" "const char *s2" "size_t count" | ||
76 | .Ft int | ||
77 | .Fn strcasecmp "const char *s1" "const char *s2" | ||
78 | .Ft int | ||
79 | .Fn strncasecmp "const char *s1" "const char *s2" "size_t count" | ||
80 | .Ft char * | ||
81 | .Fn strcpy "char *dst" "const char *src" | ||
82 | .Ft char * | ||
83 | .Fn strncpy "char *dst" "const char *src" "size_t count" | ||
84 | .Ft char * | ||
85 | .Fn strerror "int errno" | ||
86 | .Ft size_t | ||
87 | .Fn strlen "const char *s" | ||
88 | .Ft char * | ||
89 | .Fn strpbrk "const char *s" "const char *charset" | ||
90 | .Ft char * | ||
91 | .Fn strsep "char **stringp" "const char *delim" | ||
92 | .Ft size_t | ||
93 | .Fn strspn "const char *s" "const char *charset" | ||
94 | .Ft size_t | ||
95 | .Fn strcspn "const char *s" "const char *charset" | ||
96 | .Ft char * | ||
97 | .Fn strstr "const char *big" "const char *little" | ||
98 | .Ft char * | ||
99 | .Fn strtok "char *s" "const char *delim" | ||
100 | .Ft char * | ||
101 | .Fn index "const char *s" "int c" | ||
102 | .Ft char * | ||
103 | .Fn rindex "const char *s" "int c" | ||
104 | .Sh DESCRIPTION | ||
105 | The string functions | ||
106 | functions manipulate strings terminated by a | ||
107 | null byte. | ||
108 | .Pp | ||
109 | See the specific manual pages for more information. | ||
110 | For manipulating variable length generic objects as byte | ||
111 | strings (without the null byte check), see | ||
112 | .Xr bstring 3 . | ||
113 | .Pp | ||
114 | Except as noted in their specific manual pages, | ||
115 | the string functions do not test the destination | ||
116 | for size limitations. | ||
117 | .Sh SEE ALSO | ||
118 | .Xr index 3 , | ||
119 | .Xr strcat 3 , | ||
120 | .Xr strchr 3 , | ||
121 | .Xr strrchr 3 , | ||
122 | .Xr strcmp 3 , | ||
123 | .Xr strcasecmp 3 , | ||
124 | .Xr strcpy 3 , | ||
125 | .Xr strerror 3 , | ||
126 | .Xr strlen 3 , | ||
127 | .Xr strpbrk 3 , | ||
128 | .Xr strsep 3 , | ||
129 | .Xr strspn 3 , | ||
130 | .Xr strcspn 3 , | ||
131 | .Xr strstr 3 , | ||
132 | .Xr strtok 3 , | ||
133 | .Xr rindex 3 | ||
134 | .Xr bstring 3 | ||
135 | .Sh STANDARDS | ||
136 | The | ||
137 | .Fn strcat , | ||
138 | .Fn strncat , | ||
139 | .Fn strchr , | ||
140 | .Fn strrchr , | ||
141 | .Fn strcmp , | ||
142 | .Fn strncmp , | ||
143 | .Fn strcpy , | ||
144 | .Fn strncpy , | ||
145 | .Fn strerror , | ||
146 | .Fn strlen , | ||
147 | .Fn strpbrk , | ||
148 | .Fn strsep , | ||
149 | .Fn strspn , | ||
150 | .Fn strcspn , | ||
151 | .Fn strstr , | ||
152 | and | ||
153 | .Fn strtok | ||
154 | functions | ||
155 | conform to | ||
156 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 new file mode 100644 index 0000000000..f4aff363ee --- /dev/null +++ b/src/lib/libc/string/strlen.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 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 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRLEN 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strlen | ||
44 | .Nd find length of string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft size_t | ||
48 | .Fn strlen "const char *s" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strlen | ||
52 | function | ||
53 | computes the length of the string | ||
54 | .Fa s . | ||
55 | .Sh RETURN VALUES | ||
56 | The | ||
57 | .Fn strlen | ||
58 | function | ||
59 | returns | ||
60 | the number of characters that precede the | ||
61 | terminating | ||
62 | .Dv NUL | ||
63 | character. | ||
64 | .Sh SEE ALSO | ||
65 | .Xr string 3 | ||
66 | .Sh STANDARDS | ||
67 | The | ||
68 | .Fn strlen | ||
69 | function | ||
70 | conforms to | ||
71 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c new file mode 100644 index 0000000000..d23aadafc0 --- /dev/null +++ b/src/lib/libc/string/strlen.c | |||
@@ -0,0 +1,50 @@ | |||
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 *sccsid = "from: @(#)strlen.c 5.5 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strlen.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | size_t | ||
42 | strlen(str) | ||
43 | const char *str; | ||
44 | { | ||
45 | register const char *s; | ||
46 | |||
47 | for (s = str; *s; ++s); | ||
48 | return(s - str); | ||
49 | } | ||
50 | |||
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3 new file mode 100644 index 0000000000..1907e7ab03 --- /dev/null +++ b/src/lib/libc/string/strmode.3 | |||
@@ -0,0 +1,149 @@ | |||
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 | .\" from: @(#)strmode.3 5.4 (Berkeley) 7/31/91 | ||
33 | .\" $Id: strmode.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | ||
35 | .Dd July 31, 1991 | ||
36 | .Dt STRMODE 3 | ||
37 | .Os | ||
38 | .Sh NAME | ||
39 | .Nm strmode | ||
40 | .Nd convert inode status information into a symbolic string | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <string.h> | ||
43 | .Ft void | ||
44 | .Fn strmode "mode_t mode" "char *bp" | ||
45 | .Sh DESCRIPTION | ||
46 | The | ||
47 | .Fn strmode | ||
48 | function | ||
49 | converts a file | ||
50 | .Fa mode | ||
51 | (the type and permission information associated with an inode, see | ||
52 | .Xr stat 2 ) | ||
53 | into a symbolic string which is stored in the location referenced by | ||
54 | .Fa bp . | ||
55 | This stored string is eleven characters in length plus a trailing | ||
56 | .Dv NULL . | ||
57 | .Pp | ||
58 | The first character is the inode type, and will be one of the following: | ||
59 | .Pp | ||
60 | .Bl -tag -width flag -offset indent -compact | ||
61 | .It \- | ||
62 | regular file | ||
63 | .It b | ||
64 | block special | ||
65 | .It c | ||
66 | character special | ||
67 | .It d | ||
68 | directory | ||
69 | .It l | ||
70 | symbolic link | ||
71 | .It p | ||
72 | fifo | ||
73 | .It s | ||
74 | socket | ||
75 | .It ? | ||
76 | unknown inode type | ||
77 | .El | ||
78 | .Pp | ||
79 | The next nine characters encode three sets of permissions, in three | ||
80 | characters each. | ||
81 | The first three characters are the permissions for the owner of the | ||
82 | file, the second three for the group the file belongs to, and the | ||
83 | third for the ``other'', or default, set of users. | ||
84 | .Pp | ||
85 | Permission checking is done as specifically as possible. | ||
86 | If read permission is denied to the owner of a file in the first set | ||
87 | of permissions, the owner of the file will not be able to read the file. | ||
88 | This is true even if the owner is in the file's group and the group | ||
89 | permissions allow reading or the ``other'' permissions allow reading. | ||
90 | .Pp | ||
91 | If the first character of the three character set is an ``r'', the file is | ||
92 | readable for that set of users; if a dash ``\-'', it is not readable. | ||
93 | .Pp | ||
94 | If the second character of the three character set is a ``w'', the file is | ||
95 | writable for that set of users; if a dash ``\-'', it is not writable. | ||
96 | .Pp | ||
97 | The third character is the first of the following characters that apply: | ||
98 | .Bl -tag -width xxxx | ||
99 | .It S | ||
100 | If the character is part of the owner permissions and the file is not | ||
101 | executable or the directory is not searchable, by the owner, and the | ||
102 | set-user-id bit is set. | ||
103 | .It S | ||
104 | If the character is part of the group permissions and the file is not | ||
105 | executable or the directory is not searchable, by the group, and the | ||
106 | set-group-id bit is set. | ||
107 | .It T | ||
108 | If the character is part of the other permissions and the file is not | ||
109 | executable or the directory is not searchable, by others, and the ``sticky'' | ||
110 | .Pq Dv S_ISVTX | ||
111 | bit is set. | ||
112 | .It s | ||
113 | If the character is part of the owner permissions and the file is | ||
114 | executable or the directory searchable, by the owner, and the set-user-id | ||
115 | bit is set. | ||
116 | .It s | ||
117 | If the character is part of the group permissions and the file is | ||
118 | executable or the directory searchable, by the group, and the set-group-id | ||
119 | bit is set. | ||
120 | .It t | ||
121 | If the character is part of the other permissions and the file is | ||
122 | executable or the directory searchable, by others, and the ``sticky'' | ||
123 | .Pq Dv S_ISVTX | ||
124 | bit is set. | ||
125 | .It x | ||
126 | The file is executable or the directory is searchable. | ||
127 | .It \- | ||
128 | None of the above apply. | ||
129 | .El | ||
130 | .Pp | ||
131 | The last character is a plus sign ``+'' if any there are any alternate | ||
132 | or additional access control methods associated with the inode, otherwise | ||
133 | it will be a space. | ||
134 | .Sh RETURN VALUES | ||
135 | The | ||
136 | .Fn strmode | ||
137 | function | ||
138 | always returns 0. | ||
139 | .Sh SEE ALSO | ||
140 | .Xr chmod 1 , | ||
141 | .Xr find 1 , | ||
142 | .Xr stat 2 , | ||
143 | .Xr getmode 3 , | ||
144 | .Xr setmode 3 | ||
145 | .Sh HISTORY | ||
146 | The | ||
147 | .Fn strmode | ||
148 | function | ||
149 | .Ud . | ||
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c new file mode 100644 index 0000000000..441fc76e90 --- /dev/null +++ b/src/lib/libc/string/strmode.c | |||
@@ -0,0 +1,148 @@ | |||
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 *sccsid = "from: @(#)strmode.c 5.3 (Berkeley) 5/18/90";*/ | ||
36 | static char *rcsid = "$Id: strmode.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <sys/types.h> | ||
40 | #include <sys/stat.h> | ||
41 | #include <string.h> | ||
42 | |||
43 | void | ||
44 | strmode(mode, p) | ||
45 | register mode_t mode; | ||
46 | register char *p; | ||
47 | { | ||
48 | /* print type */ | ||
49 | switch (mode & S_IFMT) { | ||
50 | case S_IFDIR: /* directory */ | ||
51 | *p++ = 'd'; | ||
52 | break; | ||
53 | case S_IFCHR: /* character special */ | ||
54 | *p++ = 'c'; | ||
55 | break; | ||
56 | case S_IFBLK: /* block special */ | ||
57 | *p++ = 'b'; | ||
58 | break; | ||
59 | case S_IFREG: /* regular */ | ||
60 | *p++ = '-'; | ||
61 | break; | ||
62 | case S_IFLNK: /* symbolic link */ | ||
63 | *p++ = 'l'; | ||
64 | break; | ||
65 | case S_IFSOCK: /* socket */ | ||
66 | *p++ = 's'; | ||
67 | break; | ||
68 | #ifdef S_IFIFO | ||
69 | case S_IFIFO: /* fifo */ | ||
70 | *p++ = 'p'; | ||
71 | break; | ||
72 | #endif | ||
73 | default: /* unknown */ | ||
74 | *p++ = '?'; | ||
75 | break; | ||
76 | } | ||
77 | /* usr */ | ||
78 | if (mode & S_IRUSR) | ||
79 | *p++ = 'r'; | ||
80 | else | ||
81 | *p++ = '-'; | ||
82 | if (mode & S_IWUSR) | ||
83 | *p++ = 'w'; | ||
84 | else | ||
85 | *p++ = '-'; | ||
86 | switch (mode & (S_IXUSR | S_ISUID)) { | ||
87 | case 0: | ||
88 | *p++ = '-'; | ||
89 | break; | ||
90 | case S_IXUSR: | ||
91 | *p++ = 'x'; | ||
92 | break; | ||
93 | case S_ISUID: | ||
94 | *p++ = 'S'; | ||
95 | break; | ||
96 | case S_IXUSR | S_ISUID: | ||
97 | *p++ = 's'; | ||
98 | break; | ||
99 | } | ||
100 | /* group */ | ||
101 | if (mode & S_IRGRP) | ||
102 | *p++ = 'r'; | ||
103 | else | ||
104 | *p++ = '-'; | ||
105 | if (mode & S_IWGRP) | ||
106 | *p++ = 'w'; | ||
107 | else | ||
108 | *p++ = '-'; | ||
109 | switch (mode & (S_IXGRP | S_ISGID)) { | ||
110 | case 0: | ||
111 | *p++ = '-'; | ||
112 | break; | ||
113 | case S_IXGRP: | ||
114 | *p++ = 'x'; | ||
115 | break; | ||
116 | case S_ISGID: | ||
117 | *p++ = 'S'; | ||
118 | break; | ||
119 | case S_IXGRP | S_ISGID: | ||
120 | *p++ = 's'; | ||
121 | break; | ||
122 | } | ||
123 | /* other */ | ||
124 | if (mode & S_IROTH) | ||
125 | *p++ = 'r'; | ||
126 | else | ||
127 | *p++ = '-'; | ||
128 | if (mode & S_IWOTH) | ||
129 | *p++ = 'w'; | ||
130 | else | ||
131 | *p++ = '-'; | ||
132 | switch (mode & (S_IXOTH | S_ISVTX)) { | ||
133 | case 0: | ||
134 | *p++ = '-'; | ||
135 | break; | ||
136 | case S_IXOTH: | ||
137 | *p++ = 'x'; | ||
138 | break; | ||
139 | case S_ISVTX: | ||
140 | *p++ = 'T'; | ||
141 | break; | ||
142 | case S_IXOTH | S_ISVTX: | ||
143 | *p++ = 't'; | ||
144 | break; | ||
145 | } | ||
146 | *p++ = ' '; /* will be a '+' if ACL's implemented */ | ||
147 | *p = '\0'; | ||
148 | } | ||
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c new file mode 100644 index 0000000000..3d96452af4 --- /dev/null +++ b/src/lib/libc/string/strncat.c | |||
@@ -0,0 +1,68 @@ | |||
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 *sccsid = "from: @(#)strncat.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strncat.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes | ||
46 | * are written at dst (at most n+1 bytes being appended). Return dst. | ||
47 | */ | ||
48 | char * | ||
49 | strncat(dst, src, n) | ||
50 | char *dst; | ||
51 | const char *src; | ||
52 | register size_t n; | ||
53 | { | ||
54 | if (n != 0) { | ||
55 | register char *d = dst; | ||
56 | register const char *s = src; | ||
57 | |||
58 | while (*d != 0) | ||
59 | d++; | ||
60 | do { | ||
61 | if ((*d = *s++) == 0) | ||
62 | break; | ||
63 | d++; | ||
64 | } while (--n != 0); | ||
65 | *d = 0; | ||
66 | } | ||
67 | return (dst); | ||
68 | } | ||
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c new file mode 100644 index 0000000000..0638d4dcf2 --- /dev/null +++ b/src/lib/libc/string/strncmp.c | |||
@@ -0,0 +1,56 @@ | |||
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 *sccsid = "from: @(#)strncmp.c 5.6 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strncmp.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | int | ||
42 | strncmp(s1, s2, n) | ||
43 | register const char *s1, *s2; | ||
44 | register size_t n; | ||
45 | { | ||
46 | |||
47 | if (n == 0) | ||
48 | return (0); | ||
49 | do { | ||
50 | if (*s1 != *s2++) | ||
51 | return (*(unsigned char *)s1 - *(unsigned char *)--s2); | ||
52 | if (*s1++ == 0) | ||
53 | break; | ||
54 | } while (--n != 0); | ||
55 | return (0); | ||
56 | } | ||
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c new file mode 100644 index 0000000000..5215311b75 --- /dev/null +++ b/src/lib/libc/string/strncpy.c | |||
@@ -0,0 +1,68 @@ | |||
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 *sccsid = "from: @(#)strncpy.c 5.6 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strncpy.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Copy src to dst, truncating or null-padding to always copy n bytes. | ||
46 | * Return dst. | ||
47 | */ | ||
48 | char * | ||
49 | strncpy(dst, src, n) | ||
50 | char *dst; | ||
51 | const char *src; | ||
52 | register size_t n; | ||
53 | { | ||
54 | if (n != 0) { | ||
55 | register char *d = dst; | ||
56 | register const char *s = src; | ||
57 | |||
58 | do { | ||
59 | if ((*d++ = *s++) == 0) { | ||
60 | /* NUL pad the remaining n-1 bytes */ | ||
61 | while (--n != 0) | ||
62 | *d++ = 0; | ||
63 | break; | ||
64 | } | ||
65 | } while (--n != 0); | ||
66 | } | ||
67 | return (dst); | ||
68 | } | ||
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 new file mode 100644 index 0000000000..8578546c05 --- /dev/null +++ b/src/lib/libc/string/strpbrk.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 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 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRPBRK 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strpbrk | ||
44 | .Nd locate multiple characters in string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strpbrk "const char *s" "const char *charset" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strpbrk | ||
52 | function | ||
53 | locates in the null-terminated string | ||
54 | .Fa s | ||
55 | the first occurrence of any character in the string | ||
56 | .Fa charset | ||
57 | and returns a pointer to this character. | ||
58 | If no characters from | ||
59 | .Fa charset | ||
60 | occur anywhere in | ||
61 | .Fa s | ||
62 | .Fn strpbrk | ||
63 | returns NULL. | ||
64 | .Sh SEE ALSO | ||
65 | .Xr index 3 , | ||
66 | .Xr memchr 3 , | ||
67 | .Xr rindex 3 , | ||
68 | .Xr strchr 3 , | ||
69 | .Xr strcspn 3 , | ||
70 | .Xr strrchr 3 , | ||
71 | .Xr strsep 3 , | ||
72 | .Xr strspn 3 , | ||
73 | .Xr strstr 3 , | ||
74 | .Xr strtok 3 | ||
75 | .Sh STANDARDS | ||
76 | The | ||
77 | .Fn strpbrk | ||
78 | function | ||
79 | conforms to | ||
80 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c new file mode 100644 index 0000000000..f1d542a525 --- /dev/null +++ b/src/lib/libc/string/strpbrk.c | |||
@@ -0,0 +1,57 @@ | |||
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 *sccsid = "from: @(#)strpbrk.c 5.8 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strpbrk.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * Find the first occurrence in s1 of a character in s2 (excluding NUL). | ||
43 | */ | ||
44 | char * | ||
45 | strpbrk(s1, s2) | ||
46 | register const char *s1, *s2; | ||
47 | { | ||
48 | register const char *scanp; | ||
49 | register int c, sc; | ||
50 | |||
51 | while ((c = *s1++) != 0) { | ||
52 | for (scanp = s2; (sc = *scanp++) != 0;) | ||
53 | if (sc == c) | ||
54 | return ((char *)(s1 - 1)); | ||
55 | } | ||
56 | return (NULL); | ||
57 | } | ||
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3 new file mode 100644 index 0000000000..1d98cbff24 --- /dev/null +++ b/src/lib/libc/string/strrchr.3 | |||
@@ -0,0 +1,91 @@ | |||
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 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRRCHR 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strrchr | ||
44 | .Nd locate character in string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strrchr "const char *s" "int c" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strrchr | ||
52 | function | ||
53 | locates the last occurrence of | ||
54 | .Fa c | ||
55 | (converted to a char) | ||
56 | in the string | ||
57 | .Fa s . | ||
58 | If | ||
59 | .Fa c | ||
60 | is | ||
61 | .Ql \e0 , | ||
62 | .Fn strrchr | ||
63 | locates the terminating | ||
64 | .Ql \e0 . | ||
65 | .Sh RETURN VALUES | ||
66 | The | ||
67 | .Fn strrchr | ||
68 | function | ||
69 | returns a pointer to the character, | ||
70 | or a null | ||
71 | pointer if | ||
72 | .Fa c | ||
73 | does not occur anywhere in | ||
74 | .Fa s . | ||
75 | .Sh SEE ALSO | ||
76 | .Xr index 3 , | ||
77 | .Xr memchr 3 , | ||
78 | .Xr rindex 3 , | ||
79 | .Xr strchr 3 , | ||
80 | .Xr strcspn 3 , | ||
81 | .Xr strpbrk 3 , | ||
82 | .Xr strsep 3 , | ||
83 | .Xr strspn 3 , | ||
84 | .Xr strstr 3 , | ||
85 | .Xr strtok 3 | ||
86 | .Sh STANDARDS | ||
87 | The | ||
88 | .Fn strrchr | ||
89 | function | ||
90 | conforms to | ||
91 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 new file mode 100644 index 0000000000..21aa7376f2 --- /dev/null +++ b/src/lib/libc/string/strsep.3 | |||
@@ -0,0 +1,92 @@ | |||
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 | .\" from: @(#)strsep.3 5.3 (Berkeley) 4/19/91 | ||
35 | .\" $Id: strsep.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt STRSEP 3 | ||
39 | .Os | ||
40 | .Sh NAME | ||
41 | .Nm strsep | ||
42 | .Nd separate strings | ||
43 | .Sh SYNOPSIS | ||
44 | .Fd #include <string.h> | ||
45 | .Ft char * | ||
46 | .Fn strsep "char **stringp" "char *delim" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn strsep | ||
50 | locates in the null-terminated string at | ||
51 | .Fa *stringp | ||
52 | the first occurrence of any character in | ||
53 | .Fa delim | ||
54 | and replaces this with a | ||
55 | .Ql \e0 , | ||
56 | records the location of the immediate following character in | ||
57 | .Fa *stringp , | ||
58 | then returns the original value of | ||
59 | .Fa *stringp . | ||
60 | If no delimiter characters are found, | ||
61 | .Fn strsep | ||
62 | sets | ||
63 | .Fa *stringp | ||
64 | to | ||
65 | .Dv NULL ; | ||
66 | if | ||
67 | .Fa *stringp | ||
68 | is initially | ||
69 | .Dv NULL , | ||
70 | .Fn strsep | ||
71 | returns | ||
72 | .Dv NULL . | ||
73 | .Sh EXAMPLES | ||
74 | The following uses | ||
75 | .Fn strsep | ||
76 | to parse strings containing runs of white space, | ||
77 | making up an argument vector: | ||
78 | .Bd -literal -offset indent | ||
79 | char inputstring[100]; | ||
80 | char **argv[51], **ap = argv, *p, *val; | ||
81 | /* set up inputstring */ | ||
82 | for (p = inputstring; p != NULL; ) { | ||
83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | ||
84 | *ap++ = val; | ||
85 | } | ||
86 | *ap = 0; | ||
87 | .Ed | ||
88 | .Sh HISTORY | ||
89 | The | ||
90 | .Fn strsep | ||
91 | function is | ||
92 | .Ud . | ||
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c new file mode 100644 index 0000000000..69be7fe046 --- /dev/null +++ b/src/lib/libc/string/strsep.c | |||
@@ -0,0 +1,79 @@ | |||
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 const char sccsid[] = "from: @(#)strsep.c 5.4 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * Get next token from string *stringp, where tokens are nonempty | ||
43 | * strings separated by characters from delim. | ||
44 | * | ||
45 | * Writes NULs into the string at *stringp to end tokens. | ||
46 | * delim need not remain constant from call to call. | ||
47 | * On return, *stringp points past the last NUL written (if there might | ||
48 | * be further tokens), or is NULL (if there are definitely no more tokens). | ||
49 | * | ||
50 | * If *stringp is NULL, strtoken returns NULL. | ||
51 | */ | ||
52 | char * | ||
53 | strsep(stringp, delim) | ||
54 | register char **stringp; | ||
55 | register const char *delim; | ||
56 | { | ||
57 | register char *s; | ||
58 | register const char *spanp; | ||
59 | register int c, sc; | ||
60 | char *tok; | ||
61 | |||
62 | if ((s = *stringp) == NULL) | ||
63 | return (NULL); | ||
64 | for (tok = s;;) { | ||
65 | c = *s++; | ||
66 | spanp = delim; | ||
67 | do { | ||
68 | if ((sc = *spanp++) == c) { | ||
69 | if (c == 0) | ||
70 | s = NULL; | ||
71 | else | ||
72 | s[-1] = 0; | ||
73 | *stringp = s; | ||
74 | return (tok); | ||
75 | } | ||
76 | } while (sc != 0); | ||
77 | } | ||
78 | /* NOTREACHED */ | ||
79 | } | ||
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3 new file mode 100644 index 0000000000..3287fef53e --- /dev/null +++ b/src/lib/libc/string/strsignal.3 | |||
@@ -0,0 +1,61 @@ | |||
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 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strsignal.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRSIGNAL 3 | ||
41 | .Os BSD 4 | ||
42 | .Sh NAME | ||
43 | .Nm strsignal | ||
44 | .Nd get signal description string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strsignal "int sig" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strsignal | ||
52 | function returns a pointer to the language-dependent string describing | ||
53 | a signal. | ||
54 | .Pp | ||
55 | The array pointed to is not to be modified by the program, but may be | ||
56 | overwritten by subsequent calls to | ||
57 | .Fn strsignal . | ||
58 | .Sh SEE ALSO | ||
59 | .Xr intro 2 , | ||
60 | .Xr psignal 3 , | ||
61 | .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..ec4a267edf --- /dev/null +++ b/src/lib/libc/string/strsignal.c | |||
@@ -0,0 +1,50 @@ | |||
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 *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | ||
36 | static char *rcsid = "$Id: strsignal.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <limits.h> | ||
41 | |||
42 | extern char *__strsignal __P((int, char *)); | ||
43 | |||
44 | char * | ||
45 | strsignal(sig) | ||
46 | int sig; | ||
47 | { | ||
48 | static char buf[NL_TEXTMAX]; | ||
49 | return __strsignal(sig, buf); | ||
50 | } | ||
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3 new file mode 100644 index 0000000000..4de03aa58b --- /dev/null +++ b/src/lib/libc/string/strspn.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 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 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRSPN 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strspn | ||
44 | .Nd span a string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft size_t | ||
48 | .Fn strspn "const char *s" "const char *charset" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Xr strcspn | ||
52 | function | ||
53 | spans the initial part of the null-terminated string | ||
54 | .Fa s | ||
55 | as long as the characters from | ||
56 | .Fa s | ||
57 | occur in string | ||
58 | .Fa charset . | ||
59 | .Sh RETURN VALUES | ||
60 | The | ||
61 | .Fn strspn | ||
62 | function | ||
63 | returns the number of characters spanned. | ||
64 | .Sh SEE ALSO | ||
65 | .Xr index 3 , | ||
66 | .Xr memchr 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 strstr 3 , | ||
74 | .Xr strtok 3 | ||
75 | .Sh STANDARDS | ||
76 | The | ||
77 | .Fn strspn | ||
78 | function | ||
79 | conforms to | ||
80 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c new file mode 100644 index 0000000000..6224b25c2a --- /dev/null +++ b/src/lib/libc/string/strspn.c | |||
@@ -0,0 +1,61 @@ | |||
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 *sccsid = "from: @(#)strspn.c 5.8 (Berkeley) 1/26/91";*/ | ||
36 | static char *rcsid = "$Id: strspn.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | /* | ||
42 | * Span the string s2 (skip characters that are in s2). | ||
43 | */ | ||
44 | size_t | ||
45 | strspn(s1, s2) | ||
46 | const char *s1; | ||
47 | register const char *s2; | ||
48 | { | ||
49 | register const char *p = s1, *spanp; | ||
50 | register char c, sc; | ||
51 | |||
52 | /* | ||
53 | * Skip any characters in s2, excluding the terminating \0. | ||
54 | */ | ||
55 | cont: | ||
56 | c = *p++; | ||
57 | for (spanp = s2; (sc = *spanp++) != 0;) | ||
58 | if (sc == c) | ||
59 | goto cont; | ||
60 | return (p - 1 - s1); | ||
61 | } | ||
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3 new file mode 100644 index 0000000000..24fdf540ed --- /dev/null +++ b/src/lib/libc/string/strstr.3 | |||
@@ -0,0 +1,89 @@ | |||
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 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRSTR 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strstr | ||
44 | .Nd locate a substring in a string | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft char * | ||
48 | .Fn strstr "const char *big" "const char *little" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strstr | ||
52 | function | ||
53 | locates the first occurrence of the null-terminated string | ||
54 | .Fa little | ||
55 | in the null-terminated string | ||
56 | .Fa big . | ||
57 | If | ||
58 | .Fa little | ||
59 | is the empty string, | ||
60 | .Fn strstr | ||
61 | returns | ||
62 | .Fa big ; | ||
63 | if | ||
64 | .Fa little | ||
65 | occurs nowhere in | ||
66 | .Fa big , | ||
67 | .Fn strstr | ||
68 | returns NULL; | ||
69 | otherwise | ||
70 | .Fn strstr | ||
71 | returns a pointer to the first character of the first occurrence of | ||
72 | .Fa little . | ||
73 | .Sh SEE ALSO | ||
74 | .Xr index 3 , | ||
75 | .Xr memchr 3 , | ||
76 | .Xr rindex 3 , | ||
77 | .Xr strchr 3 , | ||
78 | .Xr strcspn 3 , | ||
79 | .Xr strpbrk 3 , | ||
80 | .Xr strrchr 3 , | ||
81 | .Xr strsep 3 , | ||
82 | .Xr strspn 3 , | ||
83 | .Xr strtok 3 | ||
84 | .Sh STANDARDS | ||
85 | The | ||
86 | .Fn strstr | ||
87 | function | ||
88 | conforms to | ||
89 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c new file mode 100644 index 0000000000..1ed59e357b --- /dev/null +++ b/src/lib/libc/string/strstr.c | |||
@@ -0,0 +1,65 @@ | |||
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 *sccsid = "from: @(#)strstr.c 5.2 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strstr.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Find the first occurrence of find in s. | ||
46 | */ | ||
47 | char * | ||
48 | strstr(s, find) | ||
49 | register const char *s, *find; | ||
50 | { | ||
51 | register char c, sc; | ||
52 | register size_t len; | ||
53 | |||
54 | if ((c = *find++) != 0) { | ||
55 | len = strlen(find); | ||
56 | do { | ||
57 | do { | ||
58 | if ((sc = *s++) == 0) | ||
59 | return (NULL); | ||
60 | } while (sc != c); | ||
61 | } while (strncmp(s, find, len) != 0); | ||
62 | s--; | ||
63 | } | ||
64 | return ((char *)s); | ||
65 | } | ||
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 new file mode 100644 index 0000000000..644bd10aed --- /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 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRTOK 3 | ||
41 | .Os BSD 3 | ||
42 | .Sh NAME | ||
43 | .Nm strtok , | ||
44 | .Nm strsep | ||
45 | .Nd string token operations | ||
46 | .Sh SYNOPSIS | ||
47 | .Fd #include <string.h> | ||
48 | .Ft char * | ||
49 | .Fn strtok "char *str" "const char *sep" | ||
50 | .Sh DESCRIPTION | ||
51 | .Bf -symbolic | ||
52 | This interface is obsoleted by 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..9f712579bf --- /dev/null +++ b/src/lib/libc/string/strtok.c | |||
@@ -0,0 +1,90 @@ | |||
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 *sccsid = "from: @(#)strtok.c 5.8 (Berkeley) 2/24/91";*/ | ||
36 | static char *rcsid = "$Id: strtok.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <string.h> | ||
40 | |||
41 | char * | ||
42 | strtok(s, delim) | ||
43 | register char *s; | ||
44 | register const char *delim; | ||
45 | { | ||
46 | register char *spanp; | ||
47 | register int c, sc; | ||
48 | char *tok; | ||
49 | static char *last; | ||
50 | |||
51 | |||
52 | if (s == NULL && (s = last) == NULL) | ||
53 | return (NULL); | ||
54 | |||
55 | /* | ||
56 | * Skip (span) leading delimiters (s += strspn(s, delim), sort of). | ||
57 | */ | ||
58 | cont: | ||
59 | c = *s++; | ||
60 | for (spanp = (char *)delim; (sc = *spanp++) != 0;) { | ||
61 | if (c == sc) | ||
62 | goto cont; | ||
63 | } | ||
64 | |||
65 | if (c == 0) { /* no non-delimiter characters */ | ||
66 | last = NULL; | ||
67 | return (NULL); | ||
68 | } | ||
69 | tok = s - 1; | ||
70 | |||
71 | /* | ||
72 | * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). | ||
73 | * Note that delim must have one NUL; we stop if we see that, too. | ||
74 | */ | ||
75 | for (;;) { | ||
76 | c = *s++; | ||
77 | spanp = (char *)delim; | ||
78 | do { | ||
79 | if ((sc = *spanp++) == c) { | ||
80 | if (c == 0) | ||
81 | s = NULL; | ||
82 | else | ||
83 | s[-1] = 0; | ||
84 | last = s; | ||
85 | return (tok); | ||
86 | } | ||
87 | } while (sc != 0); | ||
88 | } | ||
89 | /* NOTREACHED */ | ||
90 | } | ||
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3 new file mode 100644 index 0000000000..84fd945472 --- /dev/null +++ b/src/lib/libc/string/strxfrm.3 | |||
@@ -0,0 +1,69 @@ | |||
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 | .\" from: @(#)strxfrm.3 5.4 (Berkeley) 6/29/91 | ||
37 | .\" $Id: strxfrm.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRXFRM 3 | ||
41 | .Os | ||
42 | .Sh NAME | ||
43 | .Nm strxfrm | ||
44 | .Nd transform a string under locale | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <string.h> | ||
47 | .Ft size_t | ||
48 | .Fn strxfrm "char *dst" "const char *src" "size_t n" | ||
49 | .Sh DESCRIPTION | ||
50 | The | ||
51 | .Fn strxfrm | ||
52 | function | ||
53 | does something horrible (see | ||
54 | .Tn ANSI | ||
55 | standard). | ||
56 | In this implementation it just copies. | ||
57 | .Sh SEE ALSO | ||
58 | .Xr bcmp 3 , | ||
59 | .Xr memcmp 3 , | ||
60 | .\" .Xr setlocale 3 , | ||
61 | .Xr strcasecmp 3 , | ||
62 | .Xr strcmp 3 , | ||
63 | .Xr strcoll 3 | ||
64 | .Sh STANDARDS | ||
65 | The | ||
66 | .Fn strxfrm | ||
67 | function | ||
68 | conforms to | ||
69 | .St -ansiC . | ||
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c new file mode 100644 index 0000000000..d9df77b957 --- /dev/null +++ b/src/lib/libc/string/strxfrm.c | |||
@@ -0,0 +1,74 @@ | |||
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 *sccsid = "from: @(#)strxfrm.c 5.2 (Berkeley) 1/26/91";*/ | ||
39 | static char *rcsid = "$Id: strxfrm.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | /* | ||
45 | * Transform src, storing the result in dst, such that | ||
46 | * strcmp() on transformed strings returns what strcoll() | ||
47 | * on the original untransformed strings would return. | ||
48 | */ | ||
49 | size_t | ||
50 | strxfrm(dst, src, n) | ||
51 | register char *dst; | ||
52 | register const char *src; | ||
53 | register size_t n; | ||
54 | { | ||
55 | register size_t r = 0; | ||
56 | register int c; | ||
57 | |||
58 | /* | ||
59 | * Since locales are unimplemented, this is just a copy. | ||
60 | */ | ||
61 | if (n != 0) { | ||
62 | while ((c = *src++) != 0) { | ||
63 | r++; | ||
64 | if (--n == 0) { | ||
65 | while (*src++ != 0) | ||
66 | r++; | ||
67 | break; | ||
68 | } | ||
69 | *dst++ = c; | ||
70 | } | ||
71 | *dst = 0; | ||
72 | } | ||
73 | return (r); | ||
74 | } | ||
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3 new file mode 100644 index 0000000000..133c487bbd --- /dev/null +++ b/src/lib/libc/string/swab.3 | |||
@@ -0,0 +1,66 @@ | |||
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 | .\" from: @(#)swab.3 6.6 (Berkeley) 5/1/91 | ||
33 | .\" $Id: swab.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
34 | .\" | ||
35 | .Dd May 1, 1991 | ||
36 | .Dt SWAB 3 | ||
37 | .Os | ||
38 | .Sh NAME | ||
39 | .Nm swab | ||
40 | .Nd swap adjacent bytes | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <string.h> | ||
43 | .Ft void | ||
44 | .Fn swab "const void *src" "void *dst" "size_t len" | ||
45 | .Sh DESCRIPTION | ||
46 | The function | ||
47 | .Fn swab | ||
48 | copies | ||
49 | .Fa len | ||
50 | bytes from the location referenced by | ||
51 | .Fa src | ||
52 | to the location referenced by | ||
53 | .Fa dst , | ||
54 | swapping adjacent bytes. | ||
55 | .Pp | ||
56 | The argument | ||
57 | .Fa len | ||
58 | must be even number. | ||
59 | .Sh SEE ALSO | ||
60 | .Xr bzero 3 , | ||
61 | .Xr memset 3 | ||
62 | .Sh HISTORY | ||
63 | A | ||
64 | .Fn swab | ||
65 | function appeared in | ||
66 | .At v7 . | ||
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c new file mode 100644 index 0000000000..f33fc53bd6 --- /dev/null +++ b/src/lib/libc/string/swab.c | |||
@@ -0,0 +1,66 @@ | |||
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 *sccsid = "from: @(#)swab.c 5.10 (Berkeley) 3/6/91";*/ | ||
39 | static char *rcsid = "$Id: swab.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | void | ||
45 | swab(from, to, len) | ||
46 | const void *from; | ||
47 | void *to; | ||
48 | size_t len; | ||
49 | { | ||
50 | register unsigned long temp; | ||
51 | register int n; | ||
52 | register char *fp, *tp; | ||
53 | |||
54 | n = (len >> 1) + 1; | ||
55 | fp = (char *)from; | ||
56 | tp = (char *)to; | ||
57 | #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | ||
58 | /* round to multiple of 8 */ | ||
59 | while ((--n) & 07) | ||
60 | STEP; | ||
61 | n >>= 3; | ||
62 | while (--n >= 0) { | ||
63 | STEP; STEP; STEP; STEP; | ||
64 | STEP; STEP; STEP; STEP; | ||
65 | } | ||
66 | } | ||