diff options
Diffstat (limited to 'src/lib/libc/string')
102 files changed, 3174 insertions, 2102 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 2b7ce63a63..124469cd3a 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -1,36 +1,44 @@ | |||
1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 | 1 | # $OpenBSD: Makefile.inc,v 1.20 2007/10/25 22:41:02 miod Exp $ |
2 | # $Id: Makefile.inc,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
3 | 2 | ||
4 | # string sources | 3 | # string sources |
5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string |
6 | 5 | ||
7 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | 6 | SRCS+= bm.c memccpy.c memrchr.c strcasecmp.c strcasestr.c strcoll.c strdup.c \ |
8 | strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strerror.c strerror_r.c strlcat.c strmode.c strsignal.c strtok.c \ |
9 | __strerror.c __strsignal.c | 8 | strxfrm.c \ |
9 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ | ||
10 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ | ||
11 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ | ||
12 | wmemmove.c wmemset.c | ||
10 | 13 | ||
11 | # machine-dependent net sources | 14 | # machine-dependent net sources |
12 | # m-d Makefile.inc must include sources for: | 15 | # m-d Makefile.inc must include sources for: |
13 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() | 16 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() |
14 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() | 17 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() strlcpy() |
15 | # strncat() strncmp() strncpy() strpbrk() strsep() | 18 | # strncat() strncmp() strncpy() strpbrk() strsep() |
16 | # strspn() strstr() swav() | 19 | # strspn() strstr() swav() |
17 | # m-d Makefile.inc may include sources for: | 20 | # m-d Makefile.inc may include sources for: |
18 | # memcpy() memmove() strchr() strrchr() | 21 | # memcpy() memmove() strchr() strrchr() |
19 | 22 | ||
20 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" | 23 | .include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" |
21 | 24 | ||
22 | # if no machine specific memmove(3), build one out of bcopy(3). | 25 | # if no machine specific memmove(3), build one out of bcopy(3). |
23 | .if empty(SRCS:Mmemmove.S) | 26 | .if empty(SRCS:Mmemmove.S) |
24 | OBJS+= memmove.o | 27 | OBJS+= memmove.o |
25 | memmove.o: bcopy.c | 28 | memmove.o: bcopy.c |
26 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 29 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
27 | @${LD} -x -r ${.TARGET} | 30 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
28 | @mv a.out ${.TARGET} | 31 | @mv ${.TARGET}.tmp ${.TARGET} |
32 | |||
33 | memmove.go: bcopy.c | ||
34 | ${CC} -g -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
35 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
36 | @mv ${.TARGET}.tmp ${.TARGET} | ||
29 | 37 | ||
30 | memmove.po: bcopy.c | 38 | memmove.po: bcopy.c |
31 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 39 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
32 | @${LD} -X -r ${.TARGET} | 40 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
33 | @mv a.out ${.TARGET} | 41 | @mv ${.TARGET}.tmp ${.TARGET} |
34 | 42 | ||
35 | memmove.so: bcopy.c | 43 | memmove.so: bcopy.c |
36 | ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 44 | ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -45,13 +53,18 @@ memmove.so: bcopy.c | |||
45 | OBJS+= memcpy.o | 53 | OBJS+= memcpy.o |
46 | memcpy.o: bcopy.c | 54 | memcpy.o: bcopy.c |
47 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 55 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
48 | @${LD} -x -r ${.TARGET} | 56 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
49 | @mv a.out ${.TARGET} | 57 | @mv ${.TARGET}.tmp ${.TARGET} |
58 | |||
59 | memcpy.go: bcopy.c | ||
60 | ${CC} -g -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
61 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
62 | @mv ${.TARGET}.tmp ${.TARGET} | ||
50 | 63 | ||
51 | memcpy.po: bcopy.c | 64 | memcpy.po: bcopy.c |
52 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 65 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
53 | @${LD} -X -r ${.TARGET} | 66 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
54 | @mv a.out ${.TARGET} | 67 | @mv ${.TARGET}.tmp ${.TARGET} |
55 | 68 | ||
56 | memcpy.so: bcopy.c | 69 | memcpy.so: bcopy.c |
57 | ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 70 | ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -64,13 +77,18 @@ memcpy.so: bcopy.c | |||
64 | OBJS+= strchr.o | 77 | OBJS+= strchr.o |
65 | strchr.o: index.c | 78 | strchr.o: index.c |
66 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 79 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
67 | @${LD} -x -r ${.TARGET} | 80 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
68 | @mv a.out ${.TARGET} | 81 | @mv ${.TARGET}.tmp ${.TARGET} |
82 | |||
83 | strchr.go: index.c | ||
84 | ${CC} -g -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
85 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
86 | @mv ${.TARGET}.tmp ${.TARGET} | ||
69 | 87 | ||
70 | strchr.po: index.c | 88 | strchr.po: index.c |
71 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 89 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
72 | @${LD} -X -r ${.TARGET} | 90 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
73 | @mv a.out ${.TARGET} | 91 | @mv ${.TARGET}.tmp ${.TARGET} |
74 | 92 | ||
75 | strchr.so: index.c | 93 | strchr.so: index.c |
76 | ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 94 | ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -82,27 +100,79 @@ strchr.so: index.c | |||
82 | OBJS+= strrchr.o | 100 | OBJS+= strrchr.o |
83 | strrchr.o: rindex.c | 101 | strrchr.o: rindex.c |
84 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 102 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
85 | @${LD} -x -r ${.TARGET} | 103 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
86 | @mv a.out ${.TARGET} | 104 | @mv ${.TARGET}.tmp ${.TARGET} |
105 | |||
106 | strrchr.go: rindex.c | ||
107 | ${CC} -g -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
108 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
109 | @mv ${.TARGET}.tmp ${.TARGET} | ||
87 | 110 | ||
88 | strrchr.po: rindex.c | 111 | strrchr.po: rindex.c |
89 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 112 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
90 | @${LD} -X -r ${.TARGET} | 113 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
91 | @mv a.out ${.TARGET} | 114 | @mv ${.TARGET}.tmp ${.TARGET} |
92 | 115 | ||
93 | strrchr.so: rindex.c | 116 | strrchr.so: rindex.c |
94 | ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 117 | ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
95 | -o ${.TARGET} | 118 | -o ${.TARGET} |
96 | .endif | 119 | .endif |
97 | 120 | ||
98 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ | 121 | # build .ln files for memmove, memcpy, strchr and strrchr always from |
99 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ | 122 | # bcopy, index, and rindex |
100 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 strftime.3 \ | 123 | LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln |
124 | |||
125 | memmove.ln: bcopy.c | ||
126 | lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
127 | ${LIBCSRCDIR}/string/bcopy.c | ||
128 | |||
129 | memcpy.ln: bcopy.c | ||
130 | lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
131 | ${LIBCSRCDIR}/string/bcopy.c | ||
132 | |||
133 | strchr.ln: index.c | ||
134 | lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
135 | ${LIBCSRCDIR}/string/index.c | ||
136 | |||
137 | strrchr.ln: rindex.c | ||
138 | lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
139 | ${LIBCSRCDIR}/string/rindex.c | ||
140 | |||
141 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 memccpy.3 memchr.3 \ | ||
142 | memcmp.3 memcpy.3 memmove.3 memset.3 strcasecmp.3 strcat.3 \ | ||
143 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 \ | ||
101 | string.3 strlen.3 strmode.3 strdup.3 strpbrk.3 strrchr.3 strsep.3 \ | 144 | 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 | 145 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 \ |
146 | wcstok.3 wmemchr.3 | ||
103 | 147 | ||
104 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | 148 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 |
149 | MLINKS+=memchr.3 memrchr.3 | ||
150 | MLINKS+=strchr.3 index.3 | ||
151 | MLINKS+=strrchr.3 rindex.3 | ||
105 | MLINKS+=strcasecmp.3 strncasecmp.3 | 152 | MLINKS+=strcasecmp.3 strncasecmp.3 |
106 | MLINKS+=strcat.3 strncat.3 | 153 | MLINKS+=strcat.3 strncat.3 |
107 | MLINKS+=strcmp.3 strncmp.3 | 154 | MLINKS+=strcmp.3 strncmp.3 |
108 | MLINKS+=strcpy.3 strncpy.3 | 155 | MLINKS+=strcpy.3 strncpy.3 |
156 | MLINKS+=strlcpy.3 strlcat.3 | ||
157 | MLINKS+=strstr.3 strcasestr.3 | ||
158 | MLINKS+=strtok.3 strtok_r.3 | ||
159 | MLINKS+=strerror.3 strerror_r.3 | ||
160 | MLINKS+=wmemchr.3 wmemcmp.3 | ||
161 | MLINKS+=wmemchr.3 wmemcpy.3 | ||
162 | MLINKS+=wmemchr.3 wmemmove.3 | ||
163 | MLINKS+=wmemchr.3 wmemset.3 | ||
164 | MLINKS+=wmemchr.3 wcscat.3 | ||
165 | MLINKS+=wmemchr.3 wcschr.3 | ||
166 | MLINKS+=wmemchr.3 wcscmp.3 | ||
167 | MLINKS+=wmemchr.3 wcscpy.3 | ||
168 | MLINKS+=wmemchr.3 wcscspn.3 | ||
169 | MLINKS+=wmemchr.3 wcslcat.3 | ||
170 | MLINKS+=wmemchr.3 wcslcpy.3 | ||
171 | MLINKS+=wmemchr.3 wcslen.3 | ||
172 | MLINKS+=wmemchr.3 wcsncat.3 | ||
173 | MLINKS+=wmemchr.3 wcsncmp.3 | ||
174 | MLINKS+=wmemchr.3 wcsncpy.3 | ||
175 | MLINKS+=wmemchr.3 wcspbrk.3 | ||
176 | MLINKS+=wmemchr.3 wcsrchr.3 | ||
177 | MLINKS+=wmemchr.3 wcsspn.3 | ||
178 | MLINKS+=wmemchr.3 wcsstr.3 | ||
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c deleted file mode 100644 index cd604906db..0000000000 --- a/src/lib/libc/string/__strerror.c +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1988 Regents of the University of California. | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * 3. 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/bcmp.3 b/src/lib/libc/string/bcmp.3 index 118c55c579..57e1a0fade 100644 --- a/src/lib/libc/string/bcmp.3 +++ b/src/lib/libc/string/bcmp.3 | |||
@@ -11,11 +11,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
21 | .\" | 17 | .\" |
@@ -31,12 +27,11 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
33 | .\" | 29 | .\" |
34 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: bcmp.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ |
35 | .\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
36 | .\" | 31 | .\" |
37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt BCMP 3 | 33 | .Dt BCMP 3 |
39 | .Os BSD 4.2 | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
41 | .Nm bcmp | 36 | .Nm bcmp |
42 | .Nd compare byte string | 37 | .Nd compare byte string |
@@ -47,8 +42,7 @@ | |||
47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
48 | The | 43 | The |
49 | .Fn bcmp | 44 | .Fn bcmp |
50 | function | 45 | function compares byte string |
51 | compares byte string | ||
52 | .Fa b1 | 46 | .Fa b1 |
53 | against byte string | 47 | against byte string |
54 | .Fa b2 , | 48 | .Fa b2 , |
@@ -68,5 +62,5 @@ The strings may overlap. | |||
68 | .Sh HISTORY | 62 | .Sh HISTORY |
69 | A | 63 | A |
70 | .Fn bcmp | 64 | .Fn bcmp |
71 | function first appeared in | 65 | function first appeared in |
72 | .Bx 4.2 . | 66 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c index 2cc38baee3..fd5c93121e 100644 --- a/src/lib/libc/string/bcmp.c +++ b/src/lib/libc/string/bcmp.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: bcmp.c,v 1.9 2008/03/19 03:00:23 ray Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | 4 | * Copyright (c) 1987 Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,29 +29,27 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
40 | 37 | ||
41 | /* | 38 | /* |
42 | * bcmp -- vax cmpc3 instruction | 39 | * bcmp -- vax cmpc3 instruction |
43 | */ | 40 | */ |
44 | bcmp(b1, b2, length) | 41 | int |
45 | const void *b1, *b2; | 42 | bcmp(const void *b1, const void *b2, size_t length) |
46 | register size_t length; | ||
47 | { | 43 | { |
48 | register char *p1, *p2; | 44 | char *p1, *p2; |
49 | 45 | ||
50 | if (length == 0) | 46 | if (length == 0) |
51 | return(0); | 47 | return (0); |
52 | p1 = (char *)b1; | 48 | p1 = (char *)b1; |
53 | p2 = (char *)b2; | 49 | p2 = (char *)b2; |
54 | do | 50 | do |
55 | if (*p1++ != *p2++) | 51 | if (*p1++ != *p2++) |
56 | break; | 52 | return (1); |
57 | while (--length); | 53 | while (--length); |
58 | return(length); | 54 | return (0); |
59 | } | 55 | } |
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3 index 6db3812caf..3d3c8ee958 100644 --- a/src/lib/libc/string/bcopy.3 +++ b/src/lib/libc/string/bcopy.3 | |||
@@ -12,11 +12,7 @@ | |||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | 12 | .\" 2. Redistributions in binary form must reproduce the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer in the | 13 | .\" notice, this list of conditions and the following disclaimer in the |
14 | .\" documentation and/or other materials provided with the distribution. | 14 | .\" documentation and/or other materials provided with the distribution. |
15 | .\" 3. All advertising materials mentioning features or use of this software | 15 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 16 | .\" may be used to endorse or promote products derived from this software |
21 | .\" without specific prior written permission. | 17 | .\" without specific prior written permission. |
22 | .\" | 18 | .\" |
@@ -32,15 +28,14 @@ | |||
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | .\" SUCH DAMAGE. | 29 | .\" SUCH DAMAGE. |
34 | .\" | 30 | .\" |
35 | .\" from: @(#)bcopy.3 5.3 (Berkeley) 4/19/91 | 31 | .\" $OpenBSD: bcopy.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
36 | .\" $Id: bcopy.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | 32 | .\" |
38 | .Dd April 19, 1991 | 33 | .Dd $Mdocdate: May 31 2007 $ |
39 | .Dt BCOPY 3 | 34 | .Dt BCOPY 3 |
40 | .Os BSD 4.2 | 35 | .Os |
41 | .Sh NAME | 36 | .Sh NAME |
42 | .Nm bcopy | 37 | .Nm bcopy |
43 | .Nd copy byte string | 38 | .Nd copy bytes |
44 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
45 | .Fd #include <string.h> | 40 | .Fd #include <string.h> |
46 | .Ft void | 41 | .Ft void |
@@ -48,14 +43,13 @@ | |||
48 | .Sh DESCRIPTION | 43 | .Sh DESCRIPTION |
49 | The | 44 | The |
50 | .Fn bcopy | 45 | .Fn bcopy |
51 | function | 46 | function copies |
52 | copies | ||
53 | .Fa len | 47 | .Fa len |
54 | bytes from string | 48 | bytes from buffer |
55 | .Fa src | 49 | .Fa src |
56 | to string | 50 | to buffer |
57 | .Fa dst . | 51 | .Fa dst . |
58 | The two strings may overlap. | 52 | The two buffers may overlap. |
59 | If | 53 | If |
60 | .Fa len | 54 | .Fa len |
61 | is zero, no bytes are copied. | 55 | is zero, no bytes are copied. |
@@ -64,9 +58,10 @@ is zero, no bytes are copied. | |||
64 | .Xr memcpy 3 , | 58 | .Xr memcpy 3 , |
65 | .Xr memmove 3 , | 59 | .Xr memmove 3 , |
66 | .Xr strcpy 3 , | 60 | .Xr strcpy 3 , |
61 | .Xr strlcpy 3 , | ||
67 | .Xr strncpy 3 | 62 | .Xr strncpy 3 |
68 | .Sh HISTORY | 63 | .Sh HISTORY |
69 | A | 64 | A |
70 | .Fn bcopy | 65 | .Fn bcopy |
71 | function appeared in | 66 | function appeared in |
72 | .Bx 4.2 . | 67 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c index 92feed66ea..4308c6484a 100644 --- a/src/lib/libc/string/bcopy.c +++ b/src/lib/libc/string/bcopy.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: bcopy.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,11 +31,6 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
@@ -57,23 +49,20 @@ typedef long word; /* "word" used for optimal copy speed */ | |||
57 | */ | 49 | */ |
58 | #ifdef MEMCOPY | 50 | #ifdef MEMCOPY |
59 | void * | 51 | void * |
60 | memcpy(dst0, src0, length) | 52 | memcpy(void *dst0, const void *src0, size_t length) |
61 | #else | 53 | #else |
62 | #ifdef MEMMOVE | 54 | #ifdef MEMMOVE |
63 | void * | 55 | void * |
64 | memmove(dst0, src0, length) | 56 | memmove(void *dst0, const void *src0, size_t length) |
65 | #else | 57 | #else |
66 | void | 58 | void |
67 | bcopy(src0, dst0, length) | 59 | bcopy(const void *src0, void *dst0, size_t length) |
68 | #endif | 60 | #endif |
69 | #endif | 61 | #endif |
70 | void *dst0; | ||
71 | const void *src0; | ||
72 | register size_t length; | ||
73 | { | 62 | { |
74 | register char *dst = dst0; | 63 | char *dst = dst0; |
75 | register const char *src = src0; | 64 | const char *src = src0; |
76 | register size_t t; | 65 | size_t t; |
77 | 66 | ||
78 | if (length == 0 || dst == src) /* nothing to do */ | 67 | if (length == 0 || dst == src) /* nothing to do */ |
79 | goto done; | 68 | goto done; |
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 index 2264a6a1c4..749ffc9b74 100644 --- a/src/lib/libc/string/bm.3 +++ b/src/lib/libc/string/bm.3 | |||
@@ -12,11 +12,7 @@ | |||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | 12 | .\" 2. Redistributions in binary form must reproduce the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer in the | 13 | .\" notice, this list of conditions and the following disclaimer in the |
14 | .\" documentation and/or other materials provided with the distribution. | 14 | .\" documentation and/or other materials provided with the distribution. |
15 | .\" 3. All advertising materials mentioning features or use of this software | 15 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 16 | .\" may be used to endorse or promote products derived from this software |
21 | .\" without specific prior written permission. | 17 | .\" without specific prior written permission. |
22 | .\" | 18 | .\" |
@@ -32,83 +28,85 @@ | |||
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | .\" SUCH DAMAGE. | 29 | .\" SUCH DAMAGE. |
34 | .\" | 30 | .\" |
35 | .\" from: @(#)bm.3 8.4 (Berkeley) 6/21/94 | 31 | .\" $OpenBSD: bm.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
36 | .\" $Id: bm.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
37 | .\" | 32 | .\" |
38 | .TH BM 3 | 33 | .Dd $Mdocdate: May 31 2007 $ |
39 | .SH NAME | 34 | .Dt BM 3 |
40 | bm_comp, bm_exec, bm_free \- Boyer-Moore string search | 35 | .Os |
41 | .SH SYNOPSIS | 36 | .Sh NAME |
42 | .ft B | 37 | .Nm bm_comp , |
43 | #include <sys/types.h> | 38 | .Nm bm_exec , |
44 | .br | 39 | .Nm bm_free |
45 | #include <bm.h> | 40 | .Nd Boyer-Moore string search |
46 | .sp | 41 | .Sh SYNOPSIS |
47 | bm_pat * | 42 | .Fd #include <sys/types.h> |
48 | .br | 43 | .Fd #include <bm.h> |
49 | bm_comp(u_char *pattern, size_t patlen, u_char freq[256]); | 44 | .Ft bm_pat * |
50 | .sp | 45 | .Fn bm_comp "const unsigned char *pattern" "size_t patlen" \ |
51 | u_char * | 46 | "const unsigned char freq[256]" |
52 | .br | 47 | .Ft unsigned char * |
53 | bm_exec(bm_pat *pdesc, u_char *text, size_t len); | 48 | .Fn bm_exec "bm_pat *pdesc" "unsigned char *text" "size_t len" |
54 | .sp | 49 | .Ft void |
55 | void | 50 | .Fn bm_free "bm_pat *pdesc" |
56 | .br | 51 | .Sh DESCRIPTION |
57 | bm_free(bm_pat *pdesc); | ||
58 | .SH DESCRIPTION | ||
59 | These routines implement an efficient mechanism to find an | 52 | These routines implement an efficient mechanism to find an |
60 | occurrence of a byte string within another byte string. | 53 | occurrence of a byte string within another byte string. |
61 | .PP | 54 | .Pp |
62 | .I Bm_comp | 55 | .Fn bm_comp |
63 | evaluates the | 56 | evaluates |
64 | .I patlen | 57 | .Fa patlen |
65 | bytes starting at | 58 | bytes starting at |
66 | .IR pattern , | 59 | .Fa pattern |
67 | and returns a pointer to a structure describing them. | 60 | and returns a pointer to a structure describing them. |
68 | The bytes referenced by | 61 | The bytes referenced by |
69 | .I pattern | 62 | .Fa pattern |
70 | may be of any value. | 63 | may be of any value. |
71 | .PP | 64 | .Pp |
72 | The search takes advantage of the frequency distribution of the | 65 | The search takes advantage of the frequency distribution of the |
73 | bytes in the text to be searched. | 66 | bytes in the text to be searched. |
74 | If specified, | 67 | If specified, |
75 | .I freq | 68 | .Ar freq |
76 | should be an array of 256 values, | 69 | should be an array of 256 values, |
77 | with higher values indicating that the corresponding character occurs | 70 | with higher values indicating that the corresponding character occurs |
78 | more frequently. | 71 | more frequently. |
79 | (A less than optimal frequency distribution can only result in less | 72 | (A less than optimal frequency distribution can only result in less |
80 | than optimal performance, not incorrect results.) | 73 | than optimal performance, not incorrect results.) |
81 | If | 74 | If |
82 | .I freq | 75 | .Ar freq |
83 | is NULL, | 76 | is |
77 | .Dv NULL , | ||
84 | a system default table is used. | 78 | a system default table is used. |
85 | .PP | 79 | .Pp |
86 | .I Bm_exec | 80 | .Fn bm_exec |
87 | returns a pointer to the leftmost occurrence of the string given to | 81 | returns a pointer to the leftmost occurrence of the string given to |
88 | .I bm_comp | 82 | .Fn bm_comp |
89 | within | 83 | within |
90 | .IR text , | 84 | .Ar text , |
91 | or NULL if none occurs. | 85 | or |
86 | .Dv NULL | ||
87 | if none occurs. | ||
92 | The number of bytes in | 88 | The number of bytes in |
93 | .I text | 89 | .Ar text |
94 | must be specified by | 90 | must be specified by |
95 | .IR len . | 91 | .Ar len . |
96 | .PP | 92 | .Pp |
97 | Space allocated for the returned description is discarded | 93 | Space allocated for the returned description is discarded |
98 | by calling | 94 | by calling |
99 | .I bm_free | 95 | .Fn bm_free |
100 | with the returned description as an argument. | 96 | with the returned description as an argument. |
101 | .PP | 97 | .Pp |
102 | The asymptotic speed of | 98 | The asymptotic speed of |
103 | .I bm_exec | 99 | .Fn bm_exec |
104 | is | 100 | is |
105 | .RI O( len / patlen ). | 101 | .Pf O Ns Pq len / patlen . |
106 | .PP | 102 | .Sh SEE ALSO |
107 | .SH "SEE ALSO" | 103 | .Xr regexp 3 , |
108 | .IR regexp (3), | 104 | .Xr strstr 3 |
109 | .IR strstr (3) | 105 | .Rs |
110 | .sp | 106 | .%R "Fast String Searching" |
111 | .IR "Fast String Searching" , | 107 | .%A Andrew Hume |
112 | Hume and Sunday, | 108 | .%A Daniel Sunday |
113 | Software Practice and Experience, | 109 | .%J "Software Practice and Experience" |
114 | Vol. 21, 11 (November 1991) pp. 1221-48. | 110 | .%V Volume 21, 11 (November 1991) |
111 | .%P 1221-48 | ||
112 | .Re | ||
diff --git a/src/lib/libc/string/bm.c b/src/lib/libc/string/bm.c index 68eac22ecc..2c4c6ca720 100644 --- a/src/lib/libc/string/bm.c +++ b/src/lib/libc/string/bm.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: bm.c,v 1.7 2007/09/02 15:19:18 deraadt Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1994 | 3 | * Copyright (c) 1994 |
3 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,11 +31,6 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <sys/types.h> |
43 | 35 | ||
44 | #include <bm.h> | 36 | #include <bm.h> |
@@ -90,14 +82,11 @@ static u_char const freq_def[256] = { | |||
90 | }; | 82 | }; |
91 | 83 | ||
92 | bm_pat * | 84 | bm_pat * |
93 | bm_comp(pb, len, freq) | 85 | bm_comp(u_char const *pb, size_t len, u_char const *freq) |
94 | u_char const *pb; | ||
95 | size_t len; | ||
96 | u_char const *freq; | ||
97 | { | 86 | { |
98 | register u_char const *pe, *p; | 87 | u_char const *pe, *p; |
99 | register size_t *d, r; | 88 | size_t *d, r; |
100 | register int j; | 89 | int j; |
101 | int sv_errno; | 90 | int sv_errno; |
102 | bm_pat *pat; | 91 | bm_pat *pat; |
103 | 92 | ||
@@ -115,7 +104,7 @@ bm_comp(pb, len, freq) | |||
115 | goto mem; | 104 | goto mem; |
116 | memcpy(pat->pat, pb, pat->patlen); | 105 | memcpy(pat->pat, pb, pat->patlen); |
117 | /* get skip delta */ | 106 | /* get skip delta */ |
118 | if ((pat->delta = malloc(256 * sizeof(*d))) == NULL) | 107 | if ((pat->delta = calloc(256, sizeof(*d))) == NULL) |
119 | goto mem; | 108 | goto mem; |
120 | for (j = 0, d = pat->delta; j < 256; j++) | 109 | for (j = 0, d = pat->delta; j < 256; j++) |
121 | d[j] = pat->patlen; | 110 | d[j] = pat->patlen; |
@@ -147,8 +136,7 @@ mem: sv_errno = errno; | |||
147 | } | 136 | } |
148 | 137 | ||
149 | void | 138 | void |
150 | bm_free(pat) | 139 | bm_free(bm_pat *pat) |
151 | bm_pat *pat; | ||
152 | { | 140 | { |
153 | if (pat->pat != NULL) | 141 | if (pat->pat != NULL) |
154 | free(pat->pat); | 142 | free(pat->pat); |
@@ -158,14 +146,11 @@ bm_free(pat) | |||
158 | } | 146 | } |
159 | 147 | ||
160 | u_char * | 148 | u_char * |
161 | bm_exec(pat, base, n) | 149 | bm_exec(bm_pat *pat, u_char *base, size_t n) |
162 | bm_pat *pat; | ||
163 | u_char *base; | ||
164 | size_t n; | ||
165 | { | 150 | { |
166 | register u_char *e, *ep, *p, *q, *s; | 151 | u_char *e, *ep, *p, *q, *s; |
167 | register size_t *d0, k, md2, n1, ro; | 152 | size_t *d0, k, md2, n1, ro; |
168 | register int rc; | 153 | int rc; |
169 | 154 | ||
170 | if (n == 0) | 155 | if (n == 0) |
171 | return (NULL); | 156 | return (NULL); |
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3 index 12fcfb0cc1..cd16ab022d 100644 --- a/src/lib/libc/string/bstring.3 +++ b/src/lib/libc/string/bstring.3 | |||
@@ -11,11 +11,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
21 | .\" | 17 | .\" |
@@ -31,22 +27,13 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
33 | .\" | 29 | .\" |
34 | .\" from: @(#)bstring.3 6.8 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: bstring.3,v 1.8 2007/05/31 19:19:32 jmc Exp $ |
35 | .\" $Id: bstring.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 31 | .\" |
37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt BSTRING 3 | 33 | .Dt BSTRING 3 |
39 | .Os | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
41 | .Nm bcmp , | 36 | .Nm bstring |
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 | 37 | .Nd byte string operations |
51 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
52 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
@@ -70,7 +57,7 @@ | |||
70 | .Fn memset "void *b" "int c" "size_t len" | 57 | .Fn memset "void *b" "int c" "size_t len" |
71 | .Sh DESCRIPTION | 58 | .Sh DESCRIPTION |
72 | These functions operate on variable length strings of bytes. | 59 | These functions operate on variable length strings of bytes. |
73 | They do not check for terminating null bytes as the routines | 60 | They do not check for terminating NUL bytes as the routines |
74 | listed in | 61 | listed in |
75 | .Xr string 3 | 62 | .Xr string 3 |
76 | do. | 63 | do. |
@@ -97,14 +84,15 @@ and | |||
97 | conform to | 84 | conform to |
98 | .St -ansiC . | 85 | .St -ansiC . |
99 | .Sh HISTORY | 86 | .Sh HISTORY |
100 | The functions | 87 | The |
101 | .Fn bzero | 88 | .Fn bzero |
102 | and | 89 | and |
103 | .Fn memccpy | 90 | .Fn memccpy |
104 | appeared in | 91 | functions appeared in |
105 | .Bx 4.3 ; | 92 | .Bx 4.3 . |
106 | the functions | 93 | The |
107 | .Fn bcmp , | 94 | .Fn bcmp |
108 | .Fn bcopy , | 95 | and |
109 | appeared in | 96 | .Fn bcopy |
97 | functions appeared in | ||
110 | .Bx 4.2 . | 98 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3 index 4f0141e051..c5ca32f4d2 100644 --- a/src/lib/libc/string/bzero.3 +++ b/src/lib/libc/string/bzero.3 | |||
@@ -11,11 +11,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
21 | .\" | 17 | .\" |
@@ -31,12 +27,11 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
33 | .\" | 29 | .\" |
34 | .\" from: @(#)bzero.3 5.3 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: bzero.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ |
35 | .\" $Id: bzero.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 31 | .\" |
37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt BZERO 3 | 33 | .Dt BZERO 3 |
39 | .Os BSD 4.3 | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
41 | .Nm bzero | 36 | .Nm bzero |
42 | .Nd write zeroes to a byte string | 37 | .Nd write zeroes to a byte string |
@@ -47,8 +42,7 @@ | |||
47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
48 | The | 43 | The |
49 | .Fn bzero | 44 | .Fn bzero |
50 | function | 45 | function writes |
51 | writes | ||
52 | .Fa len | 46 | .Fa len |
53 | zero bytes to the string | 47 | zero bytes to the string |
54 | .Fa b . | 48 | .Fa b . |
@@ -63,6 +57,5 @@ does nothing. | |||
63 | .Sh HISTORY | 57 | .Sh HISTORY |
64 | A | 58 | A |
65 | .Fn bzero | 59 | .Fn bzero |
66 | function | 60 | function appeared in |
67 | appeared in | ||
68 | .Bx 4.3 . | 61 | .Bx 4.3 . |
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c index 4865e396ef..4d267d4f40 100644 --- a/src/lib/libc/string/bzero.c +++ b/src/lib/libc/string/bzero.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: bzero.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | 4 | * Copyright (c) 1987 Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,22 +29,19 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
40 | 37 | ||
41 | /* | 38 | /* |
42 | * bzero -- vax movc5 instruction | 39 | * bzero -- vax movc5 instruction |
43 | */ | 40 | */ |
44 | void | 41 | void |
45 | bzero(b, length) | 42 | bzero(void *b, size_t length) |
46 | void *b; | ||
47 | register size_t length; | ||
48 | { | 43 | { |
49 | register char *p; | 44 | char *p; |
50 | 45 | ||
51 | for (p = b; length--;) | 46 | for (p = b; length--;) |
52 | *p++ = '\0'; | 47 | *p++ = '\0'; |
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 index 6464bea2b1..27b26969e5 100644 --- a/src/lib/libc/string/ffs.3 +++ b/src/lib/libc/string/ffs.3 | |||
@@ -11,11 +11,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
21 | .\" | 17 | .\" |
@@ -31,10 +27,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
33 | .\" | 29 | .\" |
34 | .\" from: @(#)ffs.3 5.3 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: ffs.3,v 1.5 2007/05/31 19:19:32 jmc Exp $ |
35 | .\" $Id: ffs.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 31 | .\" |
37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt FFS 3 | 33 | .Dt FFS 3 |
39 | .Os | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
@@ -47,12 +42,10 @@ | |||
47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
48 | The | 43 | The |
49 | .Fn ffs | 44 | .Fn ffs |
50 | function | 45 | function finds the first bit set in |
51 | finds the first bit set in | ||
52 | .Fa value | 46 | .Fa value |
53 | and returns the index of that bit. | 47 | and returns the index of that bit. |
54 | Bits are numbered starting from 1, starting at the right-most | 48 | Bits are numbered starting from 1, starting at the rightmost bit. |
55 | bit. | ||
56 | A return value of 0 means that the argument was zero. | 49 | A return value of 0 means that the argument was zero. |
57 | .Sh SEE ALSO | 50 | .Sh SEE ALSO |
58 | .Xr bitstring 3 | 51 | .Xr bitstring 3 |
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c index 42bc87ddea..7dec1613a8 100644 --- a/src/lib/libc/string/ffs.c +++ b/src/lib/libc/string/ffs.c | |||
@@ -1,55 +1,44 @@ | |||
1 | /*- | 1 | /* $OpenBSD: ffs.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ |
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 | 2 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 3 | /* |
35 | /*static char *sccsid = "from: @(#)ffs.c 5.4 (Berkeley) 5/17/90";*/ | 4 | * Public domain. |
36 | static char *rcsid = "$Id: ffs.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 5 | * Written by Dale Rahn. |
37 | #endif /* LIBC_SCCS and not lint */ | 6 | */ |
38 | 7 | ||
8 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
39 | #include <string.h> | 9 | #include <string.h> |
10 | #else | ||
11 | #include <lib/libkern/libkern.h> | ||
12 | #endif | ||
40 | 13 | ||
41 | /* | 14 | /* |
42 | * ffs -- vax ffs instruction | 15 | * ffs -- vax ffs instruction |
43 | */ | 16 | */ |
44 | int | 17 | int |
45 | ffs(mask) | 18 | ffs(int mask) |
46 | register int mask; | ||
47 | { | 19 | { |
48 | register int bit; | 20 | int bit; |
21 | unsigned int r = mask; | ||
22 | static const signed char t[16] = { | ||
23 | -28, 1, 2, 1, | ||
24 | 3, 1, 2, 1, | ||
25 | 4, 1, 2, 1, | ||
26 | 3, 1, 2, 1 | ||
27 | }; | ||
28 | |||
29 | bit = 0; | ||
30 | if (!(r & 0xffff)) { | ||
31 | bit += 16; | ||
32 | r >>= 16; | ||
33 | } | ||
34 | if (!(r & 0xff)) { | ||
35 | bit += 8; | ||
36 | r >>= 8; | ||
37 | } | ||
38 | if (!(r & 0xf)) { | ||
39 | bit += 4; | ||
40 | r >>= 4; | ||
41 | } | ||
49 | 42 | ||
50 | if (mask == 0) | 43 | return (bit + t[ r & 0xf ]); |
51 | return(0); | ||
52 | for (bit = 1; !(mask & 1); bit++) | ||
53 | mask >>= 1; | ||
54 | return(bit); | ||
55 | } | 44 | } |
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/index.3 deleted file mode 100644 index 847b03628b..0000000000 --- a/src/lib/libc/string/index.3 +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" Chris Torek. | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. 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 index 3d9c05f961..50e9ca35ab 100644 --- a/src/lib/libc/string/index.c +++ b/src/lib/libc/string/index.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: index.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,20 +28,14 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <string.h> |
40 | 32 | ||
41 | char * | 33 | char * |
42 | #ifdef STRCHR | 34 | #ifdef STRCHR |
43 | strchr(p, ch) | 35 | strchr(const char *p, int ch) |
44 | #else | 36 | #else |
45 | index(p, ch) | 37 | index(const char *p, int ch) |
46 | #endif | 38 | #endif |
47 | register const char *p, ch; | ||
48 | { | 39 | { |
49 | for (;; ++p) { | 40 | for (;; ++p) { |
50 | if (*p == ch) | 41 | if (*p == ch) |
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3 index 61df704028..ef53d95645 100644 --- a/src/lib/libc/string/memccpy.3 +++ b/src/lib/libc/string/memccpy.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: memccpy.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -9,11 +11,7 @@ | |||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
11 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
12 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
18 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
19 | .\" | 17 | .\" |
@@ -29,14 +27,14 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
31 | .\" | 29 | .\" |
32 | .\" from: @(#)memccpy.3 5.4 (Berkeley) 4/19/91 | 30 | .\" @(#)memccpy.3 8.1 (Berkeley) 6/9/93 |
33 | .\" $Id: memccpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
34 | .\" | 31 | .\" |
35 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
36 | .Dt MEMCCPY 3 | 33 | .Dt MEMCCPY 3 |
37 | .Os | 34 | .Os |
38 | .Sh NAME | 35 | .Sh NAME |
39 | .Nm memccpy | 36 | .Nm memccpy |
37 | .Nd copy string until character found | ||
40 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
41 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
42 | .Ft void * | 40 | .Ft void * |
@@ -44,14 +42,15 @@ | |||
44 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
45 | The | 43 | The |
46 | .Fn memccpy | 44 | .Fn memccpy |
47 | function | 45 | function copies bytes from string |
48 | copies bytes from string | ||
49 | .Fa src | 46 | .Fa src |
50 | to string | 47 | to string |
51 | .Fa dst . | 48 | .Fa dst . |
52 | If the character | 49 | If the character |
53 | .Fa c | 50 | .Fa c |
54 | (as converted to an unsigned char) occurs in the string | 51 | (as converted to an |
52 | .Li unsigned char ) | ||
53 | occurs in the string | ||
55 | .Fa src , | 54 | .Fa src , |
56 | the copy stops and a pointer to the byte after the copy of | 55 | the copy stops and a pointer to the byte after the copy of |
57 | .Fa c | 56 | .Fa c |
@@ -60,14 +59,15 @@ in the string | |||
60 | is returned. | 59 | is returned. |
61 | Otherwise, | 60 | Otherwise, |
62 | .Fa len | 61 | .Fa len |
63 | bytes are copied, and a NULL pointer is returned. | 62 | bytes are copied, and a null pointer is returned. |
64 | .Sh SEE ALSO | 63 | .Sh SEE ALSO |
65 | .Xr bcopy 3 , | 64 | .Xr bcopy 3 , |
66 | .Xr memcpy 3 , | 65 | .Xr memcpy 3 , |
67 | .Xr memmove 3 , | 66 | .Xr memmove 3 , |
68 | .Xr strcpy 3 | 67 | .Xr strcpy 3 , |
68 | .Xr strlcpy 3 | ||
69 | .Sh HISTORY | 69 | .Sh HISTORY |
70 | The | 70 | The |
71 | .Fn memccpy | 71 | .Fn memccpy |
72 | function is | 72 | function first appeared in |
73 | .Ud . | 73 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c index 3a1d7bcca1..485c55fcab 100644 --- a/src/lib/libc/string/memccpy.c +++ b/src/lib/libc/string/memccpy.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: memccpy.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,25 +29,16 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
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> | 32 | #include <string.h> |
40 | 33 | ||
41 | void * | 34 | void * |
42 | memccpy(t, f, c, n) | 35 | memccpy(void *t, const void *f, int c, size_t n) |
43 | void *t; | ||
44 | const void *f; | ||
45 | int c; | ||
46 | register size_t n; | ||
47 | { | 36 | { |
48 | 37 | ||
49 | if (n) { | 38 | if (n) { |
50 | register unsigned char *tp = t; | 39 | unsigned char *tp = t; |
51 | register const unsigned char *fp = f; | 40 | const unsigned char *fp = f; |
52 | register unsigned char uc = c; | 41 | unsigned char uc = c; |
53 | do { | 42 | do { |
54 | if ((*tp++ = *fp++) == uc) | 43 | if ((*tp++ = *fp++) == uc) |
55 | return (tp); | 44 | return (tp); |
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3 index 265711e3b5..558848ac23 100644 --- a/src/lib/libc/string/memchr.3 +++ b/src/lib/libc/string/memchr.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memchr.3,v 1.9 2007/09/03 16:50:14 jmc Exp $ |
37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: September 3 2007 $ |
40 | .Dt MEMCHR 3 | 35 | .Dt MEMCHR 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -46,26 +41,37 @@ | |||
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft void * | 42 | .Ft void * |
48 | .Fn memchr "const void *b" "int c" "size_t len" | 43 | .Fn memchr "const void *b" "int c" "size_t len" |
44 | .Ft void * | ||
45 | .Fn memrchr "const void *b" "int c" "size_t len" | ||
49 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
50 | The | 47 | The |
51 | .Fn memchr | 48 | .Fn memchr |
52 | function | 49 | function locates the first occurrence of |
53 | locates the first occurrence of | 50 | .Fa c |
51 | (converted to an | ||
52 | .Li unsigned char ) | ||
53 | in string | ||
54 | .Fa b . | ||
55 | .Pp | ||
56 | The | ||
57 | .Fn memrchr | ||
58 | function behaves like | ||
59 | .Fn memchr , | ||
60 | except that it locates the last occurrence of | ||
54 | .Fa c | 61 | .Fa c |
55 | (converted to an unsigned char) | ||
56 | in string | 62 | in string |
57 | .Fa b . | 63 | .Fa b . |
58 | .Sh RETURN VALUES | 64 | .Sh RETURN VALUES |
59 | The | 65 | The |
60 | .Fn memchr | 66 | .Fn memchr |
61 | function | 67 | and |
62 | returns a pointer to the byte located, | 68 | .Fn memrchr |
63 | or NULL if no such byte exists within | 69 | functions return a pointer to the byte located, or |
70 | .Dv NULL | ||
71 | if no such byte exists within | ||
64 | .Fa len | 72 | .Fa len |
65 | bytes. | 73 | bytes. |
66 | .Sh SEE ALSO | 74 | .Sh SEE ALSO |
67 | .Xr index 3 , | ||
68 | .Xr rindex 3 , | ||
69 | .Xr strchr 3 , | 75 | .Xr strchr 3 , |
70 | .Xr strcspn 3 , | 76 | .Xr strcspn 3 , |
71 | .Xr strpbrk 3 , | 77 | .Xr strpbrk 3 , |
@@ -77,6 +83,11 @@ bytes. | |||
77 | .Sh STANDARDS | 83 | .Sh STANDARDS |
78 | The | 84 | The |
79 | .Fn memchr | 85 | .Fn memchr |
80 | function | 86 | function conforms to |
81 | conforms to | ||
82 | .St -ansiC . | 87 | .St -ansiC . |
88 | .Pp | ||
89 | The | ||
90 | .Fn memrchr | ||
91 | function is an | ||
92 | .Ox | ||
93 | extension. | ||
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c index 61652c6bb1..4573e3ceb1 100644 --- a/src/lib/libc/string/memchr.c +++ b/src/lib/libc/string/memchr.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: memchr.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,24 +31,16 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | void * | 36 | void * |
45 | memchr(s, c, n) | 37 | memchr(const void *s, int c, size_t n) |
46 | const void *s; | ||
47 | register unsigned char c; | ||
48 | register size_t n; | ||
49 | { | 38 | { |
50 | if (n != 0) { | 39 | if (n != 0) { |
51 | register const unsigned char *p = s; | 40 | const unsigned char *p = s; |
52 | 41 | ||
53 | do { | 42 | do { |
54 | if (*p++ == c) | 43 | if (*p++ == (unsigned char)c) |
55 | return ((void *)(p - 1)); | 44 | return ((void *)(p - 1)); |
56 | } while (--n != 0); | 45 | } while (--n != 0); |
57 | } | 46 | } |
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3 index 13901c1009..8c35f388f2 100644 --- a/src/lib/libc/string/memcmp.3 +++ b/src/lib/libc/string/memcmp.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memcmp.3,v 1.6 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt MEMCMP 3 | 35 | .Dt MEMCMP 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,8 +44,7 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn memcmp | 46 | .Fn memcmp |
52 | function | 47 | function compares byte string |
53 | compares byte string | ||
54 | .Fa b1 | 48 | .Fa b1 |
55 | against byte string | 49 | against byte string |
56 | .Fa b2 . | 50 | .Fa b2 . |
@@ -60,10 +54,11 @@ bytes long. | |||
60 | .Sh RETURN VALUES | 54 | .Sh RETURN VALUES |
61 | The | 55 | The |
62 | .Fn memcmp | 56 | .Fn memcmp |
63 | function | 57 | function returns zero if the two strings are identical, |
64 | returns zero if the the two strings are identical, | ||
65 | otherwise returns the difference between the first two differing bytes | 58 | otherwise returns the difference between the first two differing bytes |
66 | (treated as unsigned char values, so that | 59 | (treated as |
60 | .Li unsigned char | ||
61 | values, so that | ||
67 | .Sq Li \e200 | 62 | .Sq Li \e200 |
68 | is greater than | 63 | is greater than |
69 | .Sq Li \&\e0 , | 64 | .Sq Li \&\e0 , |
@@ -78,6 +73,5 @@ Zero-length strings are always identical. | |||
78 | .Sh STANDARDS | 73 | .Sh STANDARDS |
79 | The | 74 | The |
80 | .Fn memcmp | 75 | .Fn memcmp |
81 | function | 76 | function conforms to |
82 | conforms to | ||
83 | .St -ansiC . | 77 | .St -ansiC . |
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c index 23d2ab2393..49384a6fb9 100644 --- a/src/lib/libc/string/memcmp.c +++ b/src/lib/libc/string/memcmp.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: memcmp.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,23 +31,16 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
45 | * Compare memory regions. | 37 | * Compare memory regions. |
46 | */ | 38 | */ |
47 | int | 39 | int |
48 | memcmp(s1, s2, n) | 40 | memcmp(const void *s1, const void *s2, size_t n) |
49 | const void *s1, *s2; | ||
50 | size_t n; | ||
51 | { | 41 | { |
52 | if (n != 0) { | 42 | if (n != 0) { |
53 | register const unsigned char *p1 = s1, *p2 = s2; | 43 | const unsigned char *p1 = s1, *p2 = s2; |
54 | 44 | ||
55 | do { | 45 | do { |
56 | if (*p1++ != *p2++) | 46 | if (*p1++ != *p2++) |
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3 index 3f4bb643c9..1deb03631b 100644 --- a/src/lib/libc/string/memcpy.3 +++ b/src/lib/libc/string/memcpy.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,15 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memcpy.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt MEMCPY 3 | 35 | .Dt MEMCPY 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm memcpy | 38 | .Nm memcpy |
44 | .Nd copy byte string | 39 | .Nd copy bytes |
45 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft void * | 42 | .Ft void * |
@@ -49,36 +44,34 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn memcpy | 46 | .Fn memcpy |
52 | function | 47 | function copies |
53 | copies | ||
54 | .Fa len | 48 | .Fa len |
55 | bytes from string | 49 | bytes from buffer |
56 | .Fa src | 50 | .Fa src |
57 | to string | 51 | to buffer |
58 | .Fa dst . | 52 | .Fa dst . |
59 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
60 | The | 54 | The |
61 | .Fn memcpy | 55 | .Fn memcpy |
62 | function | 56 | function returns the original value of |
63 | returns the original value of | ||
64 | .Fa dst . | 57 | .Fa dst . |
65 | .Sh SEE ALSO | 58 | .Sh SEE ALSO |
66 | .Xr bcopy 3 , | 59 | .Xr bcopy 3 , |
67 | .Xr memccpy 3 , | 60 | .Xr memccpy 3 , |
68 | .Xr memmove 3 , | 61 | .Xr memmove 3 , |
69 | .Xr strcpy 3 | 62 | .Xr strcpy 3 , |
63 | .Xr strlcpy 3 | ||
70 | .Sh STANDARDS | 64 | .Sh STANDARDS |
71 | The | 65 | The |
72 | .Fn memcpy | 66 | .Fn memcpy |
73 | function | 67 | function conforms to |
74 | conforms to | ||
75 | .St -ansiC . | 68 | .St -ansiC . |
76 | .Sh BUGS | 69 | .Sh BUGS |
77 | In this implementation | 70 | In this implementation |
78 | .Fn memcpy | 71 | .Fn memcpy |
79 | is implemented using | 72 | is implemented using |
80 | .Xr bcopy 3 , | 73 | .Xr bcopy 3 , |
81 | and therefore the strings may overlap. | 74 | and therefore the buffers may overlap. |
82 | On other systems, copying overlapping strings may produce surprises. | 75 | On other systems, copying overlapping buffers may produce surprises. |
83 | A simpler solution is to not use | 76 | A simpler solution is to not use |
84 | .Fn memcpy . | 77 | .Fn memcpy . |
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 index 24422e7971..c6e3912669 100644 --- a/src/lib/libc/string/memmove.3 +++ b/src/lib/libc/string/memmove.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,15 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memmove.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt MEMMOVE 3 | 35 | .Dt MEMMOVE 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm memmove | 38 | .Nm memmove |
44 | .Nd copy byte string | 39 | .Nd copy bytes |
45 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft void * | 42 | .Ft void * |
@@ -49,14 +44,13 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn memmove | 46 | .Fn memmove |
52 | function | 47 | function copies |
53 | copies | ||
54 | .Fa len | 48 | .Fa len |
55 | bytes from string | 49 | bytes from buffer |
56 | .Fa src | 50 | .Fa src |
57 | to string | 51 | to buffer |
58 | .Fa dst . | 52 | .Fa dst . |
59 | The two strings may overlap; | 53 | The two buffers may overlap; |
60 | the copy is always done in a non-destructive manner. | 54 | the copy is always done in a non-destructive manner. |
61 | .Sh RETURN VALUES | 55 | .Sh RETURN VALUES |
62 | The | 56 | The |
@@ -67,10 +61,10 @@ function returns the original value of | |||
67 | .Xr bcopy 3 , | 61 | .Xr bcopy 3 , |
68 | .Xr memccpy 3 , | 62 | .Xr memccpy 3 , |
69 | .Xr memcpy 3 , | 63 | .Xr memcpy 3 , |
70 | .Xr strcpy 3 | 64 | .Xr strcpy 3 , |
65 | .Xr strlcpy 3 | ||
71 | .Sh STANDARDS | 66 | .Sh STANDARDS |
72 | The | 67 | The |
73 | .Fn memmove | 68 | .Fn memmove |
74 | function | 69 | function conforms to |
75 | conforms to | ||
76 | .St -ansiC . | 70 | .St -ansiC . |
diff --git a/src/lib/libc/string/memrchr.c b/src/lib/libc/string/memrchr.c new file mode 100644 index 0000000000..bd27ebc620 --- /dev/null +++ b/src/lib/libc/string/memrchr.c | |||
@@ -0,0 +1,38 @@ | |||
1 | /* $OpenBSD: memrchr.c,v 1.2 2007/11/27 16:22:12 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <string.h> | ||
20 | |||
21 | /* | ||
22 | * Reverse memchr() | ||
23 | * Find the last occurrence of 'c' in the buffer 's' of size 'n'. | ||
24 | */ | ||
25 | void * | ||
26 | memrchr(const void *s, int c, size_t n) | ||
27 | { | ||
28 | const unsigned char *cp; | ||
29 | |||
30 | if (n != 0) { | ||
31 | cp = (unsigned char *)s + n; | ||
32 | do { | ||
33 | if (*(--cp) == (unsigned char)c) | ||
34 | return((void *)cp); | ||
35 | } while (--n != 0); | ||
36 | } | ||
37 | return(NULL); | ||
38 | } | ||
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3 index 1afc052182..7799b5e2d2 100644 --- a/src/lib/libc/string/memset.3 +++ b/src/lib/libc/string/memset.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memset.3,v 1.6 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt MEMSET 3 | 35 | .Dt MEMSET 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,12 +44,18 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn memset | 46 | .Fn memset |
52 | function | 47 | function writes |
53 | writes | ||
54 | .Fa len | 48 | .Fa len |
55 | bytes of value | 49 | bytes of value |
56 | .Fa c | 50 | .Fa c |
57 | (converted to an unsigned char) to the string | 51 | (converted to an |
52 | .Li unsigned char ) | ||
53 | to the string | ||
54 | .Fa b . | ||
55 | .Sh RETURN VALUES | ||
56 | The | ||
57 | .Fn memset | ||
58 | function returns the original value of | ||
58 | .Fa b . | 59 | .Fa b . |
59 | .Sh SEE ALSO | 60 | .Sh SEE ALSO |
60 | .Xr bzero 3 , | 61 | .Xr bzero 3 , |
@@ -62,6 +63,5 @@ bytes of value | |||
62 | .Sh STANDARDS | 63 | .Sh STANDARDS |
63 | The | 64 | The |
64 | .Fn memset | 65 | .Fn memset |
65 | function | 66 | function conforms to |
66 | conforms to | ||
67 | .St -ansiC . | 67 | .St -ansiC . |
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c index 117de2e80b..61709c139d 100644 --- a/src/lib/libc/string/memset.c +++ b/src/lib/libc/string/memset.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: memset.c,v 1.6 2008/03/15 21:40:39 ray Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,25 +31,16 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | void * | 36 | void * |
45 | memset(dst, c, n) | 37 | memset(void *dst, int c, size_t n) |
46 | void *dst; | ||
47 | register int c; | ||
48 | register size_t n; | ||
49 | { | 38 | { |
50 | |||
51 | if (n != 0) { | 39 | if (n != 0) { |
52 | register char *d = dst; | 40 | unsigned char *d = dst; |
53 | 41 | ||
54 | do | 42 | do |
55 | *d++ = c; | 43 | *d++ = (unsigned char)c; |
56 | while (--n != 0); | 44 | while (--n != 0); |
57 | } | 45 | } |
58 | return (dst); | 46 | return (dst); |
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/rindex.3 deleted file mode 100644 index b13b3513e0..0000000000 --- a/src/lib/libc/string/rindex.3 +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" Chris Torek. | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. 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 index 1b84c92072..bf9d6f7cf1 100644 --- a/src/lib/libc/string/rindex.c +++ b/src/lib/libc/string/rindex.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: rindex.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 3 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,22 +28,16 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <string.h> |
40 | 32 | ||
41 | char * | 33 | char * |
42 | #ifdef STRRCHR | 34 | #ifdef STRRCHR |
43 | strrchr(p, ch) | 35 | strrchr(const char *p, int ch) |
44 | #else | 36 | #else |
45 | rindex(p, ch) | 37 | rindex(const char *p, int ch) |
46 | #endif | 38 | #endif |
47 | register const char *p, ch; | ||
48 | { | 39 | { |
49 | register char *save; | 40 | char *save; |
50 | 41 | ||
51 | for (save = NULL;; ++p) { | 42 | for (save = NULL;; ++p) { |
52 | if (*p == ch) | 43 | if (*p == ch) |
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 index 46e9010e4f..c17aa694d1 100644 --- a/src/lib/libc/string/strcasecmp.3 +++ b/src/lib/libc/string/strcasecmp.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strcasecmp.3,v 1.10 2007/05/31 19:19:32 jmc Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
@@ -11,11 +13,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
21 | .\" | 19 | .\" |
@@ -31,14 +29,14 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
33 | .\" | 31 | .\" |
34 | .\" from: @(#)strcasecmp.3 5.4 (Berkeley) 4/19/91 | 32 | .\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 |
35 | .\" $Id: strcasecmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
36 | .\" | 33 | .\" |
37 | .Dd April 19, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt STRCASECMP 3 | 35 | .Dt STRCASECMP 3 |
39 | .Os | 36 | .Os |
40 | .Sh NAME | 37 | .Sh NAME |
41 | .Nm strcasecmp | 38 | .Nm strcasecmp , |
39 | .Nm strncasecmp | ||
42 | .Nd compare strings, ignoring case | 40 | .Nd compare strings, ignoring case |
43 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
44 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
@@ -51,13 +49,12 @@ The | |||
51 | .Fn strcasecmp | 49 | .Fn strcasecmp |
52 | and | 50 | and |
53 | .Fn strncasecmp | 51 | .Fn strncasecmp |
54 | functions | 52 | functions compare the NUL-terminated strings |
55 | compare the null-terminated strings | ||
56 | .Fa s1 | 53 | .Fa s1 |
57 | and | 54 | and |
58 | .Fa s2 | 55 | .Fa s2 |
59 | and return an integer greater than, equal to, or less than 0, | 56 | and return an integer greater than, equal to, or less than 0, |
60 | according as | 57 | according to whether |
61 | .Fa s1 | 58 | .Fa s1 |
62 | is lexicographically greater than, equal to, or less than | 59 | is lexicographically greater than, equal to, or less than |
63 | .Fa s2 | 60 | .Fa s2 |
@@ -68,7 +65,6 @@ The comparison is done using unsigned characters, so that | |||
68 | is greater than | 65 | is greater than |
69 | .Ql \e0 . | 66 | .Ql \e0 . |
70 | .Pp | 67 | .Pp |
71 | The | ||
72 | .Fn strncasecmp | 68 | .Fn strncasecmp |
73 | compares at most | 69 | compares at most |
74 | .Fa len | 70 | .Fa len |
@@ -84,5 +80,5 @@ The | |||
84 | .Fn strcasecmp | 80 | .Fn strcasecmp |
85 | and | 81 | and |
86 | .Fn strncasecmp | 82 | .Fn strncasecmp |
87 | functions are | 83 | functions first appeared in |
88 | .Ud . | 84 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c index 79bd0081e3..2be09136c0 100644 --- a/src/lib/libc/string/strcasecmp.c +++ b/src/lib/libc/string/strcasecmp.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strcasecmp.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | 4 | * Copyright (c) 1987, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,11 +29,6 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
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> | 32 | #include <string.h> |
40 | 33 | ||
41 | typedef unsigned char u_char; | 34 | typedef unsigned char u_char; |
@@ -81,12 +74,11 @@ static const u_char charmap[] = { | |||
81 | }; | 74 | }; |
82 | 75 | ||
83 | int | 76 | int |
84 | strcasecmp(s1, s2) | 77 | strcasecmp(const char *s1, const char *s2) |
85 | const char *s1, *s2; | ||
86 | { | 78 | { |
87 | register const u_char *cm = charmap, | 79 | const u_char *cm = charmap; |
88 | *us1 = (const u_char *)s1, | 80 | const u_char *us1 = (const u_char *)s1; |
89 | *us2 = (const u_char *)s2; | 81 | const u_char *us2 = (const u_char *)s2; |
90 | 82 | ||
91 | while (cm[*us1] == cm[*us2++]) | 83 | while (cm[*us1] == cm[*us2++]) |
92 | if (*us1++ == '\0') | 84 | if (*us1++ == '\0') |
@@ -95,14 +87,12 @@ strcasecmp(s1, s2) | |||
95 | } | 87 | } |
96 | 88 | ||
97 | int | 89 | int |
98 | strncasecmp(s1, s2, n) | 90 | strncasecmp(const char *s1, const char *s2, size_t n) |
99 | const char *s1, *s2; | ||
100 | register size_t n; | ||
101 | { | 91 | { |
102 | if (n != 0) { | 92 | if (n != 0) { |
103 | register const u_char *cm = charmap, | 93 | const u_char *cm = charmap; |
104 | *us1 = (const u_char *)s1, | 94 | const u_char *us1 = (const u_char *)s1; |
105 | *us2 = (const u_char *)s2; | 95 | const u_char *us2 = (const u_char *)s2; |
106 | 96 | ||
107 | do { | 97 | do { |
108 | if (cm[*us1] != cm[*us2++]) | 98 | if (cm[*us1] != cm[*us2++]) |
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/strcasestr.c index 1937e2d608..aa74c0176d 100644 --- a/src/lib/libc/string/__strsignal.c +++ b/src/lib/libc/string/strcasestr.c | |||
@@ -1,6 +1,12 @@ | |||
1 | /* | 1 | /* $OpenBSD: strcasestr.c,v 1.3 2006/03/31 05:34:55 deraadt Exp $ */ |
2 | * Copyright (c) 1988 Regents of the University of California. | 2 | /* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ |
3 | * All rights reserved. | 3 | |
4 | /*- | ||
5 | * Copyright (c) 1990, 1993 | ||
6 | * The Regents of the University of California. All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to Berkeley by | ||
9 | * Chris Torek. | ||
4 | * | 10 | * |
5 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions |
@@ -10,11 +16,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 17 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 18 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 19 | * 3. Neither the name of the University nor the names of its contributors |
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 | 20 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 21 | * without specific prior written permission. |
20 | * | 22 | * |
@@ -31,56 +33,28 @@ | |||
31 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. |
32 | */ | 34 | */ |
33 | 35 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #include <ctype.h> |
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> | 37 | #include <string.h> |
51 | 38 | ||
39 | /* | ||
40 | * Find the first occurrence of find in s, ignore case. | ||
41 | */ | ||
52 | char * | 42 | char * |
53 | __strsignal(num, buf) | 43 | strcasestr(const char *s, const char *find) |
54 | int num; | ||
55 | char *buf; | ||
56 | { | 44 | { |
57 | #define UPREFIX "Unknown signal: %u" | 45 | char c, sc; |
58 | register unsigned int signum; | 46 | size_t len; |
59 | 47 | ||
60 | #ifdef NLS | 48 | if ((c = *find++) != 0) { |
61 | nl_catd catd ; | 49 | c = (char)tolower((unsigned char)c); |
62 | catd = catopen("libc", 0); | 50 | len = strlen(find); |
63 | #endif | 51 | do { |
64 | 52 | do { | |
65 | signum = num; /* convert to unsigned */ | 53 | if ((sc = *s++) == 0) |
66 | if (signum < NSIG) { | 54 | return (NULL); |
67 | #ifdef NLS | 55 | } while ((char)tolower((unsigned char)sc) != c); |
68 | strcpy(buf, catgets(catd, 2, signum, | 56 | } while (strncasecmp(s, find, len) != 0); |
69 | (char *)sys_siglist[signum])); | 57 | s--; |
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 | } | 58 | } |
80 | 59 | return ((char *)s); | |
81 | #ifdef NLS | ||
82 | catclose(catd); | ||
83 | #endif | ||
84 | |||
85 | return buf; | ||
86 | } | 60 | } |
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..4068db752c 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,14 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcat.3,v 1.12 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCAT 3 | 35 | .Dt STRCAT 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strcat | 38 | .Nm strcat , |
39 | .Nm strncat | ||
44 | .Nd concatenate strings | 40 | .Nd concatenate strings |
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
@@ -53,10 +49,9 @@ The | |||
53 | .Fn strcat | 49 | .Fn strcat |
54 | and | 50 | and |
55 | .Fn strncat | 51 | .Fn strncat |
56 | functions | 52 | functions append a copy of the NUL-terminated string |
57 | append a copy of the null-terminated string | ||
58 | .Fa append | 53 | .Fa append |
59 | to the end of the null-terminated string | 54 | to the end of the NUL-terminated string |
60 | .Fa s , | 55 | .Fa s , |
61 | then add a terminating | 56 | then add a terminating |
62 | .Ql \e0 . | 57 | .Ql \e0 . |
@@ -66,29 +61,73 @@ must have sufficient space to hold the result. | |||
66 | .Pp | 61 | .Pp |
67 | The | 62 | The |
68 | .Fn strncat | 63 | .Fn strncat |
69 | function | 64 | function appends not more than |
70 | appends not more than | ||
71 | .Fa count | 65 | .Fa count |
72 | characters. | 66 | characters where space for the terminating |
67 | .Ql \e0 | ||
68 | should not be included in | ||
69 | .Fa count . | ||
73 | .Sh RETURN VALUES | 70 | .Sh RETURN VALUES |
74 | The | 71 | The |
75 | .Fn strcat | 72 | .Fn strcat |
76 | and | 73 | and |
77 | .Fn strncat | 74 | .Fn strncat |
78 | functions | 75 | functions return the pointer |
79 | return the pointer | ||
80 | .Fa s . | 76 | .Fa s . |
77 | .Sh EXAMPLES | ||
78 | The following appends | ||
79 | .Dq Li abc | ||
80 | to | ||
81 | .Va chararray : | ||
82 | .Bd -literal -offset indent | ||
83 | char *letters = "abcdefghi"; | ||
84 | |||
85 | (void)strncat(chararray, letters, 3); | ||
86 | .Ed | ||
87 | .Pp | ||
88 | The following example shows how to use | ||
89 | .Fn strncat | ||
90 | safely in conjunction with | ||
91 | .Xr strncpy 3 . | ||
92 | .Bd -literal -offset indent | ||
93 | char buf[BUFSIZ]; | ||
94 | char *input, *suffix; | ||
95 | |||
96 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
97 | buf[sizeof(buf) - 1] = '\e0'; | ||
98 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
99 | .Ed | ||
100 | .Pp | ||
101 | The above will copy as many characters from | ||
102 | .Va input | ||
103 | to | ||
104 | .Va buf | ||
105 | as will fit. | ||
106 | It then appends as many characters from | ||
107 | .Va suffix | ||
108 | as will fit (or none | ||
109 | if there is no space). | ||
110 | For operations like this, the | ||
111 | .Xr strlcpy 3 | ||
112 | and | ||
113 | .Xr strlcat 3 | ||
114 | functions are a better choice, as shown below. | ||
115 | .Bd -literal -offset indent | ||
116 | (void)strlcpy(buf, input, sizeof(buf)); | ||
117 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
118 | .Ed | ||
81 | .Sh SEE ALSO | 119 | .Sh SEE ALSO |
82 | .Xr bcopy 3 , | 120 | .Xr bcopy 3 , |
83 | .Xr memccpy 3 , | 121 | .Xr memccpy 3 , |
84 | .Xr memcpy 3 , | 122 | .Xr memcpy 3 , |
85 | .Xr memmove 3 , | 123 | .Xr memmove 3 , |
86 | .Xr strcpy 3 | 124 | .Xr strcpy 3 , |
125 | .Xr strlcat 3 , | ||
126 | .Xr strlcpy 3 | ||
87 | .Sh STANDARDS | 127 | .Sh STANDARDS |
88 | The | 128 | The |
89 | .Fn strcat | 129 | .Fn strcat |
90 | and | 130 | and |
91 | .Fn strncat | 131 | .Fn strncat |
92 | functions | 132 | functions conform to |
93 | conform to | ||
94 | .St -ansiC . | 133 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c index e741b84f03..7cea5229fb 100644 --- a/src/lib/libc/string/strcat.c +++ b/src/lib/libc/string/strcat.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: strcat.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 4 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,21 +29,23 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
37 | |||
38 | #if defined(APIWARN) | ||
39 | __warn_references(strcat, | ||
40 | "warning: strcat() is almost always misused, please use strlcat()"); | ||
41 | #endif | ||
40 | 42 | ||
41 | char * | 43 | char * |
42 | strcat(s, append) | 44 | strcat(char *s, const char *append) |
43 | register char *s; | ||
44 | register const char *append; | ||
45 | { | 45 | { |
46 | char *save = s; | 46 | char *save = s; |
47 | 47 | ||
48 | for (; *s; ++s); | 48 | for (; *s; ++s); |
49 | while (*s++ = *append++); | 49 | while ((*s++ = *append++) != '\0'); |
50 | return(save); | 50 | return(save); |
51 | } | 51 | } |
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3 index 18b50301f3..6a9de9604e 100644 --- a/src/lib/libc/string/strchr.3 +++ b/src/lib/libc/string/strchr.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,29 +29,29 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strchr.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCHR 3 | 35 | .Dt STRCHR 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strchr | 38 | .Nm strchr , |
44 | .Nd locate character in string | 39 | .Nm index |
40 | .Nd locate first occurrence of a character in a string | ||
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
47 | .Ft char * | 43 | .Ft char * |
48 | .Fn strchr "const char *s" "int c" | 44 | .Fn strchr "const char *s" "int c" |
45 | .Ft char * | ||
46 | .Fn index "const char *s" "int c" | ||
49 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
50 | The | 48 | The |
51 | .Fn strchr | 49 | .Fn strchr |
52 | function locates the first occurrence of | 50 | function locates the first occurrence of the character |
53 | .Ar c | 51 | .Fa c |
54 | in the string pointed to by | 52 | in the string |
55 | .Ar s . | 53 | .Fa s . |
56 | The terminating | 54 | The terminating NUL character is considered part of the string. |
57 | .Dv NULL | ||
58 | character is considered part of the string. | ||
59 | If | 55 | If |
60 | .Fa c | 56 | .Fa c |
61 | is | 57 | is |
@@ -63,16 +59,31 @@ is | |||
63 | .Fn strchr | 59 | .Fn strchr |
64 | locates the terminating | 60 | locates the terminating |
65 | .Ql \e0 . | 61 | .Ql \e0 . |
62 | .Pp | ||
63 | The | ||
64 | .Fn index | ||
65 | function is an old synonym for | ||
66 | .Fn strchr . | ||
66 | .Sh RETURN VALUES | 67 | .Sh RETURN VALUES |
67 | The function | 68 | The |
68 | .Fn strchr | 69 | .Fn strchr |
69 | returns a pointer to the located character, or | 70 | function returns a pointer to the located character or |
70 | .Dv NULL | 71 | .Dv NULL |
71 | if the character does not appear in the string. | 72 | if the character does not appear in the string. |
73 | .Sh EXAMPLES | ||
74 | After the following call to | ||
75 | .Fn strchr , | ||
76 | .Va p | ||
77 | will point to the string | ||
78 | .Qq oobar : | ||
79 | .Bd -literal -offset indent | ||
80 | char *p; | ||
81 | char *s = "foobar"; | ||
82 | |||
83 | p = strchr(s, 'o'); | ||
84 | .Ed | ||
72 | .Sh SEE ALSO | 85 | .Sh SEE ALSO |
73 | .Xr index 3 , | ||
74 | .Xr memchr 3 , | 86 | .Xr memchr 3 , |
75 | .Xr rindex 3 , | ||
76 | .Xr strcspn 3 , | 87 | .Xr strcspn 3 , |
77 | .Xr strpbrk 3 , | 88 | .Xr strpbrk 3 , |
78 | .Xr strrchr 3 , | 89 | .Xr strrchr 3 , |
@@ -83,6 +94,9 @@ if the character does not appear in the string. | |||
83 | .Sh STANDARDS | 94 | .Sh STANDARDS |
84 | The | 95 | The |
85 | .Fn strchr | 96 | .Fn strchr |
86 | function | 97 | function conforms to |
87 | conforms to | ||
88 | .St -ansiC . | 98 | .St -ansiC . |
99 | .Pp | ||
100 | The | ||
101 | .Fn index | ||
102 | function is deprecated and shouldn't be used in new code. | ||
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 index fecaa85410..73cd5b40d8 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,14 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcmp.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCMP 3 | 35 | .Dt STRCMP 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strcmp | 38 | .Nm strcmp , |
39 | .Nm strncmp | ||
44 | .Nd compare strings | 40 | .Nd compare strings |
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
@@ -53,8 +49,7 @@ The | |||
53 | .Fn strcmp | 49 | .Fn strcmp |
54 | and | 50 | and |
55 | .Fn strncmp | 51 | .Fn strncmp |
56 | functions | 52 | functions lexicographically compare the NUL-terminated strings |
57 | lexicographically compare the null-terminated strings | ||
58 | .Fa s1 | 53 | .Fa s1 |
59 | and | 54 | and |
60 | .Fa s2 . | 55 | .Fa s2 . |
@@ -64,7 +59,7 @@ The | |||
64 | and | 59 | and |
65 | .Fn strncmp | 60 | .Fn strncmp |
66 | return an integer greater than, equal to, or less than 0, according | 61 | return an integer greater than, equal to, or less than 0, according |
67 | as the string | 62 | to whether the string |
68 | .Fa s1 | 63 | .Fa s1 |
69 | is greater than, equal to, or less than the string | 64 | is greater than, equal to, or less than the string |
70 | .Fa s2 . | 65 | .Fa s2 . |
@@ -73,9 +68,8 @@ The comparison is done using unsigned characters, so that | |||
73 | is greater than | 68 | is greater than |
74 | .Ql \e0 . | 69 | .Ql \e0 . |
75 | .Pp | 70 | .Pp |
76 | The | ||
77 | .Fn strncmp | 71 | .Fn strncmp |
78 | compares not more than | 72 | compares at most |
79 | .Fa len | 73 | .Fa len |
80 | characters. | 74 | characters. |
81 | .Sh SEE ALSO | 75 | .Sh SEE ALSO |
@@ -89,6 +83,5 @@ The | |||
89 | .Fn strcmp | 83 | .Fn strcmp |
90 | and | 84 | and |
91 | .Fn strncmp | 85 | .Fn strncmp |
92 | functions | 86 | functions conform to |
93 | conform to | ||
94 | .St -ansiC . | 87 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c index ae19e2e26e..816fd111ac 100644 --- a/src/lib/libc/string/strcmp.c +++ b/src/lib/libc/string/strcmp.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: strcmp.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -13,11 +15,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 16 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 17 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 18 | * 3. Neither the name of the University nor the names of its contributors |
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 | 19 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 20 | * without specific prior written permission. |
23 | * | 21 | * |
@@ -34,19 +32,17 @@ | |||
34 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. |
35 | */ | 33 | */ |
36 | 34 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 35 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 36 | #include <string.h> |
37 | #else | ||
38 | #include <lib/libkern/libkern.h> | ||
39 | #endif | ||
43 | 40 | ||
44 | /* | 41 | /* |
45 | * Compare strings. | 42 | * Compare strings. |
46 | */ | 43 | */ |
47 | int | 44 | int |
48 | strcmp(s1, s2) | 45 | strcmp(const char *s1, const char *s2) |
49 | register const char *s1, *s2; | ||
50 | { | 46 | { |
51 | while (*s1 == *s2++) | 47 | while (*s1 == *s2++) |
52 | if (*s1++ == 0) | 48 | if (*s1++ == 0) |
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3 index 12f73f98f2..ea7452a749 100644 --- a/src/lib/libc/string/strcoll.3 +++ b/src/lib/libc/string/strcoll.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strcoll.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcoll.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strcoll.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCOLL 3 | 35 | .Dt STRCOLL 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,14 +44,13 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn strcoll | 46 | .Fn strcoll |
52 | function | 47 | function lexicographically compares the NUL-terminated strings |
53 | lexicographically compares the null-terminated strings | ||
54 | .Fa s1 | 48 | .Fa s1 |
55 | and | 49 | and |
56 | .Fa s2 | 50 | .Fa s2 |
57 | according to the current locale collation | 51 | according to the current locale collation |
58 | and returns an integer greater than, equal to, or less than 0, | 52 | and returns an integer greater than, equal to, or less than 0, |
59 | according as | 53 | according to whether |
60 | .Fa s1 | 54 | .Fa s1 |
61 | is greater than, equal to, or less than | 55 | is greater than, equal to, or less than |
62 | .Fa s2 . | 56 | .Fa s2 . |
@@ -70,6 +64,5 @@ is greater than, equal to, or less than | |||
70 | .Sh STANDARDS | 64 | .Sh STANDARDS |
71 | The | 65 | The |
72 | .Fn strcoll | 66 | .Fn strcoll |
73 | function | 67 | function conforms to |
74 | conforms to | ||
75 | .St -ansiC . | 68 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c index 86c742cba9..2df983bd65 100644 --- a/src/lib/libc/string/strcoll.c +++ b/src/lib/libc/string/strcoll.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strcoll.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,19 +31,13 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
45 | * Compare strings according to LC_COLLATE category of current locale. | 37 | * Compare strings according to LC_COLLATE category of current locale. |
46 | */ | 38 | */ |
47 | int | 39 | int |
48 | strcoll(s1, s2) | 40 | strcoll(const char *s1, const char *s2) |
49 | const char *s1, *s2; | ||
50 | { | 41 | { |
51 | /* LC_COLLATE is unimplemented, hence always "C" */ | 42 | /* LC_COLLATE is unimplemented, hence always "C" */ |
52 | return (strcmp(s1, s2)); | 43 | return (strcmp(s1, s2)); |
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..428e474d43 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,14 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcpy.3,v 1.15 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCPY 3 | 35 | .Dt STRCPY 3 |
41 | .Os BSD 4 | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strcpy | 38 | .Nm strcpy , |
39 | .Nm strncpy | ||
44 | .Nd copy strings | 40 | .Nd copy strings |
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
@@ -53,8 +49,7 @@ The | |||
53 | .Fn strcpy | 49 | .Fn strcpy |
54 | and | 50 | and |
55 | .Fn strncpy | 51 | .Fn strncpy |
56 | functions | 52 | functions copy the string |
57 | copy the string | ||
58 | .Fa src | 53 | .Fa src |
59 | to | 54 | to |
60 | .Fa dst | 55 | .Fa dst |
@@ -62,7 +57,6 @@ to | |||
62 | .Ql \e0 | 57 | .Ql \e0 |
63 | character). | 58 | character). |
64 | .Pp | 59 | .Pp |
65 | The | ||
66 | .Fn strncpy | 60 | .Fn strncpy |
67 | copies not more than | 61 | copies not more than |
68 | .Fa len | 62 | .Fa len |
@@ -78,45 +72,80 @@ characters long, and | |||
78 | .Em not | 72 | .Em not |
79 | terminating | 73 | terminating |
80 | .Fa dst | 74 | .Fa dst |
81 | if | 75 | if the length of |
82 | .Fa src | 76 | .Fa src |
83 | is more than | 77 | is greater than or equal to |
84 | .Fa len | 78 | .Fa len . |
85 | characters long. | ||
86 | .Sh RETURN VALUES | 79 | .Sh RETURN VALUES |
87 | The | 80 | The |
88 | .Fn strcpy | 81 | .Fn strcpy |
89 | and | 82 | and |
90 | .Fn strncpy | 83 | .Fn strncpy |
91 | functions | 84 | functions return |
92 | return | ||
93 | .Fa dst . | 85 | .Fa dst . |
94 | .Sh EXAMPLES | 86 | .Sh EXAMPLES |
95 | The following sets | 87 | The following sets |
96 | .Dq Li chararray | 88 | .Va chararray |
97 | to | 89 | to |
98 | .Dq Li abc\e0\e0\e0 : | 90 | .Dq abc\e0\e0\e0 : |
99 | .Bd -literal -offset indent | 91 | .Bd -literal -offset indent |
100 | (void)strncpy(chararray, "abc", 6). | 92 | (void)strncpy(chararray, "abc", 6); |
101 | .Ed | 93 | .Ed |
102 | .Pp | 94 | .Pp |
103 | The following sets | 95 | The following sets |
104 | .Dq Li chararray | 96 | .Va chararray |
105 | to | 97 | to |
106 | .Dq Li abcdef : | 98 | .Dq abcdef |
99 | and does | ||
100 | .Em not | ||
101 | NUL terminate | ||
102 | .Va chararray | ||
103 | because the length of the source string is greater than or equal to the | ||
104 | length parameter. | ||
105 | .Fn strncpy | ||
106 | .Em only | ||
107 | NUL terminates the destination string when the length of the source | ||
108 | string is less than the length parameter. | ||
107 | .Bd -literal -offset indent | 109 | .Bd -literal -offset indent |
108 | (void)strncpy(chararray, "abcdefgh", 6); | 110 | (void)strncpy(chararray, "abcdefgh", 6); |
109 | .Ed | 111 | .Ed |
112 | .Pp | ||
113 | The following copies as many characters from | ||
114 | .Va input | ||
115 | to | ||
116 | .Va buf | ||
117 | as will fit and NUL terminates the result. | ||
118 | Because | ||
119 | .Fn strncpy | ||
120 | does | ||
121 | .Em not | ||
122 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
123 | .Bd -literal -offset indent | ||
124 | char buf[BUFSIZ]; | ||
125 | |||
126 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
127 | buf[sizeof(buf) - 1] = '\e0'; | ||
128 | .Ed | ||
129 | .Pp | ||
130 | Note that | ||
131 | .Xr strlcpy 3 | ||
132 | is a better choice for this kind of operation. | ||
133 | The equivalent using | ||
134 | .Xr strlcpy 3 | ||
135 | is simply: | ||
136 | .Bd -literal -offset indent | ||
137 | (void)strlcpy(buf, input, sizeof(buf)); | ||
138 | .Ed | ||
110 | .Sh SEE ALSO | 139 | .Sh SEE ALSO |
111 | .Xr bcopy 3 , | 140 | .Xr bcopy 3 , |
112 | .Xr memccpy 3 , | 141 | .Xr memccpy 3 , |
113 | .Xr memcpy 3 , | 142 | .Xr memcpy 3 , |
114 | .Xr memmove 3 | 143 | .Xr memmove 3 , |
144 | .Xr strlcpy 3 | ||
115 | .Sh STANDARDS | 145 | .Sh STANDARDS |
116 | The | 146 | The |
117 | .Fn strcpy | 147 | .Fn strcpy |
118 | and | 148 | and |
119 | .Fn strncpy | 149 | .Fn strncpy |
120 | functions | 150 | functions conform to |
121 | conform to | ||
122 | .St -ansiC . | 151 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c index 669bfde23e..71d90d4100 100644 --- a/src/lib/libc/string/strcpy.c +++ b/src/lib/libc/string/strcpy.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: strcpy.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 4 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,20 +29,22 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
37 | |||
38 | #if defined(APIWARN) | ||
39 | __warn_references(strcpy, | ||
40 | "warning: strcpy() is almost always misused, please use strlcpy()"); | ||
41 | #endif | ||
40 | 42 | ||
41 | char * | 43 | char * |
42 | strcpy(to, from) | 44 | strcpy(char *to, const char *from) |
43 | register char *to; | ||
44 | register const char *from; | ||
45 | { | 45 | { |
46 | char *save = to; | 46 | char *save = to; |
47 | 47 | ||
48 | for (; *to = *from; ++from, ++to); | 48 | for (; (*to = *from) != '\0'; ++from, ++to); |
49 | return(save); | 49 | return(save); |
50 | } | 50 | } |
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3 index cc9e5c2fe3..21c727344d 100644 --- a/src/lib/libc/string/strcspn.3 +++ b/src/lib/libc/string/strcspn.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcspn.3,v 1.9 2007/08/08 07:20:45 ray Exp $ |
37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: August 8 2007 $ |
40 | .Dt STRCSPN 3 | 35 | .Dt STRCSPN 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,27 +44,48 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn strcspn | 46 | .Fn strcspn |
52 | function | 47 | function spans the initial part of the NUL-terminated string |
53 | spans the initial part of the null-terminated string | ||
54 | .Fa s | 48 | .Fa s |
55 | as long as the characters from | 49 | as long as the characters from |
56 | .Fa s | 50 | .Fa s |
57 | do not occur in string | 51 | do not occur in string |
58 | .Fa charset | 52 | .Fa charset |
59 | (it | 53 | (it spans the |
60 | spans the | ||
61 | .Em complement | 54 | .Em complement |
62 | of | 55 | of |
63 | .Fa charset ) . | 56 | .Fa charset ) . |
64 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
65 | The | 58 | The |
66 | .Fn strcspn | 59 | .Fn strcspn |
67 | function | 60 | function returns the number of characters spanned. |
68 | returns the number of characters spanned. | 61 | .Sh EXAMPLES |
62 | The following call to | ||
63 | .Fn strcspn | ||
64 | will return 3, since the first three characters of string | ||
65 | .Fa s | ||
66 | do not occur in string | ||
67 | .Fa charset : | ||
68 | .Bd -literal -offset indent | ||
69 | char *s = "foobar"; | ||
70 | char *charset = "bar"; | ||
71 | size_t span; | ||
72 | |||
73 | span = strcspn(s, charset); | ||
74 | .Ed | ||
75 | .Pp | ||
76 | The following removes the first (if any) newline character from string | ||
77 | .Fa line . | ||
78 | This is useful for trimming the newline after a | ||
79 | .Xr fgets 3 | ||
80 | call. | ||
81 | .Bd -literal -offset indent | ||
82 | char line[BUFSIZ]; | ||
83 | |||
84 | if (fgets(line, sizeof(line), fp) != NULL) | ||
85 | line[strcspn(line, "\en")] = '\e0'; | ||
86 | .Ed | ||
69 | .Sh SEE ALSO | 87 | .Sh SEE ALSO |
70 | .Xr index 3 , | ||
71 | .Xr memchr 3 , | 88 | .Xr memchr 3 , |
72 | .Xr rindex 3 , | ||
73 | .Xr strchr 3 , | 89 | .Xr strchr 3 , |
74 | .Xr strpbrk 3 , | 90 | .Xr strpbrk 3 , |
75 | .Xr strrchr 3 , | 91 | .Xr strrchr 3 , |
@@ -80,6 +96,5 @@ returns the number of characters spanned. | |||
80 | .Sh STANDARDS | 96 | .Sh STANDARDS |
81 | The | 97 | The |
82 | .Fn strcspn | 98 | .Fn strcspn |
83 | function | 99 | function conforms to |
84 | conforms to | ||
85 | .St -ansiC . | 100 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c index acb4d2a3af..1eb233614d 100644 --- a/src/lib/libc/string/strcspn.c +++ b/src/lib/libc/string/strcspn.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strcspn.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,23 +31,16 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
45 | * Span the complement of string s2. | 37 | * Span the complement of string s2. |
46 | */ | 38 | */ |
47 | size_t | 39 | size_t |
48 | strcspn(s1, s2) | 40 | strcspn(const char *s1, const char *s2) |
49 | const char *s1; | ||
50 | register const char *s2; | ||
51 | { | 41 | { |
52 | register const char *p, *spanp; | 42 | const char *p, *spanp; |
53 | register char c, sc; | 43 | char c, sc; |
54 | 44 | ||
55 | /* | 45 | /* |
56 | * Stop as soon as we find any character from s2. Note that there | 46 | * Stop as soon as we find any character from s2. Note that there |
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 index 925cbf3d46..5ef38e38f3 100644 --- a/src/lib/libc/string/strdup.3 +++ b/src/lib/libc/string/strdup.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strdup.3,v 1.14 2007/05/31 19:19:32 jmc Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -9,11 +11,7 @@ | |||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
11 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
12 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
18 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
19 | .\" | 17 | .\" |
@@ -29,10 +27,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
31 | .\" | 29 | .\" |
32 | .\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 | 30 | .\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 |
33 | .\" $Id: strdup.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | 31 | .\" |
35 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
36 | .Dt STRDUP 3 | 33 | .Dt STRDUP 3 |
37 | .Os | 34 | .Os |
38 | .Sh NAME | 35 | .Sh NAME |
@@ -41,25 +38,47 @@ | |||
41 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
42 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
43 | .Ft char * | 40 | .Ft char * |
44 | .Fn strdup "const char *str" | 41 | .Fn strdup "const char *s" |
45 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
46 | The | 43 | The |
47 | .Fn strdup | 44 | .Fn strdup |
48 | function | 45 | function allocates sufficient memory for a copy of the string |
49 | allocates sufficient memory for a copy | 46 | .Fa s , |
50 | of the string | ||
51 | .Fa str , | ||
52 | does the copy, and returns a pointer to it. | 47 | does the copy, and returns a pointer to it. |
53 | The pointer may subsequently be used as an | 48 | The pointer may subsequently be used as an argument to the function |
54 | argument to the function | ||
55 | .Xr free 3 . | 49 | .Xr free 3 . |
50 | .Pp | ||
51 | If insufficient memory is available, | ||
52 | .Dv NULL | ||
53 | is returned. | ||
54 | .Sh EXAMPLES | ||
55 | The following will point | ||
56 | .Va p | ||
57 | to an allocated area of memory containing the NUL-terminated string | ||
58 | .Qq foobar : | ||
59 | .Bd -literal -offset indent | ||
60 | char *p; | ||
61 | |||
62 | if ((p = strdup("foobar")) == NULL) { | ||
63 | fprintf(stderr, "Out of memory.\en"); | ||
64 | exit(1); | ||
65 | } | ||
66 | .Ed | ||
67 | .Sh ERRORS | ||
68 | The | ||
69 | .Fn strdup | ||
70 | function may fail and set the external variable | ||
71 | .Va errno | ||
72 | for any of the errors specified for the library function | ||
73 | .Xr malloc 3 . | ||
56 | .Sh SEE ALSO | 74 | .Sh SEE ALSO |
57 | .Xr free 3 , | 75 | .Xr free 3 , |
58 | .Xr malloc 3 , | 76 | .Xr malloc 3 , |
59 | .Xt strcpy 3 , | 77 | .Xr strcpy 3 , |
60 | .Xt strlen 3 | 78 | .Xr strlcpy 3 , |
79 | .Xr strlen 3 | ||
61 | .Sh HISTORY | 80 | .Sh HISTORY |
62 | The | 81 | The |
63 | .Fn strdup | 82 | .Fn strdup |
64 | function | 83 | function first appeared in |
65 | .Ud . | 84 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c index 27ede44110..a6aa1e03b0 100644 --- a/src/lib/libc/string/strdup.c +++ b/src/lib/libc/string/strdup.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strdup.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1988 The Regents of the University of California. | 4 | * Copyright (c) 1988, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,24 +29,21 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #include <sys/types.h> |
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 | 33 | ||
34 | #include <stddef.h> | ||
39 | #include <stdlib.h> | 35 | #include <stdlib.h> |
40 | #include <string.h> | 36 | #include <string.h> |
41 | 37 | ||
42 | char * | 38 | char * |
43 | strdup(str) | 39 | strdup(const char *str) |
44 | const char *str; | ||
45 | { | 40 | { |
46 | size_t len; | 41 | size_t siz; |
47 | char *copy; | 42 | char *copy; |
48 | 43 | ||
49 | len = strlen(str) + 1; | 44 | siz = strlen(str) + 1; |
50 | if (!(copy = malloc(len))) | 45 | if ((copy = malloc(siz)) == NULL) |
51 | return((char *)NULL); | 46 | return(NULL); |
52 | memcpy(copy, str, len); | 47 | (void)memcpy(copy, str, siz); |
53 | return(copy); | 48 | return(copy); |
54 | } | 49 | } |
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 index c9d8504dbb..84c64c10bb 100644 --- a/src/lib/libc/string/strerror.3 +++ b/src/lib/libc/string/strerror.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,12 +29,11 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strerror.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strerror.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRERROR 3 | 35 | .Dt STRERROR 3 |
41 | .Os BSD 4 | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strerror | 38 | .Nm strerror |
44 | .Nd get error message string | 39 | .Nd get error message string |
@@ -46,15 +41,63 @@ | |||
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft char * | 42 | .Ft char * |
48 | .Fn strerror "int errnum" | 43 | .Fn strerror "int errnum" |
44 | .Ft int | ||
45 | .Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" | ||
49 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
50 | The | 47 | The |
51 | .Fn strerror | 48 | .Fn strerror |
52 | function returns a pointer to the language-dependent error message | 49 | and |
53 | string affiliated with an error number. | 50 | .Fn strerror_r |
51 | functions map the error number | ||
52 | .Fa errnum | ||
53 | to a language-dependent error message string. | ||
54 | .Pp | 54 | .Pp |
55 | The array pointed to is not to be modified by the program, but may be | 55 | .Fn strerror |
56 | overwritten by subsequent calls to | 56 | returns a string containing a maximum of |
57 | .Dv NL_TEXTMAX | ||
58 | characters, including the trailing NUL. | ||
59 | This string is not to be modified by the calling program, | ||
60 | but may be overwritten by subsequent calls to | ||
57 | .Fn strerror . | 61 | .Fn strerror . |
62 | .Pp | ||
63 | .Fn strerror_r | ||
64 | is a thread safe version of | ||
65 | .Fn strerror | ||
66 | that places the error message in the specified buffer | ||
67 | .Fa strerrbuf . | ||
68 | .Sh RETURN VALUES | ||
69 | .Fn strerror | ||
70 | returns a pointer to the error message string. | ||
71 | If an error occurs, the error code is stored in | ||
72 | .Va errno . | ||
73 | .Pp | ||
74 | .Fn strerror_r | ||
75 | returns zero upon successful completion. | ||
76 | If an error occurs, the error code is stored in | ||
77 | .Va errno | ||
78 | and the error code is returned. | ||
79 | .Sh ERRORS | ||
80 | .Fn strerror | ||
81 | and | ||
82 | .Fn strerror_r | ||
83 | may fail if: | ||
84 | .Bl -tag -width Er | ||
85 | .It Bq Er EINVAL | ||
86 | .Fa errnum | ||
87 | is not a valid error number. | ||
88 | The returned error string will consist of an error message that includes | ||
89 | .Fa errnum . | ||
90 | .El | ||
91 | .Pp | ||
92 | .Fn strerror_r | ||
93 | may fail if: | ||
94 | .Bl -tag -width Er | ||
95 | .It Bq Er ERANGE | ||
96 | The error message is larger than | ||
97 | .Fa buflen | ||
98 | characters. | ||
99 | The message will be truncated to fit. | ||
100 | .El | ||
58 | .Sh SEE ALSO | 101 | .Sh SEE ALSO |
59 | .Xr intro 2 , | 102 | .Xr intro 2 , |
60 | .Xr perror 3 , | 103 | .Xr perror 3 , |
@@ -64,3 +107,7 @@ The | |||
64 | .Fn strerror | 107 | .Fn strerror |
65 | function conforms to | 108 | function conforms to |
66 | .St -ansiC . | 109 | .St -ansiC . |
110 | The | ||
111 | .Fn strerror_r | ||
112 | function conforms to | ||
113 | .St -p1003.1 . | ||
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c index c3f5ab5d98..13996f08e9 100644 --- a/src/lib/libc/string/strerror.c +++ b/src/lib/libc/string/strerror.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strerror.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 3 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,26 +28,14 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <string.h> |
40 | #include <limits.h> | 32 | #include <limits.h> |
41 | 33 | ||
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 * | 34 | char * |
51 | strerror(num) | 35 | strerror(int num) |
52 | int num; | ||
53 | { | 36 | { |
54 | static char buf[NL_TEXTMAX]; | 37 | static char buf[NL_TEXTMAX]; |
55 | return __strerror(num, buf); | 38 | |
39 | (void)strerror_r(num, buf, sizeof(buf)); | ||
40 | return (buf); | ||
56 | } | 41 | } |
diff --git a/src/lib/libc/string/strerror_r.c b/src/lib/libc/string/strerror_r.c new file mode 100644 index 0000000000..aa63408ab8 --- /dev/null +++ b/src/lib/libc/string/strerror_r.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* $OpenBSD: strerror_r.c,v 1.7 2007/03/01 16:29:09 bluhm Exp $ */ | ||
2 | /* Public Domain <marc@snafu.org> */ | ||
3 | |||
4 | #ifdef NLS | ||
5 | #define catclose _catclose | ||
6 | #define catgets _catgets | ||
7 | #define catopen _catopen | ||
8 | #include <nl_types.h> | ||
9 | #endif | ||
10 | |||
11 | #define sys_errlist _sys_errlist | ||
12 | #define sys_nerr _sys_nerr | ||
13 | #define sys_siglist _sys_siglist | ||
14 | |||
15 | #include <errno.h> | ||
16 | #include <limits.h> | ||
17 | #include <signal.h> | ||
18 | #include <string.h> | ||
19 | |||
20 | static size_t | ||
21 | __digits10(unsigned int num) | ||
22 | { | ||
23 | size_t i = 0; | ||
24 | |||
25 | do { | ||
26 | num /= 10; | ||
27 | i++; | ||
28 | } while (num != 0); | ||
29 | |||
30 | return i; | ||
31 | } | ||
32 | |||
33 | static int | ||
34 | __itoa(int num, int sign, char *buffer, size_t start, size_t end) | ||
35 | { | ||
36 | size_t pos; | ||
37 | unsigned int a; | ||
38 | int neg; | ||
39 | |||
40 | if (sign && num < 0) { | ||
41 | a = -num; | ||
42 | neg = 1; | ||
43 | } | ||
44 | else { | ||
45 | a = num; | ||
46 | neg = 0; | ||
47 | } | ||
48 | |||
49 | pos = start + __digits10(a); | ||
50 | if (neg) | ||
51 | pos++; | ||
52 | |||
53 | if (pos < end) | ||
54 | buffer[pos] = '\0'; | ||
55 | else | ||
56 | return ERANGE; | ||
57 | pos--; | ||
58 | do { | ||
59 | buffer[pos] = (a % 10) + '0'; | ||
60 | pos--; | ||
61 | a /= 10; | ||
62 | } while (a != 0); | ||
63 | if (neg) | ||
64 | buffer[pos] = '-'; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | |||
69 | static int | ||
70 | __num2string(int num, int sign, int setid, char *buf, size_t buflen, | ||
71 | char * list[], size_t max, const char *def) | ||
72 | { | ||
73 | int ret = 0; | ||
74 | size_t len; | ||
75 | |||
76 | #ifdef NLS | ||
77 | nl_catd catd; | ||
78 | catd = catopen("libc", 0); | ||
79 | #endif | ||
80 | |||
81 | if (0 <= num && num < max) { | ||
82 | #ifdef NLS | ||
83 | len = strlcpy(buf, catgets(catd, setid, num, list[num]), | ||
84 | buflen); | ||
85 | #else | ||
86 | len = strlcpy(buf, list[num], buflen); | ||
87 | #endif | ||
88 | if (len >= buflen) | ||
89 | ret = ERANGE; | ||
90 | } else { | ||
91 | #ifdef NLS | ||
92 | len = strlcpy(buf, catgets(catd, setid, 0xffff, def), buflen); | ||
93 | #else | ||
94 | len = strlcpy(buf, def, buflen); | ||
95 | #endif | ||
96 | if (len >= buflen) | ||
97 | ret = ERANGE; | ||
98 | else { | ||
99 | ret = __itoa(num, sign, buf, len, buflen); | ||
100 | if (ret == 0) | ||
101 | ret = EINVAL; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | #ifdef NLS | ||
106 | catclose(catd); | ||
107 | #endif | ||
108 | |||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | #define UPREFIX "Unknown error: " | ||
113 | |||
114 | int | ||
115 | strerror_r(int errnum, char *strerrbuf, size_t buflen) | ||
116 | { | ||
117 | int save_errno; | ||
118 | int ret_errno; | ||
119 | |||
120 | save_errno = errno; | ||
121 | |||
122 | ret_errno = __num2string(errnum, 1, 1, strerrbuf, buflen, | ||
123 | sys_errlist, sys_nerr, UPREFIX); | ||
124 | |||
125 | errno = ret_errno ? ret_errno : save_errno; | ||
126 | return (ret_errno); | ||
127 | } | ||
128 | |||
129 | #define USIGPREFIX "Unknown signal: " | ||
130 | |||
131 | char * | ||
132 | __strsignal(int num, char *buf) | ||
133 | { | ||
134 | __num2string(num, 0, 2, buf, NL_TEXTMAX, (char **)sys_siglist, NSIG, | ||
135 | USIGPREFIX); | ||
136 | return buf; | ||
137 | } | ||
diff --git a/src/lib/libc/string/strftime.3 b/src/lib/libc/string/strftime.3 deleted file mode 100644 index f14db4bb13..0000000000 --- a/src/lib/libc/string/strftime.3 +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
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 deleted file mode 100644 index fffa9ecbb0..0000000000 --- a/src/lib/libc/string/strftime.c +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
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 index aaf97e0321..4d47ad444d 100644 --- a/src/lib/libc/string/string.3 +++ b/src/lib/libc/string/string.3 | |||
@@ -11,11 +11,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
21 | .\" | 17 | .\" |
@@ -31,38 +27,20 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
33 | .\" | 29 | .\" |
34 | .\" from: @(#)string.3 6.9 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: string.3,v 1.12 2007/05/31 19:19:32 jmc Exp $ |
35 | .\" $Id: string.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
36 | .\" | 31 | .\" |
37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt STRING 3 | 33 | .Dt STRING 3 |
39 | .Os BSD 4 | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
41 | .Nm strcat , | 36 | .Nm string |
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 | 37 | .Nd string specific functions |
62 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
63 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
64 | .Ft char * | 40 | .Ft char * |
65 | .Fn strcat "char *s" "const char * append" | 41 | .Fn strcat "char *s" "const char *append" |
42 | .Ft char * | ||
43 | .Fn strlcat "char *s" "const char *append" "size_t size" | ||
66 | .Ft char * | 44 | .Ft char * |
67 | .Fn strncat "char *s" "const char *append" "size_t count" | 45 | .Fn strncat "char *s" "const char *append" "size_t count" |
68 | .Ft char * | 46 | .Ft char * |
@@ -80,6 +58,8 @@ | |||
80 | .Ft char * | 58 | .Ft char * |
81 | .Fn strcpy "char *dst" "const char *src" | 59 | .Fn strcpy "char *dst" "const char *src" |
82 | .Ft char * | 60 | .Ft char * |
61 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
62 | .Ft char * | ||
83 | .Fn strncpy "char *dst" "const char *src" "size_t count" | 63 | .Fn strncpy "char *dst" "const char *src" "size_t count" |
84 | .Ft char * | 64 | .Ft char * |
85 | .Fn strerror "int errno" | 65 | .Fn strerror "int errno" |
@@ -103,35 +83,37 @@ | |||
103 | .Fn rindex "const char *s" "int c" | 83 | .Fn rindex "const char *s" "int c" |
104 | .Sh DESCRIPTION | 84 | .Sh DESCRIPTION |
105 | The string functions | 85 | The string functions |
106 | functions manipulate strings terminated by a | 86 | manipulate strings terminated by a |
107 | null byte. | 87 | NUL byte. |
108 | .Pp | 88 | .Pp |
109 | See the specific manual pages for more information. | 89 | See the specific manual pages for more information. |
110 | For manipulating variable length generic objects as byte | 90 | For manipulating variable length generic objects as byte |
111 | strings (without the null byte check), see | 91 | strings (without the NUL-byte check), see |
112 | .Xr bstring 3 . | 92 | .Xr bstring 3 . |
113 | .Pp | 93 | .Pp |
114 | Except as noted in their specific manual pages, | 94 | Except as noted in their specific manual pages, |
115 | the string functions do not test the destination | 95 | the string functions do not test the destination |
116 | for size limitations. | 96 | for size limitations. |
117 | .Sh SEE ALSO | 97 | .Sh SEE ALSO |
98 | .Xr bstring 3 , | ||
118 | .Xr index 3 , | 99 | .Xr index 3 , |
100 | .Xr rindex 3 , | ||
101 | .Xr strcasecmp 3 , | ||
119 | .Xr strcat 3 , | 102 | .Xr strcat 3 , |
120 | .Xr strchr 3 , | 103 | .Xr strchr 3 , |
121 | .Xr strrchr 3 , | ||
122 | .Xr strcmp 3 , | 104 | .Xr strcmp 3 , |
123 | .Xr strcasecmp 3 , | ||
124 | .Xr strcpy 3 , | 105 | .Xr strcpy 3 , |
106 | .Xr strcspn 3 , | ||
125 | .Xr strerror 3 , | 107 | .Xr strerror 3 , |
108 | .Xr strlcat 3 , | ||
109 | .Xr strlcpy 3 , | ||
126 | .Xr strlen 3 , | 110 | .Xr strlen 3 , |
127 | .Xr strpbrk 3 , | 111 | .Xr strpbrk 3 , |
112 | .Xr strrchr 3 , | ||
128 | .Xr strsep 3 , | 113 | .Xr strsep 3 , |
129 | .Xr strspn 3 , | 114 | .Xr strspn 3 , |
130 | .Xr strcspn 3 , | ||
131 | .Xr strstr 3 , | 115 | .Xr strstr 3 , |
132 | .Xr strtok 3 , | 116 | .Xr strtok 3 |
133 | .Xr rindex 3 | ||
134 | .Xr bstring 3 | ||
135 | .Sh STANDARDS | 117 | .Sh STANDARDS |
136 | The | 118 | The |
137 | .Fn strcat , | 119 | .Fn strcat , |
@@ -145,12 +127,10 @@ The | |||
145 | .Fn strerror , | 127 | .Fn strerror , |
146 | .Fn strlen , | 128 | .Fn strlen , |
147 | .Fn strpbrk , | 129 | .Fn strpbrk , |
148 | .Fn strsep , | ||
149 | .Fn strspn , | 130 | .Fn strspn , |
150 | .Fn strcspn , | 131 | .Fn strcspn , |
151 | .Fn strstr , | 132 | .Fn strstr , |
152 | and | 133 | and |
153 | .Fn strtok | 134 | .Fn strtok |
154 | functions | 135 | functions conform to |
155 | conform to | ||
156 | .St -ansiC . | 136 | .St -ansiC . |
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c new file mode 100644 index 0000000000..ceab094411 --- /dev/null +++ b/src/lib/libc/string/strlcat.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | #include <string.h> | ||
21 | |||
22 | /* | ||
23 | * Appends src to string dst of size siz (unlike strncat, siz is the | ||
24 | * full size of dst, not space left). At most siz-1 characters | ||
25 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). | ||
26 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). | ||
27 | * If retval >= siz, truncation occurred. | ||
28 | */ | ||
29 | size_t | ||
30 | strlcat(char *dst, const char *src, size_t siz) | ||
31 | { | ||
32 | char *d = dst; | ||
33 | const char *s = src; | ||
34 | size_t n = siz; | ||
35 | size_t dlen; | ||
36 | |||
37 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
38 | while (n-- != 0 && *d != '\0') | ||
39 | d++; | ||
40 | dlen = d - dst; | ||
41 | n = siz - dlen; | ||
42 | |||
43 | if (n == 0) | ||
44 | return(dlen + strlen(s)); | ||
45 | while (*s != '\0') { | ||
46 | if (n != 1) { | ||
47 | *d++ = *s; | ||
48 | n--; | ||
49 | } | ||
50 | s++; | ||
51 | } | ||
52 | *d = '\0'; | ||
53 | |||
54 | return(dlen + (s - src)); /* count does not include NUL */ | ||
55 | } | ||
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3 new file mode 100644 index 0000000000..feda63fae7 --- /dev/null +++ b/src/lib/libc/string/strlcpy.3 | |||
@@ -0,0 +1,186 @@ | |||
1 | .\" $OpenBSD: strlcpy.3,v 1.19 2007/05/31 19:19:32 jmc Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller@courtesan.com> | ||
4 | .\" | ||
5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
7 | .\" copyright notice and this permission notice appear in all copies. | ||
8 | .\" | ||
9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | .\" | ||
17 | .Dd $Mdocdate: May 31 2007 $ | ||
18 | .Dt STRLCPY 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm strlcpy , | ||
22 | .Nm strlcat | ||
23 | .Nd size-bounded string copying and concatenation | ||
24 | .Sh SYNOPSIS | ||
25 | .Fd #include <string.h> | ||
26 | .Ft size_t | ||
27 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
28 | .Ft size_t | ||
29 | .Fn strlcat "char *dst" "const char *src" "size_t size" | ||
30 | .Sh DESCRIPTION | ||
31 | The | ||
32 | .Fn strlcpy | ||
33 | and | ||
34 | .Fn strlcat | ||
35 | functions copy and concatenate strings respectively. | ||
36 | They are designed | ||
37 | to be safer, more consistent, and less error prone replacements for | ||
38 | .Xr strncpy 3 | ||
39 | and | ||
40 | .Xr strncat 3 . | ||
41 | Unlike those functions, | ||
42 | .Fn strlcpy | ||
43 | and | ||
44 | .Fn strlcat | ||
45 | take the full size of the buffer (not just the length) and guarantee to | ||
46 | NUL-terminate the result (as long as | ||
47 | .Fa size | ||
48 | is larger than 0 or, in the case of | ||
49 | .Fn strlcat , | ||
50 | as long as there is at least one byte free in | ||
51 | .Fa dst ) . | ||
52 | Note that a byte for the NUL should be included in | ||
53 | .Fa size . | ||
54 | Also note that | ||
55 | .Fn strlcpy | ||
56 | and | ||
57 | .Fn strlcat | ||
58 | only operate on true | ||
59 | .Dq C | ||
60 | strings. | ||
61 | This means that for | ||
62 | .Fn strlcpy | ||
63 | .Fa src | ||
64 | must be NUL-terminated and for | ||
65 | .Fn strlcat | ||
66 | both | ||
67 | .Fa src | ||
68 | and | ||
69 | .Fa dst | ||
70 | must be NUL-terminated. | ||
71 | .Pp | ||
72 | The | ||
73 | .Fn strlcpy | ||
74 | function copies up to | ||
75 | .Fa size | ||
76 | - 1 characters from the NUL-terminated string | ||
77 | .Fa src | ||
78 | to | ||
79 | .Fa dst , | ||
80 | NUL-terminating the result. | ||
81 | .Pp | ||
82 | The | ||
83 | .Fn strlcat | ||
84 | function appends the NUL-terminated string | ||
85 | .Fa src | ||
86 | to the end of | ||
87 | .Fa dst . | ||
88 | It will append at most | ||
89 | .Fa size | ||
90 | - strlen(dst) - 1 bytes, NUL-terminating the result. | ||
91 | .Sh RETURN VALUES | ||
92 | The | ||
93 | .Fn strlcpy | ||
94 | and | ||
95 | .Fn strlcat | ||
96 | functions return the total length of the string they tried to create. | ||
97 | For | ||
98 | .Fn strlcpy | ||
99 | that means the length of | ||
100 | .Fa src . | ||
101 | For | ||
102 | .Fn strlcat | ||
103 | that means the initial length of | ||
104 | .Fa dst | ||
105 | plus | ||
106 | the length of | ||
107 | .Fa src . | ||
108 | While this may seem somewhat confusing, it was done to make | ||
109 | truncation detection simple. | ||
110 | .Pp | ||
111 | Note, however, that if | ||
112 | .Fn strlcat | ||
113 | traverses | ||
114 | .Fa size | ||
115 | characters without finding a NUL, the length of the string is considered | ||
116 | to be | ||
117 | .Fa size | ||
118 | and the destination string will not be NUL-terminated (since there was | ||
119 | no space for the NUL). | ||
120 | This keeps | ||
121 | .Fn strlcat | ||
122 | from running off the end of a string. | ||
123 | In practice this should not happen (as it means that either | ||
124 | .Fa size | ||
125 | is incorrect or that | ||
126 | .Fa dst | ||
127 | is not a proper | ||
128 | .Dq C | ||
129 | string). | ||
130 | The check exists to prevent potential security problems in incorrect code. | ||
131 | .Sh EXAMPLES | ||
132 | The following code fragment illustrates the simple case: | ||
133 | .Bd -literal -offset indent | ||
134 | char *s, *p, buf[BUFSIZ]; | ||
135 | |||
136 | \&... | ||
137 | |||
138 | (void)strlcpy(buf, s, sizeof(buf)); | ||
139 | (void)strlcat(buf, p, sizeof(buf)); | ||
140 | .Ed | ||
141 | .Pp | ||
142 | To detect truncation, perhaps while building a pathname, something | ||
143 | like the following might be used: | ||
144 | .Bd -literal -offset indent | ||
145 | char *dir, *file, pname[MAXPATHLEN]; | ||
146 | |||
147 | \&... | ||
148 | |||
149 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
150 | goto toolong; | ||
151 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
152 | goto toolong; | ||
153 | .Ed | ||
154 | .Pp | ||
155 | Since it is known how many characters were copied the first time, things | ||
156 | can be sped up a bit by using a copy instead of an append: | ||
157 | .Bd -literal -offset indent | ||
158 | char *dir, *file, pname[MAXPATHLEN]; | ||
159 | size_t n; | ||
160 | |||
161 | \&... | ||
162 | |||
163 | n = strlcpy(pname, dir, sizeof(pname)); | ||
164 | if (n >= sizeof(pname)) | ||
165 | goto toolong; | ||
166 | if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) | ||
167 | goto toolong; | ||
168 | .Ed | ||
169 | .Pp | ||
170 | However, one may question the validity of such optimizations, as they | ||
171 | defeat the whole purpose of | ||
172 | .Fn strlcpy | ||
173 | and | ||
174 | .Fn strlcat . | ||
175 | As a matter of fact, the first version of this manual page got it wrong. | ||
176 | .Sh SEE ALSO | ||
177 | .Xr snprintf 3 , | ||
178 | .Xr strncat 3 , | ||
179 | .Xr strncpy 3 | ||
180 | .Sh HISTORY | ||
181 | The | ||
182 | .Fn strlcpy | ||
183 | and | ||
184 | .Fn strlcat | ||
185 | functions first appeared in | ||
186 | .Ox 2.4 . | ||
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c new file mode 100644 index 0000000000..d32b6590f1 --- /dev/null +++ b/src/lib/libc/string/strlcpy.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | #include <string.h> | ||
21 | |||
22 | /* | ||
23 | * Copy src to string dst of size siz. At most siz-1 characters | ||
24 | * will be copied. Always NUL terminates (unless siz == 0). | ||
25 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
26 | */ | ||
27 | size_t | ||
28 | strlcpy(char *dst, const char *src, size_t siz) | ||
29 | { | ||
30 | char *d = dst; | ||
31 | const char *s = src; | ||
32 | size_t n = siz; | ||
33 | |||
34 | /* Copy as many bytes as will fit */ | ||
35 | if (n != 0) { | ||
36 | while (--n != 0) { | ||
37 | if ((*d++ = *s++) == '\0') | ||
38 | break; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
43 | if (n == 0) { | ||
44 | if (siz != 0) | ||
45 | *d = '\0'; /* NUL-terminate dst */ | ||
46 | while (*s++) | ||
47 | ; | ||
48 | } | ||
49 | |||
50 | return(s - src - 1); /* count does not include NUL */ | ||
51 | } | ||
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 index f4aff363ee..f8a4efe9d2 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,15 +29,14 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strlen.3,v 1.6 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRLEN 3 | 35 | .Dt STRLEN 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strlen | 38 | .Nm strlen |
44 | .Nd find length of string | 39 | .Nd find length of a string |
45 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft size_t | 42 | .Ft size_t |
@@ -49,23 +44,18 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn strlen | 46 | .Fn strlen |
52 | function | 47 | function computes the length of the string |
53 | computes the length of the string | ||
54 | .Fa s . | 48 | .Fa s . |
55 | .Sh RETURN VALUES | 49 | .Sh RETURN VALUES |
56 | The | 50 | The |
57 | .Fn strlen | 51 | .Fn strlen |
58 | function | 52 | function returns the number of characters that precede the terminating |
59 | returns | 53 | .Tn NUL |
60 | the number of characters that precede the | ||
61 | terminating | ||
62 | .Dv NUL | ||
63 | character. | 54 | character. |
64 | .Sh SEE ALSO | 55 | .Sh SEE ALSO |
65 | .Xr string 3 | 56 | .Xr string 3 |
66 | .Sh STANDARDS | 57 | .Sh STANDARDS |
67 | The | 58 | The |
68 | .Fn strlen | 59 | .Fn strlen |
69 | function | 60 | function conforms to |
70 | conforms to | ||
71 | .St -ansiC . | 61 | .St -ansiC . |
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c index d23aadafc0..12d9ec4dad 100644 --- a/src/lib/libc/string/strlen.c +++ b/src/lib/libc/string/strlen.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strlen.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,20 +29,19 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
40 | 37 | ||
41 | size_t | 38 | size_t |
42 | strlen(str) | 39 | strlen(const char *str) |
43 | const char *str; | ||
44 | { | 40 | { |
45 | register const char *s; | 41 | const char *s; |
46 | 42 | ||
47 | for (s = str; *s; ++s); | 43 | for (s = str; *s; ++s) |
48 | return(s - str); | 44 | ; |
45 | return (s - str); | ||
49 | } | 46 | } |
50 | 47 | ||
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3 index 1907e7ab03..ebeafcaf6e 100644 --- a/src/lib/libc/string/strmode.3 +++ b/src/lib/libc/string/strmode.3 | |||
@@ -1,5 +1,7 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strmode.3,v 1.14 2007/05/31 19:19:32 jmc Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
@@ -9,11 +11,7 @@ | |||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
11 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
12 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 15 | .\" may be used to endorse or promote products derived from this software |
18 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
19 | .\" | 17 | .\" |
@@ -29,10 +27,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
31 | .\" | 29 | .\" |
32 | .\" from: @(#)strmode.3 5.4 (Berkeley) 7/31/91 | 30 | .\" @(#)strmode.3 8.3 (Berkeley) 7/28/94 |
33 | .\" $Id: strmode.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
34 | .\" | 31 | .\" |
35 | .Dd July 31, 1991 | 32 | .Dd $Mdocdate: May 31 2007 $ |
36 | .Dt STRMODE 3 | 33 | .Dt STRMODE 3 |
37 | .Os | 34 | .Os |
38 | .Sh NAME | 35 | .Sh NAME |
@@ -45,15 +42,13 @@ | |||
45 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
46 | The | 43 | The |
47 | .Fn strmode | 44 | .Fn strmode |
48 | function | 45 | function converts a file |
49 | converts a file | ||
50 | .Fa mode | 46 | .Fa mode |
51 | (the type and permission information associated with an inode, see | 47 | (the type and permission information associated with an inode, see |
52 | .Xr stat 2 ) | 48 | .Xr stat 2 ) |
53 | into a symbolic string which is stored in the location referenced by | 49 | into a symbolic string which is stored in the location referenced by |
54 | .Fa bp . | 50 | .Fa bp . |
55 | This stored string is eleven characters in length plus a trailing | 51 | This stored string is eleven characters in length plus a trailing NUL byte. |
56 | .Dv NULL . | ||
57 | .Pp | 52 | .Pp |
58 | The first character is the inode type, and will be one of the following: | 53 | The first character is the inode type, and will be one of the following: |
59 | .Pp | 54 | .Pp |
@@ -69,10 +64,10 @@ directory | |||
69 | .It l | 64 | .It l |
70 | symbolic link | 65 | symbolic link |
71 | .It p | 66 | .It p |
72 | fifo | 67 | FIFO |
73 | .It s | 68 | .It s |
74 | socket | 69 | socket |
75 | .It ? | 70 | .It \&? |
76 | unknown inode type | 71 | unknown inode type |
77 | .El | 72 | .El |
78 | .Pp | 73 | .Pp |
@@ -80,46 +75,58 @@ The next nine characters encode three sets of permissions, in three | |||
80 | characters each. | 75 | characters each. |
81 | The first three characters are the permissions for the owner of the | 76 | 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 | 77 | file, the second three for the group the file belongs to, and the |
83 | third for the ``other'', or default, set of users. | 78 | third for the |
79 | .Dq other , | ||
80 | or default, set of users. | ||
84 | .Pp | 81 | .Pp |
85 | Permission checking is done as specifically as possible. | 82 | Permission checking is done as specifically as possible. |
86 | If read permission is denied to the owner of a file in the first set | 83 | 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. | 84 | 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 | 85 | 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. | 86 | permissions allow reading or the |
87 | .Dq other | ||
88 | permissions allow reading. | ||
90 | .Pp | 89 | .Pp |
91 | If the first character of the three character set is an ``r'', the file is | 90 | If the first character of the three character set is an |
92 | readable for that set of users; if a dash ``\-'', it is not readable. | 91 | .Sq r , |
92 | the file is readable for that set of users; if a dash | ||
93 | .Pq Ql - , | ||
94 | it is not readable. | ||
93 | .Pp | 95 | .Pp |
94 | If the second character of the three character set is a ``w'', the file is | 96 | If the second character of the three character set is a |
95 | writable for that set of users; if a dash ``\-'', it is not writable. | 97 | .Sq w , |
98 | the file is writable for that set of users; if a dash | ||
99 | .Pq Ql - , | ||
100 | it is not writable. | ||
96 | .Pp | 101 | .Pp |
97 | The third character is the first of the following characters that apply: | 102 | The third character is the first of the following characters that apply: |
98 | .Bl -tag -width xxxx | 103 | .Bl -tag -width xxxx |
99 | .It S | 104 | .It S |
100 | If the character is part of the owner permissions and the file is not | 105 | 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 | 106 | executable or the directory is not searchable by the owner, and the |
102 | set-user-id bit is set. | 107 | set-user-ID bit is set. |
103 | .It S | 108 | .It S |
104 | If the character is part of the group permissions and the file is not | 109 | 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 | 110 | executable or the directory is not searchable by the group, and the |
106 | set-group-id bit is set. | 111 | set-group-ID bit is set. |
107 | .It T | 112 | .It T |
108 | If the character is part of the other permissions and the file is not | 113 | 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'' | 114 | executable or the directory is not searchable by others, and the |
115 | .Dq sticky | ||
110 | .Pq Dv S_ISVTX | 116 | .Pq Dv S_ISVTX |
111 | bit is set. | 117 | bit is set. |
112 | .It s | 118 | .It s |
113 | If the character is part of the owner permissions and the file is | 119 | 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 | 120 | executable or the directory searchable by the owner, and the set-user-ID |
115 | bit is set. | 121 | bit is set. |
116 | .It s | 122 | .It s |
117 | If the character is part of the group permissions and the file is | 123 | 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 | 124 | executable or the directory searchable by the group, and the set-group-ID |
119 | bit is set. | 125 | bit is set. |
120 | .It t | 126 | .It t |
121 | If the character is part of the other permissions and the file is | 127 | If the character is part of the other permissions and the file is |
122 | executable or the directory searchable, by others, and the ``sticky'' | 128 | executable or the directory searchable by others, and the |
129 | .Dq sticky | ||
123 | .Pq Dv S_ISVTX | 130 | .Pq Dv S_ISVTX |
124 | bit is set. | 131 | bit is set. |
125 | .It x | 132 | .It x |
@@ -128,14 +135,15 @@ The file is executable or the directory is searchable. | |||
128 | None of the above apply. | 135 | None of the above apply. |
129 | .El | 136 | .El |
130 | .Pp | 137 | .Pp |
131 | The last character is a plus sign ``+'' if any there are any alternate | 138 | The last character is a plus sign |
139 | .Pq Ql + | ||
140 | if there are any alternate | ||
132 | or additional access control methods associated with the inode, otherwise | 141 | or additional access control methods associated with the inode, otherwise |
133 | it will be a space. | 142 | it will be a space. |
134 | .Sh RETURN VALUES | 143 | .Sh RETURN VALUES |
135 | The | 144 | The |
136 | .Fn strmode | 145 | .Fn strmode |
137 | function | 146 | function always returns 0. |
138 | always returns 0. | ||
139 | .Sh SEE ALSO | 147 | .Sh SEE ALSO |
140 | .Xr chmod 1 , | 148 | .Xr chmod 1 , |
141 | .Xr find 1 , | 149 | .Xr find 1 , |
@@ -145,5 +153,5 @@ always returns 0. | |||
145 | .Sh HISTORY | 153 | .Sh HISTORY |
146 | The | 154 | The |
147 | .Fn strmode | 155 | .Fn strmode |
148 | function | 156 | function first appeared in |
149 | .Ud . | 157 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c index 441fc76e90..6f0fa34ed8 100644 --- a/src/lib/libc/string/strmode.c +++ b/src/lib/libc/string/strmode.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strmode.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,19 +28,14 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <sys/types.h> |
40 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
41 | #include <string.h> | 33 | #include <string.h> |
42 | 34 | ||
35 | /* XXX mode should be mode_t */ | ||
36 | |||
43 | void | 37 | void |
44 | strmode(mode, p) | 38 | strmode(int mode, char *p) |
45 | register mode_t mode; | ||
46 | register char *p; | ||
47 | { | 39 | { |
48 | /* print type */ | 40 | /* print type */ |
49 | switch (mode & S_IFMT) { | 41 | switch (mode & S_IFMT) { |
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c index 3d96452af4..c4df4f2fad 100644 --- a/src/lib/libc/string/strncat.c +++ b/src/lib/libc/string/strncat.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strncat.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,11 +31,6 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
@@ -46,14 +38,11 @@ static char *rcsid = "$Id: strncat.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | |||
46 | * are written at dst (at most n+1 bytes being appended). Return dst. | 38 | * are written at dst (at most n+1 bytes being appended). Return dst. |
47 | */ | 39 | */ |
48 | char * | 40 | char * |
49 | strncat(dst, src, n) | 41 | strncat(char *dst, const char *src, size_t n) |
50 | char *dst; | ||
51 | const char *src; | ||
52 | register size_t n; | ||
53 | { | 42 | { |
54 | if (n != 0) { | 43 | if (n != 0) { |
55 | register char *d = dst; | 44 | char *d = dst; |
56 | register const char *s = src; | 45 | const char *s = src; |
57 | 46 | ||
58 | while (*d != 0) | 47 | while (*d != 0) |
59 | d++; | 48 | d++; |
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c index 0638d4dcf2..0aea80d7d9 100644 --- a/src/lib/libc/string/strncmp.c +++ b/src/lib/libc/string/strncmp.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: strncmp.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | 4 | * Copyright (c) 1989 The Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,17 +29,14 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 33 | #include <string.h> |
34 | #else | ||
35 | #include <lib/libkern/libkern.h> | ||
36 | #endif | ||
40 | 37 | ||
41 | int | 38 | int |
42 | strncmp(s1, s2, n) | 39 | strncmp(const char *s1, const char *s2, size_t n) |
43 | register const char *s1, *s2; | ||
44 | register size_t n; | ||
45 | { | 40 | { |
46 | 41 | ||
47 | if (n == 0) | 42 | if (n == 0) |
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c index 5215311b75..4426cbe2e3 100644 --- a/src/lib/libc/string/strncpy.c +++ b/src/lib/libc/string/strncpy.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: strncpy.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 5 | * All rights reserved. |
@@ -13,11 +15,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 16 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 17 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 18 | * 3. Neither the name of the University nor the names of its contributors |
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 | 19 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 20 | * without specific prior written permission. |
23 | * | 21 | * |
@@ -34,26 +32,22 @@ | |||
34 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. |
35 | */ | 33 | */ |
36 | 34 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 35 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
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> | 36 | #include <string.h> |
37 | #else | ||
38 | #include <lib/libkern/libkern.h> | ||
39 | #endif | ||
43 | 40 | ||
44 | /* | 41 | /* |
45 | * Copy src to dst, truncating or null-padding to always copy n bytes. | 42 | * Copy src to dst, truncating or null-padding to always copy n bytes. |
46 | * Return dst. | 43 | * Return dst. |
47 | */ | 44 | */ |
48 | char * | 45 | char * |
49 | strncpy(dst, src, n) | 46 | strncpy(char *dst, const char *src, size_t n) |
50 | char *dst; | ||
51 | const char *src; | ||
52 | register size_t n; | ||
53 | { | 47 | { |
54 | if (n != 0) { | 48 | if (n != 0) { |
55 | register char *d = dst; | 49 | char *d = dst; |
56 | register const char *s = src; | 50 | const char *s = src; |
57 | 51 | ||
58 | do { | 52 | do { |
59 | if ((*d++ = *s++) == 0) { | 53 | if ((*d++ = *s++) == 0) { |
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 index 8578546c05..9d6c676c8d 100644 --- a/src/lib/libc/string/strpbrk.3 +++ b/src/lib/libc/string/strpbrk.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strpbrk.3,v 1.8 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRPBRK 3 | 35 | .Dt STRPBRK 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,8 +44,7 @@ | |||
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Fn strpbrk | 46 | .Fn strpbrk |
52 | function | 47 | function locates in the NUL-terminated string |
53 | locates in the null-terminated string | ||
54 | .Fa s | 48 | .Fa s |
55 | the first occurrence of any character in the string | 49 | the first occurrence of any character in the string |
56 | .Fa charset | 50 | .Fa charset |
@@ -58,13 +52,12 @@ and returns a pointer to this character. | |||
58 | If no characters from | 52 | If no characters from |
59 | .Fa charset | 53 | .Fa charset |
60 | occur anywhere in | 54 | occur anywhere in |
61 | .Fa s | 55 | .Fa s , |
62 | .Fn strpbrk | 56 | .Fn strpbrk |
63 | returns NULL. | 57 | returns |
58 | .Dv NULL . | ||
64 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
65 | .Xr index 3 , | ||
66 | .Xr memchr 3 , | 60 | .Xr memchr 3 , |
67 | .Xr rindex 3 , | ||
68 | .Xr strchr 3 , | 61 | .Xr strchr 3 , |
69 | .Xr strcspn 3 , | 62 | .Xr strcspn 3 , |
70 | .Xr strrchr 3 , | 63 | .Xr strrchr 3 , |
@@ -75,6 +68,5 @@ returns NULL. | |||
75 | .Sh STANDARDS | 68 | .Sh STANDARDS |
76 | The | 69 | The |
77 | .Fn strpbrk | 70 | .Fn strpbrk |
78 | function | 71 | function conforms to |
79 | conforms to | ||
80 | .St -ansiC . | 72 | .St -ansiC . |
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c index f1d542a525..cd3b71c0d3 100644 --- a/src/lib/libc/string/strpbrk.c +++ b/src/lib/libc/string/strpbrk.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strpbrk.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1985 Regents of the University of California. | 3 | * Copyright (c) 1985 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,22 +28,16 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <string.h> |
40 | 32 | ||
41 | /* | 33 | /* |
42 | * Find the first occurrence in s1 of a character in s2 (excluding NUL). | 34 | * Find the first occurrence in s1 of a character in s2 (excluding NUL). |
43 | */ | 35 | */ |
44 | char * | 36 | char * |
45 | strpbrk(s1, s2) | 37 | strpbrk(const char *s1, const char *s2) |
46 | register const char *s1, *s2; | ||
47 | { | 38 | { |
48 | register const char *scanp; | 39 | const char *scanp; |
49 | register int c, sc; | 40 | int c, sc; |
50 | 41 | ||
51 | while ((c = *s1++) != 0) { | 42 | while ((c = *s1++) != 0) { |
52 | for (scanp = s2; (sc = *scanp++) != 0;) | 43 | for (scanp = s2; (sc = *scanp++) != 0;) |
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3 index 1d98cbff24..0d1f4be971 100644 --- a/src/lib/libc/string/strrchr.3 +++ b/src/lib/libc/string/strrchr.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,28 +29,31 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strrchr.3,v 1.8 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRRCHR 3 | 35 | .Dt STRRCHR 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strrchr | 38 | .Nm strrchr , |
44 | .Nd locate character in string | 39 | .Nm rindex |
40 | .Nd locate last occurrence of a character in a string | ||
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
47 | .Ft char * | 43 | .Ft char * |
48 | .Fn strrchr "const char *s" "int c" | 44 | .Fn strrchr "const char *s" "int c" |
45 | .Ft char * | ||
46 | .Fn rindex "const char *s" "int c" | ||
49 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
50 | The | 48 | The |
51 | .Fn strrchr | 49 | .Fn strrchr |
52 | function | 50 | function locates the last occurrence of the character |
53 | locates the last occurrence of | ||
54 | .Fa c | 51 | .Fa c |
55 | (converted to a char) | ||
56 | in the string | 52 | in the string |
57 | .Fa s . | 53 | .Fa s . |
54 | The terminating | ||
55 | .Tn NUL | ||
56 | character is considered part of the string. | ||
58 | If | 57 | If |
59 | .Fa c | 58 | .Fa c |
60 | is | 59 | is |
@@ -62,20 +61,31 @@ is | |||
62 | .Fn strrchr | 61 | .Fn strrchr |
63 | locates the terminating | 62 | locates the terminating |
64 | .Ql \e0 . | 63 | .Ql \e0 . |
64 | .Pp | ||
65 | The | ||
66 | .Fn rindex | ||
67 | function is an old synonym for | ||
68 | .Fn strrchr . | ||
65 | .Sh RETURN VALUES | 69 | .Sh RETURN VALUES |
66 | The | 70 | The |
67 | .Fn strrchr | 71 | .Fn strrchr |
68 | function | 72 | function returns a pointer to the located character or |
69 | returns a pointer to the character, | 73 | .Dv NULL |
70 | or a null | 74 | if the character does not appear in the string. |
71 | pointer if | 75 | .Sh EXAMPLES |
72 | .Fa c | 76 | After the following call to |
73 | does not occur anywhere in | 77 | .Fn strrchr , |
74 | .Fa s . | 78 | .Va p |
79 | will point to the string | ||
80 | .Qq obar : | ||
81 | .Bd -literal -offset indent | ||
82 | char *p; | ||
83 | char *s = "foobar"; | ||
84 | |||
85 | p = strrchr(s, 'o'); | ||
86 | .Ed | ||
75 | .Sh SEE ALSO | 87 | .Sh SEE ALSO |
76 | .Xr index 3 , | ||
77 | .Xr memchr 3 , | 88 | .Xr memchr 3 , |
78 | .Xr rindex 3 , | ||
79 | .Xr strchr 3 , | 89 | .Xr strchr 3 , |
80 | .Xr strcspn 3 , | 90 | .Xr strcspn 3 , |
81 | .Xr strpbrk 3 , | 91 | .Xr strpbrk 3 , |
@@ -86,6 +96,9 @@ does not occur anywhere in | |||
86 | .Sh STANDARDS | 96 | .Sh STANDARDS |
87 | The | 97 | The |
88 | .Fn strrchr | 98 | .Fn strrchr |
89 | function | 99 | function conforms to |
90 | conforms to | ||
91 | .St -ansiC . | 100 | .St -ansiC . |
101 | .Pp | ||
102 | The | ||
103 | .Fn rindex | ||
104 | function is deprecated and shouldn't be used in new code. | ||
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 21aa7376f2..cceeda7577 100644 --- a/src/lib/libc/string/strsep.3 +++ b/src/lib/libc/string/strsep.3 | |||
@@ -1,8 +1,11 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strsep.3,v 1.12 2007/05/31 19:19:32 jmc Exp $ |
2 | .\" All rights reserved. | 2 | .\" |
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | 5 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
8 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | 11 | .\" are met: |
@@ -11,11 +14,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 15 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 16 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. All advertising materials mentioning features or use of this software | 17 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 18 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 19 | .\" without specific prior written permission. |
21 | .\" | 20 | .\" |
@@ -31,10 +30,9 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
33 | .\" | 32 | .\" |
34 | .\" from: @(#)strsep.3 5.3 (Berkeley) 4/19/91 | 33 | .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 |
35 | .\" $Id: strsep.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
36 | .\" | 34 | .\" |
37 | .Dd April 19, 1991 | 35 | .Dd $Mdocdate: May 31 2007 $ |
38 | .Dt STRSEP 3 | 36 | .Dt STRSEP 3 |
39 | .Os | 37 | .Os |
40 | .Sh NAME | 38 | .Sh NAME |
@@ -43,27 +41,37 @@ | |||
43 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
44 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
45 | .Ft char * | 43 | .Ft char * |
46 | .Fn strsep "char **stringp" "char *delim" | 44 | .Fn strsep "char **stringp" "const char *delim" |
47 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
48 | The | 46 | The |
49 | .Fn strsep | 47 | .Fn strsep |
50 | locates in the null-terminated string at | 48 | function locates, in the string referenced by |
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 , | 49 | .Fa *stringp , |
58 | then returns the original value of | 50 | the first occurrence of any character in the string |
51 | .Fa delim | ||
52 | (or the terminating | ||
53 | .Ql \e0 | ||
54 | character) and replaces it with a | ||
55 | .Ql \e0 . | ||
56 | The location of the next character after the delimiter character | ||
57 | (or | ||
58 | .Dv NULL , | ||
59 | if the end of the string was reached) is stored in | ||
59 | .Fa *stringp . | 60 | .Fa *stringp . |
60 | If no delimiter characters are found, | 61 | The original value of |
61 | .Fn strsep | ||
62 | sets | ||
63 | .Fa *stringp | 62 | .Fa *stringp |
63 | is returned. | ||
64 | .Pp | ||
65 | An | ||
66 | .Dq empty | ||
67 | field, i.e., one caused by two adjacent delimiter characters, | ||
68 | can be detected by comparing the location referenced by the pointer returned | ||
69 | by | ||
70 | .Fn strsep | ||
64 | to | 71 | to |
65 | .Dv NULL ; | 72 | .Ql \e0 . |
66 | if | 73 | .Pp |
74 | If | ||
67 | .Fa *stringp | 75 | .Fa *stringp |
68 | is initially | 76 | is initially |
69 | .Dv NULL , | 77 | .Dv NULL , |
@@ -73,20 +81,32 @@ returns | |||
73 | .Sh EXAMPLES | 81 | .Sh EXAMPLES |
74 | The following uses | 82 | The following uses |
75 | .Fn strsep | 83 | .Fn strsep |
76 | to parse strings containing runs of white space, | 84 | to parse a string, containing tokens delimited by whitespace, into an |
77 | making up an argument vector: | 85 | argument vector: |
78 | .Bd -literal -offset indent | 86 | .Bd -literal -offset indent |
79 | char inputstring[100]; | 87 | char **ap, *argv[10], *inputstring; |
80 | char **argv[51], **ap = argv, *p, *val; | 88 | |
81 | /* set up inputstring */ | 89 | for (ap = argv; ap < &argv[9] && |
82 | for (p = inputstring; p != NULL; ) { | 90 | (*ap = strsep(&inputstring, " \et")) != NULL;) { |
83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 91 | if (**ap != '\e0') |
84 | *ap++ = val; | 92 | ap++; |
85 | } | 93 | } |
86 | *ap = 0; | 94 | *ap = NULL; |
87 | .Ed | 95 | .Ed |
88 | .Sh HISTORY | 96 | .Sh HISTORY |
89 | The | 97 | The |
90 | .Fn strsep | 98 | .Fn strsep |
91 | function is | 99 | function is intended as a replacement for the |
92 | .Ud . | 100 | .Fn strtok |
101 | function. | ||
102 | While the | ||
103 | .Fn strtok | ||
104 | function should be preferred for portability reasons (it conforms to | ||
105 | .St -ansiC ) | ||
106 | it is unable to handle empty fields, i.e., detect fields delimited by | ||
107 | two adjacent delimiter characters, or to be used for more than a single | ||
108 | string at a time. | ||
109 | The | ||
110 | .Fn strsep | ||
111 | function first appeared in | ||
112 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c index 69be7fe046..bcca681e03 100644 --- a/src/lib/libc/string/strsep.c +++ b/src/lib/libc/string/strsep.c | |||
@@ -1,6 +1,8 @@ | |||
1 | /* $OpenBSD: strsep.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | |||
1 | /*- | 3 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990, 1993 |
3 | * All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
4 | * | 6 | * |
5 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
@@ -10,11 +12,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 15 | * 3. Neither the name of the University nor the names of its contributors |
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 | 16 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 17 | * without specific prior written permission. |
20 | * | 18 | * |
@@ -31,15 +29,11 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
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> | 32 | #include <string.h> |
33 | #include <stdio.h> | ||
40 | 34 | ||
41 | /* | 35 | /* |
42 | * Get next token from string *stringp, where tokens are nonempty | 36 | * Get next token from string *stringp, where tokens are possibly-empty |
43 | * strings separated by characters from delim. | 37 | * strings separated by characters from delim. |
44 | * | 38 | * |
45 | * Writes NULs into the string at *stringp to end tokens. | 39 | * Writes NULs into the string at *stringp to end tokens. |
@@ -47,16 +41,14 @@ static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $" | |||
47 | * On return, *stringp points past the last NUL written (if there might | 41 | * 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). | 42 | * be further tokens), or is NULL (if there are definitely no more tokens). |
49 | * | 43 | * |
50 | * If *stringp is NULL, strtoken returns NULL. | 44 | * If *stringp is NULL, strsep returns NULL. |
51 | */ | 45 | */ |
52 | char * | 46 | char * |
53 | strsep(stringp, delim) | 47 | strsep(char **stringp, const char *delim) |
54 | register char **stringp; | ||
55 | register const char *delim; | ||
56 | { | 48 | { |
57 | register char *s; | 49 | char *s; |
58 | register const char *spanp; | 50 | const char *spanp; |
59 | register int c, sc; | 51 | int c, sc; |
60 | char *tok; | 52 | char *tok; |
61 | 53 | ||
62 | if ((s = *stringp) == NULL) | 54 | if ((s = *stringp) == NULL) |
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3 index 3287fef53e..839402dcb1 100644 --- a/src/lib/libc/string/strsignal.3 +++ b/src/lib/libc/string/strsignal.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,12 +29,11 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strsignal.3,v 1.5 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strsignal.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRSIGNAL 3 | 35 | .Dt STRSIGNAL 3 |
41 | .Os BSD 4 | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strsignal | 38 | .Nm strsignal |
44 | .Nd get signal description string | 39 | .Nd get signal description string |
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c index ec4a267edf..aa541cefed 100644 --- a/src/lib/libc/string/strsignal.c +++ b/src/lib/libc/string/strsignal.c | |||
@@ -10,11 +10,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
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 | 14 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 15 | * without specific prior written permission. |
20 | * | 16 | * |
@@ -31,20 +27,15 @@ | |||
31 | * SUCH DAMAGE. | 27 | * SUCH DAMAGE. |
32 | */ | 28 | */ |
33 | 29 | ||
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> | 30 | #include <string.h> |
40 | #include <limits.h> | 31 | #include <limits.h> |
41 | 32 | ||
42 | extern char *__strsignal __P((int, char *)); | 33 | extern char *__strsignal(int, char *); |
43 | 34 | ||
44 | char * | 35 | char * |
45 | strsignal(sig) | 36 | strsignal(int sig) |
46 | int sig; | ||
47 | { | 37 | { |
48 | static char buf[NL_TEXTMAX]; | 38 | static char buf[NL_TEXTMAX]; |
39 | |||
49 | return __strsignal(sig, buf); | 40 | return __strsignal(sig, buf); |
50 | } | 41 | } |
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3 index 4de03aa58b..f902ca35d2 100644 --- a/src/lib/libc/string/strspn.3 +++ b/src/lib/libc/string/strspn.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strspn.3,v 1.9 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRSPN 3 | 35 | .Dt STRSPN 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -48,9 +43,8 @@ | |||
48 | .Fn strspn "const char *s" "const char *charset" | 43 | .Fn strspn "const char *s" "const char *charset" |
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The |
51 | .Xr strcspn | 46 | .Fn strspn |
52 | function | 47 | function spans the initial part of the NUL-terminated string |
53 | spans the initial part of the null-terminated string | ||
54 | .Fa s | 48 | .Fa s |
55 | as long as the characters from | 49 | as long as the characters from |
56 | .Fa s | 50 | .Fa s |
@@ -59,12 +53,23 @@ occur in string | |||
59 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
60 | The | 54 | The |
61 | .Fn strspn | 55 | .Fn strspn |
62 | function | 56 | function returns the number of characters spanned. |
63 | returns the number of characters spanned. | 57 | .Sh EXAMPLES |
58 | The following call to | ||
59 | .Fn strspn | ||
60 | will return 3, since the first three characters of string | ||
61 | .Fa s | ||
62 | are part of string | ||
63 | .Fa charset : | ||
64 | .Bd -literal -offset indent | ||
65 | char *s = "foobar"; | ||
66 | char *charset = "of"; | ||
67 | size_t span; | ||
68 | |||
69 | span = strspn(s, charset); | ||
70 | .Ed | ||
64 | .Sh SEE ALSO | 71 | .Sh SEE ALSO |
65 | .Xr index 3 , | ||
66 | .Xr memchr 3 , | 72 | .Xr memchr 3 , |
67 | .Xr rindex 3 , | ||
68 | .Xr strchr 3 , | 73 | .Xr strchr 3 , |
69 | .Xr strcspn 3 , | 74 | .Xr strcspn 3 , |
70 | .Xr strpbrk 3 , | 75 | .Xr strpbrk 3 , |
@@ -75,6 +80,5 @@ returns the number of characters spanned. | |||
75 | .Sh STANDARDS | 80 | .Sh STANDARDS |
76 | The | 81 | The |
77 | .Fn strspn | 82 | .Fn strspn |
78 | function | 83 | function conforms to |
79 | conforms to | ||
80 | .St -ansiC . | 84 | .St -ansiC . |
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c index 6224b25c2a..385649c041 100644 --- a/src/lib/libc/string/strspn.c +++ b/src/lib/libc/string/strspn.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strspn.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | 3 | * Copyright (c) 1989 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
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 | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,23 +28,16 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
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> | 31 | #include <string.h> |
40 | 32 | ||
41 | /* | 33 | /* |
42 | * Span the string s2 (skip characters that are in s2). | 34 | * Span the string s2 (skip characters that are in s2). |
43 | */ | 35 | */ |
44 | size_t | 36 | size_t |
45 | strspn(s1, s2) | 37 | strspn(const char *s1, const char *s2) |
46 | const char *s1; | ||
47 | register const char *s2; | ||
48 | { | 38 | { |
49 | register const char *p = s1, *spanp; | 39 | const char *p = s1, *spanp; |
50 | register char c, sc; | 40 | char c, sc; |
51 | 41 | ||
52 | /* | 42 | /* |
53 | * Skip any characters in s2, excluding the terminating \0. | 43 | * Skip any characters in s2, excluding the terminating \0. |
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3 index 24fdf540ed..38bd207727 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,47 +29,50 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strstr.3,v 1.10 2007/09/19 16:06:45 jmc Exp $ |
37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: September 19 2007 $ |
40 | .Dt STRSTR 3 | 35 | .Dt STRSTR 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strstr | 38 | .Nm strstr , strcasestr |
44 | .Nd locate a substring in a string | 39 | .Nd locate a substring in a string |
45 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
47 | .Ft char * | 42 | .Ft char * |
48 | .Fn strstr "const char *big" "const char *little" | 43 | .Fn strstr "const char *big" "const char *little" |
44 | .Ft char * | ||
45 | .Fn strcasestr "const char *big" "const char *little" | ||
49 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
50 | The | 47 | The |
51 | .Fn strstr | 48 | .Fn strstr |
52 | function | 49 | function locates the first occurrence of the NUL-terminated string |
53 | locates the first occurrence of the null-terminated string | ||
54 | .Fa little | 50 | .Fa little |
55 | in the null-terminated string | 51 | in the NUL-terminated string |
56 | .Fa big . | 52 | .Fa big . |
53 | .Pp | ||
54 | The | ||
55 | .Fn strcasestr | ||
56 | function is similar to | ||
57 | .Fn strstr | ||
58 | but ignores the case of both strings. | ||
59 | .Pp | ||
57 | If | 60 | If |
58 | .Fa little | 61 | .Fa little |
59 | is the empty string, | 62 | is an empty string, |
60 | .Fn strstr | 63 | .Fa big |
61 | returns | 64 | is returned; |
62 | .Fa big ; | ||
63 | if | 65 | if |
64 | .Fa little | 66 | .Fa little |
65 | occurs nowhere in | 67 | occurs nowhere in |
66 | .Fa big , | 68 | .Fa big , |
67 | .Fn strstr | 69 | .Dv NULL |
68 | returns NULL; | 70 | is returned; |
69 | otherwise | 71 | otherwise a pointer to the first character of the first occurrence of |
70 | .Fn strstr | 72 | .Fa little |
71 | returns a pointer to the first character of the first occurrence of | 73 | is returned. |
72 | .Fa little . | ||
73 | .Sh SEE ALSO | 74 | .Sh SEE ALSO |
74 | .Xr index 3 , | ||
75 | .Xr memchr 3 , | 75 | .Xr memchr 3 , |
76 | .Xr rindex 3 , | ||
77 | .Xr strchr 3 , | 76 | .Xr strchr 3 , |
78 | .Xr strcspn 3 , | 77 | .Xr strcspn 3 , |
79 | .Xr strpbrk 3 , | 78 | .Xr strpbrk 3 , |
@@ -84,6 +83,10 @@ returns a pointer to the first character of the first occurrence of | |||
84 | .Sh STANDARDS | 83 | .Sh STANDARDS |
85 | The | 84 | The |
86 | .Fn strstr | 85 | .Fn strstr |
87 | function | 86 | function conforms to |
88 | conforms to | ||
89 | .St -ansiC . | 87 | .St -ansiC . |
88 | .Sh HISTORY | ||
89 | The | ||
90 | .Fn strcasestr | ||
91 | function first appeared in | ||
92 | .Ox 3.8 . | ||
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c index 1ed59e357b..95a865bf79 100644 --- a/src/lib/libc/string/strstr.c +++ b/src/lib/libc/string/strstr.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strstr.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,22 +31,16 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
45 | * Find the first occurrence of find in s. | 37 | * Find the first occurrence of find in s. |
46 | */ | 38 | */ |
47 | char * | 39 | char * |
48 | strstr(s, find) | 40 | strstr(const char *s, const char *find) |
49 | register const char *s, *find; | ||
50 | { | 41 | { |
51 | register char c, sc; | 42 | char c, sc; |
52 | register size_t len; | 43 | size_t len; |
53 | 44 | ||
54 | if ((c = *find++) != 0) { | 45 | if ((c = *find++) != 0) { |
55 | len = strlen(find); | 46 | len = strlen(find); |
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 index 644bd10aed..ed7d5158ed 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,29 +29,30 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strtok.3,v 1.19 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRTOK 3 | 35 | .Dt STRTOK 3 |
41 | .Os BSD 3 | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strtok , | 38 | .Nm strtok , |
44 | .Nm strsep | 39 | .Nm strtok_r |
45 | .Nd string token operations | 40 | .Nd string token operations |
46 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
47 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
48 | .Ft char * | 43 | .Ft char * |
49 | .Fn strtok "char *str" "const char *sep" | 44 | .Fn strtok "char *str" "const char *sep" |
45 | .Ft char * | ||
46 | .Fn strtok_r "char *str" "const char *sep" "char **last" | ||
50 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
51 | .Bf -symbolic | 48 | .Bf -symbolic |
52 | This interface is obsoleted by strsep(3). | 49 | This interface is obsoleted by |
50 | .Xr strsep 3 . | ||
53 | .Ef | 51 | .Ef |
54 | .Pp | 52 | .Pp |
55 | The | 53 | The |
56 | .Fn strtok | 54 | .Fn strtok |
57 | function | 55 | function is used to isolate sequential tokens in a NUL-terminated string, |
58 | is used to isolate sequential tokens in a null-terminated string, | ||
59 | .Fa str . | 56 | .Fa str . |
60 | These tokens are separated in the string by at least one of the | 57 | These tokens are separated in the string by at least one of the |
61 | characters in | 58 | characters in |
@@ -71,17 +68,65 @@ The separator string, | |||
71 | must be supplied each time, and may change between calls. | 68 | must be supplied each time, and may change between calls. |
72 | .Pp | 69 | .Pp |
73 | The | 70 | The |
71 | .Fn strtok_r | ||
72 | function is a version of | ||
74 | .Fn strtok | 73 | .Fn strtok |
75 | function | 74 | that takes an explicit context argument and is reentrant. |
76 | returns a pointer to the beginning of each subsequent token in the string, | 75 | .Pp |
77 | after replacing the separator character itself with a | 76 | The |
78 | .Dv NUL | 77 | .Fn strtok |
78 | and | ||
79 | .Fn strtok_r | ||
80 | functions return a pointer to the beginning of each subsequent token | ||
81 | in the string, after replacing the separator character itself with an | ||
82 | .Tn ASCII NUL | ||
79 | character. | 83 | character. |
80 | When no more tokens remain, a null pointer is returned. | 84 | When no more tokens remain, a null pointer is returned. |
85 | .Pp | ||
86 | Since | ||
87 | .Fn strtok | ||
88 | and | ||
89 | .Fn strtok_r | ||
90 | modify the string, | ||
91 | .Fa str | ||
92 | should not point to an area in the initialized data segment. | ||
93 | .Sh EXAMPLES | ||
94 | The following will construct an array of pointers to each individual word in | ||
95 | the string | ||
96 | .Va s : | ||
97 | .Bd -literal -offset indent | ||
98 | #define MAXTOKENS 128 | ||
99 | |||
100 | char s[512], *p, *tokens[MAXTOKENS]; | ||
101 | char *last; | ||
102 | int i = 0; | ||
103 | |||
104 | snprintf(s, sizeof(s), "cat dog horse cow"); | ||
105 | |||
106 | for ((p = strtok_r(s, " ", &last)); p; | ||
107 | (p = strtok_r(NULL, " ", &last))) { | ||
108 | if (i < MAXTOKENS - 1) | ||
109 | tokens[i++] = p; | ||
110 | } | ||
111 | tokens[i] = NULL; | ||
112 | .Ed | ||
113 | .Pp | ||
114 | That is, | ||
115 | .Li tokens[0] | ||
116 | will point to | ||
117 | .Qq cat , | ||
118 | .Li tokens[1] | ||
119 | will point to | ||
120 | .Qq dog , | ||
121 | .Li tokens[2] | ||
122 | will point to | ||
123 | .Qq horse , | ||
124 | and | ||
125 | .Li tokens[3] | ||
126 | will point to | ||
127 | .Qq cow . | ||
81 | .Sh SEE ALSO | 128 | .Sh SEE ALSO |
82 | .Xr index 3 , | ||
83 | .Xr memchr 3 , | 129 | .Xr memchr 3 , |
84 | .Xr rindex 3 , | ||
85 | .Xr strchr 3 , | 130 | .Xr strchr 3 , |
86 | .Xr strcspn 3 , | 131 | .Xr strcspn 3 , |
87 | .Xr strpbrk 3 , | 132 | .Xr strpbrk 3 , |
@@ -92,21 +137,16 @@ When no more tokens remain, a null pointer is returned. | |||
92 | .Sh STANDARDS | 137 | .Sh STANDARDS |
93 | The | 138 | The |
94 | .Fn strtok | 139 | .Fn strtok |
95 | function | 140 | function conforms to |
96 | conforms to | ||
97 | .St -ansiC . | 141 | .St -ansiC . |
98 | .Sh BUGS | 142 | .Sh BUGS |
99 | There is no way to get tokens from multiple strings simultaneously. | ||
100 | .Pp | ||
101 | The System V | 143 | The System V |
102 | .Fn strtok , | 144 | .Fn strtok , |
103 | if handed a string containing only delimiter characters, | 145 | if handed a string containing only delimiter characters, |
104 | will not alter the next starting point, so that a call to | 146 | will not alter the next starting point, so that a call to |
105 | .Fn strtok | 147 | .Fn strtok |
106 | with a different (or empty) delimiter string | 148 | with a different (or empty) delimiter string |
107 | may return a | 149 | may return a non-null value. |
108 | .Pf non- Dv NULL | ||
109 | value. | ||
110 | Since this implementation always alters the next starting point, | 150 | Since this implementation always alters the next starting point, |
111 | such a sequence of calls would always return | 151 | such a sequence of calls would always return |
112 | .Dv NULL . | 152 | .Dv NULL . |
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c index 9f712579bf..4e963a019e 100644 --- a/src/lib/libc/string/strtok.c +++ b/src/lib/libc/string/strtok.c | |||
@@ -10,11 +10,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
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 | 14 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 15 | * without specific prior written permission. |
20 | * | 16 | * |
@@ -31,25 +27,25 @@ | |||
31 | * SUCH DAMAGE. | 27 | * SUCH DAMAGE. |
32 | */ | 28 | */ |
33 | 29 | ||
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> | 30 | #include <string.h> |
40 | 31 | ||
41 | char * | 32 | char * |
42 | strtok(s, delim) | 33 | strtok(char *s, const char *delim) |
43 | register char *s; | ||
44 | register const char *delim; | ||
45 | { | 34 | { |
46 | register char *spanp; | ||
47 | register int c, sc; | ||
48 | char *tok; | ||
49 | static char *last; | 35 | static char *last; |
50 | 36 | ||
37 | return strtok_r(s, delim, &last); | ||
38 | } | ||
39 | |||
40 | char * | ||
41 | strtok_r(char *s, const char *delim, char **last) | ||
42 | { | ||
43 | char *spanp; | ||
44 | int c, sc; | ||
45 | char *tok; | ||
46 | |||
51 | 47 | ||
52 | if (s == NULL && (s = last) == NULL) | 48 | if (s == NULL && (s = *last) == NULL) |
53 | return (NULL); | 49 | return (NULL); |
54 | 50 | ||
55 | /* | 51 | /* |
@@ -63,7 +59,7 @@ cont: | |||
63 | } | 59 | } |
64 | 60 | ||
65 | if (c == 0) { /* no non-delimiter characters */ | 61 | if (c == 0) { /* no non-delimiter characters */ |
66 | last = NULL; | 62 | *last = NULL; |
67 | return (NULL); | 63 | return (NULL); |
68 | } | 64 | } |
69 | tok = s - 1; | 65 | tok = s - 1; |
@@ -81,7 +77,7 @@ cont: | |||
81 | s = NULL; | 77 | s = NULL; |
82 | else | 78 | else |
83 | s[-1] = 0; | 79 | s[-1] = 0; |
84 | last = s; | 80 | *last = s; |
85 | return (tok); | 81 | return (tok); |
86 | } | 82 | } |
87 | } while (sc != 0); | 83 | } while (sc != 0); |
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3 index 84fd945472..73ce135191 100644 --- a/src/lib/libc/string/strxfrm.3 +++ b/src/lib/libc/string/strxfrm.3 | |||
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)strxfrm.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strxfrm.3,v 1.8 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strxfrm.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRXFRM 3 | 35 | .Dt STRXFRM 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -47,23 +42,33 @@ | |||
47 | .Ft size_t | 42 | .Ft size_t |
48 | .Fn strxfrm "char *dst" "const char *src" "size_t n" | 43 | .Fn strxfrm "char *dst" "const char *src" "size_t n" |
49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
50 | The | 45 | The idea of |
51 | .Fn strxfrm | 46 | .Fn strxfrm |
52 | function | 47 | is to |
53 | does something horrible (see | 48 | .Dq un-localize |
54 | .Tn ANSI | 49 | a string: the function transforms |
55 | standard). | 50 | .Ar src , |
56 | In this implementation it just copies. | 51 | storing the result in |
52 | .Ar dst , | ||
53 | such that | ||
54 | .Xr strcmp 3 | ||
55 | on transformed strings returns what | ||
56 | .Xr strcoll 3 | ||
57 | on the original untransformed strings would return. | ||
57 | .Sh SEE ALSO | 58 | .Sh SEE ALSO |
58 | .Xr bcmp 3 , | 59 | .Xr bcmp 3 , |
59 | .Xr memcmp 3 , | 60 | .Xr memcmp 3 , |
60 | .\" .Xr setlocale 3 , | 61 | .Xr setlocale 3 , |
61 | .Xr strcasecmp 3 , | 62 | .Xr strcasecmp 3 , |
62 | .Xr strcmp 3 , | 63 | .Xr strcmp 3 , |
63 | .Xr strcoll 3 | 64 | .Xr strcoll 3 |
64 | .Sh STANDARDS | 65 | .Sh STANDARDS |
65 | The | 66 | The |
66 | .Fn strxfrm | 67 | .Fn strxfrm |
67 | function | 68 | function conforms to |
68 | conforms to | ||
69 | .St -ansiC . | 69 | .St -ansiC . |
70 | .Sh BUGS | ||
71 | Since locales are not fully implemented on | ||
72 | .Ox , | ||
73 | .Fn strxfrm | ||
74 | just returns a copy of the original string. | ||
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c index d9df77b957..6f289c901e 100644 --- a/src/lib/libc/string/strxfrm.c +++ b/src/lib/libc/string/strxfrm.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: strxfrm.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ | ||
1 | /*- | 2 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,11 +31,6 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
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> | 34 | #include <string.h> |
43 | 35 | ||
44 | /* | 36 | /* |
@@ -47,28 +39,13 @@ static char *rcsid = "$Id: strxfrm.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | |||
47 | * on the original untransformed strings would return. | 39 | * on the original untransformed strings would return. |
48 | */ | 40 | */ |
49 | size_t | 41 | size_t |
50 | strxfrm(dst, src, n) | 42 | strxfrm(char *dst, const char *src, size_t n) |
51 | register char *dst; | ||
52 | register const char *src; | ||
53 | register size_t n; | ||
54 | { | 43 | { |
55 | register size_t r = 0; | ||
56 | register int c; | ||
57 | 44 | ||
58 | /* | 45 | /* |
59 | * Since locales are unimplemented, this is just a copy. | 46 | * Since locales are unimplemented, this is just a copy. |
60 | */ | 47 | */ |
61 | if (n != 0) { | 48 | if (n == 0) |
62 | while ((c = *src++) != 0) { | 49 | return (strlen(src)); |
63 | r++; | 50 | return (strlcpy(dst, src, n)); |
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 | } | 51 | } |
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3 index 133c487bbd..56def1ec88 100644 --- a/src/lib/libc/string/swab.3 +++ b/src/lib/libc/string/swab.3 | |||
@@ -9,11 +9,7 @@ | |||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 9 | .\" 2. Redistributions in binary form must reproduce the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer in the | 10 | .\" notice, this list of conditions and the following disclaimer in the |
11 | .\" documentation and/or other materials provided with the distribution. | 11 | .\" documentation and/or other materials provided with the distribution. |
12 | .\" 3. All advertising materials mentioning features or use of this software | 12 | .\" 3. Neither the name of the University nor the names of its contributors |
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 | 13 | .\" may be used to endorse or promote products derived from this software |
18 | .\" without specific prior written permission. | 14 | .\" without specific prior written permission. |
19 | .\" | 15 | .\" |
@@ -29,17 +25,16 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 26 | .\" SUCH DAMAGE. |
31 | .\" | 27 | .\" |
32 | .\" from: @(#)swab.3 6.6 (Berkeley) 5/1/91 | 28 | .\" $OpenBSD: swab.3,v 1.6 2007/05/31 19:19:32 jmc Exp $ |
33 | .\" $Id: swab.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
34 | .\" | 29 | .\" |
35 | .Dd May 1, 1991 | 30 | .Dd $Mdocdate: May 31 2007 $ |
36 | .Dt SWAB 3 | 31 | .Dt SWAB 3 |
37 | .Os | 32 | .Os |
38 | .Sh NAME | 33 | .Sh NAME |
39 | .Nm swab | 34 | .Nm swab |
40 | .Nd swap adjacent bytes | 35 | .Nd swap adjacent bytes |
41 | .Sh SYNOPSIS | 36 | .Sh SYNOPSIS |
42 | .Fd #include <string.h> | 37 | .Fd #include <unistd.h> |
43 | .Ft void | 38 | .Ft void |
44 | .Fn swab "const void *src" "void *dst" "size_t len" | 39 | .Fn swab "const void *src" "void *dst" "size_t len" |
45 | .Sh DESCRIPTION | 40 | .Sh DESCRIPTION |
@@ -55,7 +50,7 @@ swapping adjacent bytes. | |||
55 | .Pp | 50 | .Pp |
56 | The argument | 51 | The argument |
57 | .Fa len | 52 | .Fa len |
58 | must be even number. | 53 | must be an even number. |
59 | .Sh SEE ALSO | 54 | .Sh SEE ALSO |
60 | .Xr bzero 3 , | 55 | .Xr bzero 3 , |
61 | .Xr memset 3 | 56 | .Xr memset 3 |
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c index f33fc53bd6..b74db7e62a 100644 --- a/src/lib/libc/string/swab.c +++ b/src/lib/libc/string/swab.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: swab.c,v 1.8 2008/03/15 21:54:09 ray Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 3 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
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 | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,32 +31,30 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #include <unistd.h> |
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 | 35 | ||
44 | void | 36 | void |
45 | swab(from, to, len) | 37 | swab(const void *from, void *to, size_t len) |
46 | const void *from; | ||
47 | void *to; | ||
48 | size_t len; | ||
49 | { | 38 | { |
50 | register unsigned long temp; | 39 | size_t n; |
51 | register int n; | 40 | char *fp, *tp; |
52 | register char *fp, *tp; | 41 | char temp; |
53 | 42 | ||
54 | n = (len >> 1) + 1; | 43 | n = (len / 2) + 1; |
55 | fp = (char *)from; | 44 | fp = (char *)from; |
56 | tp = (char *)to; | 45 | tp = (char *)to; |
57 | #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | 46 | #define STEP do { \ |
47 | temp = *fp++; \ | ||
48 | *tp++ = *fp++; \ | ||
49 | *tp++ = temp; \ | ||
50 | } while (0) | ||
58 | /* round to multiple of 8 */ | 51 | /* round to multiple of 8 */ |
59 | while ((--n) & 07) | 52 | while ((--n) & 07) |
60 | STEP; | 53 | STEP; |
61 | n >>= 3; | 54 | n >>= 3; |
62 | while (--n >= 0) { | 55 | if (n == 0) |
56 | return; | ||
57 | while (n-- != 0) { | ||
63 | STEP; STEP; STEP; STEP; | 58 | STEP; STEP; STEP; STEP; |
64 | STEP; STEP; STEP; STEP; | 59 | STEP; STEP; STEP; STEP; |
65 | } | 60 | } |
diff --git a/src/lib/libc/string/wcscat.c b/src/lib/libc/string/wcscat.c new file mode 100644 index 0000000000..a4841a975a --- /dev/null +++ b/src/lib/libc/string/wcscat.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* $OpenBSD: wcscat.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | #if defined(APIWARN) | ||
35 | __warn_references(wcscat, | ||
36 | "warning: wcscat() is almost always misused, please use wcslcat()"); | ||
37 | #endif | ||
38 | |||
39 | wchar_t * | ||
40 | wcscat(wchar_t *s1, const wchar_t *s2) | ||
41 | { | ||
42 | wchar_t *p; | ||
43 | wchar_t *q; | ||
44 | const wchar_t *r; | ||
45 | |||
46 | p = s1; | ||
47 | while (*p) | ||
48 | p++; | ||
49 | q = p; | ||
50 | r = s2; | ||
51 | while (*r) | ||
52 | *q++ = *r++; | ||
53 | *q = '\0'; | ||
54 | return s1; | ||
55 | } | ||
diff --git a/src/lib/libc/string/wcschr.c b/src/lib/libc/string/wcschr.c new file mode 100644 index 0000000000..b84a2d32e3 --- /dev/null +++ b/src/lib/libc/string/wcschr.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: wcschr.c,v 1.4 2008/08/23 05:34:36 djm Exp $ */ | ||
2 | /* $NetBSD: wcschr.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcschr.c,v 1.2 2000/12/21 05:07:25 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wcschr(const wchar_t *s, wchar_t c) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | |||
39 | p = s; | ||
40 | for (;;) { | ||
41 | if (*p == c) { | ||
42 | /* LINTED interface specification */ | ||
43 | return (wchar_t *)p; | ||
44 | } | ||
45 | if (!*p) | ||
46 | return NULL; | ||
47 | p++; | ||
48 | } | ||
49 | /* NOTREACHED */ | ||
50 | } | ||
diff --git a/src/lib/libc/string/wcscmp.c b/src/lib/libc/string/wcscmp.c new file mode 100644 index 0000000000..4a8f6ba3fb --- /dev/null +++ b/src/lib/libc/string/wcscmp.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* $OpenBSD: wcscmp.c,v 1.4 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1990, 1993 | ||
6 | * The Regents of the University of California. All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to Berkeley by | ||
9 | * Chris Torek. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #include <wchar.h> | ||
37 | #include "locale/runetype.h" | ||
38 | |||
39 | /* | ||
40 | * Compare strings. | ||
41 | */ | ||
42 | int | ||
43 | wcscmp(const wchar_t *s1, const wchar_t *s2) | ||
44 | { | ||
45 | |||
46 | while (*s1 == *s2++) | ||
47 | if (*s1++ == 0) | ||
48 | return (0); | ||
49 | /* XXX assumes wchar_t = int */ | ||
50 | return (*(const rune_t *)s1 - *(const rune_t *)--s2); | ||
51 | } | ||
diff --git a/src/lib/libc/string/wcscpy.c b/src/lib/libc/string/wcscpy.c new file mode 100644 index 0000000000..75fdb75fe4 --- /dev/null +++ b/src/lib/libc/string/wcscpy.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* $OpenBSD: wcscpy.c,v 1.4 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcscpy.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | #if defined(APIWARN) | ||
35 | __warn_references(wcscpy, | ||
36 | "warning: wcscpy() is almost always misused, please use wcslcpy()"); | ||
37 | #endif | ||
38 | |||
39 | wchar_t * | ||
40 | wcscpy(wchar_t *s1, const wchar_t *s2) | ||
41 | { | ||
42 | wchar_t *p; | ||
43 | const wchar_t *q; | ||
44 | |||
45 | p = s1; | ||
46 | q = s2; | ||
47 | while (*q) | ||
48 | *p++ = *q++; | ||
49 | *p = '\0'; | ||
50 | |||
51 | return s1; | ||
52 | } | ||
diff --git a/src/lib/libc/string/wcscspn.c b/src/lib/libc/string/wcscspn.c new file mode 100644 index 0000000000..cf40092465 --- /dev/null +++ b/src/lib/libc/string/wcscspn.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* $OpenBSD: wcscspn.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | size_t | ||
35 | wcscspn(const wchar_t *s, const wchar_t *set) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | const wchar_t *q; | ||
39 | |||
40 | p = s; | ||
41 | while (*p) { | ||
42 | q = set; | ||
43 | while (*q) { | ||
44 | if (*p == *q) | ||
45 | goto done; | ||
46 | q++; | ||
47 | } | ||
48 | p++; | ||
49 | } | ||
50 | |||
51 | done: | ||
52 | return (p - s); | ||
53 | } | ||
diff --git a/src/lib/libc/string/wcslcat.c b/src/lib/libc/string/wcslcat.c new file mode 100644 index 0000000000..bcd52d1f3c --- /dev/null +++ b/src/lib/libc/string/wcslcat.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* $OpenBSD: wcslcat.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ | ||
3 | /* from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp */ | ||
4 | |||
5 | /* | ||
6 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 3. The name of the author may not be used to endorse or promote products | ||
18 | * derived from this software without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
21 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
22 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
23 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <wchar.h> | ||
34 | |||
35 | /* | ||
36 | * Appends src to string dst of size siz (unlike wcsncat, siz is the | ||
37 | * full size of dst, not space left). At most siz-1 characters | ||
38 | * will be copied. Always NUL terminates (unless siz == 0). | ||
39 | * Returns wcslen(initial dst) + wcslen(src); if retval >= siz, | ||
40 | * truncation occurred. | ||
41 | */ | ||
42 | size_t | ||
43 | wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) | ||
44 | { | ||
45 | wchar_t *d = dst; | ||
46 | const wchar_t *s = src; | ||
47 | size_t n = siz; | ||
48 | size_t dlen; | ||
49 | |||
50 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
51 | while (*d != '\0' && n-- != 0) | ||
52 | d++; | ||
53 | dlen = d - dst; | ||
54 | n = siz - dlen; | ||
55 | |||
56 | if (n == 0) | ||
57 | return(dlen + wcslen(s)); | ||
58 | while (*s != '\0') { | ||
59 | if (n != 1) { | ||
60 | *d++ = *s; | ||
61 | n--; | ||
62 | } | ||
63 | s++; | ||
64 | } | ||
65 | *d = '\0'; | ||
66 | |||
67 | return(dlen + (s - src)); /* count does not include NUL */ | ||
68 | } | ||
diff --git a/src/lib/libc/string/wcslcpy.c b/src/lib/libc/string/wcslcpy.c new file mode 100644 index 0000000000..85f51df35f --- /dev/null +++ b/src/lib/libc/string/wcslcpy.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* $OpenBSD: wcslcpy.c,v 1.4 2006/05/05 15:27:38 millert Exp $ */ | ||
2 | /* $NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ | ||
3 | /* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */ | ||
4 | |||
5 | /* | ||
6 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 3. The name of the author may not be used to endorse or promote products | ||
18 | * derived from this software without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
21 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
22 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
23 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <wchar.h> | ||
34 | |||
35 | /* | ||
36 | * Copy src to string dst of size siz. At most siz-1 characters | ||
37 | * will be copied. Always NUL terminates (unless siz == 0). | ||
38 | * Returns wcslen(src); if retval >= siz, truncation occurred. | ||
39 | */ | ||
40 | size_t | ||
41 | wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) | ||
42 | { | ||
43 | wchar_t *d = dst; | ||
44 | const wchar_t *s = src; | ||
45 | size_t n = siz; | ||
46 | |||
47 | /* Copy as many bytes as will fit */ | ||
48 | if (n != 0) { | ||
49 | while (--n != 0) { | ||
50 | if ((*d++ = *s++) == '\0') | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
56 | if (n == 0) { | ||
57 | if (siz != 0) | ||
58 | *d = '\0'; /* NUL-terminate dst */ | ||
59 | while (*s++) | ||
60 | ; | ||
61 | } | ||
62 | |||
63 | return(s - src - 1); /* count does not include NUL */ | ||
64 | } | ||
diff --git a/src/lib/libc/string/wcslen.c b/src/lib/libc/string/wcslen.c new file mode 100644 index 0000000000..c1de4a271e --- /dev/null +++ b/src/lib/libc/string/wcslen.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* $OpenBSD: wcslen.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | size_t | ||
35 | wcslen(const wchar_t *s) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | |||
39 | p = s; | ||
40 | while (*p) | ||
41 | p++; | ||
42 | |||
43 | return p - s; | ||
44 | } | ||
diff --git a/src/lib/libc/string/wcsncat.c b/src/lib/libc/string/wcsncat.c new file mode 100644 index 0000000000..eb9a701514 --- /dev/null +++ b/src/lib/libc/string/wcsncat.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* $OpenBSD: wcsncat.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcsncat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wcsncat(wchar_t *s1, const wchar_t *s2, size_t n) | ||
36 | { | ||
37 | wchar_t *p; | ||
38 | wchar_t *q; | ||
39 | const wchar_t *r; | ||
40 | |||
41 | p = s1; | ||
42 | while (*p) | ||
43 | p++; | ||
44 | q = p; | ||
45 | r = s2; | ||
46 | while (*r && n) { | ||
47 | *q++ = *r++; | ||
48 | n--; | ||
49 | } | ||
50 | *q = '\0'; | ||
51 | return s1; | ||
52 | } | ||
diff --git a/src/lib/libc/string/wcsncmp.c b/src/lib/libc/string/wcsncmp.c new file mode 100644 index 0000000000..fb3c7057cf --- /dev/null +++ b/src/lib/libc/string/wcsncmp.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* $OpenBSD: wcsncmp.c,v 1.4 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1989, 1993 | ||
6 | * The Regents of the University of California. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. Neither the name of the University nor the names of its contributors | ||
17 | * may be used to endorse or promote products derived from this software | ||
18 | * without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | * SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include <wchar.h> | ||
34 | #include "locale/runetype.h" | ||
35 | |||
36 | int | ||
37 | wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) | ||
38 | { | ||
39 | |||
40 | if (n == 0) | ||
41 | return (0); | ||
42 | do { | ||
43 | if (*s1 != *s2++) { | ||
44 | /* XXX assumes wchar_t = int */ | ||
45 | return (*(const rune_t *)s1 - | ||
46 | *(const rune_t *)--s2); | ||
47 | } | ||
48 | if (*s1++ == 0) | ||
49 | break; | ||
50 | } while (--n != 0); | ||
51 | return (0); | ||
52 | } | ||
diff --git a/src/lib/libc/string/wcsncpy.c b/src/lib/libc/string/wcsncpy.c new file mode 100644 index 0000000000..107696f1de --- /dev/null +++ b/src/lib/libc/string/wcsncpy.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: wcsncpy.c,v 1.4 2006/04/17 18:05:35 espie Exp $ */ | ||
2 | /* $NetBSD: wcsncpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcsncpy.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wcsncpy(wchar_t *s1, const wchar_t *s2, size_t n) | ||
36 | { | ||
37 | wchar_t *p; | ||
38 | |||
39 | p = s1; | ||
40 | while (n && *s2) { | ||
41 | *p++ = *s2++; | ||
42 | n--; | ||
43 | } | ||
44 | while (n) { | ||
45 | *p++ = L'\0'; | ||
46 | n--; | ||
47 | } | ||
48 | |||
49 | return s1; | ||
50 | } | ||
diff --git a/src/lib/libc/string/wcspbrk.c b/src/lib/libc/string/wcspbrk.c new file mode 100644 index 0000000000..1923abfc89 --- /dev/null +++ b/src/lib/libc/string/wcspbrk.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* $OpenBSD: wcspbrk.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcspbrk.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wcspbrk(const wchar_t *s, const wchar_t *set) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | const wchar_t *q; | ||
39 | |||
40 | p = s; | ||
41 | while (*p) { | ||
42 | q = set; | ||
43 | while (*q) { | ||
44 | if (*p == *q) { | ||
45 | /* LINTED interface specification */ | ||
46 | return (wchar_t *)p; | ||
47 | } | ||
48 | q++; | ||
49 | } | ||
50 | p++; | ||
51 | } | ||
52 | return NULL; | ||
53 | } | ||
diff --git a/src/lib/libc/string/wcsrchr.c b/src/lib/libc/string/wcsrchr.c new file mode 100644 index 0000000000..3433310c56 --- /dev/null +++ b/src/lib/libc/string/wcsrchr.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: wcsrchr.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcsrchr.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcsrchr.c,v 1.2 2000/12/21 05:07:25 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wcsrchr(const wchar_t *s, wchar_t c) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | |||
39 | p = s; | ||
40 | while (*p) | ||
41 | p++; | ||
42 | while (s <= p) { | ||
43 | if (*p == c) { | ||
44 | /* LINTED interface specification */ | ||
45 | return (wchar_t *)p; | ||
46 | } | ||
47 | p--; | ||
48 | } | ||
49 | return NULL; | ||
50 | } | ||
diff --git a/src/lib/libc/string/wcsspn.c b/src/lib/libc/string/wcsspn.c new file mode 100644 index 0000000000..5162fa0763 --- /dev/null +++ b/src/lib/libc/string/wcsspn.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* $OpenBSD: wcsspn.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999,2001 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * $Citrus: xpg4dl/FreeBSD/lib/libc/string/wcsspn.c,v 1.3 2001/09/21 16:06:43 yamt Exp $ | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | size_t | ||
35 | wcsspn(const wchar_t *s, const wchar_t *set) | ||
36 | { | ||
37 | const wchar_t *p; | ||
38 | const wchar_t *q; | ||
39 | |||
40 | p = s; | ||
41 | while (*p) { | ||
42 | q = set; | ||
43 | while (*q) { | ||
44 | if (*p == *q) | ||
45 | break; | ||
46 | q++; | ||
47 | } | ||
48 | if (!*q) | ||
49 | goto done; | ||
50 | p++; | ||
51 | } | ||
52 | |||
53 | done: | ||
54 | return (p - s); | ||
55 | } | ||
diff --git a/src/lib/libc/string/wcsstr.c b/src/lib/libc/string/wcsstr.c new file mode 100644 index 0000000000..669e340280 --- /dev/null +++ b/src/lib/libc/string/wcsstr.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* $OpenBSD: wcsstr.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | #ifdef WCSWCS | ||
36 | wcswcs(const wchar_t *big, const wchar_t *little) | ||
37 | #else | ||
38 | wcsstr(const wchar_t *big, const wchar_t *little) | ||
39 | #endif | ||
40 | { | ||
41 | const wchar_t *p; | ||
42 | const wchar_t *q; | ||
43 | const wchar_t *r; | ||
44 | |||
45 | if (!*little) { | ||
46 | /* LINTED interface specification */ | ||
47 | return (wchar_t *)big; | ||
48 | } | ||
49 | if (wcslen(big) < wcslen(little)) | ||
50 | return NULL; | ||
51 | |||
52 | p = big; | ||
53 | q = little; | ||
54 | while (*p) { | ||
55 | q = little; | ||
56 | r = p; | ||
57 | while (*q) { | ||
58 | if (*r != *q) | ||
59 | break; | ||
60 | q++; | ||
61 | r++; | ||
62 | } | ||
63 | if (!*q) { | ||
64 | /* LINTED interface specification */ | ||
65 | return (wchar_t *)p; | ||
66 | } | ||
67 | p++; | ||
68 | } | ||
69 | return NULL; | ||
70 | } | ||
diff --git a/src/lib/libc/string/wcstok.3 b/src/lib/libc/string/wcstok.3 new file mode 100644 index 0000000000..fe65f120e3 --- /dev/null +++ b/src/lib/libc/string/wcstok.3 | |||
@@ -0,0 +1,136 @@ | |||
1 | .\" $OpenBSD: wcstok.3,v 1.5 2007/05/31 19:19:32 jmc Exp $ | ||
2 | .\" | ||
3 | .\" $NetBSD: wcstok.3,v 1.3 2003/09/08 17:54:33 wiz Exp $ | ||
4 | .\" | ||
5 | .\" Copyright (c) 1998 Softweyr LLC. All rights reserved. | ||
6 | .\" | ||
7 | .\" strtok_r, from Berkeley strtok | ||
8 | .\" Oct 13, 1998 by Wes Peters <wes@softweyr.com> | ||
9 | .\" | ||
10 | .\" Copyright (c) 1988, 1991, 1993 | ||
11 | .\" The Regents of the University of California. All rights reserved. | ||
12 | .\" | ||
13 | .\" This code is derived from software contributed to Berkeley by | ||
14 | .\" the American National Standards Committee X3, on Information | ||
15 | .\" Processing Systems. | ||
16 | .\" | ||
17 | .\" Redistribution and use in source and binary forms, with or without | ||
18 | .\" modification, are permitted provided that the following conditions | ||
19 | .\" are met: | ||
20 | .\" | ||
21 | .\" 1. Redistributions of source code must retain the above copyright | ||
22 | .\" notices, this list of conditions and the following disclaimer. | ||
23 | .\" | ||
24 | .\" 2. Redistributions in binary form must reproduce the above | ||
25 | .\" copyright notices, this list of conditions and the following | ||
26 | .\" disclaimer in the documentation and/or other materials provided | ||
27 | .\" with the distribution. | ||
28 | .\" | ||
29 | .\" 3. All advertising materials mentioning features or use of this | ||
30 | .\" software must display the following acknowledgement: | ||
31 | .\" | ||
32 | .\" This product includes software developed by Softweyr LLC, the | ||
33 | .\" University of California, Berkeley, and its contributors. | ||
34 | .\" | ||
35 | .\" 4. Neither the name of Softweyr LLC, the University nor the names | ||
36 | .\" of its contributors may be used to endorse or promote products | ||
37 | .\" derived from this software without specific prior written | ||
38 | .\" permission. | ||
39 | .\" | ||
40 | .\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND | ||
41 | .\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
42 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
43 | .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
44 | .\" DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR | ||
45 | .\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
46 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
47 | .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
48 | .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
49 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
50 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
51 | .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
52 | .\" SUCH DAMAGE. | ||
53 | .\" | ||
54 | .\" Original version ID: | ||
55 | .\" FreeBSD: src/lib/libc/string/wcstok.3,v 1.4 2002/10/15 09:49:54 tjr Exp | ||
56 | .\" | ||
57 | .Dd $Mdocdate: May 31 2007 $ | ||
58 | .Dt WCSTOK 3 | ||
59 | .Os | ||
60 | .Sh NAME | ||
61 | .Nm wcstok | ||
62 | .Nd split wide-character string into tokens | ||
63 | .Sh SYNOPSIS | ||
64 | .In wchar.h | ||
65 | .Ft wchar_t * | ||
66 | .Fn wcstok "wchar_t * restrict str" "const wchar_t * restrict sep" "wchar_t ** restrict last" | ||
67 | .Sh DESCRIPTION | ||
68 | The | ||
69 | .Fn wcstok | ||
70 | function | ||
71 | is used to isolate sequential tokens in a NUL-terminated wide character | ||
72 | string, | ||
73 | .Fa str . | ||
74 | These tokens are separated in the string by at least one of the | ||
75 | characters in | ||
76 | .Fa sep . | ||
77 | The first time that | ||
78 | .Fn wcstok | ||
79 | is called, | ||
80 | .Fa str | ||
81 | should be specified; subsequent calls, wishing to obtain further tokens | ||
82 | from the same string, should pass a null pointer instead. | ||
83 | The separator string, | ||
84 | .Fa sep , | ||
85 | must be supplied each time, and may change between calls. | ||
86 | The context pointer | ||
87 | .Fa last | ||
88 | must be provided on each call. | ||
89 | .Pp | ||
90 | The | ||
91 | .Fn wcstok | ||
92 | function is the wide character counterpart of the | ||
93 | .Fn strtok_r | ||
94 | function. | ||
95 | .Sh RETURN VALUES | ||
96 | The | ||
97 | .Fn wcstok | ||
98 | function | ||
99 | returns a pointer to the beginning of each subsequent token in the string, | ||
100 | after replacing the token itself with a NUL wide character (L'\e0'). | ||
101 | When no more tokens remain, a null pointer is returned. | ||
102 | .Sh EXAMPLES | ||
103 | The following code fragment splits a wide character string on | ||
104 | .Tn ASCII | ||
105 | space, tab, and newline characters and writes the tokens to | ||
106 | standard output: | ||
107 | .Bd -literal -offset indent | ||
108 | const wchar_t *seps = L" \et\en"; | ||
109 | wchar_t *last, *tok, text[] = L" \enone\ettwo\et\etthree \en"; | ||
110 | |||
111 | for (tok = wcstok(text, seps, &last); tok != NULL; | ||
112 | tok = wcstok(NULL, seps, &last)) | ||
113 | wprintf(L"%ls\en", tok); | ||
114 | .Ed | ||
115 | .Sh SEE ALSO | ||
116 | .Xr strtok 3 , | ||
117 | .Xr wcschr 3 , | ||
118 | .Xr wcscspn 3 , | ||
119 | .Xr wcspbrk 3 , | ||
120 | .Xr wcsrchr 3 , | ||
121 | .Xr wcsspn 3 | ||
122 | .Sh STANDARDS | ||
123 | The | ||
124 | .Fn wcstok | ||
125 | function | ||
126 | conforms to | ||
127 | .St -isoC-99 . | ||
128 | .Sh HISTORY | ||
129 | Some early implementations of | ||
130 | .Fn wcstok | ||
131 | omit the | ||
132 | context pointer argument, | ||
133 | .Fa last , | ||
134 | and maintain state across calls in a static variable like | ||
135 | .Fn strtok | ||
136 | does. | ||
diff --git a/src/lib/libc/string/wcstok.c b/src/lib/libc/string/wcstok.c new file mode 100644 index 0000000000..bc1ac3e8cb --- /dev/null +++ b/src/lib/libc/string/wcstok.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* $OpenBSD: wcstok.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcstok.c,v 1.3 2003/07/10 08:50:48 tshiozak Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1998 Softweyr LLC. All rights reserved. | ||
6 | * | ||
7 | * strtok_r, from Berkeley strtok | ||
8 | * Oct 13, 1998 by Wes Peters <wes@softweyr.com> | ||
9 | * | ||
10 | * Copyright (c) 1988, 1993 | ||
11 | * The Regents of the University of California. All rights reserved. | ||
12 | * | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * 1. Redistributions of source code must retain the above copyright | ||
17 | * notices, this list of conditions and the following disclaimer. | ||
18 | * 2. Redistributions in binary form must reproduce the above copyright | ||
19 | * notices, this list of conditions and the following disclaimer in the | ||
20 | * documentation and/or other materials provided with the distribution. | ||
21 | * 3. All advertising materials mentioning features or use of this software | ||
22 | * must display the following acknowledgement: | ||
23 | * This product includes software developed by Softweyr LLC, the | ||
24 | * University of California, Berkeley, and its contributors. | ||
25 | * 4. Neither the name of the University nor the names of its contributors | ||
26 | * may be used to endorse or promote products derived from this software | ||
27 | * without specific prior written permission. | ||
28 | * | ||
29 | * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS | ||
30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
32 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE | ||
33 | * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
35 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
36 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
37 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
38 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
39 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
40 | * | ||
41 | * Original version ID: | ||
42 | * FreeBSD: src/lib/libc/string/wcstok.c,v 1.1 2002/09/07 08:16:57 tjr Exp | ||
43 | */ | ||
44 | |||
45 | #include <wchar.h> | ||
46 | |||
47 | wchar_t * | ||
48 | wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim, | ||
49 | wchar_t ** __restrict last) | ||
50 | { | ||
51 | const wchar_t *spanp; | ||
52 | wchar_t c, sc; | ||
53 | wchar_t *tok; | ||
54 | |||
55 | if (s == NULL && (s = *last) == NULL) | ||
56 | return (NULL); | ||
57 | |||
58 | /* | ||
59 | * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of). | ||
60 | */ | ||
61 | cont: | ||
62 | c = *s++; | ||
63 | for (spanp = delim; (sc = *spanp++) != L'\0';) { | ||
64 | if (c == sc) | ||
65 | goto cont; | ||
66 | } | ||
67 | |||
68 | if (c == L'\0') { /* no non-delimiter characters */ | ||
69 | *last = NULL; | ||
70 | return (NULL); | ||
71 | } | ||
72 | tok = s - 1; | ||
73 | |||
74 | /* | ||
75 | * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). | ||
76 | * Note that delim must have one NUL; we stop if we see that, too. | ||
77 | */ | ||
78 | for (;;) { | ||
79 | c = *s++; | ||
80 | spanp = delim; | ||
81 | do { | ||
82 | if ((sc = *spanp++) == c) { | ||
83 | if (c == L'\0') | ||
84 | s = NULL; | ||
85 | else | ||
86 | s[-1] = L'\0'; | ||
87 | *last = s; | ||
88 | return (tok); | ||
89 | } | ||
90 | } while (sc != L'\0'); | ||
91 | } | ||
92 | /* NOTREACHED */ | ||
93 | } | ||
diff --git a/src/lib/libc/string/wcswcs.c b/src/lib/libc/string/wcswcs.c new file mode 100644 index 0000000000..bd35605547 --- /dev/null +++ b/src/lib/libc/string/wcswcs.c | |||
@@ -0,0 +1,5 @@ | |||
1 | /* $OpenBSD: wcswcs.c,v 1.1 2005/04/13 16:35:58 espie Exp $ */ | ||
2 | /* $NetBSD: wcswcs.c,v 1.1 2003/03/05 20:18:17 tshiozak Exp $ */ | ||
3 | |||
4 | #define WCSWCS | ||
5 | #include "wcsstr.c" | ||
diff --git a/src/lib/libc/string/wcswidth.c b/src/lib/libc/string/wcswidth.c new file mode 100644 index 0000000000..cd240897b5 --- /dev/null +++ b/src/lib/libc/string/wcswidth.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* $OpenBSD: wcswidth.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | int | ||
35 | wcswidth(const wchar_t *s, size_t n) | ||
36 | { | ||
37 | int w; | ||
38 | |||
39 | w = 0; | ||
40 | while (n && *s) { | ||
41 | w += wcwidth(*s); | ||
42 | s++; | ||
43 | n--; | ||
44 | } | ||
45 | |||
46 | return w; | ||
47 | } | ||
diff --git a/src/lib/libc/string/wmemchr.3 b/src/lib/libc/string/wmemchr.3 new file mode 100644 index 0000000000..395488829d --- /dev/null +++ b/src/lib/libc/string/wmemchr.3 | |||
@@ -0,0 +1,141 @@ | |||
1 | .\" $OpenBSD: wmemchr.3,v 1.3 2007/05/31 19:19:32 jmc Exp $ | ||
2 | .\" | ||
3 | .\" $NetBSD: wmemchr.3,v 1.9 2003/09/08 17:54:33 wiz Exp $ | ||
4 | .\" | ||
5 | .\" Copyright (c) 1990, 1991, 1993 | ||
6 | .\" The Regents of the University of California. All rights reserved. | ||
7 | .\" | ||
8 | .\" This code is derived from software contributed to Berkeley by | ||
9 | .\" Chris Torek and the American National Standards Committee X3, | ||
10 | .\" on Information Processing Systems. | ||
11 | .\" | ||
12 | .\" Redistribution and use in source and binary forms, with or without | ||
13 | .\" modification, are permitted provided that the following conditions | ||
14 | .\" are met: | ||
15 | .\" 1. Redistributions of source code must retain the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer. | ||
17 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
18 | .\" notice, this list of conditions and the following disclaimer in the | ||
19 | .\" documentation and/or other materials provided with the distribution. | ||
20 | .\" 3. 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 8.1 (Berkeley) 6/4/93 | ||
37 | .\" | ||
38 | .Dd $Mdocdate: May 31 2007 $ | ||
39 | .Dt WMEMCHR 3 | ||
40 | .Os | ||
41 | .Sh NAME | ||
42 | .Nm wmemchr , | ||
43 | .Nm wmemcmp , | ||
44 | .Nm wmemcpy , | ||
45 | .Nm wmemmove , | ||
46 | .Nm wmemset , | ||
47 | .Nm wcscat , | ||
48 | .Nm wcschr , | ||
49 | .Nm wcscmp , | ||
50 | .Nm wcscpy , | ||
51 | .Nm wcscspn , | ||
52 | .Nm wcslcat , | ||
53 | .Nm wcslcpy , | ||
54 | .Nm wcslen , | ||
55 | .Nm wcsncat , | ||
56 | .Nm wcsncmp , | ||
57 | .Nm wcsncpy , | ||
58 | .Nm wcspbrk , | ||
59 | .Nm wcsrchr , | ||
60 | .Nm wcsspn , | ||
61 | .Nm wcsstr | ||
62 | .Nd wide character string manipulation operations | ||
63 | .Sh SYNOPSIS | ||
64 | .In wchar.h | ||
65 | .Ft wchar_t * | ||
66 | .Fn wmemchr "const wchar_t *s" "wchar_t c" "size_t n" | ||
67 | .Ft int | ||
68 | .Fn wmemcmp "const wchar_t *s1" "const wchar_t *s2" "size_t n" | ||
69 | .Ft wchar_t * | ||
70 | .Fn wmemcpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" | ||
71 | .Ft wchar_t * | ||
72 | .Fn wmemmove "wchar_t *s1" "const wchar_t *s2" "size_t n" | ||
73 | .Ft wchar_t * | ||
74 | .Fn wmemset "wchar_t *s" "wchar_t c" "size_t n" | ||
75 | .Ft wchar_t * | ||
76 | .Fn wcscat "wchar_t * restrict s1" "const wchar_t * restrict s2" | ||
77 | .Ft wchar_t * | ||
78 | .Fn wcschr "const wchar_t *s" "wchar_t c" | ||
79 | .Ft int | ||
80 | .Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" | ||
81 | .Ft wchar_t * | ||
82 | .Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2" | ||
83 | .Ft size_t | ||
84 | .Fn wcscspn "const wchar_t *s1" "const wchar_t *s2" | ||
85 | .Ft size_t | ||
86 | .Fn wcslcat "wchar_t *s1" "const wchar_t *s2" "size_t n" | ||
87 | .Ft size_t | ||
88 | .Fn wcslcpy "wchar_t *s1" "const wchar_t *s2" "size_t n" | ||
89 | .Ft size_t | ||
90 | .Fn wcslen "const wchar_t *s" | ||
91 | .Ft wchar_t * | ||
92 | .Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" | ||
93 | .Ft int | ||
94 | .Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" | ||
95 | .Ft wchar_t * | ||
96 | .Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" | ||
97 | .Ft wchar_t * | ||
98 | .Fn wcspbrk "const wchar_t *s1" "const wchar_t *s2" | ||
99 | .Ft wchar_t * | ||
100 | .Fn wcsrchr "const wchar_t *s" "wchar_t c" | ||
101 | .Ft size_t | ||
102 | .Fn wcsspn "const wchar_t *s1" "const wchar_t *s2" | ||
103 | .Ft wchar_t * | ||
104 | .Fn wcsstr "const wchar_t *s1" "const wchar_t *s2" | ||
105 | .Sh DESCRIPTION | ||
106 | These functions implement string manipulation operations over wide character | ||
107 | strings. | ||
108 | For a detailed description, refer to documents for the respective single-byte | ||
109 | counterpart, such as | ||
110 | .Xr memchr 3 . | ||
111 | .Sh SEE ALSO | ||
112 | .Xr memchr 3 , | ||
113 | .Xr memcmp 3 , | ||
114 | .Xr memcpy 3 , | ||
115 | .Xr memmove 3 , | ||
116 | .Xr memset 3 , | ||
117 | .Xr strcat 3 , | ||
118 | .Xr strchr 3 , | ||
119 | .Xr strcmp 3 , | ||
120 | .Xr strcpy 3 , | ||
121 | .Xr strcspn 3 , | ||
122 | .Xr strlcat 3 , | ||
123 | .Xr strlcpy 3 , | ||
124 | .Xr strlen 3 , | ||
125 | .Xr strncat 3 , | ||
126 | .Xr strncmp 3 , | ||
127 | .Xr strncpy 3 , | ||
128 | .Xr strpbrk 3 , | ||
129 | .Xr strrchr 3 , | ||
130 | .Xr strspn 3 , | ||
131 | .Xr strstr 3 | ||
132 | .Sh STANDARDS | ||
133 | These functions conform to | ||
134 | .St -isoC-99 | ||
135 | and were first introduced in | ||
136 | .St -isoC-amd1 , | ||
137 | with the exception of | ||
138 | .Fn wcslcat | ||
139 | and | ||
140 | .Fn wcslcpy , | ||
141 | which are extensions. | ||
diff --git a/src/lib/libc/string/wmemchr.c b/src/lib/libc/string/wmemchr.c new file mode 100644 index 0000000000..8c9517861b --- /dev/null +++ b/src/lib/libc/string/wmemchr.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* $OpenBSD: wmemchr.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wmemchr.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wmemchr(const wchar_t *s, wchar_t c, size_t n) | ||
36 | { | ||
37 | size_t i; | ||
38 | |||
39 | for (i = 0; i < n; i++) { | ||
40 | if (*s == c) { | ||
41 | /* LINTED const castaway */ | ||
42 | return (wchar_t *)s; | ||
43 | } | ||
44 | s++; | ||
45 | } | ||
46 | return NULL; | ||
47 | } | ||
diff --git a/src/lib/libc/string/wmemcmp.c b/src/lib/libc/string/wmemcmp.c new file mode 100644 index 0000000000..39419aeddc --- /dev/null +++ b/src/lib/libc/string/wmemcmp.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: wmemcmp.c,v 1.4 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | #include "locale/runetype.h" | ||
34 | |||
35 | int | ||
36 | wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) | ||
37 | { | ||
38 | size_t i; | ||
39 | |||
40 | for (i = 0; i < n; i++) { | ||
41 | if (*s1 != *s2) { | ||
42 | /* wchar might be unsigned */ | ||
43 | return *(const rune_t *)s1 > | ||
44 | *(const rune_t *)s2 ? 1 : -1; | ||
45 | } | ||
46 | s1++; | ||
47 | s2++; | ||
48 | } | ||
49 | return 0; | ||
50 | } | ||
diff --git a/src/lib/libc/string/wmemcpy.c b/src/lib/libc/string/wmemcpy.c new file mode 100644 index 0000000000..9bbd83648e --- /dev/null +++ b/src/lib/libc/string/wmemcpy.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* $OpenBSD: wmemcpy.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <string.h> | ||
33 | #include <wchar.h> | ||
34 | |||
35 | wchar_t * | ||
36 | wmemcpy(wchar_t *d, const wchar_t *s, size_t n) | ||
37 | { | ||
38 | |||
39 | return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); | ||
40 | } | ||
diff --git a/src/lib/libc/string/wmemmove.c b/src/lib/libc/string/wmemmove.c new file mode 100644 index 0000000000..21bbabcd0c --- /dev/null +++ b/src/lib/libc/string/wmemmove.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* $OpenBSD: wmemmove.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wmemmove.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <string.h> | ||
33 | #include <wchar.h> | ||
34 | |||
35 | wchar_t * | ||
36 | wmemmove(wchar_t *d, const wchar_t *s, size_t n) | ||
37 | { | ||
38 | |||
39 | return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); | ||
40 | } | ||
diff --git a/src/lib/libc/string/wmemset.c b/src/lib/libc/string/wmemset.c new file mode 100644 index 0000000000..ac476dba6a --- /dev/null +++ b/src/lib/libc/string/wmemset.c | |||
@@ -0,0 +1,46 @@ | |||
1 | /* $OpenBSD: wmemset.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /* $NetBSD: wmemset.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c)1999 Citrus Project, | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | * | ||
29 | * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp | ||
30 | */ | ||
31 | |||
32 | #include <wchar.h> | ||
33 | |||
34 | wchar_t * | ||
35 | wmemset(wchar_t *s, wchar_t c, size_t n) | ||
36 | { | ||
37 | size_t i; | ||
38 | wchar_t *p; | ||
39 | |||
40 | p = s; | ||
41 | for (i = 0; i < n; i++) { | ||
42 | *p = c; | ||
43 | p++; | ||
44 | } | ||
45 | return s; | ||
46 | } | ||