diff options
Diffstat (limited to 'src/lib/libc/string')
76 files changed, 1401 insertions, 1768 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 2b7ce63a63..26e2bc10f2 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
| @@ -1,23 +1,22 @@ | |||
| 1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 | 1 | # $OpenBSD: Makefile.inc,v 1.12 2003/02/20 03:20:09 deraadt Exp $ |
| 2 | # $Id: Makefile.inc,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
| 3 | 2 | ||
| 4 | # string sources | 3 | # string sources |
| 5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string |
| 6 | 5 | ||
| 7 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | 6 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ |
| 8 | strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strerror_r.c strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ |
| 9 | __strerror.c __strsignal.c | 8 | __strerror.c __strsignal.c |
| 10 | 9 | ||
| 11 | # machine-dependent net sources | 10 | # machine-dependent net sources |
| 12 | # m-d Makefile.inc must include sources for: | 11 | # m-d Makefile.inc must include sources for: |
| 13 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() | 12 | # bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() |
| 14 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() | 13 | # rindex() strcat() strcmp() strcpy() strcspn() strlen() strlcpy() |
| 15 | # strncat() strncmp() strncpy() strpbrk() strsep() | 14 | # strncat() strncmp() strncpy() strpbrk() strsep() |
| 16 | # strspn() strstr() swav() | 15 | # strspn() strstr() swav() |
| 17 | # m-d Makefile.inc may include sources for: | 16 | # m-d Makefile.inc may include sources for: |
| 18 | # memcpy() memmove() strchr() strrchr() | 17 | # memcpy() memmove() strchr() strrchr() |
| 19 | 18 | ||
| 20 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" | 19 | .include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string/Makefile.inc" |
| 21 | 20 | ||
| 22 | # if no machine specific memmove(3), build one out of bcopy(3). | 21 | # if no machine specific memmove(3), build one out of bcopy(3). |
| 23 | .if empty(SRCS:Mmemmove.S) | 22 | .if empty(SRCS:Mmemmove.S) |
| @@ -27,6 +26,11 @@ memmove.o: bcopy.c | |||
| 27 | @${LD} -x -r ${.TARGET} | 26 | @${LD} -x -r ${.TARGET} |
| 28 | @mv a.out ${.TARGET} | 27 | @mv a.out ${.TARGET} |
| 29 | 28 | ||
| 29 | memmove.go: bcopy.c | ||
| 30 | ${CC} -g -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
| 31 | @${LD} -x -r ${.TARGET} | ||
| 32 | @mv a.out ${.TARGET} | ||
| 33 | |||
| 30 | memmove.po: bcopy.c | 34 | memmove.po: bcopy.c |
| 31 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 35 | ${CC} -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
| 32 | @${LD} -X -r ${.TARGET} | 36 | @${LD} -X -r ${.TARGET} |
| @@ -48,6 +52,11 @@ memcpy.o: bcopy.c | |||
| 48 | @${LD} -x -r ${.TARGET} | 52 | @${LD} -x -r ${.TARGET} |
| 49 | @mv a.out ${.TARGET} | 53 | @mv a.out ${.TARGET} |
| 50 | 54 | ||
| 55 | memcpy.go: bcopy.c | ||
| 56 | ${CC} -g -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
| 57 | @${LD} -x -r ${.TARGET} | ||
| 58 | @mv a.out ${.TARGET} | ||
| 59 | |||
| 51 | memcpy.po: bcopy.c | 60 | memcpy.po: bcopy.c |
| 52 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 61 | ${CC} -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
| 53 | @${LD} -X -r ${.TARGET} | 62 | @${LD} -X -r ${.TARGET} |
| @@ -67,6 +76,11 @@ strchr.o: index.c | |||
| 67 | @${LD} -x -r ${.TARGET} | 76 | @${LD} -x -r ${.TARGET} |
| 68 | @mv a.out ${.TARGET} | 77 | @mv a.out ${.TARGET} |
| 69 | 78 | ||
| 79 | strchr.go: index.c | ||
| 80 | ${CC} -g -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
| 81 | @${LD} -x -r ${.TARGET} | ||
| 82 | @mv a.out ${.TARGET} | ||
| 83 | |||
| 70 | strchr.po: index.c | 84 | strchr.po: index.c |
| 71 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 85 | ${CC} -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
| 72 | @${LD} -X -r ${.TARGET} | 86 | @${LD} -X -r ${.TARGET} |
| @@ -85,6 +99,11 @@ strrchr.o: rindex.c | |||
| 85 | @${LD} -x -r ${.TARGET} | 99 | @${LD} -x -r ${.TARGET} |
| 86 | @mv a.out ${.TARGET} | 100 | @mv a.out ${.TARGET} |
| 87 | 101 | ||
| 102 | strrchr.go: rindex.c | ||
| 103 | ${CC} -g -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET} | ||
| 104 | @${LD} -x -r ${.TARGET} | ||
| 105 | @mv a.out ${.TARGET} | ||
| 106 | |||
| 88 | strrchr.po: rindex.c | 107 | strrchr.po: rindex.c |
| 89 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} | 108 | ${CC} -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} |
| 90 | @${LD} -X -r ${.TARGET} | 109 | @${LD} -X -r ${.TARGET} |
| @@ -95,14 +114,39 @@ strrchr.so: rindex.c | |||
| 95 | -o ${.TARGET} | 114 | -o ${.TARGET} |
| 96 | .endif | 115 | .endif |
| 97 | 116 | ||
| 98 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \ | 117 | # build .ln files for memmove, memcpy, strchr and strrchr always from |
| 99 | memcmp.3 memcpy.3 memmove.3 memset.3 rindex.3 strcasecmp.3 strcat.3 \ | 118 | # bcopy, index, and rindex |
| 100 | strchr.3 strcmp.3 strcoll.3 strcpy.3 strcspn.3 strerror.3 strftime.3 \ | 119 | LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln |
| 120 | |||
| 121 | memmove.ln: bcopy.c | ||
| 122 | lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
| 123 | ${LIBCSRCDIR}/string/bcopy.c | ||
| 124 | |||
| 125 | memcpy.ln: bcopy.c | ||
| 126 | lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
| 127 | ${LIBCSRCDIR}/string/bcopy.c | ||
| 128 | |||
| 129 | strchr.ln: index.c | ||
| 130 | lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
| 131 | ${LIBCSRCDIR}/string/index.c | ||
| 132 | |||
| 133 | strrchr.ln: rindex.c | ||
| 134 | lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \ | ||
| 135 | ${LIBCSRCDIR}/string/rindex.c | ||
| 136 | |||
| 137 | MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 memccpy.3 memchr.3 \ | ||
| 138 | memcmp.3 memcpy.3 memmove.3 memset.3 strcasecmp.3 strcat.3 \ | ||
| 139 | 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 \ | 140 | 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 | 141 | strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 strlcpy.3 |
| 103 | 142 | ||
| 104 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 | 143 | MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 |
| 144 | MLINKS+=strchr.3 index.3 | ||
| 145 | MLINKS+=strrchr.3 rindex.3 | ||
| 105 | MLINKS+=strcasecmp.3 strncasecmp.3 | 146 | MLINKS+=strcasecmp.3 strncasecmp.3 |
| 106 | MLINKS+=strcat.3 strncat.3 | 147 | MLINKS+=strcat.3 strncat.3 |
| 107 | MLINKS+=strcmp.3 strncmp.3 | 148 | MLINKS+=strcmp.3 strncmp.3 |
| 108 | MLINKS+=strcpy.3 strncpy.3 | 149 | MLINKS+=strcpy.3 strncpy.3 |
| 150 | MLINKS+=strlcpy.3 strlcat.3 | ||
| 151 | MLINKS+=strtok.3 strtok_r.3 | ||
| 152 | MLINKS+=strerror.3 strerror_r.3 | ||
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c index cd604906db..15436eaab2 100644 --- a/src/lib/libc/string/__strerror.c +++ b/src/lib/libc/string/__strerror.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 | * |
| @@ -32,8 +28,7 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: __strerror.c,v 1.10 2003/06/02 20:18:38 millert Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #ifdef NLS | 34 | #ifdef NLS |
| @@ -46,9 +41,27 @@ static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Ex | |||
| 46 | #define sys_errlist _sys_errlist | 41 | #define sys_errlist _sys_errlist |
| 47 | #define sys_nerr _sys_nerr | 42 | #define sys_nerr _sys_nerr |
| 48 | 43 | ||
| 44 | #include <errno.h> | ||
| 45 | #include <limits.h> | ||
| 49 | #include <stdio.h> | 46 | #include <stdio.h> |
| 50 | #include <string.h> | 47 | #include <string.h> |
| 51 | 48 | ||
| 49 | static char * | ||
| 50 | itoa(num) | ||
| 51 | int num; | ||
| 52 | { | ||
| 53 | static char buffer[11]; | ||
| 54 | char *p; | ||
| 55 | |||
| 56 | p = buffer + 4; | ||
| 57 | while (num >= 10) { | ||
| 58 | *--p = (num % 10) + '0'; | ||
| 59 | num /= 10; | ||
| 60 | } | ||
| 61 | *p = (num % 10) + '0'; | ||
| 62 | return p; | ||
| 63 | } | ||
| 64 | |||
| 52 | /* | 65 | /* |
| 53 | * Since perror() is not allowed to change the contents of strerror()'s | 66 | * Since perror() is not allowed to change the contents of strerror()'s |
| 54 | * static buffer, both functions supply their own buffers to the | 67 | * static buffer, both functions supply their own buffers to the |
| @@ -60,32 +73,37 @@ __strerror(num, buf) | |||
| 60 | int num; | 73 | int num; |
| 61 | char *buf; | 74 | char *buf; |
| 62 | { | 75 | { |
| 63 | #define UPREFIX "Unknown error: %u" | 76 | #define UPREFIX "Unknown error: " |
| 64 | register unsigned int errnum; | 77 | register unsigned int errnum; |
| 65 | |||
| 66 | #ifdef NLS | 78 | #ifdef NLS |
| 67 | nl_catd catd ; | 79 | int save_errno; |
| 80 | nl_catd catd; | ||
| 81 | |||
| 68 | catd = catopen("libc", 0); | 82 | catd = catopen("libc", 0); |
| 69 | #endif | 83 | #endif |
| 70 | 84 | ||
| 71 | errnum = num; /* convert to unsigned */ | 85 | errnum = num; /* convert to unsigned */ |
| 72 | if (errnum < sys_nerr) { | 86 | if (errnum < sys_nerr) { |
| 73 | #ifdef NLS | 87 | #ifdef NLS |
| 74 | strcpy(buf, catgets(catd, 1, errnum, | 88 | strlcpy(buf, catgets(catd, 1, errnum, |
| 75 | (char *)sys_errlist[errnum])); | 89 | (char *)sys_errlist[errnum]), NL_TEXTMAX); |
| 76 | #else | 90 | #else |
| 77 | return(sys_errlist[errnum]); | 91 | return(sys_errlist[errnum]); |
| 78 | #endif | 92 | #endif |
| 79 | } else { | 93 | } else { |
| 80 | #ifdef NLS | 94 | #ifdef NLS |
| 81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | 95 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
| 82 | #else | 96 | #else |
| 83 | sprintf(buf, UPREFIX, errnum); | 97 | strlcpy(buf, UPREFIX, NL_TEXTMAX); |
| 84 | #endif | 98 | #endif |
| 99 | strlcat(buf, itoa(errnum), NL_TEXTMAX); | ||
| 100 | errno = EINVAL; | ||
| 85 | } | 101 | } |
| 86 | 102 | ||
| 87 | #ifdef NLS | 103 | #ifdef NLS |
| 104 | save_errno = errno; | ||
| 88 | catclose(catd); | 105 | catclose(catd); |
| 106 | errno = save_errno; | ||
| 89 | #endif | 107 | #endif |
| 90 | 108 | ||
| 91 | return buf; | 109 | return buf; |
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c index 1937e2d608..5bab3cd0af 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 | * |
| @@ -32,8 +28,7 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: __strsignal.c,v 1.8 2003/06/02 20:18:38 millert Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #ifdef NLS | 34 | #ifdef NLS |
| @@ -46,15 +41,31 @@ static char *rcsid = "$Id: __strsignal.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt E | |||
| 46 | #define sys_siglist _sys_siglist | 41 | #define sys_siglist _sys_siglist |
| 47 | 42 | ||
| 48 | #include <stdio.h> | 43 | #include <stdio.h> |
| 44 | #include <limits.h> | ||
| 49 | #include <signal.h> | 45 | #include <signal.h> |
| 50 | #include <string.h> | 46 | #include <string.h> |
| 51 | 47 | ||
| 48 | static char *itoa(num) | ||
| 49 | int num; | ||
| 50 | { | ||
| 51 | static char buffer[11]; | ||
| 52 | char *p; | ||
| 53 | |||
| 54 | p = buffer + 4; | ||
| 55 | while (num >= 10) { | ||
| 56 | *--p = (num % 10) + '0'; | ||
| 57 | num /= 10; | ||
| 58 | } | ||
| 59 | *p = (num % 10) + '0'; | ||
| 60 | return p; | ||
| 61 | } | ||
| 62 | |||
| 52 | char * | 63 | char * |
| 53 | __strsignal(num, buf) | 64 | __strsignal(num, buf) |
| 54 | int num; | 65 | int num; |
| 55 | char *buf; | 66 | char *buf; |
| 56 | { | 67 | { |
| 57 | #define UPREFIX "Unknown signal: %u" | 68 | #define UPREFIX "Unknown signal: " |
| 58 | register unsigned int signum; | 69 | register unsigned int signum; |
| 59 | 70 | ||
| 60 | #ifdef NLS | 71 | #ifdef NLS |
| @@ -65,17 +76,18 @@ __strsignal(num, buf) | |||
| 65 | signum = num; /* convert to unsigned */ | 76 | signum = num; /* convert to unsigned */ |
| 66 | if (signum < NSIG) { | 77 | if (signum < NSIG) { |
| 67 | #ifdef NLS | 78 | #ifdef NLS |
| 68 | strcpy(buf, catgets(catd, 2, signum, | 79 | strlcpy(buf, catgets(catd, 2, signum, |
| 69 | (char *)sys_siglist[signum])); | 80 | (char *)sys_siglist[signum]), NL_TEXTMAX); |
| 70 | #else | 81 | #else |
| 71 | return((char *)sys_siglist[signum]); | 82 | return((char *)sys_siglist[signum]); |
| 72 | #endif | 83 | #endif |
| 73 | } else { | 84 | } else { |
| 74 | #ifdef NLS | 85 | #ifdef NLS |
| 75 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); | 86 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
| 76 | #else | 87 | #else |
| 77 | sprintf(buf, UPREFIX, signum); | 88 | strlcpy(buf, UPREFIX, NL_TEXTMAX); |
| 78 | #endif | 89 | #endif |
| 90 | strlcat(buf, itoa(signum), NL_TEXTMAX); | ||
| 79 | } | 91 | } |
| 80 | 92 | ||
| 81 | #ifdef NLS | 93 | #ifdef NLS |
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3 index 118c55c579..953476caa7 100644 --- a/src/lib/libc/string/bcmp.3 +++ b/src/lib/libc/string/bcmp.3 | |||
| @@ -11,11 +11,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 21 | .\" | 17 | .\" |
| @@ -31,12 +27,11 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 33 | .\" | 29 | .\" |
| 34 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: bcmp.3,v 1.6 2003/06/02 20:18:38 millert 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 April 19, 1991 |
| 38 | .Dt BCMP 3 | 33 | .Dt BCMP 3 |
| 39 | .Os BSD 4.2 | 34 | .Os |
| 40 | .Sh NAME | 35 | .Sh NAME |
| 41 | .Nm bcmp | 36 | .Nm bcmp |
| 42 | .Nd compare byte string | 37 | .Nd compare byte string |
| @@ -47,8 +42,7 @@ | |||
| 47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
| 48 | The | 43 | The |
| 49 | .Fn bcmp | 44 | .Fn bcmp |
| 50 | function | 45 | function compares byte string |
| 51 | compares byte string | ||
| 52 | .Fa b1 | 46 | .Fa b1 |
| 53 | against byte string | 47 | against byte string |
| 54 | .Fa b2 , | 48 | .Fa b2 , |
| @@ -68,5 +62,5 @@ The strings may overlap. | |||
| 68 | .Sh HISTORY | 62 | .Sh HISTORY |
| 69 | A | 63 | A |
| 70 | .Fn bcmp | 64 | .Fn bcmp |
| 71 | function first appeared in | 65 | function first appeared in |
| 72 | .Bx 4.2 . | 66 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c index 2cc38baee3..2beeef8298 100644 --- a/src/lib/libc/string/bcmp.c +++ b/src/lib/libc/string/bcmp.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 | * |
| @@ -32,15 +28,19 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)bcmp.c 5.6 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: bcmp.c,v 1.5 2003/06/02 20:18:38 millert Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 34 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 35 | #include <string.h> |
| 36 | #else | ||
| 37 | #include <lib/libkern/libkern.h> | ||
| 38 | #endif | ||
| 40 | 39 | ||
| 41 | /* | 40 | /* |
| 42 | * bcmp -- vax cmpc3 instruction | 41 | * bcmp -- vax cmpc3 instruction |
| 43 | */ | 42 | */ |
| 43 | int | ||
| 44 | bcmp(b1, b2, length) | 44 | bcmp(b1, b2, length) |
| 45 | const void *b1, *b2; | 45 | const void *b1, *b2; |
| 46 | register size_t length; | 46 | register size_t length; |
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3 index 6db3812caf..7b55bcbf43 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.8 2003/06/21 12:04:01 avsm 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 April 19, 1991 |
| 39 | .Dt BCOPY 3 | 34 | .Dt BCOPY 3 |
| 40 | .Os BSD 4.2 | 35 | .Os |
| 41 | .Sh NAME | 36 | .Sh NAME |
| 42 | .Nm bcopy | 37 | .Nm bcopy |
| 43 | .Nd copy byte string | 38 | .Nd copy bytes |
| 44 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
| 45 | .Fd #include <string.h> | 40 | .Fd #include <string.h> |
| 46 | .Ft void | 41 | .Ft void |
| @@ -48,14 +43,13 @@ | |||
| 48 | .Sh DESCRIPTION | 43 | .Sh DESCRIPTION |
| 49 | The | 44 | The |
| 50 | .Fn bcopy | 45 | .Fn bcopy |
| 51 | function | 46 | function copies |
| 52 | copies | ||
| 53 | .Fa len | 47 | .Fa len |
| 54 | bytes from string | 48 | bytes from buffer |
| 55 | .Fa src | 49 | .Fa src |
| 56 | to string | 50 | to buffer |
| 57 | .Fa dst . | 51 | .Fa dst . |
| 58 | The two strings may overlap. | 52 | The two buffers may overlap. |
| 59 | If | 53 | If |
| 60 | .Fa len | 54 | .Fa len |
| 61 | is zero, no bytes are copied. | 55 | is zero, no bytes are copied. |
| @@ -64,9 +58,10 @@ is zero, no bytes are copied. | |||
| 64 | .Xr memcpy 3 , | 58 | .Xr memcpy 3 , |
| 65 | .Xr memmove 3 , | 59 | .Xr memmove 3 , |
| 66 | .Xr strcpy 3 , | 60 | .Xr strcpy 3 , |
| 61 | .Xr strlcpy 3 , | ||
| 67 | .Xr strncpy 3 | 62 | .Xr strncpy 3 |
| 68 | .Sh HISTORY | 63 | .Sh HISTORY |
| 69 | A | 64 | A |
| 70 | .Fn bcopy | 65 | .Fn bcopy |
| 71 | function appeared in | 66 | function appeared in |
| 72 | .Bx 4.2 . | 67 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c index 92feed66ea..c48faa145e 100644 --- a/src/lib/libc/string/bcopy.c +++ b/src/lib/libc/string/bcopy.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)bcopy.c 5.11 (Berkeley) 6/21/91";*/ | 34 | static char *rcsid = "$OpenBSD: bcopy.c,v 1.3 2003/06/02 20:18:38 millert Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 index 2264a6a1c4..772b0d372e 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,84 @@ | |||
| 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.7 2003/06/02 20:18:38 millert 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 June 29, 1999 |
| 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 "u_char *pattern" "size_t patlen" "u_char freq[256]" |
| 51 | u_char * | 46 | .Ft u_char * |
| 52 | .br | 47 | .Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len" |
| 53 | bm_exec(bm_pat *pdesc, u_char *text, size_t len); | 48 | .Ft void |
| 54 | .sp | 49 | .Fn bm_free "bm_pat *pdesc" |
| 55 | void | 50 | .Sh DESCRIPTION |
| 56 | .br | ||
| 57 | bm_free(bm_pat *pdesc); | ||
| 58 | .SH DESCRIPTION | ||
| 59 | These routines implement an efficient mechanism to find an | 51 | These routines implement an efficient mechanism to find an |
| 60 | occurrence of a byte string within another byte string. | 52 | occurrence of a byte string within another byte string. |
| 61 | .PP | 53 | .Pp |
| 62 | .I Bm_comp | 54 | .Fn bm_comp |
| 63 | evaluates the | 55 | evaluates |
| 64 | .I patlen | 56 | .Fa patlen |
| 65 | bytes starting at | 57 | bytes starting at |
| 66 | .IR pattern , | 58 | .Fa pattern |
| 67 | and returns a pointer to a structure describing them. | 59 | and returns a pointer to a structure describing them. |
| 68 | The bytes referenced by | 60 | The bytes referenced by |
| 69 | .I pattern | 61 | .Fa pattern |
| 70 | may be of any value. | 62 | may be of any value. |
| 71 | .PP | 63 | .Pp |
| 72 | The search takes advantage of the frequency distribution of the | 64 | The search takes advantage of the frequency distribution of the |
| 73 | bytes in the text to be searched. | 65 | bytes in the text to be searched. |
| 74 | If specified, | 66 | If specified, |
| 75 | .I freq | 67 | .Ar freq |
| 76 | should be an array of 256 values, | 68 | should be an array of 256 values, |
| 77 | with higher values indicating that the corresponding character occurs | 69 | with higher values indicating that the corresponding character occurs |
| 78 | more frequently. | 70 | more frequently. |
| 79 | (A less than optimal frequency distribution can only result in less | 71 | (A less than optimal frequency distribution can only result in less |
| 80 | than optimal performance, not incorrect results.) | 72 | than optimal performance, not incorrect results.) |
| 81 | If | 73 | If |
| 82 | .I freq | 74 | .Ar freq |
| 83 | is NULL, | 75 | is |
| 76 | .Dv NULL , | ||
| 84 | a system default table is used. | 77 | a system default table is used. |
| 85 | .PP | 78 | .Pp |
| 86 | .I Bm_exec | 79 | .Fn bm_exec |
| 87 | returns a pointer to the leftmost occurrence of the string given to | 80 | returns a pointer to the leftmost occurrence of the string given to |
| 88 | .I bm_comp | 81 | .Fn bm_comp |
| 89 | within | 82 | within |
| 90 | .IR text , | 83 | .Ar text , |
| 91 | or NULL if none occurs. | 84 | or |
| 85 | .Dv NULL | ||
| 86 | if none occurs. | ||
| 92 | The number of bytes in | 87 | The number of bytes in |
| 93 | .I text | 88 | .Ar text |
| 94 | must be specified by | 89 | must be specified by |
| 95 | .IR len . | 90 | .Ar len . |
| 96 | .PP | 91 | .Pp |
| 97 | Space allocated for the returned description is discarded | 92 | Space allocated for the returned description is discarded |
| 98 | by calling | 93 | by calling |
| 99 | .I bm_free | 94 | .Fn bm_free |
| 100 | with the returned description as an argument. | 95 | with the returned description as an argument. |
| 101 | .PP | 96 | .Pp |
| 102 | The asymptotic speed of | 97 | The asymptotic speed of |
| 103 | .I bm_exec | 98 | .Fn bm_exec |
| 104 | is | 99 | is |
| 105 | .RI O( len / patlen ). | 100 | .Pf O Ns Pq len / patlen . |
| 106 | .PP | 101 | .Sh SEE ALSO |
| 107 | .SH "SEE ALSO" | 102 | .Xr regexp 3 , |
| 108 | .IR regexp (3), | 103 | .Xr strstr 3 |
| 109 | .IR strstr (3) | 104 | .Rs |
| 110 | .sp | 105 | .%R "Fast String Searching" |
| 111 | .IR "Fast String Searching" , | 106 | .%A Andrew Hume |
| 112 | Hume and Sunday, | 107 | .%A Daniel Sunday |
| 113 | Software Practice and Experience, | 108 | .%J "Software Practice and Experience" |
| 114 | Vol. 21, 11 (November 1991) pp. 1221-48. | 109 | .%V Volume 21, 11 (November 1991) |
| 110 | .%P 1221-48 | ||
| 111 | .Re | ||
diff --git a/src/lib/libc/string/bm.c b/src/lib/libc/string/bm.c index 68eac22ecc..2c7f8fac32 100644 --- a/src/lib/libc/string/bm.c +++ b/src/lib/libc/string/bm.c | |||
| @@ -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 | * |
| @@ -34,10 +30,9 @@ | |||
| 34 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. |
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #ifndef lint | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /* from: static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94"; */ | 34 | static char *rcsid = "$OpenBSD: bm.c,v 1.4 2003/06/02 20:18:38 millert Exp $"; |
| 39 | static char *rcsid = "$Id: bm.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | 35 | #endif /* LIBC_SCCS and not lint */ |
| 40 | #endif /* not lint */ | ||
| 41 | 36 | ||
| 42 | #include <sys/types.h> | 37 | #include <sys/types.h> |
| 43 | 38 | ||
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3 index 12fcfb0cc1..d33a3c1e79 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.6 2004/02/10 14:35:35 jmc Exp $ |
| 35 | .\" $Id: bstring.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | 31 | .\" |
| 37 | .Dd April 19, 1991 | 32 | .Dd April 19, 1991 |
| 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> |
| @@ -97,14 +84,15 @@ and | |||
| 97 | conform to | 84 | conform to |
| 98 | .St -ansiC . | 85 | .St -ansiC . |
| 99 | .Sh HISTORY | 86 | .Sh HISTORY |
| 100 | The functions | 87 | The |
| 101 | .Fn bzero | 88 | .Fn bzero |
| 102 | and | 89 | and |
| 103 | .Fn memccpy | 90 | .Fn memccpy |
| 104 | appeared in | 91 | functions appeared in |
| 105 | .Bx 4.3 ; | 92 | .Bx 4.3 . |
| 106 | the functions | 93 | The |
| 107 | .Fn bcmp , | 94 | .Fn bcmp |
| 108 | .Fn bcopy , | 95 | and |
| 109 | appeared in | 96 | .Fn bcopy |
| 97 | functions appeared in | ||
| 110 | .Bx 4.2 . | 98 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3 index 4f0141e051..592d9f2f08 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.6 2003/06/02 20:18:38 millert 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 April 19, 1991 |
| 38 | .Dt BZERO 3 | 33 | .Dt BZERO 3 |
| 39 | .Os BSD 4.3 | 34 | .Os |
| 40 | .Sh NAME | 35 | .Sh NAME |
| 41 | .Nm bzero | 36 | .Nm bzero |
| 42 | .Nd write zeroes to a byte string | 37 | .Nd write zeroes to a byte string |
| @@ -47,8 +42,7 @@ | |||
| 47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
| 48 | The | 43 | The |
| 49 | .Fn bzero | 44 | .Fn bzero |
| 50 | function | 45 | function writes |
| 51 | writes | ||
| 52 | .Fa len | 46 | .Fa len |
| 53 | zero bytes to the string | 47 | zero bytes to the string |
| 54 | .Fa b . | 48 | .Fa b . |
| @@ -63,6 +57,5 @@ does nothing. | |||
| 63 | .Sh HISTORY | 57 | .Sh HISTORY |
| 64 | A | 58 | A |
| 65 | .Fn bzero | 59 | .Fn bzero |
| 66 | function | 60 | function appeared in |
| 67 | appeared in | ||
| 68 | .Bx 4.3 . | 61 | .Bx 4.3 . |
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c index 4865e396ef..7e557ecd4a 100644 --- a/src/lib/libc/string/bzero.c +++ b/src/lib/libc/string/bzero.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 | * |
| @@ -32,21 +28,22 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)bzero.c 5.7 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: bzero.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 34 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 35 | #include <string.h> |
| 36 | #else | ||
| 37 | #include <lib/libkern/libkern.h> | ||
| 38 | #endif | ||
| 40 | 39 | ||
| 41 | /* | 40 | /* |
| 42 | * bzero -- vax movc5 instruction | 41 | * bzero -- vax movc5 instruction |
| 43 | */ | 42 | */ |
| 44 | void | 43 | void |
| 45 | bzero(b, length) | 44 | bzero(void *b, size_t length) |
| 46 | void *b; | ||
| 47 | register size_t length; | ||
| 48 | { | 45 | { |
| 49 | register char *p; | 46 | char *p; |
| 50 | 47 | ||
| 51 | for (p = b; length--;) | 48 | for (p = b; length--;) |
| 52 | *p++ = '\0'; | 49 | *p++ = '\0'; |
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 index 6464bea2b1..a2f0cd336d 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,8 +27,7 @@ | |||
| 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.4 2003/06/02 20:18:38 millert 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 April 19, 1991 |
| 38 | .Dt FFS 3 | 33 | .Dt FFS 3 |
| @@ -47,12 +42,10 @@ | |||
| 47 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
| 48 | The | 43 | The |
| 49 | .Fn ffs | 44 | .Fn ffs |
| 50 | function | 45 | function finds the first bit set in |
| 51 | finds the first bit set in | ||
| 52 | .Fa value | 46 | .Fa value |
| 53 | and returns the index of that bit. | 47 | and returns the index of that bit. |
| 54 | Bits are numbered starting from 1, starting at the right-most | 48 | Bits are numbered starting from 1, starting at the rightmost bit. |
| 55 | bit. | ||
| 56 | A return value of 0 means that the argument was zero. | 49 | A return value of 0 means that the argument was zero. |
| 57 | .Sh SEE ALSO | 50 | .Sh SEE ALSO |
| 58 | .Xr bitstring 3 | 51 | .Xr bitstring 3 |
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c index 42bc87ddea..f1d14096a2 100644 --- a/src/lib/libc/string/ffs.c +++ b/src/lib/libc/string/ffs.c | |||
| @@ -1,55 +1,48 @@ | |||
| 1 | /*- | 1 | /* $OpenBSD: ffs.c,v 1.6 2003/06/11 21:08:16 deraadt Exp $ */ |
| 2 | * Copyright (c) 1990 The Regents of the University of California. | 2 | |
| 3 | * All rights reserved. | 3 | /* |
| 4 | * | 4 | * Public domain. |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Written by Dale Rahn. |
| 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 | */ | 6 | */ |
| 33 | 7 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)ffs.c 5.4 (Berkeley) 5/17/90";*/ | 9 | static char *rcsid = "$OpenBSD: ffs.c,v 1.6 2003/06/11 21:08:16 deraadt Exp $"; |
| 36 | static char *rcsid = "$Id: ffs.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 10 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 11 | ||
| 12 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
| 39 | #include <string.h> | 13 | #include <string.h> |
| 14 | #else | ||
| 15 | #include <lib/libkern/libkern.h> | ||
| 16 | #endif | ||
| 40 | 17 | ||
| 41 | /* | 18 | /* |
| 42 | * ffs -- vax ffs instruction | 19 | * ffs -- vax ffs instruction |
| 43 | */ | 20 | */ |
| 44 | int | 21 | int |
| 45 | ffs(mask) | 22 | ffs(int mask) |
| 46 | register int mask; | ||
| 47 | { | 23 | { |
| 48 | register int bit; | 24 | int bit; |
| 25 | unsigned int r = mask; | ||
| 26 | static const signed char t[16] = { | ||
| 27 | -28, 1, 2, 1, | ||
| 28 | 3, 1, 2, 1, | ||
| 29 | 4, 1, 2, 1, | ||
| 30 | 3, 1, 2, 1 | ||
| 31 | }; | ||
| 32 | |||
| 33 | bit = 0; | ||
| 34 | if (!(r & 0xffff)) { | ||
| 35 | bit += 16; | ||
| 36 | r >>= 16; | ||
| 37 | } | ||
| 38 | if (!(r & 0xff)) { | ||
| 39 | bit += 8; | ||
| 40 | r >>= 8; | ||
| 41 | } | ||
| 42 | if (!(r & 0xf)) { | ||
| 43 | bit += 4; | ||
| 44 | r >>= 4; | ||
| 45 | } | ||
| 49 | 46 | ||
| 50 | if (mask == 0) | 47 | return (bit + t[ r & 0xf ]); |
| 51 | return(0); | ||
| 52 | for (bit = 1; !(mask & 1); bit++) | ||
| 53 | mask >>= 1; | ||
| 54 | return(bit); | ||
| 55 | } | 48 | } |
diff --git a/src/lib/libc/string/index.3 b/src/lib/libc/string/index.3 deleted file mode 100644 index 847b03628b..0000000000 --- a/src/lib/libc/string/index.3 +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" Chris Torek. | ||
| 6 | .\" Redistribution and use in source and binary forms, with or without | ||
| 7 | .\" modification, are permitted provided that the following conditions | ||
| 8 | .\" are met: | ||
| 9 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer. | ||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 13 | .\" documentation and/or other materials provided with the distribution. | ||
| 14 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | ||
| 20 | .\" without specific prior written permission. | ||
| 21 | .\" | ||
| 22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 32 | .\" SUCH DAMAGE. | ||
| 33 | .\" | ||
| 34 | .\" from: @(#)index.3 5.3 (Berkeley) 4/19/91 | ||
| 35 | .\" $Id: index.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | ||
| 37 | .Dd April 19, 1991 | ||
| 38 | .Dt INDEX 3 | ||
| 39 | .Os | ||
| 40 | .Sh NAME | ||
| 41 | .Nm index | ||
| 42 | .Nd locate character in string | ||
| 43 | .Sh SYNOPSIS | ||
| 44 | .Fd #include <string.h> | ||
| 45 | .Ft char * | ||
| 46 | .Fn index "const char *s" "int c" | ||
| 47 | .Sh DESCRIPTION | ||
| 48 | The | ||
| 49 | .Fn index | ||
| 50 | function | ||
| 51 | locates the first character matching | ||
| 52 | .Fa c | ||
| 53 | (converted to a | ||
| 54 | .Em char ) | ||
| 55 | in the null-terminated string | ||
| 56 | .Fa s . | ||
| 57 | .Sh RETURN VALUES | ||
| 58 | The character | ||
| 59 | .Fa c | ||
| 60 | is returned if it is found; otherwise | ||
| 61 | .Dv NULL | ||
| 62 | is returned. | ||
| 63 | If | ||
| 64 | .Fa c | ||
| 65 | is '\e0', | ||
| 66 | .Fn index | ||
| 67 | locates the terminating '\e0'. | ||
| 68 | .Sh SEE ALSO | ||
| 69 | .Xr memchr 3 , | ||
| 70 | .Xr rindex 3 , | ||
| 71 | .Xr strchr 3 , | ||
| 72 | .Xr strcspn 3 , | ||
| 73 | .Xr strpbrk 3 , | ||
| 74 | .Xr strrchr 3 , | ||
| 75 | .Xr strsep 3 , | ||
| 76 | .Xr strspn 3 , | ||
| 77 | .Xr strstr 3 , | ||
| 78 | .Xr strtok 3 | ||
| 79 | .Sh HISTORY | ||
| 80 | A | ||
| 81 | .Fn index | ||
| 82 | function appeared in | ||
| 83 | .At v6 . | ||
diff --git a/src/lib/libc/string/index.c b/src/lib/libc/string/index.c index 3d9c05f961..52d0fd46fa 100644 --- a/src/lib/libc/string/index.c +++ b/src/lib/libc/string/index.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 | * |
| @@ -32,19 +28,17 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)index.c 5.7 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: index.c,v 1.4 2003/06/02 20:18:38 millert Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| 40 | 35 | ||
| 41 | char * | 36 | char * |
| 42 | #ifdef STRCHR | 37 | #ifdef STRCHR |
| 43 | strchr(p, ch) | 38 | strchr(const char *p, int ch) |
| 44 | #else | 39 | #else |
| 45 | index(p, ch) | 40 | index(const char *p, int ch) |
| 46 | #endif | 41 | #endif |
| 47 | register const char *p, ch; | ||
| 48 | { | 42 | { |
| 49 | for (;; ++p) { | 43 | for (;; ++p) { |
| 50 | if (*p == ch) | 44 | if (*p == ch) |
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3 index 61df704028..8c159cb8de 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.8 2003/06/02 20:18:38 millert 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 June 9, 1993 |
| 36 | .Dt MEMCCPY 3 | 33 | .Dt MEMCCPY 3 |
| 37 | .Os | 34 | .Os |
| 38 | .Sh NAME | 35 | .Sh NAME |
| 39 | .Nm memccpy | 36 | .Nm memccpy |
| 37 | .Nd copy string until character found | ||
| 40 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
| 41 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
| 42 | .Ft void * | 40 | .Ft void * |
| @@ -44,14 +42,15 @@ | |||
| 44 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
| 45 | The | 43 | The |
| 46 | .Fn memccpy | 44 | .Fn memccpy |
| 47 | function | 45 | function copies bytes from string |
| 48 | copies bytes from string | ||
| 49 | .Fa src | 46 | .Fa src |
| 50 | to string | 47 | to string |
| 51 | .Fa dst . | 48 | .Fa dst . |
| 52 | If the character | 49 | If the character |
| 53 | .Fa c | 50 | .Fa c |
| 54 | (as converted to an unsigned char) occurs in the string | 51 | (as converted to an |
| 52 | .Li unsigned char ) | ||
| 53 | occurs in the string | ||
| 55 | .Fa src , | 54 | .Fa src , |
| 56 | the copy stops and a pointer to the byte after the copy of | 55 | the copy stops and a pointer to the byte after the copy of |
| 57 | .Fa c | 56 | .Fa c |
| @@ -60,14 +59,15 @@ in the string | |||
| 60 | is returned. | 59 | is returned. |
| 61 | Otherwise, | 60 | Otherwise, |
| 62 | .Fa len | 61 | .Fa len |
| 63 | bytes are copied, and a NULL pointer is returned. | 62 | bytes are copied, and a null pointer is returned. |
| 64 | .Sh SEE ALSO | 63 | .Sh SEE ALSO |
| 65 | .Xr bcopy 3 , | 64 | .Xr bcopy 3 , |
| 66 | .Xr memcpy 3 , | 65 | .Xr memcpy 3 , |
| 67 | .Xr memmove 3 , | 66 | .Xr memmove 3 , |
| 68 | .Xr strcpy 3 | 67 | .Xr strcpy 3 , |
| 68 | .Xr strlcpy 3 | ||
| 69 | .Sh HISTORY | 69 | .Sh HISTORY |
| 70 | The | 70 | The |
| 71 | .Fn memccpy | 71 | .Fn memccpy |
| 72 | function is | 72 | function first appeared in |
| 73 | .Ud . | 73 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c index 3a1d7bcca1..37496d1c26 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.4 2003/06/02 20:18:38 millert 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 | * |
| @@ -32,8 +30,11 @@ | |||
| 32 | */ | 30 | */ |
| 33 | 31 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)memccpy.c 5.8 (Berkeley) 5/30/91";*/ | 33 | #if 0 |
| 36 | static char *rcsid = "$Id: memccpy.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 34 | static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; |
| 35 | #else | ||
| 36 | static char *rcsid = "$OpenBSD: memccpy.c,v 1.4 2003/06/02 20:18:38 millert Exp $"; | ||
| 37 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 38 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 39 | ||
| 39 | #include <string.h> | 40 | #include <string.h> |
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3 index 265711e3b5..ddca58bc5e 100644 --- a/src/lib/libc/string/memchr.3 +++ b/src/lib/libc/string/memchr.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memchr.3,v 1.6 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt MEMCHR 3 | 35 | .Dt MEMCHR 3 |
| @@ -49,23 +44,21 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn memchr | 46 | .Fn memchr |
| 52 | function | 47 | function locates the first occurrence of |
| 53 | locates the first occurrence of | ||
| 54 | .Fa c | 48 | .Fa c |
| 55 | (converted to an unsigned char) | 49 | (converted to an |
| 50 | .Li unsigned char ) | ||
| 56 | in string | 51 | in string |
| 57 | .Fa b . | 52 | .Fa b . |
| 58 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
| 59 | The | 54 | The |
| 60 | .Fn memchr | 55 | .Fn memchr |
| 61 | function | 56 | function returns a pointer to the byte located, or |
| 62 | returns a pointer to the byte located, | 57 | .Dv NULL |
| 63 | or NULL if no such byte exists within | 58 | if no such byte exists within |
| 64 | .Fa len | 59 | .Fa len |
| 65 | bytes. | 60 | bytes. |
| 66 | .Sh SEE ALSO | 61 | .Sh SEE ALSO |
| 67 | .Xr index 3 , | ||
| 68 | .Xr rindex 3 , | ||
| 69 | .Xr strchr 3 , | 62 | .Xr strchr 3 , |
| 70 | .Xr strcspn 3 , | 63 | .Xr strcspn 3 , |
| 71 | .Xr strpbrk 3 , | 64 | .Xr strpbrk 3 , |
| @@ -77,6 +70,5 @@ bytes. | |||
| 77 | .Sh STANDARDS | 70 | .Sh STANDARDS |
| 78 | The | 71 | The |
| 79 | .Fn memchr | 72 | .Fn memchr |
| 80 | function | 73 | function conforms to |
| 81 | conforms to | ||
| 82 | .St -ansiC . | 74 | .St -ansiC . |
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c index 61652c6bb1..454abcbc17 100644 --- a/src/lib/libc/string/memchr.c +++ b/src/lib/libc/string/memchr.c | |||
| @@ -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 | * |
| @@ -35,23 +31,19 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memchr.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: memchr.c,v 1.6 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| 43 | 38 | ||
| 44 | void * | 39 | void * |
| 45 | memchr(s, c, n) | 40 | memchr(const void *s, int c, size_t n) |
| 46 | const void *s; | ||
| 47 | register unsigned char c; | ||
| 48 | register size_t n; | ||
| 49 | { | 41 | { |
| 50 | if (n != 0) { | 42 | if (n != 0) { |
| 51 | register const unsigned char *p = s; | 43 | const unsigned char *p = s; |
| 52 | 44 | ||
| 53 | do { | 45 | do { |
| 54 | if (*p++ == c) | 46 | if (*p++ == (unsigned char)c) |
| 55 | return ((void *)(p - 1)); | 47 | return ((void *)(p - 1)); |
| 56 | } while (--n != 0); | 48 | } while (--n != 0); |
| 57 | } | 49 | } |
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3 index 13901c1009..bd46e6898e 100644 --- a/src/lib/libc/string/memcmp.3 +++ b/src/lib/libc/string/memcmp.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memcmp.3,v 1.5 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt MEMCMP 3 | 35 | .Dt MEMCMP 3 |
| @@ -49,8 +44,7 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn memcmp | 46 | .Fn memcmp |
| 52 | function | 47 | function compares byte string |
| 53 | compares byte string | ||
| 54 | .Fa b1 | 48 | .Fa b1 |
| 55 | against byte string | 49 | against byte string |
| 56 | .Fa b2 . | 50 | .Fa b2 . |
| @@ -60,10 +54,11 @@ bytes long. | |||
| 60 | .Sh RETURN VALUES | 54 | .Sh RETURN VALUES |
| 61 | The | 55 | The |
| 62 | .Fn memcmp | 56 | .Fn memcmp |
| 63 | function | 57 | function returns zero if the two strings are identical, |
| 64 | returns zero if the the two strings are identical, | ||
| 65 | otherwise returns the difference between the first two differing bytes | 58 | otherwise returns the difference between the first two differing bytes |
| 66 | (treated as unsigned char values, so that | 59 | (treated as |
| 60 | .Li unsigned char | ||
| 61 | values, so that | ||
| 67 | .Sq Li \e200 | 62 | .Sq Li \e200 |
| 68 | is greater than | 63 | is greater than |
| 69 | .Sq Li \&\e0 , | 64 | .Sq Li \&\e0 , |
| @@ -78,6 +73,5 @@ Zero-length strings are always identical. | |||
| 78 | .Sh STANDARDS | 73 | .Sh STANDARDS |
| 79 | The | 74 | The |
| 80 | .Fn memcmp | 75 | .Fn memcmp |
| 81 | function | 76 | function conforms to |
| 82 | conforms to | ||
| 83 | .St -ansiC . | 77 | .St -ansiC . |
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c index 23d2ab2393..6c83208a7b 100644 --- a/src/lib/libc/string/memcmp.c +++ b/src/lib/libc/string/memcmp.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memcmp.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: memcmp.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -45,12 +40,10 @@ static char *rcsid = "$Id: memcmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $" | |||
| 45 | * Compare memory regions. | 40 | * Compare memory regions. |
| 46 | */ | 41 | */ |
| 47 | int | 42 | int |
| 48 | memcmp(s1, s2, n) | 43 | memcmp(const void *s1, const void *s2, size_t n) |
| 49 | const void *s1, *s2; | ||
| 50 | size_t n; | ||
| 51 | { | 44 | { |
| 52 | if (n != 0) { | 45 | if (n != 0) { |
| 53 | register const unsigned char *p1 = s1, *p2 = s2; | 46 | const unsigned char *p1 = s1, *p2 = s2; |
| 54 | 47 | ||
| 55 | do { | 48 | do { |
| 56 | if (*p1++ != *p2++) | 49 | if (*p1++ != *p2++) |
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3 index 3f4bb643c9..c8265d94a6 100644 --- a/src/lib/libc/string/memcpy.3 +++ b/src/lib/libc/string/memcpy.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,15 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memcpy.3,v 1.6 2003/06/21 12:04:01 avsm Exp $ |
| 37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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,34 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn memcpy | 46 | .Fn memcpy |
| 52 | function | 47 | function copies |
| 53 | copies | ||
| 54 | .Fa len | 48 | .Fa len |
| 55 | bytes from string | 49 | bytes from buffer |
| 56 | .Fa src | 50 | .Fa src |
| 57 | to string | 51 | to buffer |
| 58 | .Fa dst . | 52 | .Fa dst . |
| 59 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
| 60 | The | 54 | The |
| 61 | .Fn memcpy | 55 | .Fn memcpy |
| 62 | function | 56 | function returns the original value of |
| 63 | returns the original value of | ||
| 64 | .Fa dst . | 57 | .Fa dst . |
| 65 | .Sh SEE ALSO | 58 | .Sh SEE ALSO |
| 66 | .Xr bcopy 3 , | 59 | .Xr bcopy 3 , |
| 67 | .Xr memccpy 3 , | 60 | .Xr memccpy 3 , |
| 68 | .Xr memmove 3 , | 61 | .Xr memmove 3 , |
| 69 | .Xr strcpy 3 | 62 | .Xr strcpy 3 , |
| 63 | .Xr strlcpy 3 | ||
| 70 | .Sh STANDARDS | 64 | .Sh STANDARDS |
| 71 | The | 65 | The |
| 72 | .Fn memcpy | 66 | .Fn memcpy |
| 73 | function | 67 | function conforms to |
| 74 | conforms to | ||
| 75 | .St -ansiC . | 68 | .St -ansiC . |
| 76 | .Sh BUGS | 69 | .Sh BUGS |
| 77 | In this implementation | 70 | In this implementation |
| 78 | .Fn memcpy | 71 | .Fn memcpy |
| 79 | is implemented using | 72 | is implemented using |
| 80 | .Xr bcopy 3 , | 73 | .Xr bcopy 3 , |
| 81 | and therefore the strings may overlap. | 74 | and therefore the buffers may overlap. |
| 82 | On other systems, copying overlapping strings may produce surprises. | 75 | On other systems, copying overlapping buffers may produce surprises. |
| 83 | A simpler solution is to not use | 76 | A simpler solution is to not use |
| 84 | .Fn memcpy . | 77 | .Fn memcpy . |
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 index 24422e7971..d4a364eb36 100644 --- a/src/lib/libc/string/memmove.3 +++ b/src/lib/libc/string/memmove.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,15 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memmove.3,v 1.6 2003/06/21 12:04:01 avsm Exp $ |
| 37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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,10 @@ function returns the original value of | |||
| 67 | .Xr bcopy 3 , | 61 | .Xr bcopy 3 , |
| 68 | .Xr memccpy 3 , | 62 | .Xr memccpy 3 , |
| 69 | .Xr memcpy 3 , | 63 | .Xr memcpy 3 , |
| 70 | .Xr strcpy 3 | 64 | .Xr strcpy 3 , |
| 65 | .Xr strlcpy 3 | ||
| 71 | .Sh STANDARDS | 66 | .Sh STANDARDS |
| 72 | The | 67 | The |
| 73 | .Fn memmove | 68 | .Fn memmove |
| 74 | function | 69 | function conforms to |
| 75 | conforms to | ||
| 76 | .St -ansiC . | 70 | .St -ansiC . |
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3 index 1afc052182..291b1427dc 100644 --- a/src/lib/libc/string/memset.3 +++ b/src/lib/libc/string/memset.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: memset.3,v 1.5 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt MEMSET 3 | 35 | .Dt MEMSET 3 |
| @@ -49,12 +44,18 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn memset | 46 | .Fn memset |
| 52 | function | 47 | function writes |
| 53 | writes | ||
| 54 | .Fa len | 48 | .Fa len |
| 55 | bytes of value | 49 | bytes of value |
| 56 | .Fa c | 50 | .Fa c |
| 57 | (converted to an unsigned char) to the string | 51 | (converted to an |
| 52 | .Li unsigned char ) | ||
| 53 | to the string | ||
| 54 | .Fa b . | ||
| 55 | .Sh RETURN VALUES | ||
| 56 | The | ||
| 57 | .Fn memset | ||
| 58 | function returns the original value of | ||
| 58 | .Fa b . | 59 | .Fa b . |
| 59 | .Sh SEE ALSO | 60 | .Sh SEE ALSO |
| 60 | .Xr bzero 3 , | 61 | .Xr bzero 3 , |
| @@ -62,6 +63,5 @@ bytes of value | |||
| 62 | .Sh STANDARDS | 63 | .Sh STANDARDS |
| 63 | The | 64 | The |
| 64 | .Fn memset | 65 | .Fn memset |
| 65 | function | 66 | function conforms to |
| 66 | conforms to | ||
| 67 | .St -ansiC . | 67 | .St -ansiC . |
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c index 117de2e80b..9bc0556faa 100644 --- a/src/lib/libc/string/memset.c +++ b/src/lib/libc/string/memset.c | |||
| @@ -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 | * |
| @@ -35,21 +31,17 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memset.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: memset.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| 43 | 38 | ||
| 44 | void * | 39 | void * |
| 45 | memset(dst, c, n) | 40 | memset(void *dst, int c, size_t n) |
| 46 | void *dst; | ||
| 47 | register int c; | ||
| 48 | register size_t n; | ||
| 49 | { | 41 | { |
| 50 | 42 | ||
| 51 | if (n != 0) { | 43 | if (n != 0) { |
| 52 | register char *d = dst; | 44 | char *d = dst; |
| 53 | 45 | ||
| 54 | do | 46 | do |
| 55 | *d++ = c; | 47 | *d++ = c; |
diff --git a/src/lib/libc/string/rindex.3 b/src/lib/libc/string/rindex.3 deleted file mode 100644 index b13b3513e0..0000000000 --- a/src/lib/libc/string/rindex.3 +++ /dev/null | |||
| @@ -1,81 +0,0 @@ | |||
| 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" Chris Torek. | ||
| 6 | .\" Redistribution and use in source and binary forms, with or without | ||
| 7 | .\" modification, are permitted provided that the following conditions | ||
| 8 | .\" are met: | ||
| 9 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer. | ||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 13 | .\" documentation and/or other materials provided with the distribution. | ||
| 14 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | ||
| 20 | .\" without specific prior written permission. | ||
| 21 | .\" | ||
| 22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 32 | .\" SUCH DAMAGE. | ||
| 33 | .\" | ||
| 34 | .\" from: @(#)rindex.3 5.2 (Berkeley) 4/19/91 | ||
| 35 | .\" $Id: rindex.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | ||
| 37 | .Dd April 19, 1991 | ||
| 38 | .Dt RINDEX 3 | ||
| 39 | .Os | ||
| 40 | .Sh NAME | ||
| 41 | .Nm rindex | ||
| 42 | .Nd locate character in string | ||
| 43 | .Sh SYNOPSIS | ||
| 44 | .Fd #include <string.h> | ||
| 45 | .Ft char * | ||
| 46 | .Fn rindex "const char *s" "int c" | ||
| 47 | .Sh DESCRIPTION | ||
| 48 | The | ||
| 49 | .Fn rindex | ||
| 50 | function | ||
| 51 | locates the last character | ||
| 52 | matching | ||
| 53 | .Fa c | ||
| 54 | (converted to a | ||
| 55 | .Em char ) | ||
| 56 | in the null-terminated string | ||
| 57 | .Fa s . | ||
| 58 | The character c is returned if it is found; otherwise NULL is returned. | ||
| 59 | If | ||
| 60 | .Fa c | ||
| 61 | is | ||
| 62 | .Ql \e0 , | ||
| 63 | .Fn rindex | ||
| 64 | locates the terminating | ||
| 65 | .Ql \e0 . | ||
| 66 | .Sh SEE ALSO | ||
| 67 | .Xr index 3 , | ||
| 68 | .Xr memchr 3 , | ||
| 69 | .Xr strchr 3 , | ||
| 70 | .Xr strcspn 3 , | ||
| 71 | .Xr strpbrk 3 , | ||
| 72 | .Xr strrchr 3 , | ||
| 73 | .Xr strsep 3 , | ||
| 74 | .Xr strspn 3 , | ||
| 75 | .Xr strstr 3 , | ||
| 76 | .Xr strtok 3 | ||
| 77 | .Sh HISTORY | ||
| 78 | A | ||
| 79 | .Fn rindex | ||
| 80 | function appeared in | ||
| 81 | .At v6 . | ||
diff --git a/src/lib/libc/string/rindex.c b/src/lib/libc/string/rindex.c index 1b84c92072..b880d0eaeb 100644 --- a/src/lib/libc/string/rindex.c +++ b/src/lib/libc/string/rindex.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 | * |
| @@ -32,21 +28,19 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)rindex.c 5.9 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: rindex.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| 40 | 35 | ||
| 41 | char * | 36 | char * |
| 42 | #ifdef STRRCHR | 37 | #ifdef STRRCHR |
| 43 | strrchr(p, ch) | 38 | strrchr(const char *p, int ch) |
| 44 | #else | 39 | #else |
| 45 | rindex(p, ch) | 40 | rindex(const char *p, int ch) |
| 46 | #endif | 41 | #endif |
| 47 | register const char *p, ch; | ||
| 48 | { | 42 | { |
| 49 | register char *save; | 43 | char *save; |
| 50 | 44 | ||
| 51 | for (save = NULL;; ++p) { | 45 | for (save = NULL;; ++p) { |
| 52 | if (*p == ch) | 46 | if (*p == ch) |
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 index 46e9010e4f..e1f5d416d1 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.8 2003/06/02 20:18:38 millert 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 June 9, 1993 |
| 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 null-terminated strings |
| 55 | compare the null-terminated strings | ||
| 56 | .Fa s1 | 53 | .Fa s1 |
| 57 | and | 54 | and |
| 58 | .Fa s2 | 55 | .Fa s2 |
| 59 | and return an integer greater than, equal to, or less than 0, | 56 | and return an integer greater than, equal to, or less than 0, |
| 60 | according as | 57 | according to whether |
| 61 | .Fa s1 | 58 | .Fa s1 |
| 62 | is lexicographically greater than, equal to, or less than | 59 | is lexicographically greater than, equal to, or less than |
| 63 | .Fa s2 | 60 | .Fa s2 |
| @@ -68,7 +65,6 @@ The comparison is done using unsigned characters, so that | |||
| 68 | is greater than | 65 | is greater than |
| 69 | .Ql \e0 . | 66 | .Ql \e0 . |
| 70 | .Pp | 67 | .Pp |
| 71 | The | ||
| 72 | .Fn strncasecmp | 68 | .Fn strncasecmp |
| 73 | compares at most | 69 | compares at most |
| 74 | .Fa len | 70 | .Fa len |
| @@ -84,5 +80,5 @@ The | |||
| 84 | .Fn strcasecmp | 80 | .Fn strcasecmp |
| 85 | and | 81 | and |
| 86 | .Fn strncasecmp | 82 | .Fn strncasecmp |
| 87 | functions are | 83 | functions first appeared in |
| 88 | .Ud . | 84 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c index 79bd0081e3..62da063444 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.5 2003/06/11 21:08:16 deraadt 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,13 +29,16 @@ | |||
| 31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
| 32 | */ | 30 | */ |
| 33 | 31 | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static const char sccsid[] = "from: @(#)strcasecmp.c 5.10 (Berkeley) 1/26/91";*/ | 35 | #if 0 |
| 36 | static char *rcsid = "$Id: strcasecmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 36 | static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; |
| 37 | #else | ||
| 38 | static char *rcsid = "$OpenBSD: strcasecmp.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; | ||
| 39 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 40 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 41 | ||
| 39 | #include <string.h> | ||
| 40 | |||
| 41 | typedef unsigned char u_char; | 42 | typedef unsigned char u_char; |
| 42 | 43 | ||
| 43 | /* | 44 | /* |
| @@ -81,12 +82,11 @@ static const u_char charmap[] = { | |||
| 81 | }; | 82 | }; |
| 82 | 83 | ||
| 83 | int | 84 | int |
| 84 | strcasecmp(s1, s2) | 85 | strcasecmp(const char *s1, const char *s2) |
| 85 | const char *s1, *s2; | ||
| 86 | { | 86 | { |
| 87 | register const u_char *cm = charmap, | 87 | const u_char *cm = charmap; |
| 88 | *us1 = (const u_char *)s1, | 88 | const u_char *us1 = (const u_char *)s1; |
| 89 | *us2 = (const u_char *)s2; | 89 | const u_char *us2 = (const u_char *)s2; |
| 90 | 90 | ||
| 91 | while (cm[*us1] == cm[*us2++]) | 91 | while (cm[*us1] == cm[*us2++]) |
| 92 | if (*us1++ == '\0') | 92 | if (*us1++ == '\0') |
| @@ -95,14 +95,12 @@ strcasecmp(s1, s2) | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | int | 97 | int |
| 98 | strncasecmp(s1, s2, n) | 98 | strncasecmp(const char *s1, const char *s2, size_t n) |
| 99 | const char *s1, *s2; | ||
| 100 | register size_t n; | ||
| 101 | { | 99 | { |
| 102 | if (n != 0) { | 100 | if (n != 0) { |
| 103 | register const u_char *cm = charmap, | 101 | const u_char *cm = charmap; |
| 104 | *us1 = (const u_char *)s1, | 102 | const u_char *us1 = (const u_char *)s1; |
| 105 | *us2 = (const u_char *)s2; | 103 | const u_char *us2 = (const u_char *)s2; |
| 106 | 104 | ||
| 107 | do { | 105 | do { |
| 108 | if (cm[*us1] != cm[*us2++]) | 106 | if (cm[*us1] != cm[*us2++]) |
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..5b878c3e8c 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,14 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcat.3,v 1.9 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd July 8, 1997 |
| 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,8 +49,7 @@ 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 null-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 null-terminated string |
| 60 | .Fa s , | 55 | .Fa s , |
| @@ -66,29 +61,71 @@ 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 | .Dq Li 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 | .Dq Li input | ||
| 103 | to | ||
| 104 | .Dq Li buf | ||
| 105 | as will fit. | ||
| 106 | It then appends as many characters from suffix as will fit (or none | ||
| 107 | if there is no space). | ||
| 108 | For operations like this, the | ||
| 109 | .Xr strlcpy 3 | ||
| 110 | and | ||
| 111 | .Xr strlcat 3 | ||
| 112 | functions are a better choice, as shown below. | ||
| 113 | .Bd -literal -offset indent | ||
| 114 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 115 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
| 116 | .Ed | ||
| 81 | .Sh SEE ALSO | 117 | .Sh SEE ALSO |
| 82 | .Xr bcopy 3 , | 118 | .Xr bcopy 3 , |
| 83 | .Xr memccpy 3 , | 119 | .Xr memccpy 3 , |
| 84 | .Xr memcpy 3 , | 120 | .Xr memcpy 3 , |
| 85 | .Xr memmove 3 , | 121 | .Xr memmove 3 , |
| 86 | .Xr strcpy 3 | 122 | .Xr strcpy 3 , |
| 123 | .Xr strlcat 3 , | ||
| 124 | .Xr strlcpy 3 | ||
| 87 | .Sh STANDARDS | 125 | .Sh STANDARDS |
| 88 | The | 126 | The |
| 89 | .Fn strcat | 127 | .Fn strcat |
| 90 | and | 128 | and |
| 91 | .Fn strncat | 129 | .Fn strncat |
| 92 | functions | 130 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 131 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c index e741b84f03..885822bae3 100644 --- a/src/lib/libc/string/strcat.c +++ b/src/lib/libc/string/strcat.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 | * |
| @@ -32,20 +28,26 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strcat.c 5.6 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: strcat.c,v 1.6 2003/07/24 01:15:42 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 34 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 35 | #include <string.h> |
| 36 | #else | ||
| 37 | #include <lib/libkern/libkern.h> | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #if defined(APIWARN) | ||
| 41 | __warn_references(strcat, | ||
| 42 | "warning: strcat() is almost always misused, please use strlcat()"); | ||
| 43 | #endif | ||
| 40 | 44 | ||
| 41 | char * | 45 | char * |
| 42 | strcat(s, append) | 46 | strcat(char *s, const char *append) |
| 43 | register char *s; | ||
| 44 | register const char *append; | ||
| 45 | { | 47 | { |
| 46 | char *save = s; | 48 | char *save = s; |
| 47 | 49 | ||
| 48 | for (; *s; ++s); | 50 | for (; *s; ++s); |
| 49 | while (*s++ = *append++); | 51 | while ((*s++ = *append++) != '\0'); |
| 50 | return(save); | 52 | return(save); |
| 51 | } | 53 | } |
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3 index 18b50301f3..86841bac25 100644 --- a/src/lib/libc/string/strchr.3 +++ b/src/lib/libc/string/strchr.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,29 +29,29 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strchr.3,v 1.8 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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,16 +59,31 @@ is | |||
| 63 | .Fn strchr | 59 | .Fn strchr |
| 64 | locates the terminating | 60 | locates the terminating |
| 65 | .Ql \e0 . | 61 | .Ql \e0 . |
| 62 | .Pp | ||
| 63 | The | ||
| 64 | .Fn index | ||
| 65 | function is an old synonym for | ||
| 66 | .Fn strchr . | ||
| 66 | .Sh RETURN VALUES | 67 | .Sh RETURN VALUES |
| 67 | The function | 68 | The |
| 68 | .Fn strchr | 69 | .Fn strchr |
| 69 | returns a pointer to the located character, or | 70 | function returns a pointer to the located character or |
| 70 | .Dv NULL | 71 | .Dv NULL |
| 71 | if the character does not appear in the string. | 72 | if the character does not appear in the string. |
| 73 | .Sh EXAMPLES | ||
| 74 | After the following call to | ||
| 75 | .Fn strchr , | ||
| 76 | .Va p | ||
| 77 | will point to the string | ||
| 78 | .Qq oobar : | ||
| 79 | .Bd -literal -offset indent | ||
| 80 | char *p; | ||
| 81 | char *s = "foobar"; | ||
| 82 | |||
| 83 | p = strchr(s, 'o'); | ||
| 84 | .Ed | ||
| 72 | .Sh SEE ALSO | 85 | .Sh SEE ALSO |
| 73 | .Xr index 3 , | ||
| 74 | .Xr memchr 3 , | 86 | .Xr memchr 3 , |
| 75 | .Xr rindex 3 , | ||
| 76 | .Xr strcspn 3 , | 87 | .Xr strcspn 3 , |
| 77 | .Xr strpbrk 3 , | 88 | .Xr strpbrk 3 , |
| 78 | .Xr strrchr 3 , | 89 | .Xr strrchr 3 , |
| @@ -83,6 +94,9 @@ if the character does not appear in the string. | |||
| 83 | .Sh STANDARDS | 94 | .Sh STANDARDS |
| 84 | The | 95 | The |
| 85 | .Fn strchr | 96 | .Fn strchr |
| 86 | function | 97 | function conforms to |
| 87 | conforms to | ||
| 88 | .St -ansiC . | 98 | .St -ansiC . |
| 99 | .Pp | ||
| 100 | The | ||
| 101 | .Fn index | ||
| 102 | function is deprecated and shouldn't be used in new code. | ||
diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 index fecaa85410..d025b9cf7c 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,14 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcmp.3,v 1.7 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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,8 +49,7 @@ The | |||
| 53 | .Fn strcmp | 49 | .Fn strcmp |
| 54 | and | 50 | and |
| 55 | .Fn strncmp | 51 | .Fn strncmp |
| 56 | functions | 52 | functions lexicographically compare the null-terminated strings |
| 57 | lexicographically compare the null-terminated strings | ||
| 58 | .Fa s1 | 53 | .Fa s1 |
| 59 | and | 54 | and |
| 60 | .Fa s2 . | 55 | .Fa s2 . |
| @@ -64,7 +59,7 @@ The | |||
| 64 | and | 59 | and |
| 65 | .Fn strncmp | 60 | .Fn strncmp |
| 66 | return an integer greater than, equal to, or less than 0, according | 61 | return an integer greater than, equal to, or less than 0, according |
| 67 | as the string | 62 | to whether the string |
| 68 | .Fa s1 | 63 | .Fa s1 |
| 69 | is greater than, equal to, or less than the string | 64 | is greater than, equal to, or less than the string |
| 70 | .Fa s2 . | 65 | .Fa s2 . |
| @@ -73,9 +68,8 @@ The comparison is done using unsigned characters, so that | |||
| 73 | is greater than | 68 | is greater than |
| 74 | .Ql \e0 . | 69 | .Ql \e0 . |
| 75 | .Pp | 70 | .Pp |
| 76 | The | ||
| 77 | .Fn strncmp | 71 | .Fn strncmp |
| 78 | compares not more than | 72 | compares at most |
| 79 | .Fa len | 73 | .Fa len |
| 80 | characters. | 74 | characters. |
| 81 | .Sh SEE ALSO | 75 | .Sh SEE ALSO |
| @@ -89,6 +83,5 @@ The | |||
| 89 | .Fn strcmp | 83 | .Fn strcmp |
| 90 | and | 84 | and |
| 91 | .Fn strncmp | 85 | .Fn strncmp |
| 92 | functions | 86 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 87 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c index ae19e2e26e..9bda0a8d75 100644 --- a/src/lib/libc/string/strcmp.c +++ b/src/lib/libc/string/strcmp.c | |||
| @@ -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 | * |
| @@ -35,18 +31,20 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcmp.c 5.5 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strcmp.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 37 | #ifndef _KERNEL | ||
| 42 | #include <string.h> | 38 | #include <string.h> |
| 39 | #else | ||
| 40 | #include <lib/libkern/libkern.h> | ||
| 41 | #endif | ||
| 43 | 42 | ||
| 44 | /* | 43 | /* |
| 45 | * Compare strings. | 44 | * Compare strings. |
| 46 | */ | 45 | */ |
| 47 | int | 46 | int |
| 48 | strcmp(s1, s2) | 47 | strcmp(const char *s1, const char *s2) |
| 49 | register const char *s1, *s2; | ||
| 50 | { | 48 | { |
| 51 | while (*s1 == *s2++) | 49 | while (*s1 == *s2++) |
| 52 | if (*s1++ == 0) | 50 | if (*s1++ == 0) |
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3 index 12f73f98f2..fe0ff35510 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,8 +29,7 @@ | |||
| 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.5 2003/06/02 20:18:38 millert 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 June 29, 1991 |
| 40 | .Dt STRCOLL 3 | 35 | .Dt STRCOLL 3 |
| @@ -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 null-terminated strings |
| 53 | lexicographically compares the null-terminated strings | ||
| 54 | .Fa s1 | 48 | .Fa s1 |
| 55 | and | 49 | and |
| 56 | .Fa s2 | 50 | .Fa s2 |
| 57 | according to the current locale collation | 51 | according to the current locale collation |
| 58 | and returns an integer greater than, equal to, or less than 0, | 52 | and returns an integer greater than, equal to, or less than 0, |
| 59 | according as | 53 | according to whether |
| 60 | .Fa s1 | 54 | .Fa s1 |
| 61 | is greater than, equal to, or less than | 55 | is greater than, equal to, or less than |
| 62 | .Fa s2 . | 56 | .Fa s2 . |
| @@ -70,6 +64,5 @@ is greater than, equal to, or less than | |||
| 70 | .Sh STANDARDS | 64 | .Sh STANDARDS |
| 71 | The | 65 | The |
| 72 | .Fn strcoll | 66 | .Fn strcoll |
| 73 | function | 67 | function conforms to |
| 74 | conforms to | ||
| 75 | .St -ansiC . | 68 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c index 86c742cba9..9622b67281 100644 --- a/src/lib/libc/string/strcoll.c +++ b/src/lib/libc/string/strcoll.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcoll.c 5.2 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strcoll.c,v 1.4 2003/06/11 21:08:29 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -45,8 +40,7 @@ static char *rcsid = "$Id: strcoll.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | |||
| 45 | * Compare strings according to LC_COLLATE category of current locale. | 40 | * Compare strings according to LC_COLLATE category of current locale. |
| 46 | */ | 41 | */ |
| 47 | int | 42 | int |
| 48 | strcoll(s1, s2) | 43 | strcoll(const char *s1, const char *s2) |
| 49 | const char *s1, *s2; | ||
| 50 | { | 44 | { |
| 51 | /* LC_COLLATE is unimplemented, hence always "C" */ | 45 | /* LC_COLLATE is unimplemented, hence always "C" */ |
| 52 | return (strcmp(s1, s2)); | 46 | return (strcmp(s1, s2)); |
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..8304508df6 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,14 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcpy.3,v 1.12 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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 |
| @@ -62,7 +57,6 @@ to | |||
| 62 | .Ql \e0 | 57 | .Ql \e0 |
| 63 | character). | 58 | character). |
| 64 | .Pp | 59 | .Pp |
| 65 | The | ||
| 66 | .Fn strncpy | 60 | .Fn strncpy |
| 67 | copies not more than | 61 | copies not more than |
| 68 | .Fa len | 62 | .Fa len |
| @@ -78,45 +72,79 @@ characters long, and | |||
| 78 | .Em not | 72 | .Em not |
| 79 | terminating | 73 | terminating |
| 80 | .Fa dst | 74 | .Fa dst |
| 81 | if | 75 | if the length of |
| 82 | .Fa src | 76 | .Fa src |
| 83 | is more than | 77 | is greater than or equal to |
| 84 | .Fa len | 78 | .Fa len . |
| 85 | characters long. | ||
| 86 | .Sh RETURN VALUES | 79 | .Sh RETURN VALUES |
| 87 | The | 80 | The |
| 88 | .Fn strcpy | 81 | .Fn strcpy |
| 89 | and | 82 | and |
| 90 | .Fn strncpy | 83 | .Fn strncpy |
| 91 | functions | 84 | functions return |
| 92 | return | ||
| 93 | .Fa dst . | 85 | .Fa dst . |
| 94 | .Sh EXAMPLES | 86 | .Sh EXAMPLES |
| 95 | The following sets | 87 | The following sets |
| 96 | .Dq Li chararray | 88 | .Va chararray |
| 97 | to | 89 | to |
| 98 | .Dq Li abc\e0\e0\e0 : | 90 | .Dq abc\e0\e0\e0 : |
| 99 | .Bd -literal -offset indent | 91 | .Bd -literal -offset indent |
| 100 | (void)strncpy(chararray, "abc", 6). | 92 | (void)strncpy(chararray, "abc", 6); |
| 101 | .Ed | 93 | .Ed |
| 102 | .Pp | 94 | .Pp |
| 103 | The following sets | 95 | The following sets |
| 104 | .Dq Li chararray | 96 | .Va chararray |
| 105 | to | 97 | to |
| 106 | .Dq Li abcdef : | 98 | .Dq abcdef |
| 99 | and does | ||
| 100 | .Em not | ||
| 101 | null terminate | ||
| 102 | .Va chararray | ||
| 103 | because the source string is >= the length parameter. | ||
| 104 | .Fn strncpy | ||
| 105 | .Em only | ||
| 106 | null terminates the destination string when the length of the source | ||
| 107 | string is less than the length parameter. | ||
| 107 | .Bd -literal -offset indent | 108 | .Bd -literal -offset indent |
| 108 | (void)strncpy(chararray, "abcdefgh", 6); | 109 | (void)strncpy(chararray, "abcdefgh", 6); |
| 109 | .Ed | 110 | .Ed |
| 111 | .Pp | ||
| 112 | The following copies as many characters from | ||
| 113 | .Va input | ||
| 114 | to | ||
| 115 | .Va buf | ||
| 116 | as will fit and null terminates the result. | ||
| 117 | Because | ||
| 118 | .Fn strncpy | ||
| 119 | does | ||
| 120 | .Em not | ||
| 121 | guarantee to null terminate the string itself, we must do this by hand. | ||
| 122 | .Bd -literal -offset indent | ||
| 123 | char buf[BUFSIZ]; | ||
| 124 | |||
| 125 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 126 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 127 | .Ed | ||
| 128 | .Pp | ||
| 129 | Note that | ||
| 130 | .Xr strlcpy 3 | ||
| 131 | is a better choice for this kind of operation. | ||
| 132 | The equivalent using | ||
| 133 | .Xr strlcpy 3 | ||
| 134 | is simply: | ||
| 135 | .Bd -literal -offset indent | ||
| 136 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 137 | .Ed | ||
| 110 | .Sh SEE ALSO | 138 | .Sh SEE ALSO |
| 111 | .Xr bcopy 3 , | 139 | .Xr bcopy 3 , |
| 112 | .Xr memccpy 3 , | 140 | .Xr memccpy 3 , |
| 113 | .Xr memcpy 3 , | 141 | .Xr memcpy 3 , |
| 114 | .Xr memmove 3 | 142 | .Xr memmove 3 , |
| 143 | .Xr strlcpy 3 | ||
| 115 | .Sh STANDARDS | 144 | .Sh STANDARDS |
| 116 | The | 145 | The |
| 117 | .Fn strcpy | 146 | .Fn strcpy |
| 118 | and | 147 | and |
| 119 | .Fn strncpy | 148 | .Fn strncpy |
| 120 | functions | 149 | functions conform to |
| 121 | conform to | ||
| 122 | .St -ansiC . | 150 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c index 669bfde23e..e5c3d7dcbe 100644 --- a/src/lib/libc/string/strcpy.c +++ b/src/lib/libc/string/strcpy.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 | * |
| @@ -32,19 +28,25 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strcpy.c 5.7 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: strcpy.c,v 1.6 2003/07/24 01:15:42 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 34 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 35 | #include <string.h> |
| 36 | #else | ||
| 37 | #include <lib/libkern/libkern.h> | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #if defined(APIWARN) | ||
| 41 | __warn_references(strcpy, | ||
| 42 | "warning: strcpy() is almost always misused, please use strlcpy()"); | ||
| 43 | #endif | ||
| 40 | 44 | ||
| 41 | char * | 45 | char * |
| 42 | strcpy(to, from) | 46 | strcpy(char *to, const char *from) |
| 43 | register char *to; | ||
| 44 | register const char *from; | ||
| 45 | { | 47 | { |
| 46 | char *save = to; | 48 | char *save = to; |
| 47 | 49 | ||
| 48 | for (; *to = *from; ++from, ++to); | 50 | for (; (*to = *from) != '\0'; ++from, ++to); |
| 49 | return(save); | 51 | return(save); |
| 50 | } | 52 | } |
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3 index cc9e5c2fe3..6dfe1b276e 100644 --- a/src/lib/libc/string/strcspn.3 +++ b/src/lib/libc/string/strcspn.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcspn.3,v 1.6 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt STRCSPN 3 | 35 | .Dt STRCSPN 3 |
| @@ -49,27 +44,36 @@ | |||
| 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 null-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 | ||
| 69 | .Sh SEE ALSO | 75 | .Sh SEE ALSO |
| 70 | .Xr index 3 , | ||
| 71 | .Xr memchr 3 , | 76 | .Xr memchr 3 , |
| 72 | .Xr rindex 3 , | ||
| 73 | .Xr strchr 3 , | 77 | .Xr strchr 3 , |
| 74 | .Xr strpbrk 3 , | 78 | .Xr strpbrk 3 , |
| 75 | .Xr strrchr 3 , | 79 | .Xr strrchr 3 , |
| @@ -80,6 +84,5 @@ returns the number of characters spanned. | |||
| 80 | .Sh STANDARDS | 84 | .Sh STANDARDS |
| 81 | The | 85 | The |
| 82 | .Fn strcspn | 86 | .Fn strcspn |
| 83 | function | 87 | function conforms to |
| 84 | conforms to | ||
| 85 | .St -ansiC . | 88 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c index acb4d2a3af..f96f903809 100644 --- a/src/lib/libc/string/strcspn.c +++ b/src/lib/libc/string/strcspn.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcspn.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strcspn.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -45,12 +40,10 @@ static char *rcsid = "$Id: strcspn.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | |||
| 45 | * Span the complement of string s2. | 40 | * Span the complement of string s2. |
| 46 | */ | 41 | */ |
| 47 | size_t | 42 | size_t |
| 48 | strcspn(s1, s2) | 43 | strcspn(const char *s1, const char *s2) |
| 49 | const char *s1; | ||
| 50 | register const char *s2; | ||
| 51 | { | 44 | { |
| 52 | register const char *p, *spanp; | 45 | const char *p, *spanp; |
| 53 | register char c, sc; | 46 | char c, sc; |
| 54 | 47 | ||
| 55 | /* | 48 | /* |
| 56 | * Stop as soon as we find any character from s2. Note that there | 49 | * 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..59b77f7a16 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.12 2003/06/02 20:18:38 millert Exp $ |
| 2 | .\" All rights reserved. | 2 | .\" |
| 3 | .\" Copyright (c) 1990, 1991, 1993 | ||
| 4 | .\" The Regents of the University of California. All rights reserved. | ||
| 3 | .\" | 5 | .\" |
| 4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
| 5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
| @@ -9,11 +11,7 @@ | |||
| 9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 10 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 11 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 12 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 13 | .\" must display the following acknowledgement: | ||
| 14 | .\" This product includes software developed by the University of | ||
| 15 | .\" California, Berkeley and its contributors. | ||
| 16 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 17 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 18 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 19 | .\" | 17 | .\" |
| @@ -29,10 +27,9 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 31 | .\" | 29 | .\" |
| 32 | .\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 | 30 | .\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 |
| 33 | .\" $Id: strdup.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 34 | .\" | 31 | .\" |
| 35 | .Dd April 19, 1991 | 32 | .Dd June 9, 1993 |
| 36 | .Dt STRDUP 3 | 33 | .Dt STRDUP 3 |
| 37 | .Os | 34 | .Os |
| 38 | .Sh NAME | 35 | .Sh NAME |
| @@ -41,25 +38,47 @@ | |||
| 41 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS |
| 42 | .Fd #include <string.h> | 39 | .Fd #include <string.h> |
| 43 | .Ft char * | 40 | .Ft char * |
| 44 | .Fn strdup "const char *str" | 41 | .Fn strdup "const char *s" |
| 45 | .Sh DESCRIPTION | 42 | .Sh DESCRIPTION |
| 46 | The | 43 | The |
| 47 | .Fn strdup | 44 | .Fn strdup |
| 48 | function | 45 | function allocates sufficient memory for a copy of the string |
| 49 | allocates sufficient memory for a copy | 46 | .Fa s , |
| 50 | of the string | ||
| 51 | .Fa str , | ||
| 52 | does the copy, and returns a pointer to it. | 47 | does the copy, and returns a pointer to it. |
| 53 | The pointer may subsequently be used as an | 48 | The pointer may subsequently be used as an argument to the function |
| 54 | argument to the function | ||
| 55 | .Xr free 3 . | 49 | .Xr free 3 . |
| 50 | .Pp | ||
| 51 | If insufficient memory is available, | ||
| 52 | .Dv NULL | ||
| 53 | is returned. | ||
| 54 | .Sh EXAMPLES | ||
| 55 | The following will point | ||
| 56 | .Va p | ||
| 57 | to an allocated area of memory containing the null-terminated string | ||
| 58 | .Qq foobar : | ||
| 59 | .Bd -literal -offset indent | ||
| 60 | char *p; | ||
| 61 | |||
| 62 | if ((p = strdup("foobar")) == NULL) { | ||
| 63 | fprintf(stderr, "Out of memory.\en"); | ||
| 64 | exit(1); | ||
| 65 | } | ||
| 66 | .Ed | ||
| 67 | .Sh ERRORS | ||
| 68 | The | ||
| 69 | .Fn strdup | ||
| 70 | function may fail and set the external variable | ||
| 71 | .Va errno | ||
| 72 | for any of the errors specified for the library function | ||
| 73 | .Xr malloc 3 . | ||
| 56 | .Sh SEE ALSO | 74 | .Sh SEE ALSO |
| 57 | .Xr free 3 , | 75 | .Xr free 3 , |
| 58 | .Xr malloc 3 , | 76 | .Xr malloc 3 , |
| 59 | .Xt strcpy 3 , | 77 | .Xr strcpy 3 , |
| 60 | .Xt strlen 3 | 78 | .Xr strlcpy 3 , |
| 79 | .Xr strlen 3 | ||
| 61 | .Sh HISTORY | 80 | .Sh HISTORY |
| 62 | The | 81 | The |
| 63 | .Fn strdup | 82 | .Fn strdup |
| 64 | function | 83 | function first appeared in |
| 65 | .Ud . | 84 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c index 27ede44110..bbea59888c 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.5 2003/06/11 21:08:16 deraadt 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 | * |
| @@ -32,23 +30,28 @@ | |||
| 32 | */ | 30 | */ |
| 33 | 31 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strdup.c 5.4 (Berkeley) 2/24/91";*/ | 33 | #if 0 |
| 36 | static char *rcsid = "$Id: strdup.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | 34 | static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; |
| 35 | #else | ||
| 36 | static char *rcsid = "$OpenBSD: strdup.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; | ||
| 37 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 38 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 39 | ||
| 40 | #include <sys/types.h> | ||
| 41 | |||
| 42 | #include <stddef.h> | ||
| 39 | #include <stdlib.h> | 43 | #include <stdlib.h> |
| 40 | #include <string.h> | 44 | #include <string.h> |
| 41 | 45 | ||
| 42 | char * | 46 | char * |
| 43 | strdup(str) | 47 | strdup(const char *str) |
| 44 | const char *str; | ||
| 45 | { | 48 | { |
| 46 | size_t len; | 49 | size_t siz; |
| 47 | char *copy; | 50 | char *copy; |
| 48 | 51 | ||
| 49 | len = strlen(str) + 1; | 52 | siz = strlen(str) + 1; |
| 50 | if (!(copy = malloc(len))) | 53 | if ((copy = malloc(siz)) == NULL) |
| 51 | return((char *)NULL); | 54 | return(NULL); |
| 52 | memcpy(copy, str, len); | 55 | (void)memcpy(copy, str, siz); |
| 53 | return(copy); | 56 | return(copy); |
| 54 | } | 57 | } |
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 index c9d8504dbb..fa573bc72a 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.6 2003/06/02 20:18:38 millert 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 June 29, 1991 |
| 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,35 @@ | |||
| 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 | function returns a pointer to the language-dependent error message |
| 53 | string affiliated with an error number. | 50 | string affiliated with the specified error number |
| 51 | .Fa errnum . | ||
| 52 | The returned string contains a maximum of | ||
| 53 | .Dv NL_TEXTMAX | ||
| 54 | characters, including the trailing NUL. | ||
| 54 | .Pp | 55 | .Pp |
| 55 | The array pointed to is not to be modified by the program, but may be | 56 | The array pointed to is not to be modified by the program, but may be |
| 56 | overwritten by subsequent calls to | 57 | overwritten by subsequent calls to |
| 57 | .Fn strerror . | 58 | .Fn strerror . |
| 59 | .Pp | ||
| 60 | .Fn strerror_r | ||
| 61 | is a thread safe version of | ||
| 62 | .Fn strerror | ||
| 63 | that places the error message in the given buffer | ||
| 64 | .Fa strerrbuf . | ||
| 65 | If the error message is larger then | ||
| 66 | .Fa buflen | ||
| 67 | the message will be truncated to fit within buflen and | ||
| 68 | .Er ERANGE | ||
| 69 | is returned. | ||
| 70 | .Fn strerror_r | ||
| 71 | returns zero upon successful completion. | ||
| 72 | An error number is returned, otherwise. | ||
| 58 | .Sh SEE ALSO | 73 | .Sh SEE ALSO |
| 59 | .Xr intro 2 , | 74 | .Xr intro 2 , |
| 60 | .Xr perror 3 , | 75 | .Xr perror 3 , |
| @@ -64,3 +79,7 @@ The | |||
| 64 | .Fn strerror | 79 | .Fn strerror |
| 65 | function conforms to | 80 | function conforms to |
| 66 | .St -ansiC . | 81 | .St -ansiC . |
| 82 | The | ||
| 83 | .Fn strerror_r | ||
| 84 | function conforms to | ||
| 85 | .St -p1003.1 . | ||
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c index c3f5ab5d98..6496f50afd 100644 --- a/src/lib/libc/string/strerror.c +++ b/src/lib/libc/string/strerror.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 | * |
| @@ -32,8 +28,7 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: strerror.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| @@ -45,11 +40,10 @@ static char *rcsid = "$Id: strerror.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp | |||
| 45 | * internal function __strerror(). | 40 | * internal function __strerror(). |
| 46 | */ | 41 | */ |
| 47 | 42 | ||
| 48 | extern char *__strerror __P((int, char *)); | 43 | extern char *__strerror(int, char *); |
| 49 | 44 | ||
| 50 | char * | 45 | char * |
| 51 | strerror(num) | 46 | strerror(int num) |
| 52 | int num; | ||
| 53 | { | 47 | { |
| 54 | static char buf[NL_TEXTMAX]; | 48 | static char buf[NL_TEXTMAX]; |
| 55 | return __strerror(num, buf); | 49 | return __strerror(num, buf); |
diff --git a/src/lib/libc/string/strerror_r.c b/src/lib/libc/string/strerror_r.c new file mode 100644 index 0000000000..aab6db5303 --- /dev/null +++ b/src/lib/libc/string/strerror_r.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* $OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $ */ | ||
| 2 | /* Public Domain <marc@snafu.org> */ | ||
| 3 | |||
| 4 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 5 | static char *rcsid = "$OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $"; | ||
| 6 | #endif /* LIBC_SCCS and not lint */ | ||
| 7 | |||
| 8 | #include <errno.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | extern char *__strerror(int, char *); | ||
| 13 | |||
| 14 | int | ||
| 15 | strerror_r(int errnum, char *strerrbuf, size_t buflen) | ||
| 16 | { | ||
| 17 | int save_errno; | ||
| 18 | int ret_errno; | ||
| 19 | char buf[NL_TEXTMAX]; | ||
| 20 | |||
| 21 | save_errno = errno; | ||
| 22 | errno = 0; | ||
| 23 | __strerror(errnum, buf); | ||
| 24 | if (strlcpy(strerrbuf, buf, buflen) >= buflen) | ||
| 25 | errno = ERANGE; | ||
| 26 | ret_errno = errno; | ||
| 27 | errno = save_errno; | ||
| 28 | |||
| 29 | return (ret_errno); | ||
| 30 | } | ||
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..89034ac24c 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.10 2004/02/09 20:53:12 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 April 19, 1991 |
| 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,7 +83,7 @@ | |||
| 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 | null byte. |
| 108 | .Pp | 88 | .Pp |
| 109 | See the specific manual pages for more information. | 89 | See the specific manual pages for more information. |
| @@ -115,23 +95,25 @@ 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..2b6f1adbb4 --- /dev/null +++ b/src/lib/libc/string/strlcat.c | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 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 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 20 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $"; | ||
| 21 | #endif /* LIBC_SCCS and not lint */ | ||
| 22 | |||
| 23 | #include <sys/types.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Appends src to string dst of size siz (unlike strncat, siz is the | ||
| 28 | * full size of dst, not space left). At most siz-1 characters | ||
| 29 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). | ||
| 30 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). | ||
| 31 | * If retval >= siz, truncation occurred. | ||
| 32 | */ | ||
| 33 | size_t | ||
| 34 | strlcat(char *dst, const char *src, size_t siz) | ||
| 35 | { | ||
| 36 | register char *d = dst; | ||
| 37 | register const char *s = src; | ||
| 38 | register size_t n = siz; | ||
| 39 | size_t dlen; | ||
| 40 | |||
| 41 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
| 42 | while (n-- != 0 && *d != '\0') | ||
| 43 | d++; | ||
| 44 | dlen = d - dst; | ||
| 45 | n = siz - dlen; | ||
| 46 | |||
| 47 | if (n == 0) | ||
| 48 | return(dlen + strlen(s)); | ||
| 49 | while (*s != '\0') { | ||
| 50 | if (n != 1) { | ||
| 51 | *d++ = *s; | ||
| 52 | n--; | ||
| 53 | } | ||
| 54 | s++; | ||
| 55 | } | ||
| 56 | *d = '\0'; | ||
| 57 | |||
| 58 | return(dlen + (s - src)); /* count does not include NUL */ | ||
| 59 | } | ||
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3 new file mode 100644 index 0000000000..b392588879 --- /dev/null +++ b/src/lib/libc/string/strlcpy.3 | |||
| @@ -0,0 +1,179 @@ | |||
| 1 | .\" $OpenBSD: strlcpy.3,v 1.16 2003/06/17 21:56:24 millert 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 June 22, 1998 | ||
| 18 | .Dt STRLCPY 3 | ||
| 19 | .Os | ||
| 20 | .Sh NAME | ||
| 21 | .Nm strlcpy , | ||
| 22 | .Nm strlcat | ||
| 23 | .Nd size-bounded string copying and concatenation | ||
| 24 | .Sh SYNOPSIS | ||
| 25 | .Fd #include <string.h> | ||
| 26 | .Ft size_t | ||
| 27 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
| 28 | .Ft size_t | ||
| 29 | .Fn strlcat "char *dst" "const char *src" "size_t size" | ||
| 30 | .Sh DESCRIPTION | ||
| 31 | The | ||
| 32 | .Fn strlcpy | ||
| 33 | and | ||
| 34 | .Fn strlcat | ||
| 35 | functions copy and concatenate strings respectively. | ||
| 36 | They are designed | ||
| 37 | to be safer, more consistent, and less error prone replacements for | ||
| 38 | .Xr strncpy 3 | ||
| 39 | and | ||
| 40 | .Xr strncat 3 . | ||
| 41 | Unlike those functions, | ||
| 42 | .Fn strlcpy | ||
| 43 | and | ||
| 44 | .Fn strlcat | ||
| 45 | take the full size of the buffer (not just the length) and guarantee to | ||
| 46 | NUL-terminate the result (as long as | ||
| 47 | .Fa size | ||
| 48 | is larger than 0 or, in the case of | ||
| 49 | .Fn strlcat , | ||
| 50 | as long as there is at least one byte free in | ||
| 51 | .Fa dst ) . | ||
| 52 | Note that you should include a byte for the NUL in | ||
| 53 | .Fa size . | ||
| 54 | Also note that | ||
| 55 | .Fn strlcpy | ||
| 56 | and | ||
| 57 | .Fn strlcat | ||
| 58 | only operate on true | ||
| 59 | .Dq C | ||
| 60 | strings. | ||
| 61 | This means that for | ||
| 62 | .Fn strlcpy | ||
| 63 | .Fa src | ||
| 64 | must be NUL-terminated and for | ||
| 65 | .Fn strlcat | ||
| 66 | both | ||
| 67 | .Fa src | ||
| 68 | and | ||
| 69 | .Fa dst | ||
| 70 | must be NUL-terminated. | ||
| 71 | .Pp | ||
| 72 | The | ||
| 73 | .Fn strlcpy | ||
| 74 | function copies up to | ||
| 75 | .Fa size | ||
| 76 | - 1 characters from the NUL-terminated string | ||
| 77 | .Fa src | ||
| 78 | to | ||
| 79 | .Fa dst , | ||
| 80 | NUL-terminating the result. | ||
| 81 | .Pp | ||
| 82 | The | ||
| 83 | .Fn strlcat | ||
| 84 | function appends the NUL-terminated string | ||
| 85 | .Fa src | ||
| 86 | to the end of | ||
| 87 | .Fa dst . | ||
| 88 | It will append at most | ||
| 89 | .Fa size | ||
| 90 | - strlen(dst) - 1 bytes, NUL-terminating the result. | ||
| 91 | .Sh RETURN VALUES | ||
| 92 | The | ||
| 93 | .Fn strlcpy | ||
| 94 | and | ||
| 95 | .Fn strlcat | ||
| 96 | functions return the total length of the string they tried to create. | ||
| 97 | For | ||
| 98 | .Fn strlcpy | ||
| 99 | that means the length of | ||
| 100 | .Fa src . | ||
| 101 | For | ||
| 102 | .Fn strlcat | ||
| 103 | that means the initial length of | ||
| 104 | .Fa dst | ||
| 105 | plus | ||
| 106 | the length of | ||
| 107 | .Fa src . | ||
| 108 | While this may seem somewhat confusing it was done to make | ||
| 109 | truncation detection simple. | ||
| 110 | .Pp | ||
| 111 | Note however, that if | ||
| 112 | .Fn strlcat | ||
| 113 | traverses | ||
| 114 | .Fa size | ||
| 115 | characters without finding a NUL, the length of the string is considered | ||
| 116 | to be | ||
| 117 | .Fa size | ||
| 118 | and the destination string will not be NUL-terminated (since there was | ||
| 119 | no space for the NUL). | ||
| 120 | This keeps | ||
| 121 | .Fn strlcat | ||
| 122 | from running off the end of a string. | ||
| 123 | In practice this should not happen (as it means that either | ||
| 124 | .Fa size | ||
| 125 | is incorrect or that | ||
| 126 | .Fa dst | ||
| 127 | is not a proper | ||
| 128 | .Dq C | ||
| 129 | string). | ||
| 130 | The check exists to prevent potential security problems in incorrect code. | ||
| 131 | .Sh EXAMPLES | ||
| 132 | The following code fragment illustrates the simple case: | ||
| 133 | .Bd -literal -offset indent | ||
| 134 | char *s, *p, buf[BUFSIZ]; | ||
| 135 | |||
| 136 | \&... | ||
| 137 | |||
| 138 | (void)strlcpy(buf, s, sizeof(buf)); | ||
| 139 | (void)strlcat(buf, p, sizeof(buf)); | ||
| 140 | .Ed | ||
| 141 | .Pp | ||
| 142 | To detect truncation, perhaps while building a pathname, something | ||
| 143 | like the following might be used: | ||
| 144 | .Bd -literal -offset indent | ||
| 145 | char *dir, *file, pname[MAXPATHLEN]; | ||
| 146 | |||
| 147 | \&... | ||
| 148 | |||
| 149 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
| 150 | goto toolong; | ||
| 151 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
| 152 | goto toolong; | ||
| 153 | .Ed | ||
| 154 | .Pp | ||
| 155 | Since we know how many characters we copied the first time, we can | ||
| 156 | speed things up a bit by using a copy instead of an append: | ||
| 157 | .Bd -literal -offset indent | ||
| 158 | char *dir, *file, pname[MAXPATHLEN]; | ||
| 159 | size_t n; | ||
| 160 | |||
| 161 | \&... | ||
| 162 | |||
| 163 | n = strlcpy(pname, dir, sizeof(pname)); | ||
| 164 | if (n >= sizeof(pname)) | ||
| 165 | goto toolong; | ||
| 166 | if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) | ||
| 167 | goto toolong; | ||
| 168 | .Ed | ||
| 169 | .Pp | ||
| 170 | However, one may question the validity of such optimizations, as they | ||
| 171 | defeat the whole purpose of | ||
| 172 | .Fn strlcpy | ||
| 173 | and | ||
| 174 | .Fn strlcat . | ||
| 175 | As a matter of fact, the first version of this manual page got it wrong. | ||
| 176 | .Sh SEE ALSO | ||
| 177 | .Xr snprintf 3 , | ||
| 178 | .Xr strncat 3 , | ||
| 179 | .Xr strncpy 3 | ||
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c new file mode 100644 index 0000000000..82cbfac016 --- /dev/null +++ b/src/lib/libc/string/strlcpy.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | /* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 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 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 20 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $"; | ||
| 21 | #endif /* LIBC_SCCS and not lint */ | ||
| 22 | |||
| 23 | #include <sys/types.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Copy src to string dst of size siz. At most siz-1 characters | ||
| 28 | * will be copied. Always NUL terminates (unless siz == 0). | ||
| 29 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 30 | */ | ||
| 31 | size_t | ||
| 32 | strlcpy(char *dst, const char *src, size_t siz) | ||
| 33 | { | ||
| 34 | register char *d = dst; | ||
| 35 | register const char *s = src; | ||
| 36 | register size_t n = siz; | ||
| 37 | |||
| 38 | /* Copy as many bytes as will fit */ | ||
| 39 | if (n != 0 && --n != 0) { | ||
| 40 | do { | ||
| 41 | if ((*d++ = *s++) == 0) | ||
| 42 | break; | ||
| 43 | } while (--n != 0); | ||
| 44 | } | ||
| 45 | |||
| 46 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 47 | if (n == 0) { | ||
| 48 | if (siz != 0) | ||
| 49 | *d = '\0'; /* NUL-terminate dst */ | ||
| 50 | while (*s++) | ||
| 51 | ; | ||
| 52 | } | ||
| 53 | |||
| 54 | return(s - src - 1); /* count does not include NUL */ | ||
| 55 | } | ||
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 index f4aff363ee..32bbc88542 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,15 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strlen.3,v 1.5 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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 | .Nd find length of a string |
| 45 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
| 47 | .Ft size_t | 42 | .Ft size_t |
| @@ -49,23 +44,18 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn strlen | 46 | .Fn strlen |
| 52 | function | 47 | function computes the length of the string |
| 53 | computes the length of the string | ||
| 54 | .Fa s . | 48 | .Fa s . |
| 55 | .Sh RETURN VALUES | 49 | .Sh RETURN VALUES |
| 56 | The | 50 | The |
| 57 | .Fn strlen | 51 | .Fn strlen |
| 58 | function | 52 | function returns the number of characters that precede the terminating |
| 59 | returns | 53 | .Tn NUL |
| 60 | the number of characters that precede the | ||
| 61 | terminating | ||
| 62 | .Dv NUL | ||
| 63 | character. | 54 | character. |
| 64 | .Sh SEE ALSO | 55 | .Sh SEE ALSO |
| 65 | .Xr string 3 | 56 | .Xr string 3 |
| 66 | .Sh STANDARDS | 57 | .Sh STANDARDS |
| 67 | The | 58 | The |
| 68 | .Fn strlen | 59 | .Fn strlen |
| 69 | function | 60 | function conforms to |
| 70 | conforms to | ||
| 71 | .St -ansiC . | 61 | .St -ansiC . |
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c index d23aadafc0..298a9966a3 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.6 2003/06/11 21:08:16 deraadt 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 | * |
| @@ -32,19 +30,22 @@ | |||
| 32 | */ | 30 | */ |
| 33 | 31 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 32 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strlen.c 5.5 (Berkeley) 1/26/91";*/ | 33 | static char *rcsid = "$OpenBSD: strlen.c,v 1.6 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 34 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 35 | ||
| 36 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
| 39 | #include <string.h> | 37 | #include <string.h> |
| 38 | #else | ||
| 39 | #include <lib/libkern/libkern.h> | ||
| 40 | #endif | ||
| 40 | 41 | ||
| 41 | size_t | 42 | size_t |
| 42 | strlen(str) | 43 | strlen(const char *str) |
| 43 | const char *str; | ||
| 44 | { | 44 | { |
| 45 | register const char *s; | 45 | const char *s; |
| 46 | 46 | ||
| 47 | for (s = str; *s; ++s); | 47 | for (s = str; *s; ++s) |
| 48 | return(s - str); | 48 | ; |
| 49 | return (s - str); | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3 index 1907e7ab03..bc45c4ce1f 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.11 2003/09/02 18:24:21 jmc Exp $ |
| 2 | .\" All rights reserved. | 2 | .\" |
| 3 | .\" Copyright (c) 1990, 1991, 1993 | ||
| 4 | .\" The Regents of the University of California. All rights reserved. | ||
| 3 | .\" | 5 | .\" |
| 4 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without |
| 5 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions |
| @@ -9,11 +11,7 @@ | |||
| 9 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 10 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 11 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 12 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 13 | .\" must display the following acknowledgement: | ||
| 14 | .\" This product includes software developed by the University of | ||
| 15 | .\" California, Berkeley and its contributors. | ||
| 16 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 17 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 18 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 19 | .\" | 17 | .\" |
| @@ -29,10 +27,9 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 31 | .\" | 29 | .\" |
| 32 | .\" from: @(#)strmode.3 5.4 (Berkeley) 7/31/91 | 30 | .\" @(#)strmode.3 8.3 (Berkeley) 7/28/94 |
| 33 | .\" $Id: strmode.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 34 | .\" | 31 | .\" |
| 35 | .Dd July 31, 1991 | 32 | .Dd July 28, 1994 |
| 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 null 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,12 @@ 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 w |
| 71 | whiteout | ||
| 72 | .It \&? | ||
| 76 | unknown inode type | 73 | unknown inode type |
| 77 | .El | 74 | .El |
| 78 | .Pp | 75 | .Pp |
| @@ -80,46 +77,58 @@ The next nine characters encode three sets of permissions, in three | |||
| 80 | characters each. | 77 | characters each. |
| 81 | The first three characters are the permissions for the owner of the | 78 | 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 | 79 | file, the second three for the group the file belongs to, and the |
| 83 | third for the ``other'', or default, set of users. | 80 | third for the |
| 81 | .Dq other , | ||
| 82 | or default, set of users. | ||
| 84 | .Pp | 83 | .Pp |
| 85 | Permission checking is done as specifically as possible. | 84 | Permission checking is done as specifically as possible. |
| 86 | If read permission is denied to the owner of a file in the first set | 85 | 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. | 86 | 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 | 87 | 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. | 88 | permissions allow reading or the |
| 89 | .Dq other | ||
| 90 | permissions allow reading. | ||
| 90 | .Pp | 91 | .Pp |
| 91 | If the first character of the three character set is an ``r'', the file is | 92 | 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. | 93 | .Sq r , |
| 94 | the file is readable for that set of users; if a dash | ||
| 95 | .Pq Ql - , | ||
| 96 | it is not readable. | ||
| 93 | .Pp | 97 | .Pp |
| 94 | If the second character of the three character set is a ``w'', the file is | 98 | 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. | 99 | .Sq w , |
| 100 | the file is writable for that set of users; if a dash | ||
| 101 | .Pq Ql - , | ||
| 102 | it is not writable. | ||
| 96 | .Pp | 103 | .Pp |
| 97 | The third character is the first of the following characters that apply: | 104 | The third character is the first of the following characters that apply: |
| 98 | .Bl -tag -width xxxx | 105 | .Bl -tag -width xxxx |
| 99 | .It S | 106 | .It S |
| 100 | If the character is part of the owner permissions and the file is not | 107 | 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 | 108 | executable or the directory is not searchable by the owner, and the |
| 102 | set-user-id bit is set. | 109 | set-user-ID bit is set. |
| 103 | .It S | 110 | .It S |
| 104 | If the character is part of the group permissions and the file is not | 111 | 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 | 112 | executable or the directory is not searchable by the group, and the |
| 106 | set-group-id bit is set. | 113 | set-group-ID bit is set. |
| 107 | .It T | 114 | .It T |
| 108 | If the character is part of the other permissions and the file is not | 115 | 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'' | 116 | executable or the directory is not searchable by others, and the |
| 117 | .Dq sticky | ||
| 110 | .Pq Dv S_ISVTX | 118 | .Pq Dv S_ISVTX |
| 111 | bit is set. | 119 | bit is set. |
| 112 | .It s | 120 | .It s |
| 113 | If the character is part of the owner permissions and the file is | 121 | 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 | 122 | executable or the directory searchable by the owner, and the set-user-ID |
| 115 | bit is set. | 123 | bit is set. |
| 116 | .It s | 124 | .It s |
| 117 | If the character is part of the group permissions and the file is | 125 | 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 | 126 | executable or the directory searchable by the group, and the set-group-ID |
| 119 | bit is set. | 127 | bit is set. |
| 120 | .It t | 128 | .It t |
| 121 | If the character is part of the other permissions and the file is | 129 | If the character is part of the other permissions and the file is |
| 122 | executable or the directory searchable, by others, and the ``sticky'' | 130 | executable or the directory searchable by others, and the |
| 131 | .Dq sticky | ||
| 123 | .Pq Dv S_ISVTX | 132 | .Pq Dv S_ISVTX |
| 124 | bit is set. | 133 | bit is set. |
| 125 | .It x | 134 | .It x |
| @@ -128,14 +137,15 @@ The file is executable or the directory is searchable. | |||
| 128 | None of the above apply. | 137 | None of the above apply. |
| 129 | .El | 138 | .El |
| 130 | .Pp | 139 | .Pp |
| 131 | The last character is a plus sign ``+'' if any there are any alternate | 140 | The last character is a plus sign |
| 141 | .Pq Ql + | ||
| 142 | if there are any alternate | ||
| 132 | or additional access control methods associated with the inode, otherwise | 143 | or additional access control methods associated with the inode, otherwise |
| 133 | it will be a space. | 144 | it will be a space. |
| 134 | .Sh RETURN VALUES | 145 | .Sh RETURN VALUES |
| 135 | The | 146 | The |
| 136 | .Fn strmode | 147 | .Fn strmode |
| 137 | function | 148 | function always returns 0. |
| 138 | always returns 0. | ||
| 139 | .Sh SEE ALSO | 149 | .Sh SEE ALSO |
| 140 | .Xr chmod 1 , | 150 | .Xr chmod 1 , |
| 141 | .Xr find 1 , | 151 | .Xr find 1 , |
| @@ -145,5 +155,5 @@ always returns 0. | |||
| 145 | .Sh HISTORY | 155 | .Sh HISTORY |
| 146 | The | 156 | The |
| 147 | .Fn strmode | 157 | .Fn strmode |
| 148 | function | 158 | function first appeared in |
| 149 | .Ud . | 159 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c index 441fc76e90..bd78403cb2 100644 --- a/src/lib/libc/string/strmode.c +++ b/src/lib/libc/string/strmode.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 | * |
| @@ -32,18 +28,17 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strmode.c 5.3 (Berkeley) 5/18/90";*/ | 31 | static char *rcsid = "$OpenBSD: strmode.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| 40 | #include <sys/stat.h> | 35 | #include <sys/stat.h> |
| 41 | #include <string.h> | 36 | #include <string.h> |
| 42 | 37 | ||
| 38 | /* XXX mode should be mode_t */ | ||
| 39 | |||
| 43 | void | 40 | void |
| 44 | strmode(mode, p) | 41 | strmode(int mode, char *p) |
| 45 | register mode_t mode; | ||
| 46 | register char *p; | ||
| 47 | { | 42 | { |
| 48 | /* print type */ | 43 | /* print type */ |
| 49 | switch (mode & S_IFMT) { | 44 | switch (mode & S_IFMT) { |
| @@ -70,6 +65,11 @@ strmode(mode, p) | |||
| 70 | *p++ = 'p'; | 65 | *p++ = 'p'; |
| 71 | break; | 66 | break; |
| 72 | #endif | 67 | #endif |
| 68 | #ifdef S_IFWHT | ||
| 69 | case S_IFWHT: /* whiteout */ | ||
| 70 | *p++ = 'w'; | ||
| 71 | break; | ||
| 72 | #endif | ||
| 73 | default: /* unknown */ | 73 | default: /* unknown */ |
| 74 | *p++ = '?'; | 74 | *p++ = '?'; |
| 75 | break; | 75 | break; |
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c index 3d96452af4..05d35e0900 100644 --- a/src/lib/libc/string/strncat.c +++ b/src/lib/libc/string/strncat.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strncat.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strncat.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -46,14 +41,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. | 41 | * are written at dst (at most n+1 bytes being appended). Return dst. |
| 47 | */ | 42 | */ |
| 48 | char * | 43 | char * |
| 49 | strncat(dst, src, n) | 44 | strncat(char *dst, const char *src, size_t n) |
| 50 | char *dst; | ||
| 51 | const char *src; | ||
| 52 | register size_t n; | ||
| 53 | { | 45 | { |
| 54 | if (n != 0) { | 46 | if (n != 0) { |
| 55 | register char *d = dst; | 47 | char *d = dst; |
| 56 | register const char *s = src; | 48 | const char *s = src; |
| 57 | 49 | ||
| 58 | while (*d != 0) | 50 | while (*d != 0) |
| 59 | d++; | 51 | d++; |
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c index 0638d4dcf2..82420e215e 100644 --- a/src/lib/libc/string/strncmp.c +++ b/src/lib/libc/string/strncmp.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 | * |
| @@ -32,16 +28,17 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strncmp.c 5.6 (Berkeley) 1/26/91";*/ | 31 | static char *rcsid = "$OpenBSD: strncmp.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 34 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 35 | #include <string.h> |
| 36 | #else | ||
| 37 | #include <lib/libkern/libkern.h> | ||
| 38 | #endif | ||
| 40 | 39 | ||
| 41 | int | 40 | int |
| 42 | strncmp(s1, s2, n) | 41 | strncmp(const char *s1, const char *s2, size_t n) |
| 43 | register const char *s1, *s2; | ||
| 44 | register size_t n; | ||
| 45 | { | 42 | { |
| 46 | 43 | ||
| 47 | if (n == 0) | 44 | if (n == 0) |
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c index 5215311b75..00493f4f7f 100644 --- a/src/lib/libc/string/strncpy.c +++ b/src/lib/libc/string/strncpy.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strncpy.c 5.6 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strncpy.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -46,14 +41,11 @@ static char *rcsid = "$Id: strncpy.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | |||
| 46 | * Return dst. | 41 | * Return dst. |
| 47 | */ | 42 | */ |
| 48 | char * | 43 | char * |
| 49 | strncpy(dst, src, n) | 44 | strncpy(char *dst, const char *src, size_t n) |
| 50 | char *dst; | ||
| 51 | const char *src; | ||
| 52 | register size_t n; | ||
| 53 | { | 45 | { |
| 54 | if (n != 0) { | 46 | if (n != 0) { |
| 55 | register char *d = dst; | 47 | char *d = dst; |
| 56 | register const char *s = src; | 48 | const char *s = src; |
| 57 | 49 | ||
| 58 | do { | 50 | do { |
| 59 | if ((*d++ = *s++) == 0) { | 51 | if ((*d++ = *s++) == 0) { |
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 index 8578546c05..7e54f9de54 100644 --- a/src/lib/libc/string/strpbrk.3 +++ b/src/lib/libc/string/strpbrk.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strpbrk.3,v 1.6 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt STRPBRK 3 | 35 | .Dt STRPBRK 3 |
| @@ -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 null-terminated string |
| 53 | locates in the null-terminated string | ||
| 54 | .Fa s | 48 | .Fa s |
| 55 | the first occurrence of any character in the string | 49 | the first occurrence of any character in the string |
| 56 | .Fa charset | 50 | .Fa charset |
| @@ -58,13 +52,12 @@ and returns a pointer to this character. | |||
| 58 | If no characters from | 52 | If no characters from |
| 59 | .Fa charset | 53 | .Fa charset |
| 60 | occur anywhere in | 54 | occur anywhere in |
| 61 | .Fa s | 55 | .Fa s , |
| 62 | .Fn strpbrk | 56 | .Fn strpbrk |
| 63 | returns NULL. | 57 | returns |
| 58 | .Dv NULL . | ||
| 64 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
| 65 | .Xr index 3 , | ||
| 66 | .Xr memchr 3 , | 60 | .Xr memchr 3 , |
| 67 | .Xr rindex 3 , | ||
| 68 | .Xr strchr 3 , | 61 | .Xr strchr 3 , |
| 69 | .Xr strcspn 3 , | 62 | .Xr strcspn 3 , |
| 70 | .Xr strrchr 3 , | 63 | .Xr strrchr 3 , |
| @@ -75,6 +68,5 @@ returns NULL. | |||
| 75 | .Sh STANDARDS | 68 | .Sh STANDARDS |
| 76 | The | 69 | The |
| 77 | .Fn strpbrk | 70 | .Fn strpbrk |
| 78 | function | 71 | function conforms to |
| 79 | conforms to | ||
| 80 | .St -ansiC . | 72 | .St -ansiC . |
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c index f1d542a525..024c42bdc3 100644 --- a/src/lib/libc/string/strpbrk.c +++ b/src/lib/libc/string/strpbrk.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 | * |
| @@ -32,8 +28,7 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strpbrk.c 5.8 (Berkeley) 1/26/91";*/ | 31 | static char *rcsid = "$OpenBSD: strpbrk.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| @@ -42,11 +37,10 @@ static char *rcsid = "$Id: strpbrk.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | |||
| 42 | * Find the first occurrence in s1 of a character in s2 (excluding NUL). | 37 | * Find the first occurrence in s1 of a character in s2 (excluding NUL). |
| 43 | */ | 38 | */ |
| 44 | char * | 39 | char * |
| 45 | strpbrk(s1, s2) | 40 | strpbrk(const char *s1, const char *s2) |
| 46 | register const char *s1, *s2; | ||
| 47 | { | 41 | { |
| 48 | register const char *scanp; | 42 | const char *scanp; |
| 49 | register int c, sc; | 43 | int c, sc; |
| 50 | 44 | ||
| 51 | while ((c = *s1++) != 0) { | 45 | while ((c = *s1++) != 0) { |
| 52 | for (scanp = s2; (sc = *scanp++) != 0;) | 46 | for (scanp = s2; (sc = *scanp++) != 0;) |
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3 index 1d98cbff24..d7e0eeff85 100644 --- a/src/lib/libc/string/strrchr.3 +++ b/src/lib/libc/string/strrchr.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,28 +29,31 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strrchr.3,v 1.7 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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,20 +61,31 @@ is | |||
| 62 | .Fn strrchr | 61 | .Fn strrchr |
| 63 | locates the terminating | 62 | locates the terminating |
| 64 | .Ql \e0 . | 63 | .Ql \e0 . |
| 64 | .Pp | ||
| 65 | The | ||
| 66 | .Fn rindex | ||
| 67 | function is an old synonym for | ||
| 68 | .Fn strrchr . | ||
| 65 | .Sh RETURN VALUES | 69 | .Sh RETURN VALUES |
| 66 | The | 70 | The |
| 67 | .Fn strrchr | 71 | .Fn strrchr |
| 68 | function | 72 | function returns a pointer to the located character or |
| 69 | returns a pointer to the character, | 73 | .Dv NULL |
| 70 | or a null | 74 | if the character does not appear in the string. |
| 71 | pointer if | 75 | .Sh EXAMPLES |
| 72 | .Fa c | 76 | After the following call to |
| 73 | does not occur anywhere in | 77 | .Fn strrchr , |
| 74 | .Fa s . | 78 | .Va p |
| 79 | will point to the string | ||
| 80 | .Qq obar : | ||
| 81 | .Bd -literal -offset indent | ||
| 82 | char *p; | ||
| 83 | char *s = "foobar"; | ||
| 84 | |||
| 85 | p = strrchr(s, 'o'); | ||
| 86 | .Ed | ||
| 75 | .Sh SEE ALSO | 87 | .Sh SEE ALSO |
| 76 | .Xr index 3 , | ||
| 77 | .Xr memchr 3 , | 88 | .Xr memchr 3 , |
| 78 | .Xr rindex 3 , | ||
| 79 | .Xr strchr 3 , | 89 | .Xr strchr 3 , |
| 80 | .Xr strcspn 3 , | 90 | .Xr strcspn 3 , |
| 81 | .Xr strpbrk 3 , | 91 | .Xr strpbrk 3 , |
| @@ -86,6 +96,9 @@ does not occur anywhere in | |||
| 86 | .Sh STANDARDS | 96 | .Sh STANDARDS |
| 87 | The | 97 | The |
| 88 | .Fn strrchr | 98 | .Fn strrchr |
| 89 | function | 99 | function conforms to |
| 90 | conforms to | ||
| 91 | .St -ansiC . | 100 | .St -ansiC . |
| 101 | .Pp | ||
| 102 | The | ||
| 103 | .Fn rindex | ||
| 104 | function is deprecated and shouldn't be used in new code. | ||
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 21aa7376f2..ddcc22916a 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.11 2003/06/02 20:18:38 millert 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 June 9, 1993 |
| 38 | .Dt STRSEP 3 | 36 | .Dt STRSEP 3 |
| 39 | .Os | 37 | .Os |
| 40 | .Sh NAME | 38 | .Sh NAME |
| @@ -43,27 +41,37 @@ | |||
| 43 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
| 44 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
| 45 | .Ft char * | 43 | .Ft char * |
| 46 | .Fn strsep "char **stringp" "char *delim" | 44 | .Fn strsep "char **stringp" "const char *delim" |
| 47 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
| 48 | The | 46 | The |
| 49 | .Fn strsep | 47 | .Fn strsep |
| 50 | locates in the null-terminated string at | 48 | function locates, in the string referenced by |
| 51 | .Fa *stringp | ||
| 52 | the first occurrence of any character in | ||
| 53 | .Fa delim | ||
| 54 | and replaces this with a | ||
| 55 | .Ql \e0 , | ||
| 56 | records the location of the immediate following character in | ||
| 57 | .Fa *stringp , | 49 | .Fa *stringp , |
| 58 | then returns the original value of | 50 | the first occurrence of any character in the string |
| 51 | .Fa delim | ||
| 52 | (or the terminating | ||
| 53 | .Ql \e0 | ||
| 54 | character) and replaces it with a | ||
| 55 | .Ql \e0 . | ||
| 56 | The location of the next character after the delimiter character | ||
| 57 | (or | ||
| 58 | .Dv NULL , | ||
| 59 | if the end of the string was reached) is stored in | ||
| 59 | .Fa *stringp . | 60 | .Fa *stringp . |
| 60 | If no delimiter characters are found, | 61 | The original value of |
| 61 | .Fn strsep | ||
| 62 | sets | ||
| 63 | .Fa *stringp | 62 | .Fa *stringp |
| 63 | is returned. | ||
| 64 | .Pp | ||
| 65 | An | ||
| 66 | .Dq empty | ||
| 67 | field, i.e., one caused by two adjacent delimiter characters, | ||
| 68 | can be detected by comparing the location referenced by the pointer returned | ||
| 69 | by | ||
| 70 | .Fn strsep | ||
| 64 | to | 71 | to |
| 65 | .Dv NULL ; | 72 | .Ql \e0 . |
| 66 | if | 73 | .Pp |
| 74 | If | ||
| 67 | .Fa *stringp | 75 | .Fa *stringp |
| 68 | is initially | 76 | is initially |
| 69 | .Dv NULL , | 77 | .Dv NULL , |
| @@ -73,20 +81,32 @@ returns | |||
| 73 | .Sh EXAMPLES | 81 | .Sh EXAMPLES |
| 74 | The following uses | 82 | The following uses |
| 75 | .Fn strsep | 83 | .Fn strsep |
| 76 | to parse strings containing runs of white space, | 84 | to parse a string, containing tokens delimited by whitespace, into an |
| 77 | making up an argument vector: | 85 | argument vector: |
| 78 | .Bd -literal -offset indent | 86 | .Bd -literal -offset indent |
| 79 | char inputstring[100]; | 87 | char **ap, *argv[10], *inputstring; |
| 80 | char **argv[51], **ap = argv, *p, *val; | 88 | |
| 81 | /* set up inputstring */ | 89 | for (ap = argv; ap < &argv[9] && |
| 82 | for (p = inputstring; p != NULL; ) { | 90 | (*ap = strsep(&inputstring, " \et")) != NULL;) { |
| 83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 91 | if (**ap != '\e0') |
| 84 | *ap++ = val; | 92 | ap++; |
| 85 | } | 93 | } |
| 86 | *ap = 0; | 94 | *ap = NULL; |
| 87 | .Ed | 95 | .Ed |
| 88 | .Sh HISTORY | 96 | .Sh HISTORY |
| 89 | The | 97 | The |
| 90 | .Fn strsep | 98 | .Fn strsep |
| 91 | function is | 99 | function is intended as a replacement for the |
| 92 | .Ud . | 100 | .Fn strtok |
| 101 | function. | ||
| 102 | While the | ||
| 103 | .Fn strtok | ||
| 104 | function should be preferred for portability reasons (it conforms to | ||
| 105 | .St -ansiC ) | ||
| 106 | it is unable to handle empty fields, i.e., detect fields delimited by | ||
| 107 | two adjacent delimiter characters, or to be used for more than a single | ||
| 108 | string at a time. | ||
| 109 | The | ||
| 110 | .Fn strsep | ||
| 111 | function first appeared in | ||
| 112 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c index 69be7fe046..337d78e466 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.5 2003/06/11 21:08:16 deraadt 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,19 @@ | |||
| 31 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
| 32 | */ | 30 | */ |
| 33 | 31 | ||
| 32 | #include <string.h> | ||
| 33 | #include <stdio.h> | ||
| 34 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 35 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static const char sccsid[] = "from: @(#)strsep.c 5.4 (Berkeley) 1/26/91";*/ | 36 | #if 0 |
| 36 | static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | 37 | static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; |
| 38 | #else | ||
| 39 | static char *rcsid = "$OpenBSD: strsep.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; | ||
| 40 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 41 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 42 | ||
| 39 | #include <string.h> | ||
| 40 | |||
| 41 | /* | 43 | /* |
| 42 | * Get next token from string *stringp, where tokens are nonempty | 44 | * Get next token from string *stringp, where tokens are possibly-empty |
| 43 | * strings separated by characters from delim. | 45 | * strings separated by characters from delim. |
| 44 | * | 46 | * |
| 45 | * Writes NULs into the string at *stringp to end tokens. | 47 | * Writes NULs into the string at *stringp to end tokens. |
| @@ -47,16 +49,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 | 49 | * 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). | 50 | * be further tokens), or is NULL (if there are definitely no more tokens). |
| 49 | * | 51 | * |
| 50 | * If *stringp is NULL, strtoken returns NULL. | 52 | * If *stringp is NULL, strsep returns NULL. |
| 51 | */ | 53 | */ |
| 52 | char * | 54 | char * |
| 53 | strsep(stringp, delim) | 55 | strsep(char **stringp, const char *delim) |
| 54 | register char **stringp; | ||
| 55 | register const char *delim; | ||
| 56 | { | 56 | { |
| 57 | register char *s; | 57 | char *s; |
| 58 | register const char *spanp; | 58 | const char *spanp; |
| 59 | register int c, sc; | 59 | int c, sc; |
| 60 | char *tok; | 60 | char *tok; |
| 61 | 61 | ||
| 62 | if ((s = *stringp) == NULL) | 62 | if ((s = *stringp) == NULL) |
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3 index 3287fef53e..b1082c2dd0 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.4 2003/06/02 20:18:38 millert 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 June 29, 1991 |
| 40 | .Dt STRSIGNAL 3 | 35 | .Dt STRSIGNAL 3 |
| 41 | .Os BSD 4 | 36 | .Os |
| 42 | .Sh NAME | 37 | .Sh NAME |
| 43 | .Nm strsignal | 38 | .Nm strsignal |
| 44 | .Nd get signal description string | 39 | .Nd get signal description string |
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c index ec4a267edf..afe0deb272 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 | * |
| @@ -32,19 +28,18 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: strsignal.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| 40 | #include <limits.h> | 35 | #include <limits.h> |
| 41 | 36 | ||
| 42 | extern char *__strsignal __P((int, char *)); | 37 | extern char *__strsignal(int, char *); |
| 43 | 38 | ||
| 44 | char * | 39 | char * |
| 45 | strsignal(sig) | 40 | strsignal(int sig) |
| 46 | int sig; | ||
| 47 | { | 41 | { |
| 48 | static char buf[NL_TEXTMAX]; | 42 | static char buf[NL_TEXTMAX]; |
| 43 | |||
| 49 | return __strsignal(sig, buf); | 44 | return __strsignal(sig, buf); |
| 50 | } | 45 | } |
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3 index 4de03aa58b..54077b810c 100644 --- a/src/lib/libc/string/strspn.3 +++ b/src/lib/libc/string/strspn.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strspn.3,v 1.7 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt STRSPN 3 | 35 | .Dt STRSPN 3 |
| @@ -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 null-terminated string |
| 53 | spans the initial part of the null-terminated string | ||
| 54 | .Fa s | 48 | .Fa s |
| 55 | as long as the characters from | 49 | as long as the characters from |
| 56 | .Fa s | 50 | .Fa s |
| @@ -59,12 +53,23 @@ occur in string | |||
| 59 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
| 60 | The | 54 | The |
| 61 | .Fn strspn | 55 | .Fn strspn |
| 62 | function | 56 | function returns the number of characters spanned. |
| 63 | returns the number of characters spanned. | 57 | .Sh EXAMPLES |
| 58 | The following call to | ||
| 59 | .Fn strspn | ||
| 60 | will return 3, since the first three characters of string | ||
| 61 | .Fa s | ||
| 62 | are part of string | ||
| 63 | .Fa charset : | ||
| 64 | .Bd -literal -offset indent | ||
| 65 | char *s = "foobar"; | ||
| 66 | char *charset = "of"; | ||
| 67 | size_t span; | ||
| 68 | |||
| 69 | span = strspn(s, charset); | ||
| 70 | .Ed | ||
| 64 | .Sh SEE ALSO | 71 | .Sh SEE ALSO |
| 65 | .Xr index 3 , | ||
| 66 | .Xr memchr 3 , | 72 | .Xr memchr 3 , |
| 67 | .Xr rindex 3 , | ||
| 68 | .Xr strchr 3 , | 73 | .Xr strchr 3 , |
| 69 | .Xr strcspn 3 , | 74 | .Xr strcspn 3 , |
| 70 | .Xr strpbrk 3 , | 75 | .Xr strpbrk 3 , |
| @@ -75,6 +80,5 @@ returns the number of characters spanned. | |||
| 75 | .Sh STANDARDS | 80 | .Sh STANDARDS |
| 76 | The | 81 | The |
| 77 | .Fn strspn | 82 | .Fn strspn |
| 78 | function | 83 | function conforms to |
| 79 | conforms to | ||
| 80 | .St -ansiC . | 84 | .St -ansiC . |
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c index 6224b25c2a..d51a8cd3e6 100644 --- a/src/lib/libc/string/strspn.c +++ b/src/lib/libc/string/strspn.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 | * |
| @@ -32,8 +28,7 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strspn.c 5.8 (Berkeley) 1/26/91";*/ | 31 | static char *rcsid = "$OpenBSD: strspn.c,v 1.4 2003/06/11 21:08:29 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| @@ -42,12 +37,10 @@ static char *rcsid = "$Id: strspn.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $" | |||
| 42 | * Span the string s2 (skip characters that are in s2). | 37 | * Span the string s2 (skip characters that are in s2). |
| 43 | */ | 38 | */ |
| 44 | size_t | 39 | size_t |
| 45 | strspn(s1, s2) | 40 | strspn(const char *s1, const char *s2) |
| 46 | const char *s1; | ||
| 47 | register const char *s2; | ||
| 48 | { | 41 | { |
| 49 | register const char *p = s1, *spanp; | 42 | const char *p = s1, *spanp; |
| 50 | register char c, sc; | 43 | char c, sc; |
| 51 | 44 | ||
| 52 | /* | 45 | /* |
| 53 | * Skip any characters in s2, excluding the terminating \0. | 46 | * 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..47777dd89f 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,8 +29,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strstr.3,v 1.6 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 40 | .Dt STRSTR 3 | 35 | .Dt STRSTR 3 |
| @@ -49,8 +44,7 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn strstr | 46 | .Fn strstr |
| 52 | function | 47 | function locates the first occurrence of the null-terminated string |
| 53 | locates the first occurrence of the null-terminated string | ||
| 54 | .Fa little | 48 | .Fa little |
| 55 | in the null-terminated string | 49 | in the null-terminated string |
| 56 | .Fa big . | 50 | .Fa big . |
| @@ -65,15 +59,14 @@ if | |||
| 65 | occurs nowhere in | 59 | occurs nowhere in |
| 66 | .Fa big , | 60 | .Fa big , |
| 67 | .Fn strstr | 61 | .Fn strstr |
| 68 | returns NULL; | 62 | returns |
| 63 | .Dv NULL ; | ||
| 69 | otherwise | 64 | otherwise |
| 70 | .Fn strstr | 65 | .Fn strstr |
| 71 | returns a pointer to the first character of the first occurrence of | 66 | returns a pointer to the first character of the first occurrence of |
| 72 | .Fa little . | 67 | .Fa little . |
| 73 | .Sh SEE ALSO | 68 | .Sh SEE ALSO |
| 74 | .Xr index 3 , | ||
| 75 | .Xr memchr 3 , | 69 | .Xr memchr 3 , |
| 76 | .Xr rindex 3 , | ||
| 77 | .Xr strchr 3 , | 70 | .Xr strchr 3 , |
| 78 | .Xr strcspn 3 , | 71 | .Xr strcspn 3 , |
| 79 | .Xr strpbrk 3 , | 72 | .Xr strpbrk 3 , |
| @@ -84,6 +77,5 @@ returns a pointer to the first character of the first occurrence of | |||
| 84 | .Sh STANDARDS | 77 | .Sh STANDARDS |
| 85 | The | 78 | The |
| 86 | .Fn strstr | 79 | .Fn strstr |
| 87 | function | 80 | function conforms to |
| 88 | conforms to | ||
| 89 | .St -ansiC . | 81 | .St -ansiC . |
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c index 1ed59e357b..e6a94c5ce6 100644 --- a/src/lib/libc/string/strstr.c +++ b/src/lib/libc/string/strstr.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strstr.c 5.2 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strstr.c,v 1.4 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -45,11 +40,10 @@ static char *rcsid = "$Id: strstr.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $" | |||
| 45 | * Find the first occurrence of find in s. | 40 | * Find the first occurrence of find in s. |
| 46 | */ | 41 | */ |
| 47 | char * | 42 | char * |
| 48 | strstr(s, find) | 43 | strstr(const char *s, const char *find) |
| 49 | register const char *s, *find; | ||
| 50 | { | 44 | { |
| 51 | register char c, sc; | 45 | char c, sc; |
| 52 | register size_t len; | 46 | size_t len; |
| 53 | 47 | ||
| 54 | if ((c = *find++) != 0) { | 48 | if ((c = *find++) != 0) { |
| 55 | len = strlen(find); | 49 | len = strlen(find); |
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 index 644bd10aed..29eea4847e 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,29 +29,30 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strtok.3,v 1.17 2004/01/20 06:06:48 millert Exp $ |
| 37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd 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 null-terminated string, |
| 58 | is used to isolate sequential tokens in a null-terminated string, | ||
| 59 | .Fa str . | 56 | .Fa str . |
| 60 | These tokens are separated in the string by at least one of the | 57 | These tokens are separated in the string by at least one of the |
| 61 | characters in | 58 | characters in |
| @@ -71,17 +68,65 @@ The separator string, | |||
| 71 | must be supplied each time, and may change between calls. | 68 | must be supplied each time, and may change between calls. |
| 72 | .Pp | 69 | .Pp |
| 73 | The | 70 | The |
| 71 | .Fn strtok_r | ||
| 72 | function is a version of | ||
| 74 | .Fn strtok | 73 | .Fn strtok |
| 75 | function | 74 | that takes an explicit context argument and is reentrant. |
| 76 | returns a pointer to the beginning of each subsequent token in the string, | 75 | .Pp |
| 77 | after replacing the separator character itself with a | 76 | The |
| 78 | .Dv NUL | 77 | .Fn strtok |
| 78 | and | ||
| 79 | .Fn strtok_r | ||
| 80 | functions return a pointer to the beginning of each subsequent token | ||
| 81 | in the string, after replacing the separator character itself with an | ||
| 82 | .Tn ASCII NUL | ||
| 79 | character. | 83 | character. |
| 80 | When no more tokens remain, a null pointer is returned. | 84 | When no more tokens remain, a null pointer is returned. |
| 85 | .Pp | ||
| 86 | Since | ||
| 87 | .Fn strtok | ||
| 88 | and | ||
| 89 | .Fn strtok_r | ||
| 90 | modify the string, | ||
| 91 | .Fa str | ||
| 92 | should not point to an area in the initialized data segment. | ||
| 93 | .Sh EXAMPLES | ||
| 94 | The following will construct an array of pointers to each individual word in | ||
| 95 | the string | ||
| 96 | .Va s : | ||
| 97 | .Bd -literal -offset indent | ||
| 98 | #define MAXTOKENS 128 | ||
| 99 | |||
| 100 | char s[512], *p, *tokens[MAXTOKENS]; | ||
| 101 | char *last; | ||
| 102 | int i = 0; | ||
| 103 | |||
| 104 | snprintf(s, sizeof(s), "cat dog horse cow"); | ||
| 105 | |||
| 106 | for ((p = strtok_r(s, " ", &last)); p; | ||
| 107 | (p = strtok_r(NULL, " ", &last))) { | ||
| 108 | if (i < MAXTOKENS - 1) | ||
| 109 | tokens[i++] = p; | ||
| 110 | } | ||
| 111 | tokens[i] = NULL; | ||
| 112 | .Ed | ||
| 113 | .Pp | ||
| 114 | That is, | ||
| 115 | .Li tokens[0] | ||
| 116 | will point to | ||
| 117 | .Qq cat , | ||
| 118 | .Li tokens[1] | ||
| 119 | will point to | ||
| 120 | .Qq dog , | ||
| 121 | .Li tokens[2] | ||
| 122 | will point to | ||
| 123 | .Qq horse , | ||
| 124 | and | ||
| 125 | .Li tokens[3] | ||
| 126 | will point to | ||
| 127 | .Qq cow . | ||
| 81 | .Sh SEE ALSO | 128 | .Sh SEE ALSO |
| 82 | .Xr index 3 , | ||
| 83 | .Xr memchr 3 , | 129 | .Xr memchr 3 , |
| 84 | .Xr rindex 3 , | ||
| 85 | .Xr strchr 3 , | 130 | .Xr strchr 3 , |
| 86 | .Xr strcspn 3 , | 131 | .Xr strcspn 3 , |
| 87 | .Xr strpbrk 3 , | 132 | .Xr strpbrk 3 , |
| @@ -92,21 +137,16 @@ When no more tokens remain, a null pointer is returned. | |||
| 92 | .Sh STANDARDS | 137 | .Sh STANDARDS |
| 93 | The | 138 | The |
| 94 | .Fn strtok | 139 | .Fn strtok |
| 95 | function | 140 | function conforms to |
| 96 | conforms to | ||
| 97 | .St -ansiC . | 141 | .St -ansiC . |
| 98 | .Sh BUGS | 142 | .Sh BUGS |
| 99 | There is no way to get tokens from multiple strings simultaneously. | ||
| 100 | .Pp | ||
| 101 | The System V | 143 | The System V |
| 102 | .Fn strtok , | 144 | .Fn strtok , |
| 103 | if handed a string containing only delimiter characters, | 145 | if handed a string containing only delimiter characters, |
| 104 | will not alter the next starting point, so that a call to | 146 | will not alter the next starting point, so that a call to |
| 105 | .Fn strtok | 147 | .Fn strtok |
| 106 | with a different (or empty) delimiter string | 148 | with a different (or empty) delimiter string |
| 107 | may return a | 149 | may return a non-null value. |
| 108 | .Pf non- Dv NULL | ||
| 109 | value. | ||
| 110 | Since this implementation always alters the next starting point, | 150 | Since this implementation always alters the next starting point, |
| 111 | such a sequence of calls would always return | 151 | such a sequence of calls would always return |
| 112 | .Dv NULL . | 152 | .Dv NULL . |
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c index 9f712579bf..6498eac8cc 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 | * |
| @@ -32,24 +28,28 @@ | |||
| 32 | */ | 28 | */ |
| 33 | 29 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strtok.c 5.8 (Berkeley) 2/24/91";*/ | 31 | static char *rcsid = "$OpenBSD: strtok.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 33 | ||
| 39 | #include <string.h> | 34 | #include <string.h> |
| 40 | 35 | ||
| 41 | char * | 36 | char * |
| 42 | strtok(s, delim) | 37 | strtok(char *s, const char *delim) |
| 43 | register char *s; | ||
| 44 | register const char *delim; | ||
| 45 | { | 38 | { |
| 46 | register char *spanp; | ||
| 47 | register int c, sc; | ||
| 48 | char *tok; | ||
| 49 | static char *last; | 39 | static char *last; |
| 50 | 40 | ||
| 41 | return strtok_r(s, delim, &last); | ||
| 42 | } | ||
| 43 | |||
| 44 | char * | ||
| 45 | strtok_r(char *s, const char *delim, char **last) | ||
| 46 | { | ||
| 47 | char *spanp; | ||
| 48 | int c, sc; | ||
| 49 | char *tok; | ||
| 50 | |||
| 51 | 51 | ||
| 52 | if (s == NULL && (s = last) == NULL) | 52 | if (s == NULL && (s = *last) == NULL) |
| 53 | return (NULL); | 53 | return (NULL); |
| 54 | 54 | ||
| 55 | /* | 55 | /* |
| @@ -63,7 +63,7 @@ cont: | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | if (c == 0) { /* no non-delimiter characters */ | 65 | if (c == 0) { /* no non-delimiter characters */ |
| 66 | last = NULL; | 66 | *last = NULL; |
| 67 | return (NULL); | 67 | return (NULL); |
| 68 | } | 68 | } |
| 69 | tok = s - 1; | 69 | tok = s - 1; |
| @@ -81,7 +81,7 @@ cont: | |||
| 81 | s = NULL; | 81 | s = NULL; |
| 82 | else | 82 | else |
| 83 | s[-1] = 0; | 83 | s[-1] = 0; |
| 84 | last = s; | 84 | *last = s; |
| 85 | return (tok); | 85 | return (tok); |
| 86 | } | 86 | } |
| 87 | } while (sc != 0); | 87 | } while (sc != 0); |
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3 index 84fd945472..edf2bfb8a0 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,8 +29,7 @@ | |||
| 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.4 2003/06/02 20:18:38 millert 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 June 29, 1991 |
| 40 | .Dt STRXFRM 3 | 35 | .Dt STRXFRM 3 |
| @@ -49,8 +44,7 @@ | |||
| 49 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 50 | The | 45 | The |
| 51 | .Fn strxfrm | 46 | .Fn strxfrm |
| 52 | function | 47 | function does something horrible (see |
| 53 | does something horrible (see | ||
| 54 | .Tn ANSI | 48 | .Tn ANSI |
| 55 | standard). | 49 | standard). |
| 56 | In this implementation it just copies. | 50 | In this implementation it just copies. |
| @@ -64,6 +58,5 @@ In this implementation it just copies. | |||
| 64 | .Sh STANDARDS | 58 | .Sh STANDARDS |
| 65 | The | 59 | The |
| 66 | .Fn strxfrm | 60 | .Fn strxfrm |
| 67 | function | 61 | function conforms to |
| 68 | conforms to | ||
| 69 | .St -ansiC . | 62 | .St -ansiC . |
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c index d9df77b957..a2e2dbc440 100644 --- a/src/lib/libc/string/strxfrm.c +++ b/src/lib/libc/string/strxfrm.c | |||
| @@ -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 | * |
| @@ -35,8 +31,7 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strxfrm.c 5.2 (Berkeley) 1/26/91";*/ | 34 | static char *rcsid = "$OpenBSD: strxfrm.c,v 1.5 2003/09/06 22:43:12 tedu Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <string.h> |
| @@ -47,28 +42,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. | 42 | * on the original untransformed strings would return. |
| 48 | */ | 43 | */ |
| 49 | size_t | 44 | size_t |
| 50 | strxfrm(dst, src, n) | 45 | strxfrm(char *dst, const char *src, size_t n) |
| 51 | register char *dst; | ||
| 52 | register const char *src; | ||
| 53 | register size_t n; | ||
| 54 | { | 46 | { |
| 55 | register size_t r = 0; | ||
| 56 | register int c; | ||
| 57 | 47 | ||
| 58 | /* | 48 | /* |
| 59 | * Since locales are unimplemented, this is just a copy. | 49 | * Since locales are unimplemented, this is just a copy. |
| 60 | */ | 50 | */ |
| 61 | if (n != 0) { | 51 | if (n == 0) |
| 62 | while ((c = *src++) != 0) { | 52 | return (strlen(src)); |
| 63 | r++; | 53 | 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 | } | 54 | } |
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3 index 133c487bbd..abeff903de 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,8 +25,7 @@ | |||
| 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.5 2003/06/02 20:18:38 millert 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 May 1, 1991 |
| 36 | .Dt SWAB 3 | 31 | .Dt SWAB 3 |
| @@ -39,7 +34,7 @@ | |||
| 39 | .Nm swab | 34 | .Nm swab |
| 40 | .Nd swap adjacent bytes | 35 | .Nd swap adjacent bytes |
| 41 | .Sh SYNOPSIS | 36 | .Sh SYNOPSIS |
| 42 | .Fd #include <string.h> | 37 | .Fd #include <unistd.h> |
| 43 | .Ft void | 38 | .Ft void |
| 44 | .Fn swab "const void *src" "void *dst" "size_t len" | 39 | .Fn swab "const void *src" "void *dst" "size_t len" |
| 45 | .Sh DESCRIPTION | 40 | .Sh DESCRIPTION |
| @@ -55,7 +50,7 @@ swapping adjacent bytes. | |||
| 55 | .Pp | 50 | .Pp |
| 56 | The argument | 51 | The argument |
| 57 | .Fa len | 52 | .Fa len |
| 58 | must be even number. | 53 | must be an even number. |
| 59 | .Sh SEE ALSO | 54 | .Sh SEE ALSO |
| 60 | .Xr bzero 3 , | 55 | .Xr bzero 3 , |
| 61 | .Xr memset 3 | 56 | .Xr memset 3 |
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c index f33fc53bd6..b928f21aa7 100644 --- a/src/lib/libc/string/swab.c +++ b/src/lib/libc/string/swab.c | |||
| @@ -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 | * |
| @@ -35,17 +31,13 @@ | |||
| 35 | */ | 31 | */ |
| 36 | 32 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)swab.c 5.10 (Berkeley) 3/6/91";*/ | 34 | static char *rcsid = "$OpenBSD: swab.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; |
| 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 */ | 35 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 36 | ||
| 42 | #include <string.h> | 37 | #include <unistd.h> |
| 43 | 38 | ||
| 44 | void | 39 | void |
| 45 | swab(from, to, len) | 40 | swab(const void *from, void *to, size_t len) |
| 46 | const void *from; | ||
| 47 | void *to; | ||
| 48 | size_t len; | ||
| 49 | { | 41 | { |
| 50 | register unsigned long temp; | 42 | register unsigned long temp; |
| 51 | register int n; | 43 | register int n; |
