diff options
Diffstat (limited to 'src/lib/libc/string')
126 files changed, 5382 insertions, 2077 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 2b7ce63a63..6b78a4d007 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -1,36 +1,46 @@ | |||
1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 | 1 | # $OpenBSD: Makefile.inc,v 1.29 2012/08/02 13:38:38 okan 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_CPU}/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 stpcpy.c stpncpy.c \ |
8 | strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strcasecmp.c strcasestr.c strcoll.c strdup.c \ |
9 | __strerror.c __strsignal.c | 8 | strerror.c strerror_r.c strlcat.c strmode.c strndup.c strnlen.c \ |
9 | strsignal.c strtok.c strxfrm.c \ | ||
10 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ | ||
11 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ | ||
12 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ | ||
13 | wmemmove.c wmemset.c wcsdup.c \ | ||
14 | timingsafe_bcmp.c wcscasecmp.c | ||
10 | 15 | ||
11 | # machine-dependent net sources | 16 | # machine-dependent net sources |
12 | # m-d Makefile.inc must include sources for: | 17 | # m-d Makefile.inc must include sources for: |
13 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() | 18 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() |
14 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() | 19 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() strlcpy() |
15 | # strncat() strncmp() strncpy() strpbrk() strsep() | 20 | # strncat() strncmp() strncpy() strpbrk() strsep() |
16 | # strspn() strstr() swav() | 21 | # strspn() strstr() swav() |
17 | # m-d Makefile.inc may include sources for: | 22 | # m-d Makefile.inc may include sources for: |
18 | # memcpy() memmove() strchr() strrchr() | 23 | # memcpy() memmove() strchr() strrchr() |
19 | 24 | ||
20 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" | 25 | .include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/string/Makefile.inc" |
21 | 26 | ||
22 | # if no machine specific memmove(3), build one out of bcopy(3). | 27 | # if no machine specific memmove(3), build one out of bcopy(3). |
23 | .if empty(SRCS:Mmemmove.S) | 28 | .if empty(SRCS:Mmemmove.S) |
24 | OBJS+= memmove.o | 29 | OBJS+= memmove.o |
25 | memmove.o: bcopy.c | 30 | memmove.o: bcopy.c |
26 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 31 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
27 | @${LD} -x -r ${.TARGET} | 32 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
28 | @mv a.out ${.TARGET} | 33 | @mv ${.TARGET}.tmp ${.TARGET} |
34 | |||
35 | memmove.go: bcopy.c | ||
36 | ${CC} -g -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
37 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
38 | @mv ${.TARGET}.tmp ${.TARGET} | ||
29 | 39 | ||
30 | memmove.po: bcopy.c | 40 | memmove.po: bcopy.c |
31 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 41 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
32 | @${LD} -X -r ${.TARGET} | 42 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
33 | @mv a.out ${.TARGET} | 43 | @mv ${.TARGET}.tmp ${.TARGET} |
34 | 44 | ||
35 | memmove.so: bcopy.c | 45 | memmove.so: bcopy.c |
36 | ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 46 | ${CC} ${PICFLAG} -DPIC -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -45,13 +55,18 @@ memmove.so: bcopy.c | |||
45 | OBJS+= memcpy.o | 55 | OBJS+= memcpy.o |
46 | memcpy.o: bcopy.c | 56 | memcpy.o: bcopy.c |
47 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 57 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
48 | @${LD} -x -r ${.TARGET} | 58 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
49 | @mv a.out ${.TARGET} | 59 | @mv ${.TARGET}.tmp ${.TARGET} |
60 | |||
61 | memcpy.go: bcopy.c | ||
62 | ${CC} -g -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
63 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
64 | @mv ${.TARGET}.tmp ${.TARGET} | ||
50 | 65 | ||
51 | memcpy.po: bcopy.c | 66 | memcpy.po: bcopy.c |
52 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 67 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
53 | @${LD} -X -r ${.TARGET} | 68 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
54 | @mv a.out ${.TARGET} | 69 | @mv ${.TARGET}.tmp ${.TARGET} |
55 | 70 | ||
56 | memcpy.so: bcopy.c | 71 | memcpy.so: bcopy.c |
57 | ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 72 | ${CC} ${PICFLAG} -DPIC -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -64,13 +79,18 @@ memcpy.so: bcopy.c | |||
64 | OBJS+= strchr.o | 79 | OBJS+= strchr.o |
65 | strchr.o: index.c | 80 | strchr.o: index.c |
66 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 81 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
67 | @${LD} -x -r ${.TARGET} | 82 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
68 | @mv a.out ${.TARGET} | 83 | @mv ${.TARGET}.tmp ${.TARGET} |
84 | |||
85 | strchr.go: index.c | ||
86 | ${CC} -g -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
87 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
88 | @mv ${.TARGET}.tmp ${.TARGET} | ||
69 | 89 | ||
70 | strchr.po: index.c | 90 | strchr.po: index.c |
71 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 91 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
72 | @${LD} -X -r ${.TARGET} | 92 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
73 | @mv a.out ${.TARGET} | 93 | @mv ${.TARGET}.tmp ${.TARGET} |
74 | 94 | ||
75 | strchr.so: index.c | 95 | strchr.so: index.c |
76 | ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 96 | ${CC} ${PICFLAG} -DPIC -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
@@ -82,27 +102,51 @@ strchr.so: index.c | |||
82 | OBJS+= strrchr.o | 102 | OBJS+= strrchr.o |
83 | strrchr.o: rindex.c | 103 | strrchr.o: rindex.c |
84 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | 104 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} |
85 | @${LD} -x -r ${.TARGET} | 105 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} |
86 | @mv a.out ${.TARGET} | 106 | @mv ${.TARGET}.tmp ${.TARGET} |
107 | |||
108 | strrchr.go: rindex.c | ||
109 | ${CC} -g -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
110 | @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} | ||
111 | @mv ${.TARGET}.tmp ${.TARGET} | ||
87 | 112 | ||
88 | strrchr.po: rindex.c | 113 | strrchr.po: rindex.c |
89 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 114 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
90 | @${LD} -X -r ${.TARGET} | 115 | @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} |
91 | @mv a.out ${.TARGET} | 116 | @mv ${.TARGET}.tmp ${.TARGET} |
92 | 117 | ||
93 | strrchr.so: rindex.c | 118 | strrchr.so: rindex.c |
94 | ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ | 119 | ${CC} ${PICFLAG} -DPIC -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} \ |
95 | -o ${.TARGET} | 120 | -o ${.TARGET} |
96 | .endif | 121 | .endif |
97 | 122 | ||
98 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ | 123 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 memccpy.3 memchr.3 \ |
99 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ | 124 | memcmp.3 memcpy.3 memmove.3 memset.3 stpcpy.3 strcasecmp.3 strcat.3 \ |
100 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 strftime.3 \ | 125 | 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 \ | 126 | 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 | 127 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 \ |
128 | wcscasecmp.3 wcscat.3 wcschr.3 wcscmp.3 wcscpy.3 wcscspn.3 wcsdup.3 \ | ||
129 | wcslcpy.3 wcslen.3 wcspbrk.3 wcsrchr.3 wcsspn.3 wcsstr.3 wcstok.3 \ | ||
130 | wcswidth.3 wmemchr.3 wmemcmp.3 wmemcpy.3 wmemmove.3 wmemset.3 | ||
103 | 131 | ||
104 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | 132 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 |
133 | MLINKS+=memchr.3 memrchr.3 | ||
134 | MLINKS+=stpcpy.3 stpncpy.3 | ||
135 | MLINKS+=strchr.3 index.3 | ||
136 | MLINKS+=strrchr.3 rindex.3 | ||
105 | MLINKS+=strcasecmp.3 strncasecmp.3 | 137 | MLINKS+=strcasecmp.3 strncasecmp.3 |
106 | MLINKS+=strcat.3 strncat.3 | 138 | MLINKS+=strcat.3 strncat.3 |
107 | MLINKS+=strcmp.3 strncmp.3 | 139 | MLINKS+=strcmp.3 strncmp.3 |
108 | MLINKS+=strcpy.3 strncpy.3 | 140 | MLINKS+=strcpy.3 strncpy.3 |
141 | MLINKS+=strdup.3 strndup.3 | ||
142 | MLINKS+=strlcpy.3 strlcat.3 | ||
143 | MLINKS+=strlen.3 strnlen.3 | ||
144 | MLINKS+=strstr.3 strcasestr.3 | ||
145 | MLINKS+=strtok.3 strtok_r.3 | ||
146 | MLINKS+=strerror.3 strerror_r.3 | ||
147 | MLINKS+=wcscasecmp.3 wcsncasecmp.3 | ||
148 | MLINKS+=wcscat.3 wcsncat.3 | ||
149 | MLINKS+=wcscmp.3 wcsncmp.3 | ||
150 | MLINKS+=wcscpy.3 wcsncpy.3 | ||
151 | MLINKS+=wcslcpy.3 wcslcat.3 | ||
152 | MLINKS+=bcmp.3 timingsafe_bcmp.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..1660b4356b 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,24 +27,25 @@ | |||
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.9 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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 , |
37 | .Nm timingsafe_bcmp | ||
42 | .Nd compare byte string | 38 | .Nd compare byte string |
43 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
44 | .Fd #include <string.h> | 40 | .Fd #include <string.h> |
45 | .Ft int | 41 | .Ft int |
46 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" | 42 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" |
43 | .Ft int | ||
44 | .Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len" | ||
47 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
48 | The | 46 | The |
49 | .Fn bcmp | 47 | .Fn bcmp |
50 | function | 48 | function compares byte string |
51 | compares byte string | ||
52 | .Fa b1 | 49 | .Fa b1 |
53 | against byte string | 50 | against byte string |
54 | .Fa b2 , | 51 | .Fa b2 , |
@@ -59,6 +56,20 @@ bytes long. | |||
59 | Zero-length strings are always identical. | 56 | Zero-length strings are always identical. |
60 | .Pp | 57 | .Pp |
61 | The strings may overlap. | 58 | The strings may overlap. |
59 | .Pp | ||
60 | The | ||
61 | .Fn timingsafe_bcmp | ||
62 | function has the same semantics as | ||
63 | .Fn bcmp , | ||
64 | but its running time is independent of the contents of | ||
65 | .Fa b1 | ||
66 | and | ||
67 | .Fa b2 , | ||
68 | making it safe to use for comparing secret values such as cryptographic MACs. | ||
69 | In contrast, | ||
70 | .Fn bcmp | ||
71 | returns after finding the first differing byte, | ||
72 | making it vulnerable to timing attacks. | ||
62 | .Sh SEE ALSO | 73 | .Sh SEE ALSO |
63 | .Xr memcmp 3 , | 74 | .Xr memcmp 3 , |
64 | .Xr strcasecmp 3 , | 75 | .Xr strcasecmp 3 , |
@@ -66,7 +77,12 @@ The strings may overlap. | |||
66 | .Xr strcoll 3 , | 77 | .Xr strcoll 3 , |
67 | .Xr strxfrm 3 | 78 | .Xr strxfrm 3 |
68 | .Sh HISTORY | 79 | .Sh HISTORY |
69 | A | 80 | The |
70 | .Fn bcmp | 81 | .Fn bcmp |
71 | function first appeared in | 82 | function first appeared in |
72 | .Bx 4.2 . | 83 | .Bx 4.2 . |
84 | .Pp | ||
85 | The | ||
86 | .Fn timingsafe_bcmp | ||
87 | function first appeared in | ||
88 | .Ox 4.9 . | ||
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..3beaf09aca 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.10 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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 | The |
70 | .Fn bcopy | 65 | .Fn bcopy |
71 | function appeared in | 66 | function first 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..6c74848ecc 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,93 @@ | |||
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.10 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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 | ||
113 | .Sh HISTORY | ||
114 | The | ||
115 | .Fn bm_comp , | ||
116 | .Fn bm_exec , | ||
117 | and | ||
118 | .Fn bm_free | ||
119 | functions first appeared in | ||
120 | .Nx 1.0 . | ||
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..c44c5386c6 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.9 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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,25 @@ 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 | ||
102 | and | ||
103 | .Fn memccpy | ||
104 | appeared in | ||
105 | .Bx 4.3 ; | ||
106 | the functions | ||
107 | .Fn bcmp , | 88 | .Fn bcmp , |
108 | .Fn bcopy , | 89 | .Fn bcopy , |
109 | appeared in | 90 | and |
91 | .Fn bzero | ||
92 | functions first appeared in | ||
110 | .Bx 4.2 . | 93 | .Bx 4.2 . |
94 | The | ||
95 | .Fn memchr , | ||
96 | .Fn memcmp , | ||
97 | .Fn memccpy , | ||
98 | .Fn memcpy , | ||
99 | and | ||
100 | .Fn memset | ||
101 | functions first appeared in | ||
102 | .At V | ||
103 | and were reimplemented for | ||
104 | .Bx 4.3 Tahoe . | ||
105 | The | ||
106 | .Fn memmove | ||
107 | function first appeared in | ||
108 | .Bx 4.3 Reno . | ||
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3 index 4f0141e051..c79470377f 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.8 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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 . |
@@ -61,8 +55,7 @@ does nothing. | |||
61 | .Xr memset 3 , | 55 | .Xr memset 3 , |
62 | .Xr swab 3 | 56 | .Xr swab 3 |
63 | .Sh HISTORY | 57 | .Sh HISTORY |
64 | A | 58 | The |
65 | .Fn bzero | 59 | .Fn bzero |
66 | function | 60 | function first appeared in |
67 | appeared in | 61 | .Bx 4.2 . |
68 | .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..eea0994cb1 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.8 2012/01/14 13:31: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: January 14 2012 $ |
38 | .Dt FFS 3 | 33 | .Dt FFS 3 |
39 | .Os | 34 | .Os |
40 | .Sh NAME | 35 | .Sh NAME |
@@ -47,17 +42,20 @@ | |||
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 |
52 | .Sh STANDARDS | ||
53 | The | ||
54 | .Fn ffs | ||
55 | function conforms to | ||
56 | .St -p1003.1-2008 . | ||
59 | .Sh HISTORY | 57 | .Sh HISTORY |
60 | The | 58 | The |
61 | .Fn ffs | 59 | .Fn ffs |
62 | function appeared in | 60 | function first appeared in |
63 | .Bx 4.3 . | 61 | .Bx 4.2 . |
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.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..f8f880e3b1 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.10 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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,17 @@ 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 | .At V |
74 | and was reimplemented for | ||
75 | .Bx 4.3 Tahoe . | ||
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..56a4e4780e 100644 --- a/src/lib/libc/string/memchr.3 +++ b/src/lib/libc/string/memchr.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: memchr.3,v 1.10 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCHR 3 | 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 , |
@@ -73,10 +79,23 @@ bytes. | |||
73 | .Xr strsep 3 , | 79 | .Xr strsep 3 , |
74 | .Xr strspn 3 , | 80 | .Xr strspn 3 , |
75 | .Xr strstr 3 , | 81 | .Xr strstr 3 , |
76 | .Xr strtok 3 | 82 | .Xr strtok 3 , |
83 | .Xr wmemchr 3 | ||
77 | .Sh STANDARDS | 84 | .Sh STANDARDS |
78 | The | 85 | The |
79 | .Fn memchr | 86 | .Fn memchr |
80 | function | 87 | function conforms to |
81 | conforms to | ||
82 | .St -ansiC . | 88 | .St -ansiC . |
89 | .Pp | ||
90 | The | ||
91 | .Fn memrchr | ||
92 | function is an | ||
93 | .Ox | ||
94 | extension. | ||
95 | .Sh HISTORY | ||
96 | The | ||
97 | .Fn memchr | ||
98 | function first appeared in | ||
99 | .At V | ||
100 | and was reimplemented for | ||
101 | .Bx 4.3 Tahoe . | ||
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..951a04ed8a 100644 --- a/src/lib/libc/string/memcmp.3 +++ b/src/lib/libc/string/memcmp.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: memcmp.3,v 1.7 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCMP 3 | 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 , |
@@ -74,10 +69,17 @@ Zero-length strings are always identical. | |||
74 | .Xr strcasecmp 3 , | 69 | .Xr strcasecmp 3 , |
75 | .Xr strcmp 3 , | 70 | .Xr strcmp 3 , |
76 | .Xr strcoll 3 , | 71 | .Xr strcoll 3 , |
77 | .Xr strxfrm 3 | 72 | .Xr strxfrm 3 , |
73 | .Xr wmemcmp 3 | ||
78 | .Sh STANDARDS | 74 | .Sh STANDARDS |
79 | The | 75 | The |
80 | .Fn memcmp | 76 | .Fn memcmp |
81 | function | 77 | function conforms to |
82 | conforms to | ||
83 | .St -ansiC . | 78 | .St -ansiC . |
79 | .Sh HISTORY | ||
80 | The | ||
81 | .Fn memcmp | ||
82 | function first appeared in | ||
83 | .At V | ||
84 | and was reimplemented for | ||
85 | .Bx 4.3 Tahoe . | ||
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..e95d670ad9 100644 --- a/src/lib/libc/string/memcpy.3 +++ b/src/lib/libc/string/memcpy.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: memcpy.3,v 1.8 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,15 +31,12 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMCPY 3 | 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,42 @@ | |||
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 , | ||
64 | .Xr wmemcpy 3 | ||
70 | .Sh STANDARDS | 65 | .Sh STANDARDS |
71 | The | 66 | The |
72 | .Fn memcpy | 67 | .Fn memcpy |
73 | function | 68 | function conforms to |
74 | conforms to | ||
75 | .St -ansiC . | 69 | .St -ansiC . |
76 | .Sh BUGS | 70 | .Sh HISTORY |
71 | The | ||
72 | .Fn memcpy | ||
73 | function first appeared in | ||
74 | .At V | ||
75 | and was reimplemented for | ||
76 | .Bx 4.3 Tahoe . | ||
77 | .Sh CAVEATS | ||
77 | In this implementation | 78 | In this implementation |
78 | .Fn memcpy | 79 | .Fn memcpy |
79 | is implemented using | 80 | is implemented using |
80 | .Xr bcopy 3 , | 81 | .Xr bcopy 3 , |
81 | and therefore the strings may overlap. | 82 | and therefore the buffers may overlap. |
82 | On other systems, copying overlapping strings may produce surprises. | 83 | On other systems, copying overlapping buffers may produce surprises. |
83 | A simpler solution is to not use | 84 | A portable, safe solution is to use |
84 | .Fn memcpy . | 85 | .Xr memmove 3 . |
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 index 24422e7971..ae8569a1c7 100644 --- a/src/lib/libc/string/memmove.3 +++ b/src/lib/libc/string/memmove.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: memmove.3,v 1.8 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,15 +31,12 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMMOVE 3 | 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,16 @@ 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 , | ||
66 | .Xr wmemmove 3 | ||
71 | .Sh STANDARDS | 67 | .Sh STANDARDS |
72 | The | 68 | The |
73 | .Fn memmove | 69 | .Fn memmove |
74 | function | 70 | function conforms to |
75 | conforms to | ||
76 | .St -ansiC . | 71 | .St -ansiC . |
72 | .Sh HISTORY | ||
73 | The | ||
74 | .Fn memmove | ||
75 | function first appeared in | ||
76 | .Bx 4.3 Reno . | ||
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..db94cb9ba6 100644 --- a/src/lib/libc/string/memset.3 +++ b/src/lib/libc/string/memset.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: memset.3,v 1.7 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt MEMSET 3 | 35 | .Dt MEMSET 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,19 +44,32 @@ | |||
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 , |
61 | .Xr swab 3 | 62 | .Xr swab 3 , |
63 | .Xr wmemset 3 | ||
62 | .Sh STANDARDS | 64 | .Sh STANDARDS |
63 | The | 65 | The |
64 | .Fn memset | 66 | .Fn memset |
65 | function | 67 | function conforms to |
66 | conforms to | ||
67 | .St -ansiC . | 68 | .St -ansiC . |
69 | .Sh HISTORY | ||
70 | The | ||
71 | .Fn memset | ||
72 | function first appeared in | ||
73 | .At V | ||
74 | and was reimplemented for | ||
75 | .Bx 4.3 Tahoe . | ||
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.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/stpcpy.3 b/src/lib/libc/string/stpcpy.3 new file mode 100644 index 0000000000..447bfc20a9 --- /dev/null +++ b/src/lib/libc/string/stpcpy.3 | |||
@@ -0,0 +1,117 @@ | |||
1 | .\" $OpenBSD: stpcpy.3,v 1.2 2012/01/17 08:12:12 jmc Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: January 17 2012 $ | ||
35 | .Dt STPCPY 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm stpcpy , | ||
39 | .Nm stpncpy | ||
40 | .Nd copy strings | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <string.h> | ||
43 | .Ft char * | ||
44 | .Fn stpcpy "char *dst" "const char *src" | ||
45 | .Ft char * | ||
46 | .Fn stpncpy "char *dst" "const char *src" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn stpcpy | ||
50 | and | ||
51 | .Fn stpncpy | ||
52 | functions copy the string | ||
53 | .Fa src | ||
54 | to | ||
55 | .Fa dst | ||
56 | (including the terminating | ||
57 | .Ql \e0 | ||
58 | character). | ||
59 | .Pp | ||
60 | The | ||
61 | .Fn stpncpy | ||
62 | function copies not more than | ||
63 | .Fa len | ||
64 | characters into | ||
65 | .Fa dst , | ||
66 | appending | ||
67 | .Ql \e0 | ||
68 | characters if | ||
69 | .Fa src | ||
70 | is less than | ||
71 | .Fa len | ||
72 | characters long, and | ||
73 | .Em not | ||
74 | terminating | ||
75 | .Fa dst | ||
76 | if the length of | ||
77 | .Fa src | ||
78 | is greater than or equal to | ||
79 | .Fa len . | ||
80 | .Sh RETURN VALUES | ||
81 | The | ||
82 | .Fn stpcpy | ||
83 | function returns a pointer to the terminating | ||
84 | .Ql \e0 | ||
85 | character written into | ||
86 | .Fa dst . | ||
87 | .Pp | ||
88 | The | ||
89 | .Fn stpncpy | ||
90 | function returns a pointer to the first | ||
91 | .Ql \e0 | ||
92 | character written into | ||
93 | .Fa dst , | ||
94 | or to | ||
95 | .Fa &dst[len] | ||
96 | if the length of | ||
97 | .Fa src | ||
98 | is greater than or equal to | ||
99 | .Fa len . | ||
100 | .Sh SEE ALSO | ||
101 | .Xr strcpy 3 , | ||
102 | .Xr strlcpy 3 , | ||
103 | .Xr strncpy 3 | ||
104 | .Sh STANDARDS | ||
105 | The | ||
106 | .Fn stpcpy | ||
107 | and | ||
108 | .Fn stpncpy | ||
109 | functions conform to | ||
110 | .St -p1003.1-2008 . | ||
111 | .Sh HISTORY | ||
112 | The | ||
113 | .Fn stpcpy | ||
114 | and | ||
115 | .Fn stpncpy | ||
116 | functions first appeared in | ||
117 | .Ox 5.1 . | ||
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/stpcpy.c index 1937e2d608..d3d61e0f14 100644 --- a/src/lib/libc/string/__strsignal.c +++ b/src/lib/libc/string/stpcpy.c | |||
@@ -1,3 +1,5 @@ | |||
1 | /* $OpenBSD: stpcpy.c,v 1.1 2012/01/17 02:48:01 guenther 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,56 +29,16 @@ | |||
31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
32 | */ | 30 | */ |
33 | 31 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #include <string.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 | 33 | ||
39 | #ifdef NLS | 34 | #if defined(APIWARN) |
40 | #define catclose _catclose | 35 | __warn_references(stpcpy, |
41 | #define catgets _catgets | 36 | "warning: stpcpy() is dangerous GNU crap; don't use it"); |
42 | #define catopen _catopen | ||
43 | #include <nl_types.h> | ||
44 | #endif | 37 | #endif |
45 | 38 | ||
46 | #define sys_siglist _sys_siglist | ||
47 | |||
48 | #include <stdio.h> | ||
49 | #include <signal.h> | ||
50 | #include <string.h> | ||
51 | |||
52 | char * | 39 | char * |
53 | __strsignal(num, buf) | 40 | stpcpy(char *to, const char *from) |
54 | int num; | ||
55 | char *buf; | ||
56 | { | 41 | { |
57 | #define UPREFIX "Unknown signal: %u" | 42 | for (; (*to = *from) != '\0'; ++from, ++to); |
58 | register unsigned int signum; | 43 | return(to); |
59 | |||
60 | #ifdef NLS | ||
61 | nl_catd catd ; | ||
62 | catd = catopen("libc", 0); | ||
63 | #endif | ||
64 | |||
65 | signum = num; /* convert to unsigned */ | ||
66 | if (signum < NSIG) { | ||
67 | #ifdef NLS | ||
68 | strcpy(buf, catgets(catd, 2, signum, | ||
69 | (char *)sys_siglist[signum])); | ||
70 | #else | ||
71 | return((char *)sys_siglist[signum]); | ||
72 | #endif | ||
73 | } else { | ||
74 | #ifdef NLS | ||
75 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); | ||
76 | #else | ||
77 | sprintf(buf, UPREFIX, signum); | ||
78 | #endif | ||
79 | } | ||
80 | |||
81 | #ifdef NLS | ||
82 | catclose(catd); | ||
83 | #endif | ||
84 | |||
85 | return buf; | ||
86 | } | 44 | } |
diff --git a/src/lib/libc/string/stpncpy.c b/src/lib/libc/string/stpncpy.c new file mode 100644 index 0000000000..c7c2a57c4c --- /dev/null +++ b/src/lib/libc/string/stpncpy.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* $OpenBSD: stpncpy.c,v 1.2 2012/07/11 10:44:59 naddy Exp $ */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1990 The Regents of the University of California. | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * This code is derived from software contributed to Berkeley by | ||
8 | * Chris Torek. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * 3. Neither the name of the University nor the names of its contributors | ||
19 | * may be used to endorse or promote products derived from this software | ||
20 | * without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | * SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <string.h> | ||
36 | |||
37 | char * | ||
38 | stpncpy(char *dst, const char *src, size_t n) | ||
39 | { | ||
40 | if (n != 0) { | ||
41 | char *d = dst; | ||
42 | const char *s = src; | ||
43 | |||
44 | dst = &dst[n]; | ||
45 | do { | ||
46 | if ((*d++ = *s++) == 0) { | ||
47 | dst = d - 1; | ||
48 | /* NUL pad the remaining n-1 bytes */ | ||
49 | while (--n != 0) | ||
50 | *d++ = 0; | ||
51 | break; | ||
52 | } | ||
53 | } while (--n != 0); | ||
54 | } | ||
55 | return (dst); | ||
56 | } | ||
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 index 46e9010e4f..0900c8a97a 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.11 2011/07/25 00:38:52 schwarze 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: July 25 2011 $ |
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 |
@@ -78,11 +74,19 @@ characters. | |||
78 | .Xr memcmp 3 , | 74 | .Xr memcmp 3 , |
79 | .Xr strcmp 3 , | 75 | .Xr strcmp 3 , |
80 | .Xr strcoll 3 , | 76 | .Xr strcoll 3 , |
81 | .Xr strxfrm 3 | 77 | .Xr strxfrm 3 , |
78 | .Xr wcscasecmp 3 | ||
79 | .Sh STANDARDS | ||
80 | The | ||
81 | .Fn strcasecmp | ||
82 | and | ||
83 | .Fn strncasecmp | ||
84 | functions conform to | ||
85 | .St -p1003.1-2008 . | ||
82 | .Sh HISTORY | 86 | .Sh HISTORY |
83 | The | 87 | The |
84 | .Fn strcasecmp | 88 | .Fn strcasecmp |
85 | and | 89 | and |
86 | .Fn strncasecmp | 90 | .Fn strncasecmp |
87 | functions are | 91 | functions first appeared in |
88 | .Ud . | 92 | .Bx 4.3 Tahoe . |
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/strcasestr.c b/src/lib/libc/string/strcasestr.c new file mode 100644 index 0000000000..aa74c0176d --- /dev/null +++ b/src/lib/libc/string/strcasestr.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* $OpenBSD: strcasestr.c,v 1.3 2006/03/31 05:34:55 deraadt Exp $ */ | ||
2 | /* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1990, 1993 | ||
6 | * The Regents of the University of California. All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to Berkeley by | ||
9 | * Chris Torek. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #include <ctype.h> | ||
37 | #include <string.h> | ||
38 | |||
39 | /* | ||
40 | * Find the first occurrence of find in s, ignore case. | ||
41 | */ | ||
42 | char * | ||
43 | strcasestr(const char *s, const char *find) | ||
44 | { | ||
45 | char c, sc; | ||
46 | size_t len; | ||
47 | |||
48 | if ((c = *find++) != 0) { | ||
49 | c = (char)tolower((unsigned char)c); | ||
50 | len = strlen(find); | ||
51 | do { | ||
52 | do { | ||
53 | if ((sc = *s++) == 0) | ||
54 | return (NULL); | ||
55 | } while ((char)tolower((unsigned char)sc) != c); | ||
56 | } while (strncasecmp(s, find, len) != 0); | ||
57 | s--; | ||
58 | } | ||
59 | return ((char *)s); | ||
60 | } | ||
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..81aae19a63 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strcat.3,v 1.13 2011/07/25 00:38:52 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,14 +31,12 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCAT 3 | 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,81 @@ 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 strlcpy 3 , | ||
126 | .Xr wcscat 3 , | ||
127 | .Xr wcslcpy 3 | ||
87 | .Sh STANDARDS | 128 | .Sh STANDARDS |
88 | The | 129 | The |
89 | .Fn strcat | 130 | .Fn strcat |
90 | and | 131 | and |
91 | .Fn strncat | 132 | .Fn strncat |
92 | functions | 133 | functions conform to |
93 | conform to | ||
94 | .St -ansiC . | 134 | .St -ansiC . |
135 | .Sh HISTORY | ||
136 | The | ||
137 | .Fn strcat | ||
138 | and | ||
139 | .Fn strncat | ||
140 | functions first appeared in | ||
141 | .At v7 . | ||
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..d3194dffab 100644 --- a/src/lib/libc/string/strchr.3 +++ b/src/lib/libc/string/strchr.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strchr.3,v 1.10 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,29 +31,27 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCHR 3 | 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,26 +59,56 @@ 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 , |
79 | .Xr strsep 3 , | 90 | .Xr strsep 3 , |
80 | .Xr strspn 3 , | 91 | .Xr strspn 3 , |
81 | .Xr strstr 3 , | 92 | .Xr strstr 3 , |
82 | .Xr strtok 3 | 93 | .Xr strtok 3 , |
94 | .Xr wcschr 3 | ||
83 | .Sh STANDARDS | 95 | .Sh STANDARDS |
84 | The | 96 | The |
85 | .Fn strchr | 97 | .Fn strchr |
86 | function | 98 | function conforms to |
87 | conforms to | ||
88 | .St -ansiC . | 99 | .St -ansiC . |
100 | .Pp | ||
101 | The | ||
102 | .Fn index | ||
103 | function is deprecated and shouldn't be used in new code. | ||
104 | .Sh HISTORY | ||
105 | The | ||
106 | .Fn index | ||
107 | function first appeared in | ||
108 | .At v7 . | ||
109 | The | ||
110 | .Fn strchr | ||
111 | function first appeared in | ||
112 | .At III | ||
113 | and was reimplemented for | ||
114 | .Bx 4.3 Tahoe . | ||
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 index fecaa85410..5b0794208a 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strcmp.3,v 1.12 2011/07/25 07:51:30 jmc Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,14 +31,12 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCMP 3 | 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,18 +49,22 @@ 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 . |
56 | The | ||
57 | .Fn strncmp | ||
58 | function compares at most | ||
59 | .Fa len | ||
60 | characters. | ||
61 | .Sh RETURN VALUES | 61 | .Sh RETURN VALUES |
62 | The | 62 | The |
63 | .Fn strcmp | 63 | .Fn strcmp |
64 | and | 64 | and |
65 | .Fn strncmp | 65 | .Fn strncmp |
66 | return an integer greater than, equal to, or less than 0, according | 66 | functions return an integer greater than, equal to, or less than 0, according |
67 | as the string | 67 | to whether the string |
68 | .Fa s1 | 68 | .Fa s1 |
69 | is greater than, equal to, or less than the string | 69 | is greater than, equal to, or less than the string |
70 | .Fa s2 . | 70 | .Fa s2 . |
@@ -72,23 +72,24 @@ The comparison is done using unsigned characters, so that | |||
72 | .Ql \e200 | 72 | .Ql \e200 |
73 | is greater than | 73 | is greater than |
74 | .Ql \e0 . | 74 | .Ql \e0 . |
75 | .Pp | ||
76 | The | ||
77 | .Fn strncmp | ||
78 | compares not more than | ||
79 | .Fa len | ||
80 | characters. | ||
81 | .Sh SEE ALSO | 75 | .Sh SEE ALSO |
82 | .Xr bcmp 3 , | 76 | .Xr bcmp 3 , |
83 | .Xr memcmp 3 , | 77 | .Xr memcmp 3 , |
84 | .Xr strcasecmp 3 , | 78 | .Xr strcasecmp 3 , |
85 | .Xr strcoll 3 , | 79 | .Xr strcoll 3 , |
86 | .Xr strxfrm 3 | 80 | .Xr strxfrm 3 , |
81 | .Xr wcscmp 3 | ||
87 | .Sh STANDARDS | 82 | .Sh STANDARDS |
88 | The | 83 | The |
89 | .Fn strcmp | 84 | .Fn strcmp |
90 | and | 85 | and |
91 | .Fn strncmp | 86 | .Fn strncmp |
92 | functions | 87 | functions conform to |
93 | conform to | ||
94 | .St -ansiC . | 88 | .St -ansiC . |
89 | .Sh HISTORY | ||
90 | The | ||
91 | .Fn strcmp | ||
92 | and | ||
93 | .Fn strncmp | ||
94 | functions first appeared in | ||
95 | .At v7 . | ||
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..72e398c44c 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.8 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ |
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,10 @@ 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 . |
69 | .Sh HISTORY | ||
70 | The | ||
71 | .Fn strcoll | ||
72 | function first appeared in | ||
73 | .Bx 4.3 Reno . | ||
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..400eeee622 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strcpy.3,v 1.16 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,14 +31,12 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCPY 3 | 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 |
@@ -64,7 +59,7 @@ character). | |||
64 | .Pp | 59 | .Pp |
65 | The | 60 | The |
66 | .Fn strncpy | 61 | .Fn strncpy |
67 | copies not more than | 62 | function copies not more than |
68 | .Fa len | 63 | .Fa len |
69 | characters into | 64 | characters into |
70 | .Fa dst , | 65 | .Fa dst , |
@@ -78,45 +73,90 @@ characters long, and | |||
78 | .Em not | 73 | .Em not |
79 | terminating | 74 | terminating |
80 | .Fa dst | 75 | .Fa dst |
81 | if | 76 | if the length of |
82 | .Fa src | 77 | .Fa src |
83 | is more than | 78 | is greater than or equal to |
84 | .Fa len | 79 | .Fa len . |
85 | characters long. | ||
86 | .Sh RETURN VALUES | 80 | .Sh RETURN VALUES |
87 | The | 81 | The |
88 | .Fn strcpy | 82 | .Fn strcpy |
89 | and | 83 | and |
90 | .Fn strncpy | 84 | .Fn strncpy |
91 | functions | 85 | functions return |
92 | return | ||
93 | .Fa dst . | 86 | .Fa dst . |
94 | .Sh EXAMPLES | 87 | .Sh EXAMPLES |
95 | The following sets | 88 | The following sets |
96 | .Dq Li chararray | 89 | .Va chararray |
97 | to | 90 | to |
98 | .Dq Li abc\e0\e0\e0 : | 91 | .Dq abc\e0\e0\e0 : |
99 | .Bd -literal -offset indent | 92 | .Bd -literal -offset indent |
100 | (void)strncpy(chararray, "abc", 6). | 93 | (void)strncpy(chararray, "abc", 6); |
101 | .Ed | 94 | .Ed |
102 | .Pp | 95 | .Pp |
103 | The following sets | 96 | The following sets |
104 | .Dq Li chararray | 97 | .Va chararray |
105 | to | 98 | to |
106 | .Dq Li abcdef : | 99 | .Dq abcdef |
100 | and does | ||
101 | .Em not | ||
102 | NUL terminate | ||
103 | .Va chararray | ||
104 | because the length of the source string is greater than or equal to the | ||
105 | length parameter. | ||
106 | .Fn strncpy | ||
107 | .Em only | ||
108 | NUL terminates the destination string when the length of the source | ||
109 | string is less than the length parameter. | ||
107 | .Bd -literal -offset indent | 110 | .Bd -literal -offset indent |
108 | (void)strncpy(chararray, "abcdefgh", 6); | 111 | (void)strncpy(chararray, "abcdefgh", 6); |
109 | .Ed | 112 | .Ed |
113 | .Pp | ||
114 | The following copies as many characters from | ||
115 | .Va input | ||
116 | to | ||
117 | .Va buf | ||
118 | as will fit and NUL terminates the result. | ||
119 | Because | ||
120 | .Fn strncpy | ||
121 | does | ||
122 | .Em not | ||
123 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
124 | .Bd -literal -offset indent | ||
125 | char buf[BUFSIZ]; | ||
126 | |||
127 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
128 | buf[sizeof(buf) - 1] = '\e0'; | ||
129 | .Ed | ||
130 | .Pp | ||
131 | Note that | ||
132 | .Xr strlcpy 3 | ||
133 | is a better choice for this kind of operation. | ||
134 | The equivalent using | ||
135 | .Xr strlcpy 3 | ||
136 | is simply: | ||
137 | .Bd -literal -offset indent | ||
138 | (void)strlcpy(buf, input, sizeof(buf)); | ||
139 | .Ed | ||
110 | .Sh SEE ALSO | 140 | .Sh SEE ALSO |
111 | .Xr bcopy 3 , | 141 | .Xr bcopy 3 , |
112 | .Xr memccpy 3 , | 142 | .Xr memccpy 3 , |
113 | .Xr memcpy 3 , | 143 | .Xr memcpy 3 , |
114 | .Xr memmove 3 | 144 | .Xr memmove 3 , |
145 | .Xr strcat 3 , | ||
146 | .Xr strlcpy 3 , | ||
147 | .Xr wcscpy 3 , | ||
148 | .Xr wcslcpy 3 | ||
115 | .Sh STANDARDS | 149 | .Sh STANDARDS |
116 | The | 150 | The |
117 | .Fn strcpy | 151 | .Fn strcpy |
118 | and | 152 | and |
119 | .Fn strncpy | 153 | .Fn strncpy |
120 | functions | 154 | functions conform to |
121 | conform to | ||
122 | .St -ansiC . | 155 | .St -ansiC . |
156 | .Sh HISTORY | ||
157 | The | ||
158 | .Fn strcpy | ||
159 | and | ||
160 | .Fn strncpy | ||
161 | functions first appeared in | ||
162 | .At v7 . | ||
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..70c8ef7612 100644 --- a/src/lib/libc/string/strcspn.3 +++ b/src/lib/libc/string/strcspn.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strcspn.3,v 1.10 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRCSPN 3 | 35 | .Dt STRCSPN 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -49,37 +44,65 @@ | |||
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 , |
76 | .Xr strsep 3 , | 92 | .Xr strsep 3 , |
77 | .Xr strspn 3 , | 93 | .Xr strspn 3 , |
78 | .Xr strstr 3 , | 94 | .Xr strstr 3 , |
79 | .Xr strtok 3 | 95 | .Xr strtok 3 , |
96 | .Xr wcscspn 3 | ||
80 | .Sh STANDARDS | 97 | .Sh STANDARDS |
81 | The | 98 | The |
82 | .Fn strcspn | 99 | .Fn strcspn |
83 | function | 100 | function conforms to |
84 | conforms to | ||
85 | .St -ansiC . | 101 | .St -ansiC . |
102 | .Sh HISTORY | ||
103 | The | ||
104 | .Fn strcspn | ||
105 | function first appeared in | ||
106 | .At III | ||
107 | and was reimplemented for | ||
108 | .Bx 4.3 Tahoe . | ||
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..45a7bd1826 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.19 2011/12/08 08:06:19 lum 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,37 +27,86 @@ | |||
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: December 8 2011 $ |
36 | .Dt STRDUP 3 | 33 | .Dt STRDUP 3 |
37 | .Os | 34 | .Os |
38 | .Sh NAME | 35 | .Sh NAME |
39 | .Nm strdup | 36 | .Nm strdup , |
37 | .Nm strndup | ||
40 | .Nd save a copy of a string | 38 | .Nd save a copy of a string |
41 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
42 | .Fd #include <string.h> | 40 | .Fd #include <string.h> |
43 | .Ft char * | 41 | .Ft char * |
44 | .Fn strdup "const char *str" | 42 | .Fn strdup "const char *s" |
43 | .Ft char * | ||
44 | .Fn strndup "const char *s" "size_t maxlen" | ||
45 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
46 | The | 46 | The |
47 | .Fn strdup | 47 | .Fn strdup |
48 | function | 48 | function allocates sufficient memory for a copy of the string |
49 | allocates sufficient memory for a copy | 49 | .Fa s , |
50 | of the string | ||
51 | .Fa str , | ||
52 | does the copy, and returns a pointer to it. | 50 | does the copy, and returns a pointer to it. |
53 | The pointer may subsequently be used as an | 51 | The pointer may subsequently be used as an argument to the function |
54 | argument to the function | ||
55 | .Xr free 3 . | 52 | .Xr free 3 . |
53 | .Pp | ||
54 | The | ||
55 | .Fn strndup | ||
56 | function behaves similarly to | ||
57 | .Nm strdup | ||
58 | but only copies up to | ||
59 | .Fa maxlen | ||
60 | characters from | ||
61 | .Fa s . | ||
62 | The resulting string is always NUL-terminated. | ||
63 | .Pp | ||
64 | If insufficient memory is available, | ||
65 | .Dv NULL | ||
66 | is returned. | ||
67 | .Sh EXAMPLES | ||
68 | The following will point | ||
69 | .Va p | ||
70 | to an allocated area of memory containing the NUL-terminated string | ||
71 | .Qq foobar : | ||
72 | .Bd -literal -offset indent | ||
73 | char *p; | ||
74 | |||
75 | p = strdup("foobar"); | ||
76 | if (p == NULL) | ||
77 | err(1, NULL); | ||
78 | .Ed | ||
79 | .Sh ERRORS | ||
80 | The | ||
81 | .Fn strdup | ||
82 | and | ||
83 | .Fn strndup | ||
84 | functions may fail and set the external variable | ||
85 | .Va errno | ||
86 | for any of the errors specified for the library function | ||
87 | .Xr malloc 3 . | ||
56 | .Sh SEE ALSO | 88 | .Sh SEE ALSO |
57 | .Xr free 3 , | 89 | .Xr free 3 , |
58 | .Xr malloc 3 , | 90 | .Xr malloc 3 , |
59 | .Xt strcpy 3 , | 91 | .Xr strcpy 3 , |
60 | .Xt strlen 3 | 92 | .Xr strlcpy 3 , |
93 | .Xr strlen 3 , | ||
94 | .Xr wcsdup 3 | ||
95 | .Sh STANDARDS | ||
96 | The | ||
97 | .Fn strdup | ||
98 | and | ||
99 | .Fn strndup | ||
100 | functions conform to | ||
101 | .St -p1003.1-2008 . | ||
61 | .Sh HISTORY | 102 | .Sh HISTORY |
62 | The | 103 | The |
63 | .Fn strdup | 104 | .Fn strdup |
64 | function | 105 | function first appeared in |
65 | .Ud . | 106 | .Bx 4.3 Reno . |
107 | The | ||
108 | .Fn strndup | ||
109 | function appeared in glibc 2.0, was reimplemented for | ||
110 | .Nx 4.0 , | ||
111 | and ported to | ||
112 | .Ox 4.8 . | ||
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..bab48af308 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.11 2012/03/26 05:07:38 guenther 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: March 26 2012 $ |
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 , |
@@ -63,4 +106,17 @@ overwritten by subsequent calls to | |||
63 | The | 106 | The |
64 | .Fn strerror | 107 | .Fn strerror |
65 | function conforms to | 108 | function conforms to |
66 | .St -ansiC . | 109 | .St -ansiC-99 . |
110 | The | ||
111 | .Fn strerror_r | ||
112 | function conforms to | ||
113 | .St -p1003.1-2008 . | ||
114 | .Sh HISTORY | ||
115 | The | ||
116 | .Fn strerror | ||
117 | function first appeared in | ||
118 | .Bx 4.3 Reno . | ||
119 | The | ||
120 | .Fn strerror_r | ||
121 | function first appeared in | ||
122 | .Ox 3.3 . | ||
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..acce0f7d43 --- /dev/null +++ b/src/lib/libc/string/strlcpy.3 | |||
@@ -0,0 +1,182 @@ | |||
1 | .\" $OpenBSD: strlcpy.3,v 1.22 2012/04/03 14:01:55 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: April 3 2012 $ | ||
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 dstsize" | ||
28 | .Ft size_t | ||
29 | .Fn strlcat "char *dst" "const char *src" "size_t dstsize" | ||
30 | .Sh DESCRIPTION | ||
31 | The | ||
32 | .Fn strlcpy | ||
33 | and | ||
34 | .Fn strlcat | ||
35 | functions copy and concatenate strings with the | ||
36 | same input parameters and output result as | ||
37 | .Xr snprintf 3 . | ||
38 | They are designed to be safer, more consistent, and less error | ||
39 | prone replacements for the easily misused functions | ||
40 | .Xr strncpy 3 | ||
41 | and | ||
42 | .Xr strncat 3 . | ||
43 | .Pp | ||
44 | .Fn strlcpy | ||
45 | and | ||
46 | .Fn strlcat | ||
47 | take the full size of the destination buffer and guarantee | ||
48 | NUL-termination if there is room. | ||
49 | Note that room for the NUL should be included in | ||
50 | .Fa dstsize . | ||
51 | .Pp | ||
52 | .Fn strlcpy | ||
53 | copies up to | ||
54 | .Fa dstsize | ||
55 | \- 1 characters from the string | ||
56 | .Fa src | ||
57 | to | ||
58 | .Fa dst , | ||
59 | NUL-terminating the result if | ||
60 | .Fa dstsize | ||
61 | is not 0. | ||
62 | .Pp | ||
63 | .Fn strlcat | ||
64 | appends string | ||
65 | .Fa src | ||
66 | to the end of | ||
67 | .Fa dst . | ||
68 | It will append at most | ||
69 | .Fa dstsize | ||
70 | \- strlen(dst) \- 1 characters. | ||
71 | It will then NUL-terminate, unless | ||
72 | .Fa dstsize | ||
73 | is 0 or the original | ||
74 | .Fa dst | ||
75 | string was longer than | ||
76 | .Fa dstsize | ||
77 | (in practice this should not happen | ||
78 | as it means that either | ||
79 | .Fa dstsize | ||
80 | is incorrect or that | ||
81 | .Fa dst | ||
82 | is not a proper string). | ||
83 | .Sh RETURN VALUES | ||
84 | Besides quibbles over the return type | ||
85 | .Pf ( Va size_t | ||
86 | versus | ||
87 | .Va int ) | ||
88 | and signal handler safety | ||
89 | .Pf ( Xr snprintf 3 | ||
90 | is not entirely safe on some systems), the | ||
91 | following two are equivalent: | ||
92 | .Bd -literal -offset indent | ||
93 | n = strlcpy(dst, src, len); | ||
94 | n = snprintf(dst, len, "%s", src); | ||
95 | .Ed | ||
96 | .Pp | ||
97 | Like | ||
98 | .Xr snprintf 3 , | ||
99 | the | ||
100 | .Fn strlcpy | ||
101 | and | ||
102 | .Fn strlcat | ||
103 | functions return the total length of the string they tried to create. | ||
104 | For | ||
105 | .Fn strlcpy | ||
106 | that means the length of | ||
107 | .Fa src . | ||
108 | For | ||
109 | .Fn strlcat | ||
110 | that means the initial length of | ||
111 | .Fa dst | ||
112 | plus | ||
113 | the length of | ||
114 | .Fa src . | ||
115 | .Pp | ||
116 | If the return value is | ||
117 | .Cm >= | ||
118 | .Va dstsize , | ||
119 | the output string has been truncated. | ||
120 | It is the caller's responsibility to handle this. | ||
121 | .Sh EXAMPLES | ||
122 | The following code fragment illustrates the simple case: | ||
123 | .Bd -literal -offset indent | ||
124 | char *s, *p, buf[BUFSIZ]; | ||
125 | |||
126 | \&... | ||
127 | |||
128 | (void)strlcpy(buf, s, sizeof(buf)); | ||
129 | (void)strlcat(buf, p, sizeof(buf)); | ||
130 | .Ed | ||
131 | .Pp | ||
132 | To detect truncation, perhaps while building a pathname, something | ||
133 | like the following might be used: | ||
134 | .Bd -literal -offset indent | ||
135 | char *dir, *file, pname[MAXPATHLEN]; | ||
136 | |||
137 | \&... | ||
138 | |||
139 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
140 | goto toolong; | ||
141 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
142 | goto toolong; | ||
143 | .Ed | ||
144 | .Pp | ||
145 | Since it is known how many characters were copied the first time, things | ||
146 | can be sped up a bit by using a copy instead of an append: | ||
147 | .Bd -literal -offset indent | ||
148 | char *dir, *file, pname[MAXPATHLEN]; | ||
149 | size_t n; | ||
150 | |||
151 | \&... | ||
152 | |||
153 | n = strlcpy(pname, dir, sizeof(pname)); | ||
154 | if (n >= sizeof(pname)) | ||
155 | goto toolong; | ||
156 | if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) | ||
157 | goto toolong; | ||
158 | .Ed | ||
159 | .Pp | ||
160 | However, one may question the validity of such optimizations, as they | ||
161 | defeat the whole purpose of | ||
162 | .Fn strlcpy | ||
163 | and | ||
164 | .Fn strlcat . | ||
165 | As a matter of fact, the first version of this manual page got it wrong. | ||
166 | .Sh SEE ALSO | ||
167 | .Xr snprintf 3 , | ||
168 | .Xr strncat 3 , | ||
169 | .Xr strncpy 3 , | ||
170 | .Xr wcslcpy 3 | ||
171 | .Sh HISTORY | ||
172 | .Fn strlcpy | ||
173 | and | ||
174 | .Fn strlcat | ||
175 | first appeared in | ||
176 | .Ox 2.4 . | ||
177 | .Sh AUTHORS | ||
178 | .Fn strlcpy | ||
179 | and | ||
180 | .Fn strlcat | ||
181 | were created by | ||
182 | .An Todd C. Miller Aq Todd.Miller@courtesan.com . | ||
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..9187496a00 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strlen.3,v 1.10 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,39 +31,74 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRLEN 3 | 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 | .Nm strnlen |
40 | .Nd find length of a string | ||
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
47 | .Ft size_t | 43 | .Ft size_t |
48 | .Fn strlen "const char *s" | 44 | .Fn strlen "const char *s" |
45 | .Ft size_t | ||
46 | .Fn strnlen "const char *s" "size_t maxlen" | ||
49 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
50 | The | 48 | The |
51 | .Fn strlen | 49 | .Fn strlen |
52 | function | 50 | function computes the length of the string |
53 | computes the length of the string | ||
54 | .Fa s . | 51 | .Fa s . |
52 | .Pp | ||
53 | The | ||
54 | .Fn strnlen | ||
55 | function computes the length of the string | ||
56 | .Fa s , | ||
57 | up to | ||
58 | .Fa maxlen | ||
59 | characters. | ||
60 | The | ||
61 | .Fn strnlen | ||
62 | function will never attempt to address more than | ||
63 | .Fa maxlen | ||
64 | characters, making it suitable for use with character arrays that are | ||
65 | not guaranteed to be NUL-terminated. | ||
55 | .Sh RETURN VALUES | 66 | .Sh RETURN VALUES |
56 | The | 67 | The |
57 | .Fn strlen | 68 | .Fn strlen |
58 | function | 69 | function returns the number of characters that precede the terminating |
59 | returns | 70 | .Tn NUL |
60 | the number of characters that precede the | ||
61 | terminating | ||
62 | .Dv NUL | ||
63 | character. | 71 | character. |
72 | .Pp | ||
73 | The | ||
74 | .Fn strnlen | ||
75 | function returns the number of characters that precede the terminating | ||
76 | .Tn NUL | ||
77 | or | ||
78 | .Fa maxlen , | ||
79 | whichever is smaller. | ||
64 | .Sh SEE ALSO | 80 | .Sh SEE ALSO |
65 | .Xr string 3 | 81 | .Xr string 3 , |
82 | .Xr wcslen 3 | ||
66 | .Sh STANDARDS | 83 | .Sh STANDARDS |
67 | The | 84 | The |
68 | .Fn strlen | 85 | .Fn strlen |
69 | function | 86 | function conforms to |
70 | conforms to | ||
71 | .St -ansiC . | 87 | .St -ansiC . |
88 | .Pp | ||
89 | The | ||
90 | .Fn strlen | ||
91 | and | ||
92 | .Fn strnlen | ||
93 | functions conform to | ||
94 | .St -p1003.1-2008 . | ||
95 | .Sh HISTORY | ||
96 | The | ||
97 | .Fn strlen | ||
98 | function first appeared in | ||
99 | .At v7 . | ||
100 | The | ||
101 | .Fn strnlen | ||
102 | function appeared in glibc 2.0 | ||
103 | and was reimplemented for | ||
104 | .Ox 4.8 . | ||
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..5d371b38c8 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.15 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ |
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.3 Reno . |
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/strndup.c b/src/lib/libc/string/strndup.c new file mode 100644 index 0000000000..27701ac555 --- /dev/null +++ b/src/lib/libc/string/strndup.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* $OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 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 | |||
21 | #include <stddef.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | char * | ||
26 | strndup(const char *str, size_t maxlen) | ||
27 | { | ||
28 | char *copy; | ||
29 | size_t len; | ||
30 | |||
31 | len = strnlen(str, maxlen); | ||
32 | copy = malloc(len + 1); | ||
33 | if (copy != NULL) { | ||
34 | (void)memcpy(copy, str, len); | ||
35 | copy[len] = '\0'; | ||
36 | } | ||
37 | |||
38 | return copy; | ||
39 | } | ||
diff --git a/src/lib/libc/string/strnlen.c b/src/lib/libc/string/strnlen.c new file mode 100644 index 0000000000..a5e13ae04e --- /dev/null +++ b/src/lib/libc/string/strnlen.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /* $OpenBSD: strnlen.c,v 1.4 2012/04/26 01:22:31 matthew Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 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 | |||
21 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
22 | #include <string.h> | ||
23 | #else | ||
24 | #include <lib/libkern/libkern.h> | ||
25 | #endif | ||
26 | |||
27 | size_t | ||
28 | strnlen(const char *str, size_t maxlen) | ||
29 | { | ||
30 | const char *cp; | ||
31 | |||
32 | for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) | ||
33 | ; | ||
34 | |||
35 | return (size_t)(cp - str); | ||
36 | } | ||
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 index 8578546c05..9e13c42ad0 100644 --- a/src/lib/libc/string/strpbrk.3 +++ b/src/lib/libc/string/strpbrk.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strpbrk.3,v 1.9 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRPBRK 3 | 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,23 +52,29 @@ 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 , |
71 | .Xr strsep 3 , | 64 | .Xr strsep 3 , |
72 | .Xr strspn 3 , | 65 | .Xr strspn 3 , |
73 | .Xr strstr 3 , | 66 | .Xr strstr 3 , |
74 | .Xr strtok 3 | 67 | .Xr strtok 3 , |
68 | .Xr wcspbrk 3 | ||
75 | .Sh STANDARDS | 69 | .Sh STANDARDS |
76 | The | 70 | The |
77 | .Fn strpbrk | 71 | .Fn strpbrk |
78 | function | 72 | function conforms to |
79 | conforms to | ||
80 | .St -ansiC . | 73 | .St -ansiC . |
74 | .Sh HISTORY | ||
75 | The | ||
76 | .Fn strpbrk | ||
77 | function first appeared in | ||
78 | .At III | ||
79 | and was reimplemented for | ||
80 | .Bx 4.3 Tahoe . | ||
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..9eea08b0a9 100644 --- a/src/lib/libc/string/strrchr.3 +++ b/src/lib/libc/string/strrchr.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strrchr.3,v 1.9 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,28 +31,29 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRRCHR 3 | 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,30 +61,56 @@ 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 , |
82 | .Xr strsep 3 , | 92 | .Xr strsep 3 , |
83 | .Xr strspn 3 , | 93 | .Xr strspn 3 , |
84 | .Xr strstr 3 , | 94 | .Xr strstr 3 , |
85 | .Xr strtok 3 | 95 | .Xr strtok 3 , |
96 | .Xr wcsrchr 3 | ||
86 | .Sh STANDARDS | 97 | .Sh STANDARDS |
87 | The | 98 | The |
88 | .Fn strrchr | 99 | .Fn strrchr |
89 | function | 100 | function conforms to |
90 | conforms to | ||
91 | .St -ansiC . | 101 | .St -ansiC . |
102 | .Pp | ||
103 | The | ||
104 | .Fn rindex | ||
105 | function is deprecated and shouldn't be used in new code. | ||
106 | .Sh HISTORY | ||
107 | The | ||
108 | .Fn rindex | ||
109 | function first appeared in | ||
110 | .At v7 . | ||
111 | The | ||
112 | .Fn strrchr | ||
113 | function first appeared in | ||
114 | .At III | ||
115 | and was reimplemented for | ||
116 | .Bx 4.3 Tahoe . | ||
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 21aa7376f2..63cdf2333a 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.13 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ |
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,30 @@ 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 first appeared in |
92 | .Ud . | 100 | .Bx 4.3 Reno . |
101 | It is intended as a replacement for the | ||
102 | .Xr strtok 3 | ||
103 | function. | ||
104 | While the | ||
105 | .Xr strtok 3 | ||
106 | function should be preferred for portability reasons (it conforms to | ||
107 | .St -ansiC ) | ||
108 | it is unable to handle empty fields, i.e., detect fields delimited by | ||
109 | two adjacent delimiter characters, or to be used for more than a single | ||
110 | string at a time. | ||
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..7128d811fd 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.7 2012/03/26 05:06:35 guenther 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: March 26 2012 $ |
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 |
@@ -59,3 +54,15 @@ overwritten by subsequent calls to | |||
59 | .Xr intro 2 , | 54 | .Xr intro 2 , |
60 | .Xr psignal 3 , | 55 | .Xr psignal 3 , |
61 | .Xr setlocale 3 | 56 | .Xr setlocale 3 |
57 | .Sh STANDARDS | ||
58 | The | ||
59 | .Fn strsignal | ||
60 | function conforms to | ||
61 | .St -p1003.1-2008 . | ||
62 | .Sh HISTORY | ||
63 | The | ||
64 | .Fn strsignal | ||
65 | function first appeared in | ||
66 | .At V.4 | ||
67 | and was reimplemented for | ||
68 | .Nx 1.0 . | ||
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..b1a2ae3014 100644 --- a/src/lib/libc/string/strspn.3 +++ b/src/lib/libc/string/strspn.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strspn.3,v 1.10 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,10 +31,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRSPN 3 | 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,22 +53,40 @@ 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 , |
71 | .Xr strrchr 3 , | 76 | .Xr strrchr 3 , |
72 | .Xr strsep 3 , | 77 | .Xr strsep 3 , |
73 | .Xr strstr 3 , | 78 | .Xr strstr 3 , |
74 | .Xr strtok 3 | 79 | .Xr strtok 3 , |
80 | .Xr wcsspn 3 | ||
75 | .Sh STANDARDS | 81 | .Sh STANDARDS |
76 | The | 82 | The |
77 | .Fn strspn | 83 | .Fn strspn |
78 | function | 84 | function conforms to |
79 | conforms to | ||
80 | .St -ansiC . | 85 | .St -ansiC . |
86 | .Sh HISTORY | ||
87 | The | ||
88 | .Fn strspn | ||
89 | function first appeared in | ||
90 | .At III | ||
91 | and was reimplemented for | ||
92 | .Bx 4.3 Tahoe . | ||
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..4069d55ed2 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strstr.3,v 1.11 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,57 +31,70 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRSTR 3 | 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 , |
80 | .Xr strrchr 3 , | 79 | .Xr strrchr 3 , |
81 | .Xr strsep 3 , | 80 | .Xr strsep 3 , |
82 | .Xr strspn 3 , | 81 | .Xr strspn 3 , |
83 | .Xr strtok 3 | 82 | .Xr strtok 3 , |
83 | .Xr wcsstr 3 | ||
84 | .Sh STANDARDS | 84 | .Sh STANDARDS |
85 | The | 85 | The |
86 | .Fn strstr | 86 | .Fn strstr |
87 | function | 87 | function conforms to |
88 | conforms to | ||
89 | .St -ansiC . | 88 | .St -ansiC . |
89 | .Sh HISTORY | ||
90 | The | ||
91 | .Fn strstr | ||
92 | function first appeared in | ||
93 | .Bx 4.3 Reno . | ||
94 | The | ||
95 | .Fn strcasestr | ||
96 | function appeared in glibc 2.1, | ||
97 | was reimplemented for | ||
98 | .Fx 4.5 | ||
99 | and ported to | ||
100 | .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..fbf0abfc26 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 | |||
@@ -1,3 +1,5 @@ | |||
1 | .\" $OpenBSD: strtok.3,v 1.20 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1988, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1988, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3 | .\" | 5 | .\" |
@@ -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 | .\" |
@@ -33,29 +31,28 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
35 | .\" | 33 | .\" |
36 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
38 | .\" | ||
39 | .Dd June 29, 1991 | ||
40 | .Dt STRTOK 3 | 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,42 +68,99 @@ 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 | Since |
78 | .Dv NUL | 77 | .Fn strtok |
78 | and | ||
79 | .Fn strtok_r | ||
80 | modify the string, | ||
81 | .Fa str | ||
82 | should not point to an area in the initialized data segment. | ||
83 | .Sh RETURN VALUES | ||
84 | The | ||
85 | .Fn strtok | ||
86 | and | ||
87 | .Fn strtok_r | ||
88 | functions return a pointer to the beginning of each subsequent token | ||
89 | in the string, after replacing the separator character itself with an | ||
90 | .Tn ASCII NUL | ||
79 | character. | 91 | character. |
80 | When no more tokens remain, a null pointer is returned. | 92 | When no more tokens remain, a null pointer is returned. |
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 , |
88 | .Xr strrchr 3 , | 133 | .Xr strrchr 3 , |
89 | .Xr strsep 3 , | 134 | .Xr strsep 3 , |
90 | .Xr strspn 3 , | 135 | .Xr strspn 3 , |
91 | .Xr strstr 3 | 136 | .Xr strstr 3 , |
137 | .Xr wcstok 3 | ||
92 | .Sh STANDARDS | 138 | .Sh STANDARDS |
93 | The | 139 | The |
94 | .Fn strtok | 140 | .Fn strtok |
95 | function | 141 | function conforms to |
96 | conforms to | ||
97 | .St -ansiC . | 142 | .St -ansiC . |
143 | .Sh HISTORY | ||
144 | The | ||
145 | .Fn strtok | ||
146 | function first appeared in | ||
147 | .At III | ||
148 | and was reimplemented for | ||
149 | .Bx 4.3 Tahoe . | ||
150 | The | ||
151 | .Fn strtok_r | ||
152 | function first appeared in | ||
153 | .Nx 1.3 | ||
154 | and was reimplemented for | ||
155 | .Ox 2.7 . | ||
98 | .Sh BUGS | 156 | .Sh BUGS |
99 | There is no way to get tokens from multiple strings simultaneously. | ||
100 | .Pp | ||
101 | The System V | 157 | The System V |
102 | .Fn strtok , | 158 | .Fn strtok , |
103 | if handed a string containing only delimiter characters, | 159 | if handed a string containing only delimiter characters, |
104 | will not alter the next starting point, so that a call to | 160 | will not alter the next starting point, so that a call to |
105 | .Fn strtok | 161 | .Fn strtok |
106 | with a different (or empty) delimiter string | 162 | with a different (or empty) delimiter string |
107 | may return a | 163 | may return a non-null value. |
108 | .Pf non- Dv NULL | ||
109 | value. | ||
110 | Since this implementation always alters the next starting point, | 164 | Since this implementation always alters the next starting point, |
111 | such a sequence of calls would always return | 165 | such a sequence of calls would always return |
112 | .Dv NULL . | 166 | .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..e4472946be 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.9 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ |
40 | .Dt STRXFRM 3 | 35 | .Dt STRXFRM 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -47,23 +42,38 @@ | |||
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 HISTORY | ||
71 | The | ||
72 | .Fn strxfrm | ||
73 | function first appeared in | ||
74 | .Bx 4.3 Reno . | ||
75 | .Sh BUGS | ||
76 | Since locales are not fully implemented on | ||
77 | .Ox , | ||
78 | .Fn strxfrm | ||
79 | 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..5ebaa485e9 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.7 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ |
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,12 +50,12 @@ 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 |
62 | .Sh HISTORY | 57 | .Sh HISTORY |
63 | A | 58 | The |
64 | .Fn swab | 59 | .Fn swab |
65 | function appeared in | 60 | function first appeared in |
66 | .At v7 . | 61 | .At v7 . |
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/timingsafe_bcmp.c b/src/lib/libc/string/timingsafe_bcmp.c new file mode 100644 index 0000000000..9c4287cf63 --- /dev/null +++ b/src/lib/libc/string/timingsafe_bcmp.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* $OpenBSD: timingsafe_bcmp.c,v 1.1 2010/09/24 13:33:00 matthew Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2010 Damien Miller. All rights reserved. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
19 | #include <string.h> | ||
20 | #else | ||
21 | #include <lib/libkern/libkern.h> | ||
22 | #endif | ||
23 | |||
24 | int | ||
25 | timingsafe_bcmp(const void *b1, const void *b2, size_t n) | ||
26 | { | ||
27 | const unsigned char *p1 = b1, *p2 = b2; | ||
28 | int ret = 0; | ||
29 | |||
30 | for (; n > 0; n--) | ||
31 | ret |= *p1++ ^ *p2++; | ||
32 | return (ret != 0); | ||
33 | } | ||
diff --git a/src/lib/libc/string/wcscasecmp.3 b/src/lib/libc/string/wcscasecmp.3 new file mode 100644 index 0000000000..94cd6e0c38 --- /dev/null +++ b/src/lib/libc/string/wcscasecmp.3 | |||
@@ -0,0 +1,94 @@ | |||
1 | .\" $OpenBSD: wcscasecmp.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek. | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 3. 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 | .\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCASECMP 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcscasecmp , | ||
39 | .Nm wcsncasecmp | ||
40 | .Nd compare wide strings, ignoring case | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <wchar.h> | ||
43 | .Ft int | ||
44 | .Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" | ||
45 | .Ft int | ||
46 | .Fn wcsncasecmp "const wchar_t *s1" "const wchar_t *s2" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn wcscasecmp | ||
50 | and | ||
51 | .Fn wcsncasecmp | ||
52 | functions compare the wide strings | ||
53 | .Fa s1 | ||
54 | and | ||
55 | .Fa s2 | ||
56 | and return an integer greater than, equal to, or less than 0, | ||
57 | according to whether | ||
58 | .Fa s1 | ||
59 | is lexicographically greater than, equal to, or less than | ||
60 | .Fa s2 | ||
61 | after translation of each corresponding wide character to lower case. | ||
62 | The wide strings themselves are not modified. | ||
63 | .Pp | ||
64 | .Fn wcsncasecmp | ||
65 | compares at most | ||
66 | .Fa len | ||
67 | wide characters. | ||
68 | .Sh SEE ALSO | ||
69 | .Xr strcasecmp 3 , | ||
70 | .Xr wcscmp 3 , | ||
71 | .Xr wmemcmp 3 | ||
72 | .Sh STANDARDS | ||
73 | The | ||
74 | .Fn wcscasecmp | ||
75 | and | ||
76 | .Fn wcsncasecmp | ||
77 | functions conform to | ||
78 | .St -p1003.1-2008 . | ||
79 | .Sh HISTORY | ||
80 | The | ||
81 | .Fn wcscasecmp | ||
82 | and | ||
83 | .Fn wcsncasecmp | ||
84 | functions first appeared in | ||
85 | .Ox 5.0 . | ||
86 | .Sh AUTHORS | ||
87 | The | ||
88 | .Ox | ||
89 | versions of | ||
90 | .Fn wcscasecmp | ||
91 | and | ||
92 | .Fn wcsncasecmp | ||
93 | were implemented by | ||
94 | .An Marc Espie Aq espie@openbsd.org . | ||
diff --git a/src/lib/libc/string/wcscasecmp.c b/src/lib/libc/string/wcscasecmp.c new file mode 100644 index 0000000000..b14997ee75 --- /dev/null +++ b/src/lib/libc/string/wcscasecmp.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* $OpenBSD: wcscasecmp.c,v 1.2 2011/06/01 19:29:48 naddy Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2011 Marc Espie | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS | ||
16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD | ||
19 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | #include <wchar.h> | ||
29 | #include <wctype.h> | ||
30 | #include "locale/runetype.h" | ||
31 | |||
32 | int | ||
33 | wcscasecmp(const wchar_t *s1, const wchar_t *s2) | ||
34 | { | ||
35 | wchar_t l1, l2; | ||
36 | |||
37 | while ((l1 = towlower(*s1++)) == (l2 = towlower(*s2++))) { | ||
38 | if (l1 == 0) | ||
39 | return (0); | ||
40 | } | ||
41 | /* XXX assumes wchar_t = int */ | ||
42 | return ((rune_t)l1 - (rune_t)l2); | ||
43 | } | ||
44 | |||
45 | int | ||
46 | wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) | ||
47 | { | ||
48 | wchar_t l1, l2; | ||
49 | |||
50 | if (n == 0) | ||
51 | return (0); | ||
52 | do { | ||
53 | if (((l1 = towlower(*s1++))) != (l2 = towlower(*s2++))) { | ||
54 | /* XXX assumes wchar_t = int */ | ||
55 | return ((rune_t)l1 - (rune_t)l2); | ||
56 | } | ||
57 | if (l1 == 0) | ||
58 | break; | ||
59 | } while (--n != 0); | ||
60 | return (0); | ||
61 | } | ||
diff --git a/src/lib/libc/string/wcscat.3 b/src/lib/libc/string/wcscat.3 new file mode 100644 index 0000000000..d0281b8bd1 --- /dev/null +++ b/src/lib/libc/string/wcscat.3 | |||
@@ -0,0 +1,115 @@ | |||
1 | .\" $OpenBSD: wcscat.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCAT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcscat , | ||
39 | .Nm wcsncat | ||
40 | .Nd concatenate wide strings | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <wchar.h> | ||
43 | .Ft wchar_t * | ||
44 | .Fn wcscat "wchar_t * restrict s" "const wchar_t * restrict append" | ||
45 | .Ft wchar_t * | ||
46 | .Fo wcsncat | ||
47 | .Fa "wchar_t * restrict s" | ||
48 | .Fa "const wchar_t * restrict append" | ||
49 | .Fa "size_t count" | ||
50 | .Fc | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn wcscat | ||
54 | and | ||
55 | .Fn wcsncat | ||
56 | functions append a copy of the wide string | ||
57 | .Fa append | ||
58 | to the end of the wide string | ||
59 | .Fa s , | ||
60 | then add a terminating null wide character (L'\e0'). | ||
61 | The wide string | ||
62 | .Fa s | ||
63 | must have sufficient space to hold the result. | ||
64 | .Pp | ||
65 | The | ||
66 | .Fn wcsncat | ||
67 | function appends not more than | ||
68 | .Fa count | ||
69 | wide characters where space for the terminating null wide character | ||
70 | should not be included in | ||
71 | .Fa count . | ||
72 | .Sh RETURN VALUES | ||
73 | The | ||
74 | .Fn wcscat | ||
75 | and | ||
76 | .Fn wcsncat | ||
77 | functions return the pointer | ||
78 | .Fa s . | ||
79 | .Sh SEE ALSO | ||
80 | .Xr strcat 3 , | ||
81 | .Xr strlcpy 3 , | ||
82 | .Xr wcscpy 3 , | ||
83 | .Xr wcslcpy 3 , | ||
84 | .Xr wmemcpy 3 , | ||
85 | .Xr wmemmove 3 | ||
86 | .Sh STANDARDS | ||
87 | The | ||
88 | .Fn wcscat | ||
89 | and | ||
90 | .Fn wcsncat | ||
91 | functions conform to | ||
92 | .St -isoC-99 | ||
93 | and were first introduced in | ||
94 | .St -isoC-amd1 . | ||
95 | .Sh HISTORY | ||
96 | The | ||
97 | .Fn wcscat | ||
98 | and | ||
99 | .Fn wcsncat | ||
100 | functions were ported from | ||
101 | .Nx | ||
102 | and first appeared in | ||
103 | .Ox 3.8 . | ||
104 | .Sh CAVEATS | ||
105 | Using the functions | ||
106 | .Fn wcscat | ||
107 | and | ||
108 | .Fn wcsncat | ||
109 | is very error-prone with respect to buffer overflows; | ||
110 | see the EXAMPLES section in | ||
111 | .Xr strcat 3 | ||
112 | for correct usage. | ||
113 | Using | ||
114 | .Xr wcslcat 3 | ||
115 | is a better choice in most cases. | ||
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.3 b/src/lib/libc/string/wcschr.3 new file mode 100644 index 0000000000..ca2c0ed743 --- /dev/null +++ b/src/lib/libc/string/wcschr.3 | |||
@@ -0,0 +1,85 @@ | |||
1 | .\" $OpenBSD: wcschr.3,v 1.3 2011/07/25 07:51:30 jmc Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCHR 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcschr | ||
39 | .Nd locate first occurrence of a wide character in a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wcschr "const wchar_t *s" "wchar_t c" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcschr | ||
47 | function locates the first occurrence of the wide character | ||
48 | .Fa c | ||
49 | in the wide string | ||
50 | .Fa s . | ||
51 | The terminating null wide character is considered part of the wide string. | ||
52 | If | ||
53 | .Fa c | ||
54 | is the null wide character (L'\e0'), | ||
55 | .Fn wcschr | ||
56 | locates the terminating null wide character. | ||
57 | .Sh RETURN VALUES | ||
58 | The | ||
59 | .Fn wcschr | ||
60 | function returns a pointer to the located wide character or | ||
61 | .Dv NULL | ||
62 | if the wide character does not appear in the wide string. | ||
63 | .Sh SEE ALSO | ||
64 | .Xr strchr 3 , | ||
65 | .Xr wcscspn 3 , | ||
66 | .Xr wcspbrk 3 , | ||
67 | .Xr wcsrchr 3 , | ||
68 | .Xr wcsspn 3 , | ||
69 | .Xr wcsstr 3 , | ||
70 | .Xr wcstok 3 , | ||
71 | .Xr wmemchr 3 | ||
72 | .Sh STANDARDS | ||
73 | The | ||
74 | .Fn wcschr | ||
75 | function conforms to | ||
76 | .St -isoC-99 | ||
77 | and was first introduced in | ||
78 | .St -isoC-amd1 . | ||
79 | .Sh HISTORY | ||
80 | The | ||
81 | .Fn wcschr | ||
82 | function was ported from | ||
83 | .Nx | ||
84 | and first appeared in | ||
85 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcscmp.3 new file mode 100644 index 0000000000..b34e5c2168 --- /dev/null +++ b/src/lib/libc/string/wcscmp.3 | |||
@@ -0,0 +1,92 @@ | |||
1 | .\" $OpenBSD: wcscmp.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCMP 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcscmp , | ||
39 | .Nm wcsncmp | ||
40 | .Nd compare wide strings | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <wchar.h> | ||
43 | .Ft int | ||
44 | .Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" | ||
45 | .Ft int | ||
46 | .Fn wcsncmp "const wchar_t *s1" "const wchar_t *s2" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn wcscmp | ||
50 | and | ||
51 | .Fn wcsncmp | ||
52 | functions lexicographically compare the wide strings | ||
53 | .Fa s1 | ||
54 | and | ||
55 | .Fa s2 . | ||
56 | The | ||
57 | .Fn wcsncmp | ||
58 | function compares at most | ||
59 | .Fa len | ||
60 | wide characters. | ||
61 | .Sh RETURN VALUES | ||
62 | The | ||
63 | .Fn wcscmp | ||
64 | and | ||
65 | .Fn wcsncmp | ||
66 | functions return an integer greater than, equal to, or less than 0, according | ||
67 | to whether the wide string | ||
68 | .Fa s1 | ||
69 | is greater than, equal to, or less than the wide string | ||
70 | .Fa s2 . | ||
71 | .Sh SEE ALSO | ||
72 | .Xr strcmp 3 , | ||
73 | .Xr wcscasecmp 3 , | ||
74 | .Xr wmemcmp 3 | ||
75 | .Sh STANDARDS | ||
76 | The | ||
77 | .Fn wcscmp | ||
78 | and | ||
79 | .Fn wcsncmp | ||
80 | functions conform to | ||
81 | .St -isoC-99 | ||
82 | and were first introduced in | ||
83 | .St -isoC-amd1 . | ||
84 | .Sh HISTORY | ||
85 | The | ||
86 | .Fn wcscmp | ||
87 | and | ||
88 | .Fn wcsncmp | ||
89 | functions were ported from | ||
90 | .Nx | ||
91 | and first appeared in | ||
92 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcscpy.3 new file mode 100644 index 0000000000..dcc375acbf --- /dev/null +++ b/src/lib/libc/string/wcscpy.3 | |||
@@ -0,0 +1,123 @@ | |||
1 | .\" $OpenBSD: wcscpy.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCPY 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcscpy , | ||
39 | .Nm wcsncpy | ||
40 | .Nd copy wide strings | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <wchar.h> | ||
43 | .Ft wchar_t * | ||
44 | .Fn wcscpy "wchar_t * restrict dst" "const wchar_t * restrict src" | ||
45 | .Ft wchar_t * | ||
46 | .Fo wcsncpy | ||
47 | .Fa "wchar_t * restrict dst" | ||
48 | .Fa "const wchar_t * restrict src" | ||
49 | .Fa "size_t len" | ||
50 | .Fc | ||
51 | .Sh DESCRIPTION | ||
52 | The | ||
53 | .Fn wcscpy | ||
54 | and | ||
55 | .Fn wcsncpy | ||
56 | functions copy the wide string | ||
57 | .Fa src | ||
58 | to | ||
59 | .Fa dst | ||
60 | (including the terminating null wide character). | ||
61 | .Pp | ||
62 | The | ||
63 | .Fn wcsncpy | ||
64 | function copies not more than | ||
65 | .Fa len | ||
66 | wide characters to | ||
67 | .Fa dst , | ||
68 | appending null wide characters if the length of | ||
69 | .Fa src | ||
70 | is less than | ||
71 | .Fa len , | ||
72 | and | ||
73 | .Em not | ||
74 | terminating | ||
75 | .Fa dst | ||
76 | if the length of | ||
77 | .Fa src | ||
78 | is greater than or equal to | ||
79 | .Fa len . | ||
80 | .Sh RETURN VALUES | ||
81 | The | ||
82 | .Fn wcscpy | ||
83 | and | ||
84 | .Fn wcsncpy | ||
85 | functions return | ||
86 | .Fa dst . | ||
87 | .Sh SEE ALSO | ||
88 | .Xr strcpy 3 , | ||
89 | .Xr strlcpy 3 , | ||
90 | .Xr wcscat 3 , | ||
91 | .Xr wcslcpy 3 , | ||
92 | .Xr wmemcpy 3 , | ||
93 | .Xr wmemmove 3 | ||
94 | .Sh STANDARDS | ||
95 | The | ||
96 | .Fn wcscpy | ||
97 | and | ||
98 | .Fn wcsncpy | ||
99 | functions conform to | ||
100 | .St -isoC-99 | ||
101 | and were first introduced in | ||
102 | .St -isoC-amd1 . | ||
103 | .Sh HISTORY | ||
104 | The | ||
105 | .Fn wcscpy | ||
106 | and | ||
107 | .Fn wcsncpy | ||
108 | functions were ported from | ||
109 | .Nx | ||
110 | and first appeared in | ||
111 | .Ox 3.8 . | ||
112 | .Sh CAVEATS | ||
113 | Using the functions | ||
114 | .Fn wcscpy | ||
115 | and | ||
116 | .Fn wcsncpy | ||
117 | is very error-prone with respect to buffer overflows; | ||
118 | see the EXAMPLES section in | ||
119 | .Xr strcpy 3 | ||
120 | for correct usage. | ||
121 | Using | ||
122 | .Xr wcslcpy 3 | ||
123 | is a better choice in most cases. | ||
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.3 b/src/lib/libc/string/wcscspn.3 new file mode 100644 index 0000000000..c17992501f --- /dev/null +++ b/src/lib/libc/string/wcscspn.3 | |||
@@ -0,0 +1,83 @@ | |||
1 | .\" $OpenBSD: wcscspn.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSCSPN 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcscspn | ||
39 | .Nd span the complement of a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft size_t | ||
43 | .Fn wcscspn "const wchar_t *s" "const wchar_t *charset" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcscspn | ||
47 | function spans the initial part of the wide string | ||
48 | .Fa s | ||
49 | as long as the wide characters from | ||
50 | .Fa s | ||
51 | do not occur in string | ||
52 | .Fa charset | ||
53 | (it spans the | ||
54 | .Em complement | ||
55 | of | ||
56 | .Fa charset ) . | ||
57 | .Sh RETURN VALUES | ||
58 | The | ||
59 | .Fn wcscspn | ||
60 | function returns the number of wide characters spanned. | ||
61 | .Sh SEE ALSO | ||
62 | .Xr strcspn 3 , | ||
63 | .Xr wcschr 3 , | ||
64 | .Xr wcspbrk 3 , | ||
65 | .Xr wcsrchr 3 , | ||
66 | .Xr wcsspn 3 , | ||
67 | .Xr wcsstr 3 , | ||
68 | .Xr wcstok 3 , | ||
69 | .Xr wmemchr 3 | ||
70 | .Sh STANDARDS | ||
71 | The | ||
72 | .Fn wcscspn | ||
73 | function conforms to | ||
74 | .St -isoC-99 | ||
75 | and was first introduced in | ||
76 | .St -isoC-amd1 . | ||
77 | .Sh HISTORY | ||
78 | The | ||
79 | .Fn wcscspn | ||
80 | function was ported from | ||
81 | .Nx | ||
82 | and first appeared in | ||
83 | .Ox 3.8 . | ||
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/wcsdup.3 b/src/lib/libc/string/wcsdup.3 new file mode 100644 index 0000000000..588a2571db --- /dev/null +++ b/src/lib/libc/string/wcsdup.3 | |||
@@ -0,0 +1,97 @@ | |||
1 | .\" $OpenBSD: wcsdup.3,v 1.4 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1990, 1991, 1993 | ||
5 | .\" The Regents of the University of California. All rights reserved. | ||
6 | .\" | ||
7 | .\" Redistribution and use in source and binary forms, with or without | ||
8 | .\" modification, are permitted provided that the following conditions | ||
9 | .\" are met: | ||
10 | .\" 1. Redistributions of source code must retain the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer. | ||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
13 | .\" notice, this list of conditions and the following disclaimer in the | ||
14 | .\" documentation and/or other materials provided with the distribution. | ||
15 | .\" 3. Neither the name of the University nor the names of its contributors | ||
16 | .\" may be used to endorse or promote products derived from this software | ||
17 | .\" without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 | ||
32 | .\" | ||
33 | .Dd $Mdocdate: July 25 2011 $ | ||
34 | .Dt WCSDUP 3 | ||
35 | .Os | ||
36 | .Sh NAME | ||
37 | .Nm wcsdup | ||
38 | .Nd save a copy of a wide string | ||
39 | .Sh SYNOPSIS | ||
40 | .In wchar.h | ||
41 | .Ft wchar_t * | ||
42 | .Fn wcsdup "const wchar_t *str" | ||
43 | .Sh DESCRIPTION | ||
44 | The | ||
45 | .Fn wcsdup | ||
46 | function | ||
47 | allocates sufficient memory for a copy | ||
48 | of the wide-character string | ||
49 | .Fa str , | ||
50 | does the copy, and returns a pointer to it. | ||
51 | The pointer may subsequently be used as an | ||
52 | argument to the function | ||
53 | .Xr free 3 . | ||
54 | .Pp | ||
55 | If insufficient memory is available, | ||
56 | .Dv NULL | ||
57 | is returned. | ||
58 | .Sh EXAMPLES | ||
59 | The following will point | ||
60 | .Va p | ||
61 | to an allocated area of memory containing the nul-terminated string | ||
62 | .Qq foobar : | ||
63 | .Bd -literal -offset indent | ||
64 | const char *o = "foobar"; | ||
65 | wchar_t *p, b[32]; | ||
66 | size_t blen; | ||
67 | |||
68 | blen = sizeof(b) / sizeof(b[0]); | ||
69 | if (mbstowcs(b, o, blen) == (size_t)-1) | ||
70 | err(1, NULL); | ||
71 | b[blen - 1] = 0; | ||
72 | if ((p = wcsdup(b)) == NULL) | ||
73 | err(1, NULL); | ||
74 | .Ed | ||
75 | .Sh ERRORS | ||
76 | The | ||
77 | .Fn wcsdup | ||
78 | function may fail and set the external variable | ||
79 | .Va errno | ||
80 | for any of the errors specified for the library function | ||
81 | .Xr malloc 3 . | ||
82 | .Sh SEE ALSO | ||
83 | .Xr free 3 , | ||
84 | .Xr malloc 3 , | ||
85 | .Xr strdup 3 | ||
86 | .Sh STANDARDS | ||
87 | The | ||
88 | .Fn wcsdup | ||
89 | function conforms to | ||
90 | .St -p1003.1-2008 . | ||
91 | .Sh HISTORY | ||
92 | The | ||
93 | .Fn wcsdup | ||
94 | function was ported from | ||
95 | .Nx | ||
96 | and first appeared in | ||
97 | .Ox 5.0 . | ||
diff --git a/src/lib/libc/string/wcsdup.c b/src/lib/libc/string/wcsdup.c new file mode 100644 index 0000000000..57a328a8c2 --- /dev/null +++ b/src/lib/libc/string/wcsdup.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* $OpenBSD: wcsdup.c,v 1.1 2011/07/04 04:37:34 nicm Exp $ */ | ||
2 | /* $NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 2006 Aleksey Cheusov | ||
6 | * | ||
7 | * This material is provided "as is", with absolutely no warranty expressed | ||
8 | * or implied. Any use is at your own risk. | ||
9 | * | ||
10 | * Permission to use or copy this software for any purpose is hereby granted | ||
11 | * without fee. Permission to modify the code and to distribute modified | ||
12 | * code is also granted without any restrictions. | ||
13 | */ | ||
14 | |||
15 | #include <stdlib.h> | ||
16 | #include <wchar.h> | ||
17 | |||
18 | wchar_t * | ||
19 | wcsdup(const wchar_t *str) | ||
20 | { | ||
21 | wchar_t *copy; | ||
22 | size_t len; | ||
23 | |||
24 | len = wcslen(str) + 1; | ||
25 | copy = malloc(len * sizeof (wchar_t)); | ||
26 | |||
27 | if (!copy) | ||
28 | return (NULL); | ||
29 | |||
30 | return (wmemcpy(copy, str, len)); | ||
31 | } | ||
diff --git a/src/lib/libc/string/wcslcat.c b/src/lib/libc/string/wcslcat.c new file mode 100644 index 0000000000..ee8ff3c343 --- /dev/null +++ b/src/lib/libc/string/wcslcat.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* $OpenBSD: wcslcat.c,v 1.4 2011/07/24 15:21:28 millert Exp $ */ | ||
2 | /* $NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
6 | * | ||
7 | * Permission to use, copy, modify, and distribute this software for any | ||
8 | * purpose with or without fee is hereby granted, provided that the above | ||
9 | * copyright notice and this permission notice appear in all copies. | ||
10 | * | ||
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #include <sys/types.h> | ||
21 | #include <wchar.h> | ||
22 | |||
23 | /* | ||
24 | * Appends src to string dst of size siz (unlike wcsncat, siz is the | ||
25 | * full size of dst, not space left). At most siz-1 characters | ||
26 | * will be copied. Always NUL terminates (unless siz <= wcslen(dst)). | ||
27 | * Returns wcslen(src) + MIN(siz, wcslen(initial dst)). | ||
28 | * If retval >= siz, truncation occurred. | ||
29 | */ | ||
30 | size_t | ||
31 | wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) | ||
32 | { | ||
33 | wchar_t *d = dst; | ||
34 | const wchar_t *s = src; | ||
35 | size_t n = siz; | ||
36 | size_t dlen; | ||
37 | |||
38 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
39 | while (n-- != 0 && *d != '\0') | ||
40 | d++; | ||
41 | dlen = d - dst; | ||
42 | n = siz - dlen; | ||
43 | |||
44 | if (n == 0) | ||
45 | return(dlen + wcslen(s)); | ||
46 | while (*s != '\0') { | ||
47 | if (n != 1) { | ||
48 | *d++ = *s; | ||
49 | n--; | ||
50 | } | ||
51 | s++; | ||
52 | } | ||
53 | *d = '\0'; | ||
54 | |||
55 | return(dlen + (s - src)); /* count does not include NUL */ | ||
56 | } | ||
diff --git a/src/lib/libc/string/wcslcpy.3 b/src/lib/libc/string/wcslcpy.3 new file mode 100644 index 0000000000..98ecf0aabc --- /dev/null +++ b/src/lib/libc/string/wcslcpy.3 | |||
@@ -0,0 +1,147 @@ | |||
1 | .\" $OpenBSD: wcslcpy.3,v 1.3 2011/07/25 07:51:30 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: July 25 2011 $ | ||
18 | .Dt WCSLCPY 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm wcslcpy , | ||
22 | .Nm wcslcat | ||
23 | .Nd size-bounded wide string copying and concatenation | ||
24 | .Sh SYNOPSIS | ||
25 | .Fd #include <wchar.h> | ||
26 | .Ft size_t | ||
27 | .Fn wcslcpy "wchar_t *dst" "const wchar_t *src" "size_t size" | ||
28 | .Ft size_t | ||
29 | .Fn wcslcat "wchar_t *dst" "const wchar_t *src" "size_t size" | ||
30 | .Sh DESCRIPTION | ||
31 | The | ||
32 | .Fn wcslcpy | ||
33 | and | ||
34 | .Fn wcslcat | ||
35 | functions copy and concatenate wide strings respectively. | ||
36 | They are designed to be safer, more consistent, and less error prone | ||
37 | replacements for | ||
38 | .Xr wcsncpy 3 | ||
39 | and | ||
40 | .Xr wcsncat 3 . | ||
41 | Unlike those functions, | ||
42 | .Fn wcslcpy | ||
43 | and | ||
44 | .Fn wcslcat | ||
45 | take the full size of the buffer (not just the length) and guarantee to | ||
46 | terminate the result with a null wide character (as long as | ||
47 | .Fa size | ||
48 | is larger than 0 or, in the case of | ||
49 | .Fn wcslcat , | ||
50 | as long as there is at least one wide character free in | ||
51 | .Fa dst ) . | ||
52 | Note that a wide character for the null wide character should be included in | ||
53 | .Fa size . | ||
54 | Also note that | ||
55 | .Fn wcslcpy | ||
56 | and | ||
57 | .Fn wcslcat | ||
58 | only operate on wide strings that are terminated with a null wide character | ||
59 | (L'\e0'). | ||
60 | This means that for | ||
61 | .Fn wcslcpy | ||
62 | .Fa src | ||
63 | must be terminated with a null wide character and for | ||
64 | .Fn wcslcat | ||
65 | both | ||
66 | .Fa src | ||
67 | and | ||
68 | .Fa dst | ||
69 | must be terminated with a null wide character. | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn wcslcpy | ||
73 | function copies up to | ||
74 | .Fa size | ||
75 | \(mi 1 wide characters from the wide string | ||
76 | .Fa src | ||
77 | to | ||
78 | .Fa dst , | ||
79 | terminating the result with a null wide character. | ||
80 | .Pp | ||
81 | The | ||
82 | .Fn wcslcat | ||
83 | function appends the wide string | ||
84 | .Fa src | ||
85 | to the end of | ||
86 | .Fa dst . | ||
87 | It will append at most | ||
88 | .Fa size | ||
89 | \(mi wcslen(dst) \(mi 1 wide characters, terminating the result with a null | ||
90 | wide character. | ||
91 | .Sh RETURN VALUES | ||
92 | The | ||
93 | .Fn wcslcpy | ||
94 | and | ||
95 | .Fn wcslcat | ||
96 | functions return the total length of the wide string they tried to create. | ||
97 | For | ||
98 | .Fn wcslcpy | ||
99 | that means the length of | ||
100 | .Fa src . | ||
101 | For | ||
102 | .Fn wcslcat | ||
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 wcslcat | ||
113 | traverses | ||
114 | .Fa size | ||
115 | wide characters without finding a null wide character, the length of the | ||
116 | string is considered to be | ||
117 | .Fa size | ||
118 | and the destination wide string will not be terminated with a null wide | ||
119 | character (since there was no space for it). | ||
120 | This keeps | ||
121 | .Fn wcslcat | ||
122 | from running off the end of a wide 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 terminated with a null wide character). | ||
128 | The check exists to prevent potential security problems in incorrect code. | ||
129 | .Sh SEE ALSO | ||
130 | .Xr strlcpy 3 , | ||
131 | .Xr swprintf 3 , | ||
132 | .Xr wcsncat 3 , | ||
133 | .Xr wcsncpy 3 | ||
134 | .Sh HISTORY | ||
135 | The | ||
136 | .Fn wcslcpy | ||
137 | and | ||
138 | .Fn wcslcat | ||
139 | functions first appeared in | ||
140 | .Ox 3.8 . | ||
141 | .Sh AUTHORS | ||
142 | The | ||
143 | .Fn wcslcpy | ||
144 | and | ||
145 | .Fn wcslcat | ||
146 | functions are based on code by | ||
147 | .An Todd C. Miller Aq Todd.Miller@courtesan.com . | ||
diff --git a/src/lib/libc/string/wcslcpy.c b/src/lib/libc/string/wcslcpy.c new file mode 100644 index 0000000000..f49936a885 --- /dev/null +++ b/src/lib/libc/string/wcslcpy.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* $OpenBSD: wcslcpy.c,v 1.5 2011/07/24 15:21:28 millert Exp $ */ | ||
2 | /* $NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
6 | * | ||
7 | * Permission to use, copy, modify, and distribute this software for any | ||
8 | * purpose with or without fee is hereby granted, provided that the above | ||
9 | * copyright notice and this permission notice appear in all copies. | ||
10 | * | ||
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #include <sys/types.h> | ||
21 | #include <wchar.h> | ||
22 | |||
23 | /* | ||
24 | * Copy src to string dst of size siz. At most siz-1 characters | ||
25 | * will be copied. Always NUL terminates (unless siz == 0). | ||
26 | * Returns wcslen(src); if retval >= siz, truncation occurred. | ||
27 | */ | ||
28 | size_t | ||
29 | wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) | ||
30 | { | ||
31 | wchar_t *d = dst; | ||
32 | const wchar_t *s = src; | ||
33 | size_t n = siz; | ||
34 | |||
35 | /* Copy as many bytes as will fit */ | ||
36 | if (n != 0) { | ||
37 | while (--n != 0) { | ||
38 | if ((*d++ = *s++) == '\0') | ||
39 | break; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
44 | if (n == 0) { | ||
45 | if (siz != 0) | ||
46 | *d = '\0'; /* NUL-terminate dst */ | ||
47 | while (*s++) | ||
48 | ; | ||
49 | } | ||
50 | |||
51 | return(s - src - 1); /* count does not include NUL */ | ||
52 | } | ||
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/wcslen.3 index b13b3513e0..1b2eceab93 100644 --- a/src/lib/libc/string/rindex.3 +++ b/src/lib/libc/string/wcslen.3 | |||
@@ -1,8 +1,12 @@ | |||
1 | .\" $OpenBSD: wcslen.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" 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 and the American National Standards Committee X3, |
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | 10 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | 11 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | 12 | .\" are met: |
@@ -11,11 +15,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 15 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 16 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 17 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 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 |
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 | 19 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 20 | .\" without specific prior written permission. |
21 | .\" | 21 | .\" |
@@ -31,51 +31,40 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)rindex.3 5.2 (Berkeley) 4/19/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
35 | .\" $Id: rindex.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | 35 | .Dt WCSLEN 3 |
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt RINDEX 3 | ||
39 | .Os | 36 | .Os |
40 | .Sh NAME | 37 | .Sh NAME |
41 | .Nm rindex | 38 | .Nm wcslen |
42 | .Nd locate character in string | 39 | .Nd find length of a wide string |
43 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
44 | .Fd #include <string.h> | 41 | .Fd #include <wchar.h> |
45 | .Ft char * | 42 | .Ft size_t |
46 | .Fn rindex "const char *s" "int c" | 43 | .Fn wcslen "const wchar_t *s" |
47 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
48 | The | 45 | The |
49 | .Fn rindex | 46 | .Fn wcslen |
50 | function | 47 | function computes the length of the wide string |
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 . | 48 | .Fa s . |
58 | The character c is returned if it is found; otherwise NULL is returned. | 49 | .Sh RETURN VALUES |
59 | If | 50 | The |
60 | .Fa c | 51 | .Fn wcslen |
61 | is | 52 | function returns the number of wide characters that precede the terminating |
62 | .Ql \e0 , | 53 | null wide character. |
63 | .Fn rindex | ||
64 | locates the terminating | ||
65 | .Ql \e0 . | ||
66 | .Sh SEE ALSO | 54 | .Sh SEE ALSO |
67 | .Xr index 3 , | 55 | .Xr strlen 3 , |
68 | .Xr memchr 3 , | 56 | .Xr wcswidth 3 |
69 | .Xr strchr 3 , | 57 | .Sh STANDARDS |
70 | .Xr strcspn 3 , | 58 | The |
71 | .Xr strpbrk 3 , | 59 | .Fn wcslen |
72 | .Xr strrchr 3 , | 60 | function conforms to |
73 | .Xr strsep 3 , | 61 | .St -isoC-99 |
74 | .Xr strspn 3 , | 62 | and was first introduced in |
75 | .Xr strstr 3 , | 63 | .St -isoC-amd1 . |
76 | .Xr strtok 3 | ||
77 | .Sh HISTORY | 64 | .Sh HISTORY |
78 | A | 65 | The |
79 | .Fn rindex | 66 | .Fn wcslen |
80 | function appeared in | 67 | function was ported from |
81 | .At v6 . | 68 | .Nx |
69 | and first appeared in | ||
70 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcspbrk.3 new file mode 100644 index 0000000000..6589e83c83 --- /dev/null +++ b/src/lib/libc/string/wcspbrk.3 | |||
@@ -0,0 +1,81 @@ | |||
1 | .\" $OpenBSD: wcspbrk.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSPBRK 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcspbrk | ||
39 | .Nd locate multiple wide characters in a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wcspbrk "const wchar_t *s" "const wchar_t *charset" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcspbrk | ||
47 | function locates in the wide string | ||
48 | .Fa s | ||
49 | the first occurrence of any wide character in the wide string | ||
50 | .Fa charset | ||
51 | and returns a pointer to this wide character. | ||
52 | If no wide characters from | ||
53 | .Fa charset | ||
54 | occur anywhere in | ||
55 | .Fa s , | ||
56 | .Fn wcspbrk | ||
57 | returns | ||
58 | .Dv NULL . | ||
59 | .Sh SEE ALSO | ||
60 | .Xr strpbrk 3 , | ||
61 | .Xr wcschr 3 , | ||
62 | .Xr wcscspn 3 , | ||
63 | .Xr wcsrchr 3 , | ||
64 | .Xr wcsspn 3 , | ||
65 | .Xr wcsstr 3 , | ||
66 | .Xr wcstok 3 , | ||
67 | .Xr wmemchr 3 | ||
68 | .Sh STANDARDS | ||
69 | The | ||
70 | .Fn wcspbrk | ||
71 | function conforms to | ||
72 | .St -isoC-99 | ||
73 | and was first introduced in | ||
74 | .St -isoC-amd1 . | ||
75 | .Sh HISTORY | ||
76 | The | ||
77 | .Fn wcspbrk | ||
78 | function was ported from | ||
79 | .Nx | ||
80 | and first appeared in | ||
81 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcsrchr.3 new file mode 100644 index 0000000000..d65caa4292 --- /dev/null +++ b/src/lib/libc/string/wcsrchr.3 | |||
@@ -0,0 +1,85 @@ | |||
1 | .\" $OpenBSD: wcsrchr.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSRCHR 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcsrchr | ||
39 | .Nd locate last occurrence of a wide character in a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wcsrchr "const wchar_t *s" "wchar_t c" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcsrchr | ||
47 | function locates the last occurrence of the wide character | ||
48 | .Fa c | ||
49 | in the wide string | ||
50 | .Fa s . | ||
51 | The terminating null wide character is considered part of the wide string. | ||
52 | If | ||
53 | .Fa c | ||
54 | is the null wide character (L'\e0'), | ||
55 | .Fn wcsrchr | ||
56 | locates the terminating null wide character. | ||
57 | .Sh RETURN VALUES | ||
58 | The | ||
59 | .Fn wcsrchr | ||
60 | function returns a pointer to the located wide character or | ||
61 | .Dv NULL | ||
62 | if the wide character does not appear in the wide string. | ||
63 | .Sh SEE ALSO | ||
64 | .Xr strrchr 3 , | ||
65 | .Xr wcschr 3 , | ||
66 | .Xr wcscspn 3 , | ||
67 | .Xr wcspbrk 3 , | ||
68 | .Xr wcsspn 3 , | ||
69 | .Xr wcsstr 3 , | ||
70 | .Xr wcstok 3 , | ||
71 | .Xr wmemchr 3 | ||
72 | .Sh STANDARDS | ||
73 | The | ||
74 | .Fn wcsrchr | ||
75 | function conforms to | ||
76 | .St -isoC-99 | ||
77 | and was first introduced in | ||
78 | .St -isoC-amd1 . | ||
79 | .Sh HISTORY | ||
80 | The | ||
81 | .Fn wcsrchr | ||
82 | function was ported from | ||
83 | .Nx | ||
84 | and first appeared in | ||
85 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcsspn.3 new file mode 100644 index 0000000000..66505c59d1 --- /dev/null +++ b/src/lib/libc/string/wcsspn.3 | |||
@@ -0,0 +1,79 @@ | |||
1 | .\" $OpenBSD: wcsspn.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSSPN 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcsspn | ||
39 | .Nd span a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft size_t | ||
43 | .Fn wcsspn "const wchar_t *s" "const wchar_t *charset" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcsspn | ||
47 | function spans the initial part of the wide string | ||
48 | .Fa s | ||
49 | as long as the wide characters from | ||
50 | .Fa s | ||
51 | occur in the wide string | ||
52 | .Fa charset . | ||
53 | .Sh RETURN VALUES | ||
54 | The | ||
55 | .Fn wcsspn | ||
56 | function returns the number of wide characters spanned. | ||
57 | .Sh SEE ALSO | ||
58 | .Xr strspn 3 , | ||
59 | .Xr wcschr 3 , | ||
60 | .Xr wcscspn 3 , | ||
61 | .Xr wcspbrk 3 , | ||
62 | .Xr wcsrchr 3 , | ||
63 | .Xr wcsstr 3 , | ||
64 | .Xr wcstok 3 , | ||
65 | .Xr wmemchr 3 | ||
66 | .Sh STANDARDS | ||
67 | The | ||
68 | .Fn wcsspn | ||
69 | function conforms to | ||
70 | .St -isoC-99 | ||
71 | and was first introduced in | ||
72 | .St -isoC-amd1 . | ||
73 | .Sh HISTORY | ||
74 | The | ||
75 | .Fn wcsspn | ||
76 | function was ported from | ||
77 | .Nx | ||
78 | and first appeared in | ||
79 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wcsstr.3 new file mode 100644 index 0000000000..73f85c3504 --- /dev/null +++ b/src/lib/libc/string/wcsstr.3 | |||
@@ -0,0 +1,88 @@ | |||
1 | .\" $OpenBSD: wcsstr.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WCSSTR 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wcsstr | ||
39 | .Nd locate a wide substring in a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wcsstr "const wchar_t *big" "const wchar_t *little" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wcsstr | ||
47 | function locates the first occurrence of the wide string | ||
48 | .Fa little | ||
49 | in the wide string | ||
50 | .Fa big . | ||
51 | .Pp | ||
52 | If | ||
53 | .Fa little | ||
54 | is an empty wide string, | ||
55 | .Fa big | ||
56 | is returned; | ||
57 | if | ||
58 | .Fa little | ||
59 | occurs nowhere in | ||
60 | .Fa big , | ||
61 | .Dv NULL | ||
62 | is returned; | ||
63 | otherwise a pointer to the first wide character of the first occurrence of | ||
64 | .Fa little | ||
65 | is returned. | ||
66 | .Sh SEE ALSO | ||
67 | .Xr strstr 3 , | ||
68 | .Xr wcschr 3 , | ||
69 | .Xr wcscspn 3 , | ||
70 | .Xr wcspbrk 3 , | ||
71 | .Xr wcsrchr 3 , | ||
72 | .Xr wcsspn 3 , | ||
73 | .Xr wcstok 3 , | ||
74 | .Xr wmemchr 3 | ||
75 | .Sh STANDARDS | ||
76 | The | ||
77 | .Fn wcsstr | ||
78 | function conforms to | ||
79 | .St -isoC-99 | ||
80 | and was first introduced in | ||
81 | .St -isoC-amd1 . | ||
82 | .Sh HISTORY | ||
83 | The | ||
84 | .Fn wcsstr | ||
85 | function was ported from | ||
86 | .Nx | ||
87 | and first appeared in | ||
88 | .Ox 3.8 . | ||
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..33ba1318a1 --- /dev/null +++ b/src/lib/libc/string/wcstok.3 | |||
@@ -0,0 +1,151 @@ | |||
1 | .\" $OpenBSD: wcstok.3,v 1.7 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" $NetBSD: wcstok.3,v 1.3 2003/09/08 17:54:33 wiz Exp $ | ||
4 | .\" | ||
5 | .\" Copyright (c) 1998 Softweyr LLC. All rights reserved. | ||
6 | .\" | ||
7 | .\" strtok_r, from Berkeley strtok | ||
8 | .\" Oct 13, 1998 by Wes Peters <wes@softweyr.com> | ||
9 | .\" | ||
10 | .\" Copyright (c) 1988, 1991, 1993 | ||
11 | .\" The Regents of the University of California. All rights reserved. | ||
12 | .\" | ||
13 | .\" This code is derived from software contributed to Berkeley by | ||
14 | .\" the American National Standards Committee X3, on Information | ||
15 | .\" Processing Systems. | ||
16 | .\" | ||
17 | .\" Redistribution and use in source and binary forms, with or without | ||
18 | .\" modification, are permitted provided that the following conditions | ||
19 | .\" are met: | ||
20 | .\" | ||
21 | .\" 1. Redistributions of source code must retain the above copyright | ||
22 | .\" notices, this list of conditions and the following disclaimer. | ||
23 | .\" | ||
24 | .\" 2. Redistributions in binary form must reproduce the above | ||
25 | .\" copyright notices, this list of conditions and the following | ||
26 | .\" disclaimer in the documentation and/or other materials provided | ||
27 | .\" with the distribution. | ||
28 | .\" | ||
29 | .\" 3. All advertising materials mentioning features or use of this | ||
30 | .\" software must display the following acknowledgement: | ||
31 | .\" | ||
32 | .\" This product includes software developed by Softweyr LLC, the | ||
33 | .\" University of California, Berkeley, and its contributors. | ||
34 | .\" | ||
35 | .\" 4. Neither the name of Softweyr LLC, the University nor the names | ||
36 | .\" of its contributors may be used to endorse or promote products | ||
37 | .\" derived from this software without specific prior written | ||
38 | .\" permission. | ||
39 | .\" | ||
40 | .\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND | ||
41 | .\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
42 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
43 | .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
44 | .\" DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR | ||
45 | .\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
46 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
47 | .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
48 | .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
49 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
50 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
51 | .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
52 | .\" SUCH DAMAGE. | ||
53 | .\" | ||
54 | .\" Original version ID: | ||
55 | .\" FreeBSD: src/lib/libc/string/wcstok.3,v 1.4 2002/10/15 09:49:54 tjr Exp | ||
56 | .\" | ||
57 | .Dd $Mdocdate: July 25 2011 $ | ||
58 | .Dt WCSTOK 3 | ||
59 | .Os | ||
60 | .Sh NAME | ||
61 | .Nm wcstok | ||
62 | .Nd split wide-character string into tokens | ||
63 | .Sh SYNOPSIS | ||
64 | .In wchar.h | ||
65 | .Ft wchar_t * | ||
66 | .Fn wcstok "wchar_t * restrict str" "const wchar_t * restrict sep" "wchar_t ** restrict last" | ||
67 | .Sh DESCRIPTION | ||
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 | .Xr strtok_r 3 | ||
94 | function. | ||
95 | .Pp | ||
96 | Since | ||
97 | .Fn wcstok | ||
98 | modifies the string, | ||
99 | .Fa str | ||
100 | should not point to an area in the initialized data segment. | ||
101 | .Sh RETURN VALUES | ||
102 | The | ||
103 | .Fn wcstok | ||
104 | function | ||
105 | returns a pointer to the beginning of each subsequent token in the string, | ||
106 | after replacing the token itself with a NUL wide character (L'\e0'). | ||
107 | When no more tokens remain, a null pointer is returned. | ||
108 | .Sh EXAMPLES | ||
109 | The following code fragment splits a wide-character string on | ||
110 | .Tn ASCII | ||
111 | space, tab, and newline characters and writes the tokens to | ||
112 | standard output: | ||
113 | .Bd -literal -offset indent | ||
114 | const wchar_t *seps = L" \et\en"; | ||
115 | wchar_t *last, *tok, text[] = L" \enone\ettwo\et\etthree \en"; | ||
116 | |||
117 | for (tok = wcstok(text, seps, &last); tok != NULL; | ||
118 | tok = wcstok(NULL, seps, &last)) | ||
119 | wprintf(L"%ls\en", tok); | ||
120 | .Ed | ||
121 | .Sh SEE ALSO | ||
122 | .Xr strtok 3 , | ||
123 | .Xr wcschr 3 , | ||
124 | .Xr wcscspn 3 , | ||
125 | .Xr wcspbrk 3 , | ||
126 | .Xr wcsrchr 3 , | ||
127 | .Xr wcsspn 3 , | ||
128 | .Xr wcsstr 3 , | ||
129 | .Xr wmemchr 3 | ||
130 | .Sh STANDARDS | ||
131 | The | ||
132 | .Fn wcstok | ||
133 | function | ||
134 | conforms to | ||
135 | .St -isoC-99 . | ||
136 | .Sh HISTORY | ||
137 | The | ||
138 | .Fn wcstok | ||
139 | function was ported from | ||
140 | .Nx | ||
141 | and first appeared in | ||
142 | .Ox 3.8 . | ||
143 | .Pp | ||
144 | Some early implementations of | ||
145 | .Fn wcstok | ||
146 | omit the | ||
147 | context pointer argument, | ||
148 | .Fa last , | ||
149 | and maintain state across calls in a static variable like | ||
150 | .Xr strtok 3 | ||
151 | 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.3 b/src/lib/libc/string/wcswidth.3 new file mode 100644 index 0000000000..a2a5b2df86 --- /dev/null +++ b/src/lib/libc/string/wcswidth.3 | |||
@@ -0,0 +1,69 @@ | |||
1 | .\" $OpenBSD: wcswidth.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 2002 Tim J. Robbins | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" | ||
15 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | .\" SUCH DAMAGE. | ||
26 | .\" | ||
27 | .Dd $Mdocdate: July 25 2011 $ | ||
28 | .Dt WCSWIDTH 3 | ||
29 | .Os | ||
30 | .Sh NAME | ||
31 | .Nm wcswidth | ||
32 | .Nd number of column positions in wide-character string | ||
33 | .Sh SYNOPSIS | ||
34 | .In wchar.h | ||
35 | .Ft int | ||
36 | .Fn wcswidth "const wchar_t *pwcs" "size_t n" | ||
37 | .Sh DESCRIPTION | ||
38 | The | ||
39 | .Fn wcswidth | ||
40 | function determines the number of column positions required for the first | ||
41 | .Fa n | ||
42 | characters of | ||
43 | .Fa pwcs , | ||
44 | or until a null wide character (L'\e0') is encountered. | ||
45 | .Sh RETURN VALUES | ||
46 | The | ||
47 | .Fn wcswidth | ||
48 | function returns 0 if | ||
49 | .Fa pwcs | ||
50 | is an empty string (L""), | ||
51 | \-1 if a non-printing wide character is encountered, | ||
52 | otherwise it returns the number of column positions occupied. | ||
53 | .Sh SEE ALSO | ||
54 | .Xr iswprint 3 , | ||
55 | .Xr strlen 3 , | ||
56 | .Xr wcslen 3 , | ||
57 | .Xr wcwidth 3 | ||
58 | .Sh STANDARDS | ||
59 | The | ||
60 | .Fn wcswidth | ||
61 | function conforms to | ||
62 | .St -p1003.1-2001 . | ||
63 | .Sh HISTORY | ||
64 | The | ||
65 | .Fn wcswidth | ||
66 | function was ported from | ||
67 | .Nx | ||
68 | and first appeared in | ||
69 | .Ox 3.8 . | ||
diff --git a/src/lib/libc/string/wcswidth.c b/src/lib/libc/string/wcswidth.c new file mode 100644 index 0000000000..8ea1bdf6e6 --- /dev/null +++ b/src/lib/libc/string/wcswidth.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* $OpenBSD: wcswidth.c,v 1.4 2011/04/04 18:16:24 stsp 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, q; | ||
38 | |||
39 | w = 0; | ||
40 | while (n && *s) { | ||
41 | q = wcwidth(*s); | ||
42 | if (q == -1) | ||
43 | return (-1); | ||
44 | w += q; | ||
45 | s++; | ||
46 | n--; | ||
47 | } | ||
48 | |||
49 | return w; | ||
50 | } | ||
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/wmemchr.3 index 847b03628b..21df1aaa88 100644 --- a/src/lib/libc/string/index.3 +++ b/src/lib/libc/string/wmemchr.3 | |||
@@ -1,8 +1,12 @@ | |||
1 | .\" $OpenBSD: wmemchr.3,v 1.9 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | 4 | .\" 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 and the American National Standards Committee X3, |
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | 10 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | 11 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | 12 | .\" are met: |
@@ -11,11 +15,7 @@ | |||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 15 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | 16 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | 17 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 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 |
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 | 19 | .\" may be used to endorse or promote products derived from this software |
20 | .\" without specific prior written permission. | 20 | .\" without specific prior written permission. |
21 | .\" | 21 | .\" |
@@ -31,53 +31,51 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" from: @(#)index.3 5.3 (Berkeley) 4/19/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
35 | .\" $Id: index.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | 35 | .Dt WMEMCHR 3 |
36 | .\" | ||
37 | .Dd April 19, 1991 | ||
38 | .Dt INDEX 3 | ||
39 | .Os | 36 | .Os |
40 | .Sh NAME | 37 | .Sh NAME |
41 | .Nm index | 38 | .Nm wmemchr |
42 | .Nd locate character in string | 39 | .Nd locate wide character in wide string |
43 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
44 | .Fd #include <string.h> | 41 | .Fd #include <wchar.h> |
45 | .Ft char * | 42 | .Ft wchar_t * |
46 | .Fn index "const char *s" "int c" | 43 | .Fn wmemchr "const wchar_t *b" "wchar_t c" "size_t len" |
47 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
48 | The | 45 | The |
49 | .Fn index | 46 | .Fn wmemchr |
50 | function | 47 | function locates the first occurrence of |
51 | locates the first character matching | ||
52 | .Fa c | 48 | .Fa c |
53 | (converted to a | 49 | in wide string |
54 | .Em char ) | 50 | .Fa b . |
55 | in the null-terminated string | ||
56 | .Fa s . | ||
57 | .Sh RETURN VALUES | 51 | .Sh RETURN VALUES |
58 | The character | 52 | The |
59 | .Fa c | 53 | .Fn wmemchr |
60 | is returned if it is found; otherwise | 54 | function returns a pointer to the wide character located, or |
61 | .Dv NULL | 55 | .Dv NULL |
62 | is returned. | 56 | if no such wide character exists within |
63 | If | 57 | .Fa len |
64 | .Fa c | 58 | wide characters. |
65 | is '\e0', | ||
66 | .Fn index | ||
67 | locates the terminating '\e0'. | ||
68 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
69 | .Xr memchr 3 , | 60 | .Xr memchr 3 , |
70 | .Xr rindex 3 , | 61 | .Xr wcschr 3 , |
71 | .Xr strchr 3 , | 62 | .Xr wcscspn 3 , |
72 | .Xr strcspn 3 , | 63 | .Xr wcspbrk 3 , |
73 | .Xr strpbrk 3 , | 64 | .Xr wcsrchr 3 , |
74 | .Xr strrchr 3 , | 65 | .Xr wcsspn 3 , |
75 | .Xr strsep 3 , | 66 | .Xr wcsstr 3 , |
76 | .Xr strspn 3 , | 67 | .Xr wcstok 3 |
77 | .Xr strstr 3 , | 68 | .Sh STANDARDS |
78 | .Xr strtok 3 | 69 | The |
70 | .Fn wmemchr | ||
71 | function conforms to | ||
72 | .St -isoC-99 | ||
73 | and was first introduced in | ||
74 | .St -isoC-amd1 . | ||
79 | .Sh HISTORY | 75 | .Sh HISTORY |
80 | A | 76 | The |
81 | .Fn index | 77 | .Fn wmemchr |
82 | function appeared in | 78 | function was ported from |
83 | .At v6 . | 79 | .Nx |
80 | and first appeared in | ||
81 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wmemcmp.3 new file mode 100644 index 0000000000..6006b4e5c1 --- /dev/null +++ b/src/lib/libc/string/wmemcmp.3 | |||
@@ -0,0 +1,78 @@ | |||
1 | .\" $OpenBSD: wmemcmp.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WMEMCMP 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wmemcmp | ||
39 | .Nd compare wide strings | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft int | ||
43 | .Fn wmemcmp "const wchar_t *s1" "const wchar_t *s2" "size_t len" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wmemcmp | ||
47 | function compares the wide string | ||
48 | .Fa s1 | ||
49 | against the wide string | ||
50 | .Fa s2 . | ||
51 | Both wide strings are assumed to be | ||
52 | .Fa len | ||
53 | wide characters long. | ||
54 | .Sh RETURN VALUES | ||
55 | The | ||
56 | .Fn wmemcmp | ||
57 | function returns zero if the two wide strings are identical, | ||
58 | otherwise the difference between the first two differing wide characters is | ||
59 | returned. | ||
60 | Zero-length wide strings are always identical. | ||
61 | .Sh SEE ALSO | ||
62 | .Xr memcmp 3 , | ||
63 | .Xr wcscasecmp 3 , | ||
64 | .Xr wcscmp 3 | ||
65 | .Sh STANDARDS | ||
66 | The | ||
67 | .Fn wmemcmp | ||
68 | function conforms to | ||
69 | .St -isoC-99 | ||
70 | and was first introduced in | ||
71 | .St -isoC-amd1 . | ||
72 | .Sh HISTORY | ||
73 | The | ||
74 | .Fn wmemcmp | ||
75 | function was ported from | ||
76 | .Nx | ||
77 | and first appeared in | ||
78 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wmemcpy.3 new file mode 100644 index 0000000000..1102640ad4 --- /dev/null +++ b/src/lib/libc/string/wmemcpy.3 | |||
@@ -0,0 +1,85 @@ | |||
1 | .\" $OpenBSD: wmemcpy.3,v 1.3 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WMEMCPY 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wmemcpy | ||
39 | .Nd copy wide characters | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wmemcpy "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t len" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wmemcpy | ||
47 | function copies | ||
48 | .Fa len | ||
49 | wide characters from buffer | ||
50 | .Fa src | ||
51 | to buffer | ||
52 | .Fa dst . | ||
53 | .Sh RETURN VALUES | ||
54 | The | ||
55 | .Fn wmemcpy | ||
56 | function returns the original value of | ||
57 | .Fa dst . | ||
58 | .Sh SEE ALSO | ||
59 | .Xr memcpy 3 , | ||
60 | .Xr wcscpy 3 , | ||
61 | .Xr wcslcpy 3 , | ||
62 | .Xr wmemmove 3 | ||
63 | .Sh STANDARDS | ||
64 | The | ||
65 | .Fn wmemcpy | ||
66 | function conforms to | ||
67 | .St -isoC-99 | ||
68 | and was first introduced in | ||
69 | .St -isoC-amd1 . | ||
70 | .Sh HISTORY | ||
71 | The | ||
72 | .Fn wmemcpy | ||
73 | function was ported from | ||
74 | .Nx | ||
75 | and first appeared in | ||
76 | .Ox 3.8 . | ||
77 | .Sh CAVEATS | ||
78 | In this implementation | ||
79 | .Fn wmemcpy | ||
80 | is implemented using | ||
81 | .Xr bcopy 3 , | ||
82 | and therefore the buffers may overlap. | ||
83 | On other systems, copying overlapping buffers may produce surprises. | ||
84 | A portable, safe solution is to use | ||
85 | .Xr wmemmove 3 . | ||
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.3 b/src/lib/libc/string/wmemmove.3 new file mode 100644 index 0000000000..45daa854ba --- /dev/null +++ b/src/lib/libc/string/wmemmove.3 | |||
@@ -0,0 +1,78 @@ | |||
1 | .\" $OpenBSD: wmemmove.3,v 1.2 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WMEMMOVE 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wmemmove | ||
39 | .Nd copy wide characters | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wmemmove "wchar_t *dst" "const wchar_t *src" "size_t len" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wmemmove | ||
47 | function copies | ||
48 | .Fa len | ||
49 | wide characters from buffer | ||
50 | .Fa src | ||
51 | to buffer | ||
52 | .Fa dst . | ||
53 | The two buffers may overlap; | ||
54 | the copy is always done in a non-destructive manner. | ||
55 | .Sh RETURN VALUES | ||
56 | The | ||
57 | .Fn wmemmove | ||
58 | function returns the original value of | ||
59 | .Fa dst . | ||
60 | .Sh SEE ALSO | ||
61 | .Xr memmove 3 , | ||
62 | .Xr wcscpy 3 , | ||
63 | .Xr wcslcpy 3 , | ||
64 | .Xr wmemcpy 3 | ||
65 | .Sh STANDARDS | ||
66 | The | ||
67 | .Fn wmemmove | ||
68 | function conforms to | ||
69 | .St -isoC-99 | ||
70 | and was first introduced in | ||
71 | .St -isoC-amd1 . | ||
72 | .Sh HISTORY | ||
73 | The | ||
74 | .Fn wmemmove | ||
75 | function was ported from | ||
76 | .Nx | ||
77 | and first appeared in | ||
78 | .Ox 3.8 . | ||
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.3 b/src/lib/libc/string/wmemset.3 new file mode 100644 index 0000000000..1b840762ec --- /dev/null +++ b/src/lib/libc/string/wmemset.3 | |||
@@ -0,0 +1,73 @@ | |||
1 | .\" $OpenBSD: wmemset.3,v 1.3 2011/07/25 00:38:53 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: July 25 2011 $ | ||
35 | .Dt WMEMSET 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm wmemset | ||
39 | .Nd write a wide string | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <wchar.h> | ||
42 | .Ft wchar_t * | ||
43 | .Fn wmemset "wchar_t *s" "wchar_t c" "size_t len" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn wmemset | ||
47 | function writes | ||
48 | .Fa len | ||
49 | wide characters of value | ||
50 | .Fa c | ||
51 | to the wide string | ||
52 | .Fa s . | ||
53 | .Sh RETURN VALUES | ||
54 | The | ||
55 | .Fn wmemset | ||
56 | function returns the original value of | ||
57 | .Fa s . | ||
58 | .Sh SEE ALSO | ||
59 | .Xr memset 3 | ||
60 | .Sh STANDARDS | ||
61 | The | ||
62 | .Fn wmemset | ||
63 | function conforms to | ||
64 | .St -isoC-99 | ||
65 | and was first introduced in | ||
66 | .St -isoC-amd1 . | ||
67 | .Sh HISTORY | ||
68 | The | ||
69 | .Fn wmemset | ||
70 | function was ported from | ||
71 | .Nx | ||
72 | and first appeared in | ||
73 | .Ox 3.8 . | ||
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 | } | ||