diff options
Diffstat (limited to 'src/lib/libc/string')
75 files changed, 1234 insertions, 1273 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 2b7ce63a63..e7b81d0c43 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.10 2001/09/05 16:27:01 mickey 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 | 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,38 @@ 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 | ||
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c index cd604906db..ae19ab3365 100644 --- a/src/lib/libc/string/__strerror.c +++ b/src/lib/libc/string/__strerror.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: __strerror.c,v 1.8 2001/12/08 20:37:32 deraadt 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #ifdef NLS | 38 | #ifdef NLS |
| @@ -46,9 +45,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 | 45 | #define sys_errlist _sys_errlist |
| 47 | #define sys_nerr _sys_nerr | 46 | #define sys_nerr _sys_nerr |
| 48 | 47 | ||
| 48 | #include <errno.h> | ||
| 49 | #include <limits.h> | ||
| 49 | #include <stdio.h> | 50 | #include <stdio.h> |
| 50 | #include <string.h> | 51 | #include <string.h> |
| 51 | 52 | ||
| 53 | static char * | ||
| 54 | itoa(num) | ||
| 55 | int num; | ||
| 56 | { | ||
| 57 | static char buffer[11]; | ||
| 58 | char *p; | ||
| 59 | |||
| 60 | p = buffer + 4; | ||
| 61 | while (num >= 10) { | ||
| 62 | *--p = (num % 10) + '0'; | ||
| 63 | num /= 10; | ||
| 64 | } | ||
| 65 | *p = (num % 10) + '0'; | ||
| 66 | return p; | ||
| 67 | } | ||
| 68 | |||
| 52 | /* | 69 | /* |
| 53 | * Since perror() is not allowed to change the contents of strerror()'s | 70 | * Since perror() is not allowed to change the contents of strerror()'s |
| 54 | * static buffer, both functions supply their own buffers to the | 71 | * static buffer, both functions supply their own buffers to the |
| @@ -60,32 +77,37 @@ __strerror(num, buf) | |||
| 60 | int num; | 77 | int num; |
| 61 | char *buf; | 78 | char *buf; |
| 62 | { | 79 | { |
| 63 | #define UPREFIX "Unknown error: %u" | 80 | #define UPREFIX "Unknown error: " |
| 64 | register unsigned int errnum; | 81 | register unsigned int errnum; |
| 65 | |||
| 66 | #ifdef NLS | 82 | #ifdef NLS |
| 67 | nl_catd catd ; | 83 | int save_errno; |
| 84 | nl_catd catd; | ||
| 85 | |||
| 68 | catd = catopen("libc", 0); | 86 | catd = catopen("libc", 0); |
| 69 | #endif | 87 | #endif |
| 70 | 88 | ||
| 71 | errnum = num; /* convert to unsigned */ | 89 | errnum = num; /* convert to unsigned */ |
| 72 | if (errnum < sys_nerr) { | 90 | if (errnum < sys_nerr) { |
| 73 | #ifdef NLS | 91 | #ifdef NLS |
| 74 | strcpy(buf, catgets(catd, 1, errnum, | 92 | strlcpy(buf, catgets(catd, 1, errnum, |
| 75 | (char *)sys_errlist[errnum])); | 93 | (char *)sys_errlist[errnum]), NL_TEXTMAX); |
| 76 | #else | 94 | #else |
| 77 | return(sys_errlist[errnum]); | 95 | return(sys_errlist[errnum]); |
| 78 | #endif | 96 | #endif |
| 79 | } else { | 97 | } else { |
| 80 | #ifdef NLS | 98 | #ifdef NLS |
| 81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | 99 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
| 82 | #else | 100 | #else |
| 83 | sprintf(buf, UPREFIX, errnum); | 101 | strcpy(buf, UPREFIX); |
| 84 | #endif | 102 | #endif |
| 103 | strncat(buf, itoa(errnum), NL_TEXTMAX-strlen(buf)-1); | ||
| 104 | errno = EINVAL; | ||
| 85 | } | 105 | } |
| 86 | 106 | ||
| 87 | #ifdef NLS | 107 | #ifdef NLS |
| 108 | save_errno = errno; | ||
| 88 | catclose(catd); | 109 | catclose(catd); |
| 110 | errno = save_errno; | ||
| 89 | #endif | 111 | #endif |
| 90 | 112 | ||
| 91 | return buf; | 113 | return buf; |
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c index 1937e2d608..4ca5bad3c0 100644 --- a/src/lib/libc/string/__strsignal.c +++ b/src/lib/libc/string/__strsignal.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: __strsignal.c,v 1.6 2001/06/27 00:58:56 lebel 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #ifdef NLS | 38 | #ifdef NLS |
| @@ -46,15 +45,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 | 45 | #define sys_siglist _sys_siglist |
| 47 | 46 | ||
| 48 | #include <stdio.h> | 47 | #include <stdio.h> |
| 48 | #include <limits.h> | ||
| 49 | #include <signal.h> | 49 | #include <signal.h> |
| 50 | #include <string.h> | 50 | #include <string.h> |
| 51 | 51 | ||
| 52 | static char *itoa(num) | ||
| 53 | int num; | ||
| 54 | { | ||
| 55 | static char buffer[11]; | ||
| 56 | char *p; | ||
| 57 | |||
| 58 | p = buffer + 4; | ||
| 59 | while (num >= 10) { | ||
| 60 | *--p = (num % 10) + '0'; | ||
| 61 | num /= 10; | ||
| 62 | } | ||
| 63 | *p = (num % 10) + '0'; | ||
| 64 | return p; | ||
| 65 | } | ||
| 66 | |||
| 52 | char * | 67 | char * |
| 53 | __strsignal(num, buf) | 68 | __strsignal(num, buf) |
| 54 | int num; | 69 | int num; |
| 55 | char *buf; | 70 | char *buf; |
| 56 | { | 71 | { |
| 57 | #define UPREFIX "Unknown signal: %u" | 72 | #define UPREFIX "Unknown signal: " |
| 58 | register unsigned int signum; | 73 | register unsigned int signum; |
| 59 | 74 | ||
| 60 | #ifdef NLS | 75 | #ifdef NLS |
| @@ -65,17 +80,18 @@ __strsignal(num, buf) | |||
| 65 | signum = num; /* convert to unsigned */ | 80 | signum = num; /* convert to unsigned */ |
| 66 | if (signum < NSIG) { | 81 | if (signum < NSIG) { |
| 67 | #ifdef NLS | 82 | #ifdef NLS |
| 68 | strcpy(buf, catgets(catd, 2, signum, | 83 | strlcpy(buf, catgets(catd, 2, signum, |
| 69 | (char *)sys_siglist[signum])); | 84 | (char *)sys_siglist[signum]), NL_TEXTMAX); |
| 70 | #else | 85 | #else |
| 71 | return((char *)sys_siglist[signum]); | 86 | return((char *)sys_siglist[signum]); |
| 72 | #endif | 87 | #endif |
| 73 | } else { | 88 | } else { |
| 74 | #ifdef NLS | 89 | #ifdef NLS |
| 75 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); | 90 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
| 76 | #else | 91 | #else |
| 77 | sprintf(buf, UPREFIX, signum); | 92 | strcpy(buf, UPREFIX); |
| 78 | #endif | 93 | #endif |
| 94 | strncat(buf, itoa(signum), NL_TEXTMAX-strlen(buf)-1); | ||
| 79 | } | 95 | } |
| 80 | 96 | ||
| 81 | #ifdef NLS | 97 | #ifdef NLS |
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3 index 118c55c579..d880c1e6f0 100644 --- a/src/lib/libc/string/bcmp.3 +++ b/src/lib/libc/string/bcmp.3 | |||
| @@ -31,12 +31,11 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bcmp.3,v 1.5 2000/04/21 15:24:18 aaron Exp $ |
| 35 | .\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
| 36 | .\" | 35 | .\" |
| 37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
| 38 | .Dt BCMP 3 | 37 | .Dt BCMP 3 |
| 39 | .Os BSD 4.2 | 38 | .Os |
| 40 | .Sh NAME | 39 | .Sh NAME |
| 41 | .Nm bcmp | 40 | .Nm bcmp |
| 42 | .Nd compare byte string | 41 | .Nd compare byte string |
| @@ -47,8 +46,7 @@ | |||
| 47 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 48 | The | 47 | The |
| 49 | .Fn bcmp | 48 | .Fn bcmp |
| 50 | function | 49 | function compares byte string |
| 51 | compares byte string | ||
| 52 | .Fa b1 | 50 | .Fa b1 |
| 53 | against byte string | 51 | against byte string |
| 54 | .Fa b2 , | 52 | .Fa b2 , |
| @@ -68,5 +66,5 @@ The strings may overlap. | |||
| 68 | .Sh HISTORY | 66 | .Sh HISTORY |
| 69 | A | 67 | A |
| 70 | .Fn bcmp | 68 | .Fn bcmp |
| 71 | function first appeared in | 69 | function first appeared in |
| 72 | .Bx 4.2 . | 70 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c index 2cc38baee3..4ed00975a4 100644 --- a/src/lib/libc/string/bcmp.c +++ b/src/lib/libc/string/bcmp.c | |||
| @@ -32,15 +32,19 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)bcmp.c 5.6 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: bcmp.c,v 1.4 1996/08/19 08:33:57 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 38 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 39 | #include <string.h> |
| 40 | #else | ||
| 41 | #include <lib/libkern/libkern.h> | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | /* | 44 | /* |
| 42 | * bcmp -- vax cmpc3 instruction | 45 | * bcmp -- vax cmpc3 instruction |
| 43 | */ | 46 | */ |
| 47 | int | ||
| 44 | bcmp(b1, b2, length) | 48 | bcmp(b1, b2, length) |
| 45 | const void *b1, *b2; | 49 | const void *b1, *b2; |
| 46 | register size_t length; | 50 | register size_t length; |
diff --git a/src/lib/libc/string/bcopy.3 b/src/lib/libc/string/bcopy.3 index 6db3812caf..b290418f4a 100644 --- a/src/lib/libc/string/bcopy.3 +++ b/src/lib/libc/string/bcopy.3 | |||
| @@ -32,12 +32,11 @@ | |||
| 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
| 34 | .\" | 34 | .\" |
| 35 | .\" from: @(#)bcopy.3 5.3 (Berkeley) 4/19/91 | 35 | .\" $OpenBSD: bcopy.3,v 1.5 2000/04/21 15:24:19 aaron Exp $ |
| 36 | .\" $Id: bcopy.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
| 37 | .\" | 36 | .\" |
| 38 | .Dd April 19, 1991 | 37 | .Dd April 19, 1991 |
| 39 | .Dt BCOPY 3 | 38 | .Dt BCOPY 3 |
| 40 | .Os BSD 4.2 | 39 | .Os |
| 41 | .Sh NAME | 40 | .Sh NAME |
| 42 | .Nm bcopy | 41 | .Nm bcopy |
| 43 | .Nd copy byte string | 42 | .Nd copy byte string |
| @@ -48,8 +47,7 @@ | |||
| 48 | .Sh DESCRIPTION | 47 | .Sh DESCRIPTION |
| 49 | The | 48 | The |
| 50 | .Fn bcopy | 49 | .Fn bcopy |
| 51 | function | 50 | function copies |
| 52 | copies | ||
| 53 | .Fa len | 51 | .Fa len |
| 54 | bytes from string | 52 | bytes from string |
| 55 | .Fa src | 53 | .Fa src |
| @@ -68,5 +66,5 @@ is zero, no bytes are copied. | |||
| 68 | .Sh HISTORY | 66 | .Sh HISTORY |
| 69 | A | 67 | A |
| 70 | .Fn bcopy | 68 | .Fn bcopy |
| 71 | function appeared in | 69 | function appeared in |
| 72 | .Bx 4.2 . | 70 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c index 92feed66ea..023a3b2db2 100644 --- a/src/lib/libc/string/bcopy.c +++ b/src/lib/libc/string/bcopy.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)bcopy.c 5.11 (Berkeley) 6/21/91";*/ | 38 | static char *rcsid = "$OpenBSD: bcopy.c,v 1.2 1996/08/19 08:33:58 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 index 2264a6a1c4..7138ee4271 100644 --- a/src/lib/libc/string/bm.3 +++ b/src/lib/libc/string/bm.3 | |||
| @@ -32,83 +32,84 @@ | |||
| 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
| 34 | .\" | 34 | .\" |
| 35 | .\" from: @(#)bm.3 8.4 (Berkeley) 6/21/94 | 35 | .\" $OpenBSD: bm.3,v 1.6 2001/06/23 14:42:12 deraadt Exp $ |
| 36 | .\" $Id: bm.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
| 37 | .\" | 36 | .\" |
| 38 | .TH BM 3 | 37 | .Dd June 29, 1999 |
| 39 | .SH NAME | 38 | .Dt BM 3 |
| 40 | bm_comp, bm_exec, bm_free \- Boyer-Moore string search | 39 | .Os |
| 41 | .SH SYNOPSIS | 40 | .Sh NAME |
| 42 | .ft B | 41 | .Nm bm_comp , |
| 43 | #include <sys/types.h> | 42 | .Nm bm_exec , |
| 44 | .br | 43 | .Nm bm_free |
| 45 | #include <bm.h> | 44 | .Nd Boyer-Moore string search |
| 46 | .sp | 45 | .Sh SYNOPSIS |
| 47 | bm_pat * | 46 | .Fd #include <sys/types.h> |
| 48 | .br | 47 | .Fd #include <bm.h> |
| 49 | bm_comp(u_char *pattern, size_t patlen, u_char freq[256]); | 48 | .Ft bm_pat * |
| 50 | .sp | 49 | .Fn bm_comp "u_char *pattern" "size_t patlen" "u_char freq[256]" |
| 51 | u_char * | 50 | .Ft u_char * |
| 52 | .br | 51 | .Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len" |
| 53 | bm_exec(bm_pat *pdesc, u_char *text, size_t len); | 52 | .Ft void |
| 54 | .sp | 53 | .Fn bm_free "bm_pat *pdesc" |
| 55 | void | 54 | .Sh DESCRIPTION |
| 56 | .br | ||
| 57 | bm_free(bm_pat *pdesc); | ||
| 58 | .SH DESCRIPTION | ||
| 59 | These routines implement an efficient mechanism to find an | 55 | These routines implement an efficient mechanism to find an |
| 60 | occurrence of a byte string within another byte string. | 56 | occurrence of a byte string within another byte string. |
| 61 | .PP | 57 | .Pp |
| 62 | .I Bm_comp | 58 | .Fn bm_comp |
| 63 | evaluates the | 59 | evaluates |
| 64 | .I patlen | 60 | .Fa patlen |
| 65 | bytes starting at | 61 | bytes starting at |
| 66 | .IR pattern , | 62 | .Fa pattern |
| 67 | and returns a pointer to a structure describing them. | 63 | and returns a pointer to a structure describing them. |
| 68 | The bytes referenced by | 64 | The bytes referenced by |
| 69 | .I pattern | 65 | .Fa pattern |
| 70 | may be of any value. | 66 | may be of any value. |
| 71 | .PP | 67 | .Pp |
| 72 | The search takes advantage of the frequency distribution of the | 68 | The search takes advantage of the frequency distribution of the |
| 73 | bytes in the text to be searched. | 69 | bytes in the text to be searched. |
| 74 | If specified, | 70 | If specified, |
| 75 | .I freq | 71 | .Ar freq |
| 76 | should be an array of 256 values, | 72 | should be an array of 256 values, |
| 77 | with higher values indicating that the corresponding character occurs | 73 | with higher values indicating that the corresponding character occurs |
| 78 | more frequently. | 74 | more frequently. |
| 79 | (A less than optimal frequency distribution can only result in less | 75 | (A less than optimal frequency distribution can only result in less |
| 80 | than optimal performance, not incorrect results.) | 76 | than optimal performance, not incorrect results.) |
| 81 | If | 77 | If |
| 82 | .I freq | 78 | .Ar freq |
| 83 | is NULL, | 79 | is |
| 80 | .Dv NULL , | ||
| 84 | a system default table is used. | 81 | a system default table is used. |
| 85 | .PP | 82 | .Pp |
| 86 | .I Bm_exec | 83 | .Fn bm_exec |
| 87 | returns a pointer to the leftmost occurrence of the string given to | 84 | returns a pointer to the leftmost occurrence of the string given to |
| 88 | .I bm_comp | 85 | .Fn bm_comp |
| 89 | within | 86 | within |
| 90 | .IR text , | 87 | .Ar text , |
| 91 | or NULL if none occurs. | 88 | or |
| 89 | .Dv NULL | ||
| 90 | if none occurs. | ||
| 92 | The number of bytes in | 91 | The number of bytes in |
| 93 | .I text | 92 | .Ar text |
| 94 | must be specified by | 93 | must be specified by |
| 95 | .IR len . | 94 | .Ar len . |
| 96 | .PP | 95 | .Pp |
| 97 | Space allocated for the returned description is discarded | 96 | Space allocated for the returned description is discarded |
| 98 | by calling | 97 | by calling |
| 99 | .I bm_free | 98 | .Fn bm_free |
| 100 | with the returned description as an argument. | 99 | with the returned description as an argument. |
| 101 | .PP | 100 | .Pp |
| 102 | The asymptotic speed of | 101 | The asymptotic speed of |
| 103 | .I bm_exec | 102 | .Fn bm_exec |
| 104 | is | 103 | is |
| 105 | .RI O( len / patlen ). | 104 | .Pf O Ns Pq len / patlen . |
| 106 | .PP | 105 | .Sh SEE ALSO |
| 107 | .SH "SEE ALSO" | 106 | .Xr regexp 3 , |
| 108 | .IR regexp (3), | 107 | .Xr strstr 3 |
| 109 | .IR strstr (3) | 108 | .Rs |
| 110 | .sp | 109 | .%R "Fast String Searching" |
| 111 | .IR "Fast String Searching" , | 110 | .%A Andrew Hume |
| 112 | Hume and Sunday, | 111 | .%A Daniel Sunday |
| 113 | Software Practice and Experience, | 112 | .%J "Software Practice and Experience" |
| 114 | Vol. 21, 11 (November 1991) pp. 1221-48. | 113 | .%V Volume 21, 11 (November 1991) |
| 114 | .%P 1221-48 | ||
| 115 | .Re | ||
diff --git a/src/lib/libc/string/bm.c b/src/lib/libc/string/bm.c index 68eac22ecc..b191d340f6 100644 --- a/src/lib/libc/string/bm.c +++ b/src/lib/libc/string/bm.c | |||
| @@ -34,10 +34,9 @@ | |||
| 34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #ifndef lint | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /* from: static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94"; */ | 38 | static char *rcsid = "$OpenBSD: bm.c,v 1.3 1996/08/19 08:33:59 tholo Exp $"; |
| 39 | static char *rcsid = "$Id: bm.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | 39 | #endif /* LIBC_SCCS and not lint */ |
| 40 | #endif /* not lint */ | ||
| 41 | 40 | ||
| 42 | #include <sys/types.h> | 41 | #include <sys/types.h> |
| 43 | 42 | ||
diff --git a/src/lib/libc/string/bstring.3 b/src/lib/libc/string/bstring.3 index 12fcfb0cc1..85283321c8 100644 --- a/src/lib/libc/string/bstring.3 +++ b/src/lib/libc/string/bstring.3 | |||
| @@ -31,8 +31,7 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" from: @(#)bstring.3 6.8 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bstring.3,v 1.4 2000/04/21 15:24:19 aaron Exp $ |
| 35 | .\" $Id: bstring.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | 35 | .\" |
| 37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
| 38 | .Dt BSTRING 3 | 37 | .Dt BSTRING 3 |
| @@ -45,7 +44,7 @@ | |||
| 45 | .Nm memchr , | 44 | .Nm memchr , |
| 46 | .Nm memcmp , | 45 | .Nm memcmp , |
| 47 | .Nm memcpy , | 46 | .Nm memcpy , |
| 48 | .Nm memmove, | 47 | .Nm memmove , |
| 49 | .Nm memset | 48 | .Nm memset |
| 50 | .Nd byte string operations | 49 | .Nd byte string operations |
| 51 | .Sh SYNOPSIS | 50 | .Sh SYNOPSIS |
| @@ -97,14 +96,15 @@ and | |||
| 97 | conform to | 96 | conform to |
| 98 | .St -ansiC . | 97 | .St -ansiC . |
| 99 | .Sh HISTORY | 98 | .Sh HISTORY |
| 100 | The functions | 99 | The |
| 101 | .Fn bzero | 100 | .Fn bzero |
| 102 | and | 101 | and |
| 103 | .Fn memccpy | 102 | .Fn memccpy |
| 104 | appeared in | 103 | functions appeared in |
| 105 | .Bx 4.3 ; | 104 | .Bx 4.3 . |
| 106 | the functions | 105 | The |
| 107 | .Fn bcmp , | 106 | .Fn bcmp |
| 108 | .Fn bcopy , | 107 | and |
| 109 | appeared in | 108 | .Fn bcopy |
| 109 | functions appeared in | ||
| 110 | .Bx 4.2 . | 110 | .Bx 4.2 . |
diff --git a/src/lib/libc/string/bzero.3 b/src/lib/libc/string/bzero.3 index 4f0141e051..a735d5ef3f 100644 --- a/src/lib/libc/string/bzero.3 +++ b/src/lib/libc/string/bzero.3 | |||
| @@ -31,12 +31,11 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" from: @(#)bzero.3 5.3 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: bzero.3,v 1.5 2000/04/21 15:24:19 aaron Exp $ |
| 35 | .\" $Id: bzero.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | 35 | .\" |
| 37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
| 38 | .Dt BZERO 3 | 37 | .Dt BZERO 3 |
| 39 | .Os BSD 4.3 | 38 | .Os |
| 40 | .Sh NAME | 39 | .Sh NAME |
| 41 | .Nm bzero | 40 | .Nm bzero |
| 42 | .Nd write zeroes to a byte string | 41 | .Nd write zeroes to a byte string |
| @@ -47,8 +46,7 @@ | |||
| 47 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 48 | The | 47 | The |
| 49 | .Fn bzero | 48 | .Fn bzero |
| 50 | function | 49 | function writes |
| 51 | writes | ||
| 52 | .Fa len | 50 | .Fa len |
| 53 | zero bytes to the string | 51 | zero bytes to the string |
| 54 | .Fa b . | 52 | .Fa b . |
| @@ -63,6 +61,5 @@ does nothing. | |||
| 63 | .Sh HISTORY | 61 | .Sh HISTORY |
| 64 | A | 62 | A |
| 65 | .Fn bzero | 63 | .Fn bzero |
| 66 | function | 64 | function appeared in |
| 67 | appeared in | ||
| 68 | .Bx 4.3 . | 65 | .Bx 4.3 . |
diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c index 4865e396ef..3e660a307f 100644 --- a/src/lib/libc/string/bzero.c +++ b/src/lib/libc/string/bzero.c | |||
| @@ -32,11 +32,14 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)bzero.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: bzero.c,v 1.3 1996/08/19 08:34:00 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 38 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 39 | #include <string.h> |
| 40 | #else | ||
| 41 | #include <lib/libkern/libkern.h> | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | /* | 44 | /* |
| 42 | * bzero -- vax movc5 instruction | 45 | * bzero -- vax movc5 instruction |
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 index 6464bea2b1..dc7a20741e 100644 --- a/src/lib/libc/string/ffs.3 +++ b/src/lib/libc/string/ffs.3 | |||
| @@ -31,8 +31,7 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" from: @(#)ffs.3 5.3 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: ffs.3,v 1.3 2000/04/21 15:24:19 aaron Exp $ |
| 35 | .\" $Id: ffs.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 36 | .\" | 35 | .\" |
| 37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
| 38 | .Dt FFS 3 | 37 | .Dt FFS 3 |
| @@ -47,12 +46,10 @@ | |||
| 47 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 48 | The | 47 | The |
| 49 | .Fn ffs | 48 | .Fn ffs |
| 50 | function | 49 | function finds the first bit set in |
| 51 | finds the first bit set in | ||
| 52 | .Fa value | 50 | .Fa value |
| 53 | and returns the index of that bit. | 51 | and returns the index of that bit. |
| 54 | Bits are numbered starting from 1, starting at the right-most | 52 | 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. | 53 | A return value of 0 means that the argument was zero. |
| 57 | .Sh SEE ALSO | 54 | .Sh SEE ALSO |
| 58 | .Xr bitstring 3 | 55 | .Xr bitstring 3 |
diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c index 42bc87ddea..887ce437d4 100644 --- a/src/lib/libc/string/ffs.c +++ b/src/lib/libc/string/ffs.c | |||
| @@ -1,42 +1,19 @@ | |||
| 1 | /*- | 1 | /* $OpenBSD: ffs.c,v 1.5 2000/07/02 03:10:38 mickey 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.5 2000/07/02 03:10:38 mickey 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 |
| @@ -46,10 +23,27 @@ ffs(mask) | |||
| 46 | register int mask; | 23 | register int mask; |
| 47 | { | 24 | { |
| 48 | register int bit; | 25 | register int bit; |
| 26 | register unsigned int r = mask; | ||
| 27 | static const signed char t[16] = { | ||
| 28 | -28, 1, 2, 1, | ||
| 29 | 3, 1, 2, 1, | ||
| 30 | 4, 1, 2, 1, | ||
| 31 | 3, 1, 2, 1 | ||
| 32 | }; | ||
| 33 | |||
| 34 | bit = 0; | ||
| 35 | if (!(r & 0xffff)) { | ||
| 36 | bit += 16; | ||
| 37 | r >>= 16; | ||
| 38 | } | ||
| 39 | if (!(r & 0xff)) { | ||
| 40 | bit += 8; | ||
| 41 | r >>= 8; | ||
| 42 | } | ||
| 43 | if (!(r & 0xf)) { | ||
| 44 | bit += 4; | ||
| 45 | r >>= 4; | ||
| 46 | } | ||
| 49 | 47 | ||
| 50 | if (mask == 0) | 48 | return (bit + t[ r & 0xf ]); |
| 51 | return(0); | ||
| 52 | for (bit = 1; !(mask & 1); bit++) | ||
| 53 | mask >>= 1; | ||
| 54 | return(bit); | ||
| 55 | } | 49 | } |
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..8e4b146493 100644 --- a/src/lib/libc/string/index.c +++ b/src/lib/libc/string/index.c | |||
| @@ -32,19 +32,17 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)index.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: index.c,v 1.3 2002/07/24 04:16:01 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
| 40 | 39 | ||
| 41 | char * | 40 | char * |
| 42 | #ifdef STRCHR | 41 | #ifdef STRCHR |
| 43 | strchr(p, ch) | 42 | strchr(const char *p, int ch) |
| 44 | #else | 43 | #else |
| 45 | index(p, ch) | 44 | index(const char *p, int ch) |
| 46 | #endif | 45 | #endif |
| 47 | register const char *p, ch; | ||
| 48 | { | 46 | { |
| 49 | for (;; ++p) { | 47 | for (;; ++p) { |
| 50 | if (*p == ch) | 48 | if (*p == ch) |
diff --git a/src/lib/libc/string/memccpy.3 b/src/lib/libc/string/memccpy.3 index 61df704028..feedeff3a6 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.6 2000/04/21 15:24:19 aaron 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 |
| @@ -29,14 +31,14 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 31 | .\" | 33 | .\" |
| 32 | .\" from: @(#)memccpy.3 5.4 (Berkeley) 4/19/91 | 34 | .\" @(#)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 | .\" | 35 | .\" |
| 35 | .Dd April 19, 1991 | 36 | .Dd June 9, 1993 |
| 36 | .Dt MEMCCPY 3 | 37 | .Dt MEMCCPY 3 |
| 37 | .Os | 38 | .Os |
| 38 | .Sh NAME | 39 | .Sh NAME |
| 39 | .Nm memccpy | 40 | .Nm memccpy |
| 41 | .Nd copy string until character found | ||
| 40 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
| 41 | .Fd #include <string.h> | 43 | .Fd #include <string.h> |
| 42 | .Ft void * | 44 | .Ft void * |
| @@ -44,14 +46,15 @@ | |||
| 44 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 45 | The | 47 | The |
| 46 | .Fn memccpy | 48 | .Fn memccpy |
| 47 | function | 49 | function copies bytes from string |
| 48 | copies bytes from string | ||
| 49 | .Fa src | 50 | .Fa src |
| 50 | to string | 51 | to string |
| 51 | .Fa dst . | 52 | .Fa dst . |
| 52 | If the character | 53 | If the character |
| 53 | .Fa c | 54 | .Fa c |
| 54 | (as converted to an unsigned char) occurs in the string | 55 | (as converted to an |
| 56 | .Li unsigned char ) | ||
| 57 | occurs in the string | ||
| 55 | .Fa src , | 58 | .Fa src , |
| 56 | the copy stops and a pointer to the byte after the copy of | 59 | the copy stops and a pointer to the byte after the copy of |
| 57 | .Fa c | 60 | .Fa c |
| @@ -60,7 +63,7 @@ in the string | |||
| 60 | is returned. | 63 | is returned. |
| 61 | Otherwise, | 64 | Otherwise, |
| 62 | .Fa len | 65 | .Fa len |
| 63 | bytes are copied, and a NULL pointer is returned. | 66 | bytes are copied, and a null pointer is returned. |
| 64 | .Sh SEE ALSO | 67 | .Sh SEE ALSO |
| 65 | .Xr bcopy 3 , | 68 | .Xr bcopy 3 , |
| 66 | .Xr memcpy 3 , | 69 | .Xr memcpy 3 , |
| @@ -69,5 +72,5 @@ bytes are copied, and a NULL pointer is returned. | |||
| 69 | .Sh HISTORY | 72 | .Sh HISTORY |
| 70 | The | 73 | The |
| 71 | .Fn memccpy | 74 | .Fn memccpy |
| 72 | function is | 75 | function first appeared in |
| 73 | .Ud . | 76 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c index 3a1d7bcca1..020e6e5679 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.3 1997/08/20 04:09:39 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 |
| @@ -32,8 +34,11 @@ | |||
| 32 | */ | 34 | */ |
| 33 | 35 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)memccpy.c 5.8 (Berkeley) 5/30/91";*/ | 37 | #if 0 |
| 36 | static char *rcsid = "$Id: memccpy.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 38 | static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; |
| 39 | #else | ||
| 40 | static char *rcsid = "$OpenBSD: memccpy.c,v 1.3 1997/08/20 04:09:39 millert Exp $"; | ||
| 41 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 42 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 43 | ||
| 39 | #include <string.h> | 44 | #include <string.h> |
diff --git a/src/lib/libc/string/memchr.3 b/src/lib/libc/string/memchr.3 index 265711e3b5..632c440b5b 100644 --- a/src/lib/libc/string/memchr.3 +++ b/src/lib/libc/string/memchr.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)memchr.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memchr.3,v 1.5 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: memchr.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt MEMCHR 3 | 39 | .Dt MEMCHR 3 |
| @@ -49,23 +48,21 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn memchr | 50 | .Fn memchr |
| 52 | function | 51 | function locates the first occurrence of |
| 53 | locates the first occurrence of | ||
| 54 | .Fa c | 52 | .Fa c |
| 55 | (converted to an unsigned char) | 53 | (converted to an |
| 54 | .Li unsigned char ) | ||
| 56 | in string | 55 | in string |
| 57 | .Fa b . | 56 | .Fa b . |
| 58 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
| 59 | The | 58 | The |
| 60 | .Fn memchr | 59 | .Fn memchr |
| 61 | function | 60 | function returns a pointer to the byte located, or |
| 62 | returns a pointer to the byte located, | 61 | .Dv NULL |
| 63 | or NULL if no such byte exists within | 62 | if no such byte exists within |
| 64 | .Fa len | 63 | .Fa len |
| 65 | bytes. | 64 | bytes. |
| 66 | .Sh SEE ALSO | 65 | .Sh SEE ALSO |
| 67 | .Xr index 3 , | ||
| 68 | .Xr rindex 3 , | ||
| 69 | .Xr strchr 3 , | 66 | .Xr strchr 3 , |
| 70 | .Xr strcspn 3 , | 67 | .Xr strcspn 3 , |
| 71 | .Xr strpbrk 3 , | 68 | .Xr strpbrk 3 , |
| @@ -77,6 +74,5 @@ bytes. | |||
| 77 | .Sh STANDARDS | 74 | .Sh STANDARDS |
| 78 | The | 75 | The |
| 79 | .Fn memchr | 76 | .Fn memchr |
| 80 | function | 77 | function conforms to |
| 81 | conforms to | ||
| 82 | .St -ansiC . | 78 | .St -ansiC . |
diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c index 61652c6bb1..d605d4734f 100644 --- a/src/lib/libc/string/memchr.c +++ b/src/lib/libc/string/memchr.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memchr.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memchr.c,v 1.4 2001/09/07 08:09:31 espie 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
| @@ -44,14 +43,14 @@ static char *rcsid = "$Id: memchr.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $" | |||
| 44 | void * | 43 | void * |
| 45 | memchr(s, c, n) | 44 | memchr(s, c, n) |
| 46 | const void *s; | 45 | const void *s; |
| 47 | register unsigned char c; | 46 | int c; |
| 48 | register size_t n; | 47 | size_t n; |
| 49 | { | 48 | { |
| 50 | if (n != 0) { | 49 | if (n != 0) { |
| 51 | register const unsigned char *p = s; | 50 | const unsigned char *p = s; |
| 52 | 51 | ||
| 53 | do { | 52 | do { |
| 54 | if (*p++ == c) | 53 | if (*p++ == (unsigned char)c) |
| 55 | return ((void *)(p - 1)); | 54 | return ((void *)(p - 1)); |
| 56 | } while (--n != 0); | 55 | } while (--n != 0); |
| 57 | } | 56 | } |
diff --git a/src/lib/libc/string/memcmp.3 b/src/lib/libc/string/memcmp.3 index 13901c1009..db4fef364b 100644 --- a/src/lib/libc/string/memcmp.3 +++ b/src/lib/libc/string/memcmp.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)memcmp.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memcmp.3,v 1.4 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: memcmp.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt MEMCMP 3 | 39 | .Dt MEMCMP 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn memcmp | 50 | .Fn memcmp |
| 52 | function | 51 | function compares byte string |
| 53 | compares byte string | ||
| 54 | .Fa b1 | 52 | .Fa b1 |
| 55 | against byte string | 53 | against byte string |
| 56 | .Fa b2 . | 54 | .Fa b2 . |
| @@ -60,10 +58,11 @@ bytes long. | |||
| 60 | .Sh RETURN VALUES | 58 | .Sh RETURN VALUES |
| 61 | The | 59 | The |
| 62 | .Fn memcmp | 60 | .Fn memcmp |
| 63 | function | 61 | 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 | 62 | otherwise returns the difference between the first two differing bytes |
| 66 | (treated as unsigned char values, so that | 63 | (treated as |
| 64 | .Li unsigned char | ||
| 65 | values, so that | ||
| 67 | .Sq Li \e200 | 66 | .Sq Li \e200 |
| 68 | is greater than | 67 | is greater than |
| 69 | .Sq Li \&\e0 , | 68 | .Sq Li \&\e0 , |
| @@ -78,6 +77,5 @@ Zero-length strings are always identical. | |||
| 78 | .Sh STANDARDS | 77 | .Sh STANDARDS |
| 79 | The | 78 | The |
| 80 | .Fn memcmp | 79 | .Fn memcmp |
| 81 | function | 80 | function conforms to |
| 82 | conforms to | ||
| 83 | .St -ansiC . | 81 | .St -ansiC . |
diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c index 23d2ab2393..5ce33e2998 100644 --- a/src/lib/libc/string/memcmp.c +++ b/src/lib/libc/string/memcmp.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memcmp.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/memcpy.3 b/src/lib/libc/string/memcpy.3 index 3f4bb643c9..030eadff20 100644 --- a/src/lib/libc/string/memcpy.3 +++ b/src/lib/libc/string/memcpy.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)memcpy.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memcpy.3,v 1.3 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: memcpy.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt MEMCPY 3 | 39 | .Dt MEMCPY 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn memcpy | 50 | .Fn memcpy |
| 52 | function | 51 | function copies |
| 53 | copies | ||
| 54 | .Fa len | 52 | .Fa len |
| 55 | bytes from string | 53 | bytes from string |
| 56 | .Fa src | 54 | .Fa src |
| @@ -59,8 +57,7 @@ to string | |||
| 59 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
| 60 | The | 58 | The |
| 61 | .Fn memcpy | 59 | .Fn memcpy |
| 62 | function | 60 | function returns the original value of |
| 63 | returns the original value of | ||
| 64 | .Fa dst . | 61 | .Fa dst . |
| 65 | .Sh SEE ALSO | 62 | .Sh SEE ALSO |
| 66 | .Xr bcopy 3 , | 63 | .Xr bcopy 3 , |
| @@ -70,8 +67,7 @@ returns the original value of | |||
| 70 | .Sh STANDARDS | 67 | .Sh STANDARDS |
| 71 | The | 68 | The |
| 72 | .Fn memcpy | 69 | .Fn memcpy |
| 73 | function | 70 | function conforms to |
| 74 | conforms to | ||
| 75 | .St -ansiC . | 71 | .St -ansiC . |
| 76 | .Sh BUGS | 72 | .Sh BUGS |
| 77 | In this implementation | 73 | In this implementation |
diff --git a/src/lib/libc/string/memmove.3 b/src/lib/libc/string/memmove.3 index 24422e7971..026dab0f9f 100644 --- a/src/lib/libc/string/memmove.3 +++ b/src/lib/libc/string/memmove.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)memmove.3 5.5 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memmove.3,v 1.3 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: memmove.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt MEMMOVE 3 | 39 | .Dt MEMMOVE 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn memmove | 50 | .Fn memmove |
| 52 | function | 51 | function copies |
| 53 | copies | ||
| 54 | .Fa len | 52 | .Fa len |
| 55 | bytes from string | 53 | bytes from string |
| 56 | .Fa src | 54 | .Fa src |
| @@ -71,6 +69,5 @@ function returns the original value of | |||
| 71 | .Sh STANDARDS | 69 | .Sh STANDARDS |
| 72 | The | 70 | The |
| 73 | .Fn memmove | 71 | .Fn memmove |
| 74 | function | 72 | function conforms to |
| 75 | conforms to | ||
| 76 | .St -ansiC . | 73 | .St -ansiC . |
diff --git a/src/lib/libc/string/memset.3 b/src/lib/libc/string/memset.3 index 1afc052182..9da14983c7 100644 --- a/src/lib/libc/string/memset.3 +++ b/src/lib/libc/string/memset.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)memset.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: memset.3,v 1.4 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: memset.3,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt MEMSET 3 | 39 | .Dt MEMSET 3 |
| @@ -49,12 +48,18 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn memset | 50 | .Fn memset |
| 52 | function | 51 | function writes |
| 53 | writes | ||
| 54 | .Fa len | 52 | .Fa len |
| 55 | bytes of value | 53 | bytes of value |
| 56 | .Fa c | 54 | .Fa c |
| 57 | (converted to an unsigned char) to the string | 55 | (converted to an |
| 56 | .Li unsigned char ) | ||
| 57 | to the string | ||
| 58 | .Fa b . | ||
| 59 | .Sh RETURN VALUES | ||
| 60 | The | ||
| 61 | .Fn memset | ||
| 62 | function returns the original value of | ||
| 58 | .Fa b . | 63 | .Fa b . |
| 59 | .Sh SEE ALSO | 64 | .Sh SEE ALSO |
| 60 | .Xr bzero 3 , | 65 | .Xr bzero 3 , |
| @@ -62,6 +67,5 @@ bytes of value | |||
| 62 | .Sh STANDARDS | 67 | .Sh STANDARDS |
| 63 | The | 68 | The |
| 64 | .Fn memset | 69 | .Fn memset |
| 65 | function | 70 | function conforms to |
| 66 | conforms to | ||
| 67 | .St -ansiC . | 71 | .St -ansiC . |
diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c index 117de2e80b..c3373a21a9 100644 --- a/src/lib/libc/string/memset.c +++ b/src/lib/libc/string/memset.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)memset.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: memset.c,v 1.2 1996/08/19 08:34:07 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
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..7c7c94ae81 100644 --- a/src/lib/libc/string/rindex.c +++ b/src/lib/libc/string/rindex.c | |||
| @@ -32,19 +32,17 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)rindex.c 5.9 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: rindex.c,v 1.3 2002/07/24 04:16:01 millert 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
| 40 | 39 | ||
| 41 | char * | 40 | char * |
| 42 | #ifdef STRRCHR | 41 | #ifdef STRRCHR |
| 43 | strrchr(p, ch) | 42 | strrchr(const char *p, int ch) |
| 44 | #else | 43 | #else |
| 45 | rindex(p, ch) | 44 | rindex(const char *p, int ch) |
| 46 | #endif | 45 | #endif |
| 47 | register const char *p, ch; | ||
| 48 | { | 46 | { |
| 49 | register char *save; | 47 | register char *save; |
| 50 | 48 | ||
diff --git a/src/lib/libc/string/strcasecmp.3 b/src/lib/libc/string/strcasecmp.3 index 46e9010e4f..3cfc76e36f 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.6 2000/04/21 15:24:19 aaron 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. |
| @@ -31,14 +33,14 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 33 | .\" | 35 | .\" |
| 34 | .\" from: @(#)strcasecmp.3 5.4 (Berkeley) 4/19/91 | 36 | .\" @(#)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 | .\" | 37 | .\" |
| 37 | .Dd April 19, 1991 | 38 | .Dd June 9, 1993 |
| 38 | .Dt STRCASECMP 3 | 39 | .Dt STRCASECMP 3 |
| 39 | .Os | 40 | .Os |
| 40 | .Sh NAME | 41 | .Sh NAME |
| 41 | .Nm strcasecmp | 42 | .Nm strcasecmp , |
| 43 | .Nm strncasecmp | ||
| 42 | .Nd compare strings, ignoring case | 44 | .Nd compare strings, ignoring case |
| 43 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 44 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| @@ -51,8 +53,7 @@ The | |||
| 51 | .Fn strcasecmp | 53 | .Fn strcasecmp |
| 52 | and | 54 | and |
| 53 | .Fn strncasecmp | 55 | .Fn strncasecmp |
| 54 | functions | 56 | functions compare the null-terminated strings |
| 55 | compare the null-terminated strings | ||
| 56 | .Fa s1 | 57 | .Fa s1 |
| 57 | and | 58 | and |
| 58 | .Fa s2 | 59 | .Fa s2 |
| @@ -68,7 +69,6 @@ The comparison is done using unsigned characters, so that | |||
| 68 | is greater than | 69 | is greater than |
| 69 | .Ql \e0 . | 70 | .Ql \e0 . |
| 70 | .Pp | 71 | .Pp |
| 71 | The | ||
| 72 | .Fn strncasecmp | 72 | .Fn strncasecmp |
| 73 | compares at most | 73 | compares at most |
| 74 | .Fa len | 74 | .Fa len |
| @@ -84,5 +84,5 @@ The | |||
| 84 | .Fn strcasecmp | 84 | .Fn strcasecmp |
| 85 | and | 85 | and |
| 86 | .Fn strncasecmp | 86 | .Fn strncasecmp |
| 87 | functions are | 87 | functions first appeared in |
| 88 | .Ud . | 88 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c index 79bd0081e3..1f487524aa 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.3 1997/08/20 04:13:57 millert 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 |
| @@ -31,13 +33,16 @@ | |||
| 31 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. |
| 32 | */ | 34 | */ |
| 33 | 35 | ||
| 36 | #include <string.h> | ||
| 37 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 38 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static const char sccsid[] = "from: @(#)strcasecmp.c 5.10 (Berkeley) 1/26/91";*/ | 39 | #if 0 |
| 36 | static char *rcsid = "$Id: strcasecmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; | 40 | static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; |
| 41 | #else | ||
| 42 | static char *rcsid = "$OpenBSD: strcasecmp.c,v 1.3 1997/08/20 04:13:57 millert Exp $"; | ||
| 43 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 44 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 45 | ||
| 39 | #include <string.h> | ||
| 40 | |||
| 41 | typedef unsigned char u_char; | 46 | typedef unsigned char u_char; |
| 42 | 47 | ||
| 43 | /* | 48 | /* |
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..e9e5163bd3 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -33,14 +33,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcat.3,v 1.8 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd July 8, 1997 |
| 40 | .Dt STRCAT 3 | 39 | .Dt STRCAT 3 |
| 41 | .Os | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strcat | 42 | .Nm strcat , |
| 43 | .Nm strncat | ||
| 44 | .Nd concatenate strings | 44 | .Nd concatenate strings |
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| @@ -53,8 +53,7 @@ The | |||
| 53 | .Fn strcat | 53 | .Fn strcat |
| 54 | and | 54 | and |
| 55 | .Fn strncat | 55 | .Fn strncat |
| 56 | functions | 56 | functions append a copy of the null-terminated string |
| 57 | append a copy of the null-terminated string | ||
| 58 | .Fa append | 57 | .Fa append |
| 59 | to the end of the null-terminated string | 58 | to the end of the null-terminated string |
| 60 | .Fa s , | 59 | .Fa s , |
| @@ -66,29 +65,71 @@ must have sufficient space to hold the result. | |||
| 66 | .Pp | 65 | .Pp |
| 67 | The | 66 | The |
| 68 | .Fn strncat | 67 | .Fn strncat |
| 69 | function | 68 | function appends not more than |
| 70 | appends not more than | ||
| 71 | .Fa count | 69 | .Fa count |
| 72 | characters. | 70 | characters where space for the terminating |
| 71 | .Ql \e0 | ||
| 72 | should not be included in | ||
| 73 | .Fa count . | ||
| 73 | .Sh RETURN VALUES | 74 | .Sh RETURN VALUES |
| 74 | The | 75 | The |
| 75 | .Fn strcat | 76 | .Fn strcat |
| 76 | and | 77 | and |
| 77 | .Fn strncat | 78 | .Fn strncat |
| 78 | functions | 79 | functions return the pointer |
| 79 | return the pointer | ||
| 80 | .Fa s . | 80 | .Fa s . |
| 81 | .Sh EXAMPLES | ||
| 82 | The following appends | ||
| 83 | .Dq Li abc | ||
| 84 | to | ||
| 85 | .Dq Li chararray : | ||
| 86 | .Bd -literal -offset indent | ||
| 87 | char *letters = "abcdefghi"; | ||
| 88 | |||
| 89 | (void)strncat(chararray, letters, 3); | ||
| 90 | .Ed | ||
| 91 | .Pp | ||
| 92 | The following example shows how to use | ||
| 93 | .Fn strncat | ||
| 94 | safely in conjunction with | ||
| 95 | .Xr strncpy 3 . | ||
| 96 | .Bd -literal -offset indent | ||
| 97 | char buf[BUFSIZ]; | ||
| 98 | char *input, *suffix; | ||
| 99 | |||
| 100 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 101 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 102 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
| 103 | .Ed | ||
| 104 | .Pp | ||
| 105 | The above will copy as many characters from | ||
| 106 | .Dq Li input | ||
| 107 | to | ||
| 108 | .Dq Li buf | ||
| 109 | as will fit. | ||
| 110 | It then appends as many characters from suffix as will fit (or none | ||
| 111 | if there is no space). | ||
| 112 | For operations like this, the | ||
| 113 | .Xr strlcpy 3 | ||
| 114 | and | ||
| 115 | .Xr strlcat 3 | ||
| 116 | functions are a better choice, as shown below. | ||
| 117 | .Bd -literal -offset indent | ||
| 118 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 119 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
| 120 | .Ed | ||
| 81 | .Sh SEE ALSO | 121 | .Sh SEE ALSO |
| 82 | .Xr bcopy 3 , | 122 | .Xr bcopy 3 , |
| 83 | .Xr memccpy 3 , | 123 | .Xr memccpy 3 , |
| 84 | .Xr memcpy 3 , | 124 | .Xr memcpy 3 , |
| 85 | .Xr memmove 3 , | 125 | .Xr memmove 3 , |
| 86 | .Xr strcpy 3 | 126 | .Xr strcpy 3 , |
| 127 | .Xr strlcat 3 , | ||
| 128 | .Xr strlcpy 3 | ||
| 87 | .Sh STANDARDS | 129 | .Sh STANDARDS |
| 88 | The | 130 | The |
| 89 | .Fn strcat | 131 | .Fn strcat |
| 90 | and | 132 | and |
| 91 | .Fn strncat | 133 | .Fn strncat |
| 92 | functions | 134 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 135 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c index e741b84f03..374a2b7464 100644 --- a/src/lib/libc/string/strcat.c +++ b/src/lib/libc/string/strcat.c | |||
| @@ -32,11 +32,14 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strcat.c 5.6 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strcat.c,v 1.4 1996/08/19 08:34:10 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 38 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 39 | #include <string.h> |
| 40 | #else | ||
| 41 | #include <lib/libkern/libkern.h> | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | char * | 44 | char * |
| 42 | strcat(s, append) | 45 | strcat(s, append) |
| @@ -46,6 +49,6 @@ strcat(s, append) | |||
| 46 | char *save = s; | 49 | char *save = s; |
| 47 | 50 | ||
| 48 | for (; *s; ++s); | 51 | for (; *s; ++s); |
| 49 | while (*s++ = *append++); | 52 | while ((*s++ = *append++) != '\0'); |
| 50 | return(save); | 53 | return(save); |
| 51 | } | 54 | } |
diff --git a/src/lib/libc/string/strchr.3 b/src/lib/libc/string/strchr.3 index 18b50301f3..1333a305d6 100644 --- a/src/lib/libc/string/strchr.3 +++ b/src/lib/libc/string/strchr.3 | |||
| @@ -33,29 +33,29 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strchr.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strchr.3,v 1.7 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: strchr.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRCHR 3 | 39 | .Dt STRCHR 3 |
| 41 | .Os | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strchr | 42 | .Nm strchr , |
| 44 | .Nd locate character in string | 43 | .Nm index |
| 44 | .Nd locate first occurrence of a character in a string | ||
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| 47 | .Ft char * | 47 | .Ft char * |
| 48 | .Fn strchr "const char *s" "int c" | 48 | .Fn strchr "const char *s" "int c" |
| 49 | .Ft char * | ||
| 50 | .Fn index "const char *s" "int c" | ||
| 49 | .Sh DESCRIPTION | 51 | .Sh DESCRIPTION |
| 50 | The | 52 | The |
| 51 | .Fn strchr | 53 | .Fn strchr |
| 52 | function locates the first occurrence of | 54 | function locates the first occurrence of the character |
| 53 | .Ar c | 55 | .Fa c |
| 54 | in the string pointed to by | 56 | in the string |
| 55 | .Ar s . | 57 | .Fa s . |
| 56 | The terminating | 58 | The terminating NUL character is considered part of the string. |
| 57 | .Dv NULL | ||
| 58 | character is considered part of the string. | ||
| 59 | If | 59 | If |
| 60 | .Fa c | 60 | .Fa c |
| 61 | is | 61 | is |
| @@ -63,16 +63,31 @@ is | |||
| 63 | .Fn strchr | 63 | .Fn strchr |
| 64 | locates the terminating | 64 | locates the terminating |
| 65 | .Ql \e0 . | 65 | .Ql \e0 . |
| 66 | .Pp | ||
| 67 | The | ||
| 68 | .Fn index | ||
| 69 | function is an old synonym for | ||
| 70 | .Fn strchr . | ||
| 66 | .Sh RETURN VALUES | 71 | .Sh RETURN VALUES |
| 67 | The function | 72 | The |
| 68 | .Fn strchr | 73 | .Fn strchr |
| 69 | returns a pointer to the located character, or | 74 | function returns a pointer to the located character or |
| 70 | .Dv NULL | 75 | .Dv NULL |
| 71 | if the character does not appear in the string. | 76 | if the character does not appear in the string. |
| 77 | .Sh EXAMPLES | ||
| 78 | After the following call to | ||
| 79 | .Fn strchr , | ||
| 80 | .Va p | ||
| 81 | will point to the string | ||
| 82 | .Qq oobar : | ||
| 83 | .Bd -literal -offset indent | ||
| 84 | char *p; | ||
| 85 | char *s = "foobar"; | ||
| 86 | |||
| 87 | p = strchr(s, 'o'); | ||
| 88 | .Ed | ||
| 72 | .Sh SEE ALSO | 89 | .Sh SEE ALSO |
| 73 | .Xr index 3 , | ||
| 74 | .Xr memchr 3 , | 90 | .Xr memchr 3 , |
| 75 | .Xr rindex 3 , | ||
| 76 | .Xr strcspn 3 , | 91 | .Xr strcspn 3 , |
| 77 | .Xr strpbrk 3 , | 92 | .Xr strpbrk 3 , |
| 78 | .Xr strrchr 3 , | 93 | .Xr strrchr 3 , |
| @@ -83,6 +98,9 @@ if the character does not appear in the string. | |||
| 83 | .Sh STANDARDS | 98 | .Sh STANDARDS |
| 84 | The | 99 | The |
| 85 | .Fn strchr | 100 | .Fn strchr |
| 86 | function | 101 | function conforms to |
| 87 | conforms to | ||
| 88 | .St -ansiC . | 102 | .St -ansiC . |
| 103 | .Pp | ||
| 104 | The | ||
| 105 | .Fn index | ||
| 106 | 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..c1173a423a 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 | |||
| @@ -33,14 +33,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcmp.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcmp.3,v 1.5 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: strcmp.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRCMP 3 | 39 | .Dt STRCMP 3 |
| 41 | .Os | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strcmp | 42 | .Nm strcmp , |
| 43 | .Nm strncmp | ||
| 44 | .Nd compare strings | 44 | .Nd compare strings |
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| @@ -53,8 +53,7 @@ The | |||
| 53 | .Fn strcmp | 53 | .Fn strcmp |
| 54 | and | 54 | and |
| 55 | .Fn strncmp | 55 | .Fn strncmp |
| 56 | functions | 56 | functions lexicographically compare the null-terminated strings |
| 57 | lexicographically compare the null-terminated strings | ||
| 58 | .Fa s1 | 57 | .Fa s1 |
| 59 | and | 58 | and |
| 60 | .Fa s2 . | 59 | .Fa s2 . |
| @@ -73,9 +72,8 @@ The comparison is done using unsigned characters, so that | |||
| 73 | is greater than | 72 | is greater than |
| 74 | .Ql \e0 . | 73 | .Ql \e0 . |
| 75 | .Pp | 74 | .Pp |
| 76 | The | ||
| 77 | .Fn strncmp | 75 | .Fn strncmp |
| 78 | compares not more than | 76 | compares at most |
| 79 | .Fa len | 77 | .Fa len |
| 80 | characters. | 78 | characters. |
| 81 | .Sh SEE ALSO | 79 | .Sh SEE ALSO |
| @@ -89,6 +87,5 @@ The | |||
| 89 | .Fn strcmp | 87 | .Fn strcmp |
| 90 | and | 88 | and |
| 91 | .Fn strncmp | 89 | .Fn strncmp |
| 92 | functions | 90 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 91 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c index ae19e2e26e..9a5b208323 100644 --- a/src/lib/libc/string/strcmp.c +++ b/src/lib/libc/string/strcmp.c | |||
| @@ -35,11 +35,14 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcmp.c 5.5 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcmp.c,v 1.3 1996/08/19 08:34:12 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 41 | #ifndef _KERNEL | ||
| 42 | #include <string.h> | 42 | #include <string.h> |
| 43 | #else | ||
| 44 | #include <lib/libkern/libkern.h> | ||
| 45 | #endif | ||
| 43 | 46 | ||
| 44 | /* | 47 | /* |
| 45 | * Compare strings. | 48 | * Compare strings. |
diff --git a/src/lib/libc/string/strcoll.3 b/src/lib/libc/string/strcoll.3 index 12f73f98f2..5d3e44ee96 100644 --- a/src/lib/libc/string/strcoll.3 +++ b/src/lib/libc/string/strcoll.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcoll.3 5.6 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcoll.3,v 1.3 2000/04/21 15:24:19 aaron Exp $ |
| 37 | .\" $Id: strcoll.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRCOLL 3 | 39 | .Dt STRCOLL 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strcoll | 50 | .Fn strcoll |
| 52 | function | 51 | function lexicographically compares the null-terminated strings |
| 53 | lexicographically compares the null-terminated strings | ||
| 54 | .Fa s1 | 52 | .Fa s1 |
| 55 | and | 53 | and |
| 56 | .Fa s2 | 54 | .Fa s2 |
| @@ -70,6 +68,5 @@ is greater than, equal to, or less than | |||
| 70 | .Sh STANDARDS | 68 | .Sh STANDARDS |
| 71 | The | 69 | The |
| 72 | .Fn strcoll | 70 | .Fn strcoll |
| 73 | function | 71 | function conforms to |
| 74 | conforms to | ||
| 75 | .St -ansiC . | 72 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c index 86c742cba9..dca0b10d25 100644 --- a/src/lib/libc/string/strcoll.c +++ b/src/lib/libc/string/strcoll.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcoll.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcoll.c,v 1.2 1996/08/19 08:34:13 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..d3c095916b 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
| @@ -33,14 +33,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcpy.3,v 1.11 2002/05/13 17:04:43 millert Exp $ |
| 37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRCPY 3 | 39 | .Dt STRCPY 3 |
| 41 | .Os BSD 4 | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strcpy | 42 | .Nm strcpy , |
| 43 | .Nm strncpy | ||
| 44 | .Nd copy strings | 44 | .Nd copy strings |
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| @@ -53,8 +53,7 @@ The | |||
| 53 | .Fn strcpy | 53 | .Fn strcpy |
| 54 | and | 54 | and |
| 55 | .Fn strncpy | 55 | .Fn strncpy |
| 56 | functions | 56 | functions copy the string |
| 57 | copy the string | ||
| 58 | .Fa src | 57 | .Fa src |
| 59 | to | 58 | to |
| 60 | .Fa dst | 59 | .Fa dst |
| @@ -62,7 +61,6 @@ to | |||
| 62 | .Ql \e0 | 61 | .Ql \e0 |
| 63 | character). | 62 | character). |
| 64 | .Pp | 63 | .Pp |
| 65 | The | ||
| 66 | .Fn strncpy | 64 | .Fn strncpy |
| 67 | copies not more than | 65 | copies not more than |
| 68 | .Fa len | 66 | .Fa len |
| @@ -78,45 +76,79 @@ characters long, and | |||
| 78 | .Em not | 76 | .Em not |
| 79 | terminating | 77 | terminating |
| 80 | .Fa dst | 78 | .Fa dst |
| 81 | if | 79 | if the length of |
| 82 | .Fa src | 80 | .Fa src |
| 83 | is more than | 81 | is greater than or equal to |
| 84 | .Fa len | 82 | .Fa len . |
| 85 | characters long. | ||
| 86 | .Sh RETURN VALUES | 83 | .Sh RETURN VALUES |
| 87 | The | 84 | The |
| 88 | .Fn strcpy | 85 | .Fn strcpy |
| 89 | and | 86 | and |
| 90 | .Fn strncpy | 87 | .Fn strncpy |
| 91 | functions | 88 | functions return |
| 92 | return | ||
| 93 | .Fa dst . | 89 | .Fa dst . |
| 94 | .Sh EXAMPLES | 90 | .Sh EXAMPLES |
| 95 | The following sets | 91 | The following sets |
| 96 | .Dq Li chararray | 92 | .Va chararray |
| 97 | to | 93 | to |
| 98 | .Dq Li abc\e0\e0\e0 : | 94 | .Dq abc\e0\e0\e0 : |
| 99 | .Bd -literal -offset indent | 95 | .Bd -literal -offset indent |
| 100 | (void)strncpy(chararray, "abc", 6). | 96 | (void)strncpy(chararray, "abc", 6); |
| 101 | .Ed | 97 | .Ed |
| 102 | .Pp | 98 | .Pp |
| 103 | The following sets | 99 | The following sets |
| 104 | .Dq Li chararray | 100 | .Va chararray |
| 105 | to | 101 | to |
| 106 | .Dq Li abcdef : | 102 | .Dq abcdef |
| 103 | and does | ||
| 104 | .Em not | ||
| 105 | null terminate | ||
| 106 | .Va chararray | ||
| 107 | because the source string is >= the length parameter. | ||
| 108 | .Fn strncpy | ||
| 109 | .Em only | ||
| 110 | null terminates the destination string when the length of the source | ||
| 111 | string is less than the length parameter. | ||
| 107 | .Bd -literal -offset indent | 112 | .Bd -literal -offset indent |
| 108 | (void)strncpy(chararray, "abcdefgh", 6); | 113 | (void)strncpy(chararray, "abcdefgh", 6); |
| 109 | .Ed | 114 | .Ed |
| 115 | .Pp | ||
| 116 | The following copies as many characters from | ||
| 117 | .Va input | ||
| 118 | to | ||
| 119 | .Va buf | ||
| 120 | as will fit and null terminates the result. | ||
| 121 | Because | ||
| 122 | .Fn strncpy | ||
| 123 | does | ||
| 124 | .Em not | ||
| 125 | guarantee to null terminate the string itself, we must do this by hand. | ||
| 126 | .Bd -literal -offset indent | ||
| 127 | char buf[BUFSIZ]; | ||
| 128 | |||
| 129 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 130 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 131 | .Ed | ||
| 132 | .Pp | ||
| 133 | Note that | ||
| 134 | .Xr strlcpy 3 | ||
| 135 | is a better choice for this kind of operation. | ||
| 136 | The equivalent using | ||
| 137 | .Xr strlcpy 3 | ||
| 138 | is simply: | ||
| 139 | .Bd -literal -offset indent | ||
| 140 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 141 | .Ed | ||
| 110 | .Sh SEE ALSO | 142 | .Sh SEE ALSO |
| 111 | .Xr bcopy 3 , | 143 | .Xr bcopy 3 , |
| 112 | .Xr memccpy 3 , | 144 | .Xr memccpy 3 , |
| 113 | .Xr memcpy 3 , | 145 | .Xr memcpy 3 , |
| 114 | .Xr memmove 3 | 146 | .Xr memmove 3 , |
| 147 | .Xr strlcpy 3 | ||
| 115 | .Sh STANDARDS | 148 | .Sh STANDARDS |
| 116 | The | 149 | The |
| 117 | .Fn strcpy | 150 | .Fn strcpy |
| 118 | and | 151 | and |
| 119 | .Fn strncpy | 152 | .Fn strncpy |
| 120 | functions | 153 | functions conform to |
| 121 | conform to | ||
| 122 | .St -ansiC . | 154 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c index 669bfde23e..76b063fc10 100644 --- a/src/lib/libc/string/strcpy.c +++ b/src/lib/libc/string/strcpy.c | |||
| @@ -32,11 +32,14 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strcpy.c 5.7 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strcpy.c,v 1.4 1996/08/19 08:34:14 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 38 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 39 | #include <string.h> |
| 40 | #else | ||
| 41 | #include <lib/libkern/libkern.h> | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | char * | 44 | char * |
| 42 | strcpy(to, from) | 45 | strcpy(to, from) |
| @@ -45,6 +48,6 @@ strcpy(to, from) | |||
| 45 | { | 48 | { |
| 46 | char *save = to; | 49 | char *save = to; |
| 47 | 50 | ||
| 48 | for (; *to = *from; ++from, ++to); | 51 | for (; (*to = *from) != '\0'; ++from, ++to); |
| 49 | return(save); | 52 | return(save); |
| 50 | } | 53 | } |
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3 index cc9e5c2fe3..37e8f163f1 100644 --- a/src/lib/libc/string/strcspn.3 +++ b/src/lib/libc/string/strcspn.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcspn.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strcspn.3,v 1.5 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strcspn.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRCSPN 3 | 39 | .Dt STRCSPN 3 |
| @@ -49,27 +48,36 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strcspn | 50 | .Fn strcspn |
| 52 | function | 51 | function spans the initial part of the null-terminated string |
| 53 | spans the initial part of the null-terminated string | ||
| 54 | .Fa s | 52 | .Fa s |
| 55 | as long as the characters from | 53 | as long as the characters from |
| 56 | .Fa s | 54 | .Fa s |
| 57 | do not occur in string | 55 | do not occur in string |
| 58 | .Fa charset | 56 | .Fa charset |
| 59 | (it | 57 | (it spans the |
| 60 | spans the | ||
| 61 | .Em complement | 58 | .Em complement |
| 62 | of | 59 | of |
| 63 | .Fa charset ) . | 60 | .Fa charset ) . |
| 64 | .Sh RETURN VALUES | 61 | .Sh RETURN VALUES |
| 65 | The | 62 | The |
| 66 | .Fn strcspn | 63 | .Fn strcspn |
| 67 | function | 64 | function returns the number of characters spanned. |
| 68 | returns the number of characters spanned. | 65 | .Sh EXAMPLES |
| 66 | The following call to | ||
| 67 | .Fn strcspn | ||
| 68 | will return 3, since the first three characters of string | ||
| 69 | .Fa s | ||
| 70 | do not occur in string | ||
| 71 | .Fa charset : | ||
| 72 | .Bd -literal -offset indent | ||
| 73 | char *s = "foobar"; | ||
| 74 | char *charset = "bar"; | ||
| 75 | size_t span; | ||
| 76 | |||
| 77 | span = strcspn(s, charset); | ||
| 78 | .Ed | ||
| 69 | .Sh SEE ALSO | 79 | .Sh SEE ALSO |
| 70 | .Xr index 3 , | ||
| 71 | .Xr memchr 3 , | 80 | .Xr memchr 3 , |
| 72 | .Xr rindex 3 , | ||
| 73 | .Xr strchr 3 , | 81 | .Xr strchr 3 , |
| 74 | .Xr strpbrk 3 , | 82 | .Xr strpbrk 3 , |
| 75 | .Xr strrchr 3 , | 83 | .Xr strrchr 3 , |
| @@ -80,6 +88,5 @@ returns the number of characters spanned. | |||
| 80 | .Sh STANDARDS | 88 | .Sh STANDARDS |
| 81 | The | 89 | The |
| 82 | .Fn strcspn | 90 | .Fn strcspn |
| 83 | function | 91 | function conforms to |
| 84 | conforms to | ||
| 85 | .St -ansiC . | 92 | .St -ansiC . |
diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c index acb4d2a3af..f7261564a7 100644 --- a/src/lib/libc/string/strcspn.c +++ b/src/lib/libc/string/strcspn.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strcspn.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strcspn.c,v 1.2 1996/08/19 08:34:15 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 index 925cbf3d46..9c154c7d70 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.10 2000/04/21 15:32:15 aaron 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 |
| @@ -29,10 +31,9 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 31 | .\" | 33 | .\" |
| 32 | .\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 | 34 | .\" @(#)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 | .\" | 35 | .\" |
| 35 | .Dd April 19, 1991 | 36 | .Dd June 9, 1993 |
| 36 | .Dt STRDUP 3 | 37 | .Dt STRDUP 3 |
| 37 | .Os | 38 | .Os |
| 38 | .Sh NAME | 39 | .Sh NAME |
| @@ -41,25 +42,46 @@ | |||
| 41 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
| 42 | .Fd #include <string.h> | 43 | .Fd #include <string.h> |
| 43 | .Ft char * | 44 | .Ft char * |
| 44 | .Fn strdup "const char *str" | 45 | .Fn strdup "const char *s" |
| 45 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 46 | The | 47 | The |
| 47 | .Fn strdup | 48 | .Fn strdup |
| 48 | function | 49 | function allocates sufficient memory for a copy of the string |
| 49 | allocates sufficient memory for a copy | 50 | .Fa s , |
| 50 | of the string | ||
| 51 | .Fa str , | ||
| 52 | does the copy, and returns a pointer to it. | 51 | does the copy, and returns a pointer to it. |
| 53 | The pointer may subsequently be used as an | 52 | The pointer may subsequently be used as an argument to the function |
| 54 | argument to the function | ||
| 55 | .Xr free 3 . | 53 | .Xr free 3 . |
| 54 | .Pp | ||
| 55 | If insufficient memory is available, | ||
| 56 | .Dv NULL | ||
| 57 | is returned. | ||
| 58 | .Sh EXAMPLES | ||
| 59 | The following will point | ||
| 60 | .Va p | ||
| 61 | to an allocated area of memory containing the null-terminated string | ||
| 62 | .Qq foobar : | ||
| 63 | .Bd -literal -offset indent | ||
| 64 | char *p; | ||
| 65 | |||
| 66 | if ((p = strdup("foobar")) == NULL) { | ||
| 67 | fprintf(stderr, "Out of memory.\en"); | ||
| 68 | exit(1); | ||
| 69 | } | ||
| 70 | .Ed | ||
| 71 | .Sh ERRORS | ||
| 72 | The | ||
| 73 | .Fn strdup | ||
| 74 | function may fail and set the external variable | ||
| 75 | .Va errno | ||
| 76 | for any of the errors specified for the library function | ||
| 77 | .Xr malloc 3 . | ||
| 56 | .Sh SEE ALSO | 78 | .Sh SEE ALSO |
| 57 | .Xr free 3 , | 79 | .Xr free 3 , |
| 58 | .Xr malloc 3 , | 80 | .Xr malloc 3 , |
| 59 | .Xt strcpy 3 , | 81 | .Xr strcpy 3 , |
| 60 | .Xt strlen 3 | 82 | .Xr strlen 3 |
| 61 | .Sh HISTORY | 83 | .Sh HISTORY |
| 62 | The | 84 | The |
| 63 | .Fn strdup | 85 | .Fn strdup |
| 64 | function | 86 | function first appeared in |
| 65 | .Ud . | 87 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c index 27ede44110..be7f7ad094 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.3 1997/08/20 04:18:52 millert 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 |
| @@ -32,10 +34,16 @@ | |||
| 32 | */ | 34 | */ |
| 33 | 35 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strdup.c 5.4 (Berkeley) 2/24/91";*/ | 37 | #if 0 |
| 36 | static char *rcsid = "$Id: strdup.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; | 38 | static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; |
| 39 | #else | ||
| 40 | static char *rcsid = "$OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $"; | ||
| 41 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 42 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 43 | ||
| 44 | #include <sys/types.h> | ||
| 45 | |||
| 46 | #include <stddef.h> | ||
| 39 | #include <stdlib.h> | 47 | #include <stdlib.h> |
| 40 | #include <string.h> | 48 | #include <string.h> |
| 41 | 49 | ||
| @@ -43,12 +51,12 @@ char * | |||
| 43 | strdup(str) | 51 | strdup(str) |
| 44 | const char *str; | 52 | const char *str; |
| 45 | { | 53 | { |
| 46 | size_t len; | 54 | size_t siz; |
| 47 | char *copy; | 55 | char *copy; |
| 48 | 56 | ||
| 49 | len = strlen(str) + 1; | 57 | siz = strlen(str) + 1; |
| 50 | if (!(copy = malloc(len))) | 58 | if ((copy = malloc(siz)) == NULL) |
| 51 | return((char *)NULL); | 59 | return(NULL); |
| 52 | memcpy(copy, str, len); | 60 | (void)memcpy(copy, str, siz); |
| 53 | return(copy); | 61 | return(copy); |
| 54 | } | 62 | } |
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 index c9d8504dbb..11bacd313e 100644 --- a/src/lib/libc/string/strerror.3 +++ b/src/lib/libc/string/strerror.3 | |||
| @@ -33,12 +33,11 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strerror.3,v 1.4 2000/10/23 19:14:41 aaron Exp $ |
| 37 | .\" $Id: strerror.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRERROR 3 | 39 | .Dt STRERROR 3 |
| 41 | .Os BSD 4 | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strerror | 42 | .Nm strerror |
| 44 | .Nd get error message string | 43 | .Nd get error message string |
| @@ -50,7 +49,11 @@ | |||
| 50 | The | 49 | The |
| 51 | .Fn strerror | 50 | .Fn strerror |
| 52 | function returns a pointer to the language-dependent error message | 51 | function returns a pointer to the language-dependent error message |
| 53 | string affiliated with an error number. | 52 | string affiliated with the specified error number |
| 53 | .Fa errnum . | ||
| 54 | The returned string contains a maximum of | ||
| 55 | .Dv NL_TEXTMAX | ||
| 56 | characters, including the trailing NUL. | ||
| 54 | .Pp | 57 | .Pp |
| 55 | The array pointed to is not to be modified by the program, but may be | 58 | The array pointed to is not to be modified by the program, but may be |
| 56 | overwritten by subsequent calls to | 59 | overwritten by subsequent calls to |
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c index c3f5ab5d98..b884a67df3 100644 --- a/src/lib/libc/string/strerror.c +++ b/src/lib/libc/string/strerror.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: strerror.c,v 1.3 2002/02/16 21:27:24 millert 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
| @@ -45,7 +44,7 @@ static char *rcsid = "$Id: strerror.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp | |||
| 45 | * internal function __strerror(). | 44 | * internal function __strerror(). |
| 46 | */ | 45 | */ |
| 47 | 46 | ||
| 48 | extern char *__strerror __P((int, char *)); | 47 | extern char *__strerror(int, char *); |
| 49 | 48 | ||
| 50 | char * | 49 | char * |
| 51 | strerror(num) | 50 | strerror(num) |
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..7a67b96b53 100644 --- a/src/lib/libc/string/string.3 +++ b/src/lib/libc/string/string.3 | |||
| @@ -31,27 +31,28 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" from: @(#)string.3 6.9 (Berkeley) 4/19/91 | 34 | .\" $OpenBSD: string.3,v 1.8 2000/04/21 15:24:20 aaron Exp $ |
| 35 | .\" $Id: string.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 36 | .\" | 35 | .\" |
| 37 | .Dd April 19, 1991 | 36 | .Dd April 19, 1991 |
| 38 | .Dt STRING 3 | 37 | .Dt STRING 3 |
| 39 | .Os BSD 4 | 38 | .Os |
| 40 | .Sh NAME | 39 | .Sh NAME |
| 41 | .Nm strcat , | 40 | .Nm strcat , |
| 41 | .Nm strlcat , | ||
| 42 | .Nm strncat , | 42 | .Nm strncat , |
| 43 | .Nm strchr , | 43 | .Nm strchr , |
| 44 | .Nm strrchr , | 44 | .Nm strrchr , |
| 45 | .Nm strcmp , | 45 | .Nm strcmp , |
| 46 | .Nm strncmp , | 46 | .Nm strncmp , |
| 47 | .Nm strcasecmp, | 47 | .Nm strcasecmp , |
| 48 | .Nm strncasecmp , | 48 | .Nm strncasecmp , |
| 49 | .Nm strcpy , | 49 | .Nm strcpy , |
| 50 | .Nm strlcpy , | ||
| 50 | .Nm strncpy , | 51 | .Nm strncpy , |
| 51 | .Nm strerror , | 52 | .Nm strerror , |
| 52 | .Nm strlen , | 53 | .Nm strlen , |
| 53 | .Nm strpbrk , | 54 | .Nm strpbrk , |
| 54 | .Nm strsep, | 55 | .Nm strsep , |
| 55 | .Nm strspn , | 56 | .Nm strspn , |
| 56 | .Nm strcspn , | 57 | .Nm strcspn , |
| 57 | .Nm strstr , | 58 | .Nm strstr , |
| @@ -62,7 +63,9 @@ | |||
| 62 | .Sh SYNOPSIS | 63 | .Sh SYNOPSIS |
| 63 | .Fd #include <string.h> | 64 | .Fd #include <string.h> |
| 64 | .Ft char * | 65 | .Ft char * |
| 65 | .Fn strcat "char *s" "const char * append" | 66 | .Fn strcat "char *s" "const char *append" |
| 67 | .Ft char * | ||
| 68 | .Fn strlcat "char *s" "const char *append" "size_t size" | ||
| 66 | .Ft char * | 69 | .Ft char * |
| 67 | .Fn strncat "char *s" "const char *append" "size_t count" | 70 | .Fn strncat "char *s" "const char *append" "size_t count" |
| 68 | .Ft char * | 71 | .Ft char * |
| @@ -80,6 +83,8 @@ | |||
| 80 | .Ft char * | 83 | .Ft char * |
| 81 | .Fn strcpy "char *dst" "const char *src" | 84 | .Fn strcpy "char *dst" "const char *src" |
| 82 | .Ft char * | 85 | .Ft char * |
| 86 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
| 87 | .Ft char * | ||
| 83 | .Fn strncpy "char *dst" "const char *src" "size_t count" | 88 | .Fn strncpy "char *dst" "const char *src" "size_t count" |
| 84 | .Ft char * | 89 | .Ft char * |
| 85 | .Fn strerror "int errno" | 90 | .Fn strerror "int errno" |
| @@ -103,7 +108,7 @@ | |||
| 103 | .Fn rindex "const char *s" "int c" | 108 | .Fn rindex "const char *s" "int c" |
| 104 | .Sh DESCRIPTION | 109 | .Sh DESCRIPTION |
| 105 | The string functions | 110 | The string functions |
| 106 | functions manipulate strings terminated by a | 111 | manipulate strings terminated by a |
| 107 | null byte. | 112 | null byte. |
| 108 | .Pp | 113 | .Pp |
| 109 | See the specific manual pages for more information. | 114 | See the specific manual pages for more information. |
| @@ -115,23 +120,25 @@ Except as noted in their specific manual pages, | |||
| 115 | the string functions do not test the destination | 120 | the string functions do not test the destination |
| 116 | for size limitations. | 121 | for size limitations. |
| 117 | .Sh SEE ALSO | 122 | .Sh SEE ALSO |
| 123 | .Xr bstring 3 , | ||
| 118 | .Xr index 3 , | 124 | .Xr index 3 , |
| 125 | .Xr rindex 3 , | ||
| 126 | .Xr strcasecmp 3 , | ||
| 119 | .Xr strcat 3 , | 127 | .Xr strcat 3 , |
| 120 | .Xr strchr 3 , | 128 | .Xr strchr 3 , |
| 121 | .Xr strrchr 3 , | ||
| 122 | .Xr strcmp 3 , | 129 | .Xr strcmp 3 , |
| 123 | .Xr strcasecmp 3 , | ||
| 124 | .Xr strcpy 3 , | 130 | .Xr strcpy 3 , |
| 131 | .Xr strcspn 3 , | ||
| 125 | .Xr strerror 3 , | 132 | .Xr strerror 3 , |
| 133 | .Xr strlcat 3 , | ||
| 134 | .Xr strlcpy 3 , | ||
| 126 | .Xr strlen 3 , | 135 | .Xr strlen 3 , |
| 127 | .Xr strpbrk 3 , | 136 | .Xr strpbrk 3 , |
| 137 | .Xr strrchr 3 , | ||
| 128 | .Xr strsep 3 , | 138 | .Xr strsep 3 , |
| 129 | .Xr strspn 3 , | 139 | .Xr strspn 3 , |
| 130 | .Xr strcspn 3 , | ||
| 131 | .Xr strstr 3 , | 140 | .Xr strstr 3 , |
| 132 | .Xr strtok 3 , | 141 | .Xr strtok 3 |
| 133 | .Xr rindex 3 | ||
| 134 | .Xr bstring 3 | ||
| 135 | .Sh STANDARDS | 142 | .Sh STANDARDS |
| 136 | The | 143 | The |
| 137 | .Fn strcat , | 144 | .Fn strcat , |
| @@ -145,12 +152,10 @@ The | |||
| 145 | .Fn strerror , | 152 | .Fn strerror , |
| 146 | .Fn strlen , | 153 | .Fn strlen , |
| 147 | .Fn strpbrk , | 154 | .Fn strpbrk , |
| 148 | .Fn strsep , | ||
| 149 | .Fn strspn , | 155 | .Fn strspn , |
| 150 | .Fn strcspn , | 156 | .Fn strcspn , |
| 151 | .Fn strstr , | 157 | .Fn strstr , |
| 152 | and | 158 | and |
| 153 | .Fn strtok | 159 | .Fn strtok |
| 154 | functions | 160 | functions conform to |
| 155 | conform to | ||
| 156 | .St -ansiC . | 161 | .St -ansiC . |
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c new file mode 100644 index 0000000000..b309648155 --- /dev/null +++ b/src/lib/libc/string/strlcat.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. The name of the author may not be used to endorse or promote products | ||
| 16 | * derived from this software without specific prior written permission. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 31 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"; | ||
| 32 | #endif /* LIBC_SCCS and not lint */ | ||
| 33 | |||
| 34 | #include <sys/types.h> | ||
| 35 | #include <string.h> | ||
| 36 | |||
| 37 | /* | ||
| 38 | * Appends src to string dst of size siz (unlike strncat, siz is the | ||
| 39 | * full size of dst, not space left). At most siz-1 characters | ||
| 40 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). | ||
| 41 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). | ||
| 42 | * If retval >= siz, truncation occurred. | ||
| 43 | */ | ||
| 44 | size_t | ||
| 45 | strlcat(dst, src, siz) | ||
| 46 | char *dst; | ||
| 47 | const char *src; | ||
| 48 | size_t siz; | ||
| 49 | { | ||
| 50 | register char *d = dst; | ||
| 51 | register const char *s = src; | ||
| 52 | register size_t n = siz; | ||
| 53 | size_t dlen; | ||
| 54 | |||
| 55 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
| 56 | while (n-- != 0 && *d != '\0') | ||
| 57 | d++; | ||
| 58 | dlen = d - dst; | ||
| 59 | n = siz - dlen; | ||
| 60 | |||
| 61 | if (n == 0) | ||
| 62 | return(dlen + strlen(s)); | ||
| 63 | while (*s != '\0') { | ||
| 64 | if (n != 1) { | ||
| 65 | *d++ = *s; | ||
| 66 | n--; | ||
| 67 | } | ||
| 68 | s++; | ||
| 69 | } | ||
| 70 | *d = '\0'; | ||
| 71 | |||
| 72 | return(dlen + (s - src)); /* count does not include NUL */ | ||
| 73 | } | ||
diff --git a/src/lib/libc/string/strlcpy.3 b/src/lib/libc/string/strlcpy.3 new file mode 100644 index 0000000000..b103588b96 --- /dev/null +++ b/src/lib/libc/string/strlcpy.3 | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | .\" $OpenBSD: strlcpy.3,v 1.14 2002/04/30 16:31:42 mpech Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 4 | .\" All rights reserved. | ||
| 5 | .\" | ||
| 6 | .\" Redistribution and use in source and binary forms, with or without | ||
| 7 | .\" modification, are permitted provided that the following conditions | ||
| 8 | .\" are met: | ||
| 9 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer. | ||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 13 | .\" documentation and/or other materials provided with the distribution. | ||
| 14 | .\" 3. The name of the author may not be used to endorse or promote products | ||
| 15 | .\" derived from this software without specific prior written permission. | ||
| 16 | .\" | ||
| 17 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 18 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 19 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 20 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 21 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 22 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 23 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 24 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 25 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 26 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 27 | .\" | ||
| 28 | .Dd June 22, 1998 | ||
| 29 | .Dt STRLCPY 3 | ||
| 30 | .Os | ||
| 31 | .Sh NAME | ||
| 32 | .Nm strlcpy , | ||
| 33 | .Nm strlcat | ||
| 34 | .Nd size-bounded string copying and concatenation | ||
| 35 | .Sh SYNOPSIS | ||
| 36 | .Fd #include <string.h> | ||
| 37 | .Ft size_t | ||
| 38 | .Fn strlcpy "char *dst" "const char *src" "size_t size" | ||
| 39 | .Ft size_t | ||
| 40 | .Fn strlcat "char *dst" "const char *src" "size_t size" | ||
| 41 | .Sh DESCRIPTION | ||
| 42 | The | ||
| 43 | .Fn strlcpy | ||
| 44 | and | ||
| 45 | .Fn strlcat | ||
| 46 | functions copy and concatenate strings respectively. | ||
| 47 | They are designed | ||
| 48 | to be safer, more consistent, and less error prone replacements for | ||
| 49 | .Xr strncpy 3 | ||
| 50 | and | ||
| 51 | .Xr strncat 3 . | ||
| 52 | Unlike those functions, | ||
| 53 | .Fn strlcpy | ||
| 54 | and | ||
| 55 | .Fn strlcat | ||
| 56 | take the full size of the buffer (not just the length) and guarantee to | ||
| 57 | NUL-terminate the result (as long as | ||
| 58 | .Fa size | ||
| 59 | is larger than 0 or, in the case of | ||
| 60 | .Fn strlcat , | ||
| 61 | as long as there is at least one byte free in | ||
| 62 | .Fa dst ) . | ||
| 63 | Note that you should include a byte for the NUL in | ||
| 64 | .Fa size . | ||
| 65 | Also note that | ||
| 66 | .Fn strlcpy | ||
| 67 | and | ||
| 68 | .Fn strlcat | ||
| 69 | only operate on true | ||
| 70 | .Dq C | ||
| 71 | strings. | ||
| 72 | This means that for | ||
| 73 | .Fn strlcpy | ||
| 74 | .Fa src | ||
| 75 | must be NUL-terminated and for | ||
| 76 | .Fn strlcat | ||
| 77 | both | ||
| 78 | .Fa src | ||
| 79 | and | ||
| 80 | .Fa dst | ||
| 81 | must be NUL-terminated. | ||
| 82 | .Pp | ||
| 83 | The | ||
| 84 | .Fn strlcpy | ||
| 85 | function copies up to | ||
| 86 | .Fa size | ||
| 87 | - 1 characters from the NUL-terminated string | ||
| 88 | .Fa src | ||
| 89 | to | ||
| 90 | .Fa dst , | ||
| 91 | NUL-terminating the result. | ||
| 92 | .Pp | ||
| 93 | The | ||
| 94 | .Fn strlcat | ||
| 95 | function appends the NUL-terminated string | ||
| 96 | .Fa src | ||
| 97 | to the end of | ||
| 98 | .Fa dst . | ||
| 99 | It will append at most | ||
| 100 | .Fa size | ||
| 101 | - strlen(dst) - 1 bytes, NUL-terminating the result. | ||
| 102 | .Sh RETURN VALUES | ||
| 103 | The | ||
| 104 | .Fn strlcpy | ||
| 105 | and | ||
| 106 | .Fn strlcat | ||
| 107 | functions return the total length of the string they tried to create. | ||
| 108 | For | ||
| 109 | .Fn strlcpy | ||
| 110 | that means the length of | ||
| 111 | .Fa src . | ||
| 112 | For | ||
| 113 | .Fn strlcat | ||
| 114 | that means the initial length of | ||
| 115 | .Fa dst | ||
| 116 | plus | ||
| 117 | the length of | ||
| 118 | .Fa src . | ||
| 119 | While this may seem somewhat confusing it was done to make | ||
| 120 | truncation detection simple. | ||
| 121 | .Pp | ||
| 122 | Note however, that if | ||
| 123 | .Fn strlcat | ||
| 124 | traverses | ||
| 125 | .Fa size | ||
| 126 | characters without finding a NUL, the length of the string is considered | ||
| 127 | to be | ||
| 128 | .Fa size | ||
| 129 | and the destination string will not be NUL-terminated (since there was | ||
| 130 | no space for the NUL). | ||
| 131 | This keeps | ||
| 132 | .Fn strlcat | ||
| 133 | from running off the end of a string. | ||
| 134 | In practice this should not happen (as it means that either | ||
| 135 | .Fa size | ||
| 136 | is incorrect or that | ||
| 137 | .Fa dst | ||
| 138 | is not a proper | ||
| 139 | .Dq C | ||
| 140 | string). | ||
| 141 | The check exists to prevent potential security problems in incorrect code. | ||
| 142 | .Sh EXAMPLES | ||
| 143 | The following code fragment illustrates the simple case: | ||
| 144 | .Bd -literal -offset indent | ||
| 145 | char *s, *p, buf[BUFSIZ]; | ||
| 146 | |||
| 147 | \&... | ||
| 148 | |||
| 149 | (void)strlcpy(buf, s, sizeof(buf)); | ||
| 150 | (void)strlcat(buf, p, sizeof(buf)); | ||
| 151 | .Ed | ||
| 152 | .Pp | ||
| 153 | To detect truncation, perhaps while building a pathname, something | ||
| 154 | like the following might be used: | ||
| 155 | .Bd -literal -offset indent | ||
| 156 | char *dir, *file, pname[MAXPATHLEN]; | ||
| 157 | |||
| 158 | \&... | ||
| 159 | |||
| 160 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) | ||
| 161 | goto toolong; | ||
| 162 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) | ||
| 163 | goto toolong; | ||
| 164 | .Ed | ||
| 165 | .Pp | ||
| 166 | Since we know how many characters we copied the first time, we can | ||
| 167 | speed things up a bit by using a copy instead of an append: | ||
| 168 | .Bd -literal -offset indent | ||
| 169 | char *dir, *file, pname[MAXPATHLEN]; | ||
| 170 | size_t n; | ||
| 171 | |||
| 172 | \&... | ||
| 173 | |||
| 174 | n = strlcpy(pname, dir, sizeof(pname)); | ||
| 175 | if (n >= sizeof(pname)) | ||
| 176 | goto toolong; | ||
| 177 | if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) | ||
| 178 | goto toolong; | ||
| 179 | .Ed | ||
| 180 | .Pp | ||
| 181 | However, one may question the validity of such optimizations, as they | ||
| 182 | defeat the whole purpose of | ||
| 183 | .Fn strlcpy | ||
| 184 | and | ||
| 185 | .Fn strlcat . | ||
| 186 | As a matter of fact, the first version of this manual page got it wrong. | ||
| 187 | .Sh SEE ALSO | ||
| 188 | .Xr snprintf 3 , | ||
| 189 | .Xr strncat 3 , | ||
| 190 | .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..5f586964b7 --- /dev/null +++ b/src/lib/libc/string/strlcpy.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. The name of the author may not be used to endorse or promote products | ||
| 16 | * derived from this software without specific prior written permission. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; | ||
| 32 | #endif /* LIBC_SCCS and not lint */ | ||
| 33 | |||
| 34 | #include <sys/types.h> | ||
| 35 | #include <string.h> | ||
| 36 | |||
| 37 | /* | ||
| 38 | * Copy src to string dst of size siz. At most siz-1 characters | ||
| 39 | * will be copied. Always NUL terminates (unless siz == 0). | ||
| 40 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 41 | */ | ||
| 42 | size_t | ||
| 43 | strlcpy(dst, src, siz) | ||
| 44 | char *dst; | ||
| 45 | const char *src; | ||
| 46 | size_t siz; | ||
| 47 | { | ||
| 48 | register char *d = dst; | ||
| 49 | register const char *s = src; | ||
| 50 | register size_t n = siz; | ||
| 51 | |||
| 52 | /* Copy as many bytes as will fit */ | ||
| 53 | if (n != 0 && --n != 0) { | ||
| 54 | do { | ||
| 55 | if ((*d++ = *s++) == 0) | ||
| 56 | break; | ||
| 57 | } while (--n != 0); | ||
| 58 | } | ||
| 59 | |||
| 60 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 61 | if (n == 0) { | ||
| 62 | if (siz != 0) | ||
| 63 | *d = '\0'; /* NUL-terminate dst */ | ||
| 64 | while (*s++) | ||
| 65 | ; | ||
| 66 | } | ||
| 67 | |||
| 68 | return(s - src - 1); /* count does not include NUL */ | ||
| 69 | } | ||
diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 index f4aff363ee..759e724056 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 | |||
| @@ -33,15 +33,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strlen.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strlen.3,v 1.4 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strlen.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRLEN 3 | 39 | .Dt STRLEN 3 |
| 41 | .Os | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strlen | 42 | .Nm strlen |
| 44 | .Nd find length of string | 43 | .Nd find length of a string |
| 45 | .Sh SYNOPSIS | 44 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 45 | .Fd #include <string.h> |
| 47 | .Ft size_t | 46 | .Ft size_t |
| @@ -49,23 +48,18 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strlen | 50 | .Fn strlen |
| 52 | function | 51 | function computes the length of the string |
| 53 | computes the length of the string | ||
| 54 | .Fa s . | 52 | .Fa s . |
| 55 | .Sh RETURN VALUES | 53 | .Sh RETURN VALUES |
| 56 | The | 54 | The |
| 57 | .Fn strlen | 55 | .Fn strlen |
| 58 | function | 56 | function returns the number of characters that precede the terminating |
| 59 | returns | 57 | .Tn NUL |
| 60 | the number of characters that precede the | ||
| 61 | terminating | ||
| 62 | .Dv NUL | ||
| 63 | character. | 58 | character. |
| 64 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
| 65 | .Xr string 3 | 60 | .Xr string 3 |
| 66 | .Sh STANDARDS | 61 | .Sh STANDARDS |
| 67 | The | 62 | The |
| 68 | .Fn strlen | 63 | .Fn strlen |
| 69 | function | 64 | function conforms to |
| 70 | conforms to | ||
| 71 | .St -ansiC . | 65 | .St -ansiC . |
diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c index d23aadafc0..ab006e04c2 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.4 2001/07/29 21:15:23 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 |
| @@ -32,19 +34,23 @@ | |||
| 32 | */ | 34 | */ |
| 33 | 35 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strlen.c 5.5 (Berkeley) 1/26/91";*/ | 37 | static char *rcsid = "$OpenBSD: strlen.c,v 1.4 2001/07/29 21:15:23 millert 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 */ | 38 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 39 | ||
| 40 | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||
| 39 | #include <string.h> | 41 | #include <string.h> |
| 42 | #else | ||
| 43 | #include <lib/libkern/libkern.h> | ||
| 44 | #endif | ||
| 40 | 45 | ||
| 41 | size_t | 46 | size_t |
| 42 | strlen(str) | 47 | strlen(str) |
| 43 | const char *str; | 48 | const char *str; |
| 44 | { | 49 | { |
| 45 | register const char *s; | 50 | const char *s; |
| 46 | 51 | ||
| 47 | for (s = str; *s; ++s); | 52 | for (s = str; *s; ++s) |
| 48 | return(s - str); | 53 | ; |
| 54 | return (s - str); | ||
| 49 | } | 55 | } |
| 50 | 56 | ||
diff --git a/src/lib/libc/string/strmode.3 b/src/lib/libc/string/strmode.3 index 1907e7ab03..bf311f1f99 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.8 2000/04/21 15:24:20 aaron 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 |
| @@ -29,10 +31,9 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 31 | .\" | 33 | .\" |
| 32 | .\" from: @(#)strmode.3 5.4 (Berkeley) 7/31/91 | 34 | .\" @(#)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 | .\" | 35 | .\" |
| 35 | .Dd July 31, 1991 | 36 | .Dd July 28, 1994 |
| 36 | .Dt STRMODE 3 | 37 | .Dt STRMODE 3 |
| 37 | .Os | 38 | .Os |
| 38 | .Sh NAME | 39 | .Sh NAME |
| @@ -45,15 +46,13 @@ | |||
| 45 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 46 | The | 47 | The |
| 47 | .Fn strmode | 48 | .Fn strmode |
| 48 | function | 49 | function converts a file |
| 49 | converts a file | ||
| 50 | .Fa mode | 50 | .Fa mode |
| 51 | (the type and permission information associated with an inode, see | 51 | (the type and permission information associated with an inode, see |
| 52 | .Xr stat 2 ) | 52 | .Xr stat 2 ) |
| 53 | into a symbolic string which is stored in the location referenced by | 53 | into a symbolic string which is stored in the location referenced by |
| 54 | .Fa bp . | 54 | .Fa bp . |
| 55 | This stored string is eleven characters in length plus a trailing | 55 | This stored string is eleven characters in length plus a trailing null byte. |
| 56 | .Dv NULL . | ||
| 57 | .Pp | 56 | .Pp |
| 58 | The first character is the inode type, and will be one of the following: | 57 | The first character is the inode type, and will be one of the following: |
| 59 | .Pp | 58 | .Pp |
| @@ -72,6 +71,8 @@ symbolic link | |||
| 72 | fifo | 71 | fifo |
| 73 | .It s | 72 | .It s |
| 74 | socket | 73 | socket |
| 74 | .It w | ||
| 75 | whiteout | ||
| 75 | .It ? | 76 | .It ? |
| 76 | unknown inode type | 77 | unknown inode type |
| 77 | .El | 78 | .El |
| @@ -80,46 +81,58 @@ The next nine characters encode three sets of permissions, in three | |||
| 80 | characters each. | 81 | characters each. |
| 81 | The first three characters are the permissions for the owner of the | 82 | The first three characters are the permissions for the owner of the |
| 82 | file, the second three for the group the file belongs to, and the | 83 | file, the second three for the group the file belongs to, and the |
| 83 | third for the ``other'', or default, set of users. | 84 | third for the |
| 85 | .Dq other , | ||
| 86 | or default, set of users. | ||
| 84 | .Pp | 87 | .Pp |
| 85 | Permission checking is done as specifically as possible. | 88 | Permission checking is done as specifically as possible. |
| 86 | If read permission is denied to the owner of a file in the first set | 89 | 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. | 90 | 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 | 91 | 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. | 92 | permissions allow reading or the |
| 93 | .Dq other | ||
| 94 | permissions allow reading. | ||
| 90 | .Pp | 95 | .Pp |
| 91 | If the first character of the three character set is an ``r'', the file is | 96 | 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. | 97 | .Sq r , |
| 98 | the file is readable for that set of users; if a dash | ||
| 99 | .Pq Ql - , | ||
| 100 | it is not readable. | ||
| 93 | .Pp | 101 | .Pp |
| 94 | If the second character of the three character set is a ``w'', the file is | 102 | 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. | 103 | .Sq w , |
| 104 | the file is writable for that set of users; if a dash | ||
| 105 | .Pq Ql - , | ||
| 106 | it is not writable. | ||
| 96 | .Pp | 107 | .Pp |
| 97 | The third character is the first of the following characters that apply: | 108 | The third character is the first of the following characters that apply: |
| 98 | .Bl -tag -width xxxx | 109 | .Bl -tag -width xxxx |
| 99 | .It S | 110 | .It S |
| 100 | If the character is part of the owner permissions and the file is not | 111 | 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 | 112 | executable or the directory is not searchable by the owner, and the |
| 102 | set-user-id bit is set. | 113 | set-user-ID bit is set. |
| 103 | .It S | 114 | .It S |
| 104 | If the character is part of the group permissions and the file is not | 115 | 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 | 116 | executable or the directory is not searchable by the group, and the |
| 106 | set-group-id bit is set. | 117 | set-group-ID bit is set. |
| 107 | .It T | 118 | .It T |
| 108 | If the character is part of the other permissions and the file is not | 119 | 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'' | 120 | executable or the directory is not searchable by others, and the |
| 121 | .Dq sticky | ||
| 110 | .Pq Dv S_ISVTX | 122 | .Pq Dv S_ISVTX |
| 111 | bit is set. | 123 | bit is set. |
| 112 | .It s | 124 | .It s |
| 113 | If the character is part of the owner permissions and the file is | 125 | 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 | 126 | executable or the directory searchable by the owner, and the set-user-ID |
| 115 | bit is set. | 127 | bit is set. |
| 116 | .It s | 128 | .It s |
| 117 | If the character is part of the group permissions and the file is | 129 | 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 | 130 | executable or the directory searchable by the group, and the set-group-ID |
| 119 | bit is set. | 131 | bit is set. |
| 120 | .It t | 132 | .It t |
| 121 | If the character is part of the other permissions and the file is | 133 | If the character is part of the other permissions and the file is |
| 122 | executable or the directory searchable, by others, and the ``sticky'' | 134 | executable or the directory searchable by others, and the |
| 135 | .Dq sticky | ||
| 123 | .Pq Dv S_ISVTX | 136 | .Pq Dv S_ISVTX |
| 124 | bit is set. | 137 | bit is set. |
| 125 | .It x | 138 | .It x |
| @@ -128,14 +141,15 @@ The file is executable or the directory is searchable. | |||
| 128 | None of the above apply. | 141 | None of the above apply. |
| 129 | .El | 142 | .El |
| 130 | .Pp | 143 | .Pp |
| 131 | The last character is a plus sign ``+'' if any there are any alternate | 144 | The last character is a plus sign |
| 145 | .Pq Ql + | ||
| 146 | if there are any alternate | ||
| 132 | or additional access control methods associated with the inode, otherwise | 147 | or additional access control methods associated with the inode, otherwise |
| 133 | it will be a space. | 148 | it will be a space. |
| 134 | .Sh RETURN VALUES | 149 | .Sh RETURN VALUES |
| 135 | The | 150 | The |
| 136 | .Fn strmode | 151 | .Fn strmode |
| 137 | function | 152 | function always returns 0. |
| 138 | always returns 0. | ||
| 139 | .Sh SEE ALSO | 153 | .Sh SEE ALSO |
| 140 | .Xr chmod 1 , | 154 | .Xr chmod 1 , |
| 141 | .Xr find 1 , | 155 | .Xr find 1 , |
| @@ -145,5 +159,5 @@ always returns 0. | |||
| 145 | .Sh HISTORY | 159 | .Sh HISTORY |
| 146 | The | 160 | The |
| 147 | .Fn strmode | 161 | .Fn strmode |
| 148 | function | 162 | function first appeared in |
| 149 | .Ud . | 163 | .Bx 4.4 . |
diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c index 441fc76e90..5e7f15e857 100644 --- a/src/lib/libc/string/strmode.c +++ b/src/lib/libc/string/strmode.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strmode.c 5.3 (Berkeley) 5/18/90";*/ | 35 | static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
| @@ -70,6 +69,11 @@ strmode(mode, p) | |||
| 70 | *p++ = 'p'; | 69 | *p++ = 'p'; |
| 71 | break; | 70 | break; |
| 72 | #endif | 71 | #endif |
| 72 | #ifdef S_IFWHT | ||
| 73 | case S_IFWHT: /* whiteout */ | ||
| 74 | *p++ = 'w'; | ||
| 75 | break; | ||
| 76 | #endif | ||
| 73 | default: /* unknown */ | 77 | default: /* unknown */ |
| 74 | *p++ = '?'; | 78 | *p++ = '?'; |
| 75 | break; | 79 | break; |
diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c index 3d96452af4..27ae2ba324 100644 --- a/src/lib/libc/string/strncat.c +++ b/src/lib/libc/string/strncat.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strncat.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strncat.c,v 1.2 1996/08/19 08:34:21 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c index 0638d4dcf2..0224957f8b 100644 --- a/src/lib/libc/string/strncmp.c +++ b/src/lib/libc/string/strncmp.c | |||
| @@ -32,11 +32,14 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strncmp.c 5.6 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strncmp.c,v 1.3 1996/08/19 08:34:21 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 38 | #ifndef _KERNEL | ||
| 39 | #include <string.h> | 39 | #include <string.h> |
| 40 | #else | ||
| 41 | #include <lib/libkern/libkern.h> | ||
| 42 | #endif | ||
| 40 | 43 | ||
| 41 | int | 44 | int |
| 42 | strncmp(s1, s2, n) | 45 | strncmp(s1, s2, n) |
diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c index 5215311b75..01bc8a872e 100644 --- a/src/lib/libc/string/strncpy.c +++ b/src/lib/libc/string/strncpy.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strncpy.c 5.6 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strncpy.c,v 1.2 1996/08/19 08:34:22 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strpbrk.3 b/src/lib/libc/string/strpbrk.3 index 8578546c05..52bf13b924 100644 --- a/src/lib/libc/string/strpbrk.3 +++ b/src/lib/libc/string/strpbrk.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strpbrk.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strpbrk.3,v 1.5 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strpbrk.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRPBRK 3 | 39 | .Dt STRPBRK 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strpbrk | 50 | .Fn strpbrk |
| 52 | function | 51 | function locates in the null-terminated string |
| 53 | locates in the null-terminated string | ||
| 54 | .Fa s | 52 | .Fa s |
| 55 | the first occurrence of any character in the string | 53 | the first occurrence of any character in the string |
| 56 | .Fa charset | 54 | .Fa charset |
| @@ -58,13 +56,12 @@ and returns a pointer to this character. | |||
| 58 | If no characters from | 56 | If no characters from |
| 59 | .Fa charset | 57 | .Fa charset |
| 60 | occur anywhere in | 58 | occur anywhere in |
| 61 | .Fa s | 59 | .Fa s , |
| 62 | .Fn strpbrk | 60 | .Fn strpbrk |
| 63 | returns NULL. | 61 | returns |
| 62 | .Dv NULL . | ||
| 64 | .Sh SEE ALSO | 63 | .Sh SEE ALSO |
| 65 | .Xr index 3 , | ||
| 66 | .Xr memchr 3 , | 64 | .Xr memchr 3 , |
| 67 | .Xr rindex 3 , | ||
| 68 | .Xr strchr 3 , | 65 | .Xr strchr 3 , |
| 69 | .Xr strcspn 3 , | 66 | .Xr strcspn 3 , |
| 70 | .Xr strrchr 3 , | 67 | .Xr strrchr 3 , |
| @@ -75,6 +72,5 @@ returns NULL. | |||
| 75 | .Sh STANDARDS | 72 | .Sh STANDARDS |
| 76 | The | 73 | The |
| 77 | .Fn strpbrk | 74 | .Fn strpbrk |
| 78 | function | 75 | function conforms to |
| 79 | conforms to | ||
| 80 | .St -ansiC . | 76 | .St -ansiC . |
diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c index f1d542a525..748a3a8c94 100644 --- a/src/lib/libc/string/strpbrk.c +++ b/src/lib/libc/string/strpbrk.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strpbrk.c 5.8 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strpbrk.c,v 1.2 1996/08/19 08:34:23 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strrchr.3 b/src/lib/libc/string/strrchr.3 index 1d98cbff24..394fc2aad3 100644 --- a/src/lib/libc/string/strrchr.3 +++ b/src/lib/libc/string/strrchr.3 | |||
| @@ -33,28 +33,31 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strrchr.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strrchr.3,v 1.6 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strrchr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRRCHR 3 | 39 | .Dt STRRCHR 3 |
| 41 | .Os | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strrchr | 42 | .Nm strrchr , |
| 44 | .Nd locate character in string | 43 | .Nm rindex |
| 44 | .Nd locate last occurrence of a character in a string | ||
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| 47 | .Ft char * | 47 | .Ft char * |
| 48 | .Fn strrchr "const char *s" "int c" | 48 | .Fn strrchr "const char *s" "int c" |
| 49 | .Ft char * | ||
| 50 | .Fn rindex "const char *s" "int c" | ||
| 49 | .Sh DESCRIPTION | 51 | .Sh DESCRIPTION |
| 50 | The | 52 | The |
| 51 | .Fn strrchr | 53 | .Fn strrchr |
| 52 | function | 54 | function locates the last occurrence of the character |
| 53 | locates the last occurrence of | ||
| 54 | .Fa c | 55 | .Fa c |
| 55 | (converted to a char) | ||
| 56 | in the string | 56 | in the string |
| 57 | .Fa s . | 57 | .Fa s . |
| 58 | The terminating | ||
| 59 | .Tn NUL | ||
| 60 | character is considered part of the string. | ||
| 58 | If | 61 | If |
| 59 | .Fa c | 62 | .Fa c |
| 60 | is | 63 | is |
| @@ -62,20 +65,31 @@ is | |||
| 62 | .Fn strrchr | 65 | .Fn strrchr |
| 63 | locates the terminating | 66 | locates the terminating |
| 64 | .Ql \e0 . | 67 | .Ql \e0 . |
| 68 | .Pp | ||
| 69 | The | ||
| 70 | .Fn rindex | ||
| 71 | function is an old synonym for | ||
| 72 | .Fn strrchr . | ||
| 65 | .Sh RETURN VALUES | 73 | .Sh RETURN VALUES |
| 66 | The | 74 | The |
| 67 | .Fn strrchr | 75 | .Fn strrchr |
| 68 | function | 76 | function returns a pointer to the located character or |
| 69 | returns a pointer to the character, | 77 | .Dv NULL |
| 70 | or a null | 78 | if the character does not appear in the string. |
| 71 | pointer if | 79 | .Sh EXAMPLES |
| 72 | .Fa c | 80 | After the following call to |
| 73 | does not occur anywhere in | 81 | .Fn strrchr , |
| 74 | .Fa s . | 82 | .Va p |
| 83 | will point to the string | ||
| 84 | .Qq obar : | ||
| 85 | .Bd -literal -offset indent | ||
| 86 | char *p; | ||
| 87 | char *s = "foobar"; | ||
| 88 | |||
| 89 | p = strrchr(s, 'o'); | ||
| 90 | .Ed | ||
| 75 | .Sh SEE ALSO | 91 | .Sh SEE ALSO |
| 76 | .Xr index 3 , | ||
| 77 | .Xr memchr 3 , | 92 | .Xr memchr 3 , |
| 78 | .Xr rindex 3 , | ||
| 79 | .Xr strchr 3 , | 93 | .Xr strchr 3 , |
| 80 | .Xr strcspn 3 , | 94 | .Xr strcspn 3 , |
| 81 | .Xr strpbrk 3 , | 95 | .Xr strpbrk 3 , |
| @@ -86,6 +100,9 @@ does not occur anywhere in | |||
| 86 | .Sh STANDARDS | 100 | .Sh STANDARDS |
| 87 | The | 101 | The |
| 88 | .Fn strrchr | 102 | .Fn strrchr |
| 89 | function | 103 | function conforms to |
| 90 | conforms to | ||
| 91 | .St -ansiC . | 104 | .St -ansiC . |
| 105 | .Pp | ||
| 106 | The | ||
| 107 | .Fn rindex | ||
| 108 | 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..848dab1eb3 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.10 2001/11/21 14:32:45 deraadt 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: |
| @@ -31,10 +34,9 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 35 | .\" SUCH DAMAGE. |
| 33 | .\" | 36 | .\" |
| 34 | .\" from: @(#)strsep.3 5.3 (Berkeley) 4/19/91 | 37 | .\" @(#)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 | .\" | 38 | .\" |
| 37 | .Dd April 19, 1991 | 39 | .Dd June 9, 1993 |
| 38 | .Dt STRSEP 3 | 40 | .Dt STRSEP 3 |
| 39 | .Os | 41 | .Os |
| 40 | .Sh NAME | 42 | .Sh NAME |
| @@ -43,27 +45,37 @@ | |||
| 43 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 44 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| 45 | .Ft char * | 47 | .Ft char * |
| 46 | .Fn strsep "char **stringp" "char *delim" | 48 | .Fn strsep "char **stringp" "const char *delim" |
| 47 | .Sh DESCRIPTION | 49 | .Sh DESCRIPTION |
| 48 | The | 50 | The |
| 49 | .Fn strsep | 51 | .Fn strsep |
| 50 | locates in the null-terminated string at | 52 | 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 , | 53 | .Fa *stringp , |
| 58 | then returns the original value of | 54 | the first occurrence of any character in the string |
| 55 | .Fa delim | ||
| 56 | (or the terminating | ||
| 57 | .Ql \e0 | ||
| 58 | character) and replaces it with a | ||
| 59 | .Ql \e0 . | ||
| 60 | The location of the next character after the delimiter character | ||
| 61 | (or | ||
| 62 | .Dv NULL , | ||
| 63 | if the end of the string was reached) is stored in | ||
| 59 | .Fa *stringp . | 64 | .Fa *stringp . |
| 60 | If no delimiter characters are found, | 65 | The original value of |
| 61 | .Fn strsep | ||
| 62 | sets | ||
| 63 | .Fa *stringp | 66 | .Fa *stringp |
| 67 | is returned. | ||
| 68 | .Pp | ||
| 69 | An | ||
| 70 | .Dq empty | ||
| 71 | field, i.e., one caused by two adjacent delimiter characters, | ||
| 72 | can be detected by comparing the location referenced by the pointer returned | ||
| 73 | by | ||
| 74 | .Fn strsep | ||
| 64 | to | 75 | to |
| 65 | .Dv NULL ; | 76 | .Ql \e0 . |
| 66 | if | 77 | .Pp |
| 78 | If | ||
| 67 | .Fa *stringp | 79 | .Fa *stringp |
| 68 | is initially | 80 | is initially |
| 69 | .Dv NULL , | 81 | .Dv NULL , |
| @@ -73,20 +85,32 @@ returns | |||
| 73 | .Sh EXAMPLES | 85 | .Sh EXAMPLES |
| 74 | The following uses | 86 | The following uses |
| 75 | .Fn strsep | 87 | .Fn strsep |
| 76 | to parse strings containing runs of white space, | 88 | to parse a string, containing tokens delimited by whitespace, into an |
| 77 | making up an argument vector: | 89 | argument vector: |
| 78 | .Bd -literal -offset indent | 90 | .Bd -literal -offset indent |
| 79 | char inputstring[100]; | 91 | char **ap, *argv[10], *inputstring; |
| 80 | char **argv[51], **ap = argv, *p, *val; | 92 | |
| 81 | /* set up inputstring */ | 93 | for (ap = argv; ap < &argv[9] && |
| 82 | for (p = inputstring; p != NULL; ) { | 94 | (*ap = strsep(&inputstring, " \et")) != NULL;) { |
| 83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 95 | if (**ap != '\e0') |
| 84 | *ap++ = val; | 96 | ap++; |
| 85 | } | 97 | } |
| 86 | *ap = 0; | 98 | *ap = NULL; |
| 87 | .Ed | 99 | .Ed |
| 88 | .Sh HISTORY | 100 | .Sh HISTORY |
| 89 | The | 101 | The |
| 90 | .Fn strsep | 102 | .Fn strsep |
| 91 | function is | 103 | function is intended as a replacement for the |
| 92 | .Ud . | 104 | .Fn strtok |
| 105 | function. | ||
| 106 | While the | ||
| 107 | .Fn strtok | ||
| 108 | function should be preferred for portability reasons (it conforms to | ||
| 109 | .St -ansiC ) | ||
| 110 | it is unable to handle empty fields, i.e., detect fields delimited by | ||
| 111 | two adjacent delimiter characters, or to be used for more than a single | ||
| 112 | string at a time. | ||
| 113 | The | ||
| 114 | .Fn strsep | ||
| 115 | function first appeared in | ||
| 116 | .Bx 4.4 . | ||
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c index 69be7fe046..b69b715fc5 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.3 1997/08/20 04:28:14 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 |
| @@ -31,15 +33,19 @@ | |||
| 31 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. |
| 32 | */ | 34 | */ |
| 33 | 35 | ||
| 36 | #include <string.h> | ||
| 37 | #include <stdio.h> | ||
| 38 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 39 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static const char sccsid[] = "from: @(#)strsep.c 5.4 (Berkeley) 1/26/91";*/ | 40 | #if 0 |
| 36 | static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | 41 | static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; |
| 42 | #else | ||
| 43 | static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $"; | ||
| 44 | #endif | ||
| 37 | #endif /* LIBC_SCCS and not lint */ | 45 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 46 | ||
| 39 | #include <string.h> | ||
| 40 | |||
| 41 | /* | 47 | /* |
| 42 | * Get next token from string *stringp, where tokens are nonempty | 48 | * Get next token from string *stringp, where tokens are possibly-empty |
| 43 | * strings separated by characters from delim. | 49 | * strings separated by characters from delim. |
| 44 | * | 50 | * |
| 45 | * Writes NULs into the string at *stringp to end tokens. | 51 | * Writes NULs into the string at *stringp to end tokens. |
| @@ -47,7 +53,7 @@ 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 | 53 | * 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). | 54 | * be further tokens), or is NULL (if there are definitely no more tokens). |
| 49 | * | 55 | * |
| 50 | * If *stringp is NULL, strtoken returns NULL. | 56 | * If *stringp is NULL, strsep returns NULL. |
| 51 | */ | 57 | */ |
| 52 | char * | 58 | char * |
| 53 | strsep(stringp, delim) | 59 | strsep(stringp, delim) |
diff --git a/src/lib/libc/string/strsignal.3 b/src/lib/libc/string/strsignal.3 index 3287fef53e..83b3775f4e 100644 --- a/src/lib/libc/string/strsignal.3 +++ b/src/lib/libc/string/strsignal.3 | |||
| @@ -33,12 +33,11 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strsignal.3,v 1.3 1999/05/23 14:11:03 aaron Exp $ |
| 37 | .\" $Id: strsignal.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRSIGNAL 3 | 39 | .Dt STRSIGNAL 3 |
| 41 | .Os BSD 4 | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strsignal | 42 | .Nm strsignal |
| 44 | .Nd get signal description string | 43 | .Nd get signal description string |
diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c index ec4a267edf..90118f70f9 100644 --- a/src/lib/libc/string/strsignal.c +++ b/src/lib/libc/string/strsignal.c | |||
| @@ -32,14 +32,13 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: strsignal.c,v 1.3 2002/02/16 21:27:24 millert 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
| 40 | #include <limits.h> | 39 | #include <limits.h> |
| 41 | 40 | ||
| 42 | extern char *__strsignal __P((int, char *)); | 41 | extern char *__strsignal(int, char *); |
| 43 | 42 | ||
| 44 | char * | 43 | char * |
| 45 | strsignal(sig) | 44 | strsignal(sig) |
diff --git a/src/lib/libc/string/strspn.3 b/src/lib/libc/string/strspn.3 index 4de03aa58b..ca965aeb18 100644 --- a/src/lib/libc/string/strspn.3 +++ b/src/lib/libc/string/strspn.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strspn.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strspn.3,v 1.6 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strspn.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRSPN 3 | 39 | .Dt STRSPN 3 |
| @@ -48,9 +47,8 @@ | |||
| 48 | .Fn strspn "const char *s" "const char *charset" | 47 | .Fn strspn "const char *s" "const char *charset" |
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Xr strcspn | 50 | .Fn strspn |
| 52 | function | 51 | function spans the initial part of the null-terminated string |
| 53 | spans the initial part of the null-terminated string | ||
| 54 | .Fa s | 52 | .Fa s |
| 55 | as long as the characters from | 53 | as long as the characters from |
| 56 | .Fa s | 54 | .Fa s |
| @@ -59,12 +57,23 @@ occur in string | |||
| 59 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
| 60 | The | 58 | The |
| 61 | .Fn strspn | 59 | .Fn strspn |
| 62 | function | 60 | function returns the number of characters spanned. |
| 63 | returns the number of characters spanned. | 61 | .Sh EXAMPLES |
| 62 | The following call to | ||
| 63 | .Fn strspn | ||
| 64 | will return 3, since the first three characters of string | ||
| 65 | .Fa s | ||
| 66 | are part of string | ||
| 67 | .Fa charset : | ||
| 68 | .Bd -literal -offset indent | ||
| 69 | char *s = "foobar"; | ||
| 70 | char *charset = "of"; | ||
| 71 | size_t span; | ||
| 72 | |||
| 73 | span = strspn(s, charset); | ||
| 74 | .Ed | ||
| 64 | .Sh SEE ALSO | 75 | .Sh SEE ALSO |
| 65 | .Xr index 3 , | ||
| 66 | .Xr memchr 3 , | 76 | .Xr memchr 3 , |
| 67 | .Xr rindex 3 , | ||
| 68 | .Xr strchr 3 , | 77 | .Xr strchr 3 , |
| 69 | .Xr strcspn 3 , | 78 | .Xr strcspn 3 , |
| 70 | .Xr strpbrk 3 , | 79 | .Xr strpbrk 3 , |
| @@ -75,6 +84,5 @@ returns the number of characters spanned. | |||
| 75 | .Sh STANDARDS | 84 | .Sh STANDARDS |
| 76 | The | 85 | The |
| 77 | .Fn strspn | 86 | .Fn strspn |
| 78 | function | 87 | function conforms to |
| 79 | conforms to | ||
| 80 | .St -ansiC . | 88 | .St -ansiC . |
diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c index 6224b25c2a..41940f9190 100644 --- a/src/lib/libc/string/strspn.c +++ b/src/lib/libc/string/strspn.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strspn.c 5.8 (Berkeley) 1/26/91";*/ | 35 | static char *rcsid = "$OpenBSD: strspn.c,v 1.2 1996/08/19 08:34:26 tholo 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3 index 24fdf540ed..10beea42ca 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strstr.3 5.3 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strstr.3,v 1.5 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strstr.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRSTR 3 | 39 | .Dt STRSTR 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strstr | 50 | .Fn strstr |
| 52 | function | 51 | function locates the first occurrence of the null-terminated string |
| 53 | locates the first occurrence of the null-terminated string | ||
| 54 | .Fa little | 52 | .Fa little |
| 55 | in the null-terminated string | 53 | in the null-terminated string |
| 56 | .Fa big . | 54 | .Fa big . |
| @@ -65,15 +63,14 @@ if | |||
| 65 | occurs nowhere in | 63 | occurs nowhere in |
| 66 | .Fa big , | 64 | .Fa big , |
| 67 | .Fn strstr | 65 | .Fn strstr |
| 68 | returns NULL; | 66 | returns |
| 67 | .Dv NULL ; | ||
| 69 | otherwise | 68 | otherwise |
| 70 | .Fn strstr | 69 | .Fn strstr |
| 71 | returns a pointer to the first character of the first occurrence of | 70 | returns a pointer to the first character of the first occurrence of |
| 72 | .Fa little . | 71 | .Fa little . |
| 73 | .Sh SEE ALSO | 72 | .Sh SEE ALSO |
| 74 | .Xr index 3 , | ||
| 75 | .Xr memchr 3 , | 73 | .Xr memchr 3 , |
| 76 | .Xr rindex 3 , | ||
| 77 | .Xr strchr 3 , | 74 | .Xr strchr 3 , |
| 78 | .Xr strcspn 3 , | 75 | .Xr strcspn 3 , |
| 79 | .Xr strpbrk 3 , | 76 | .Xr strpbrk 3 , |
| @@ -84,6 +81,5 @@ returns a pointer to the first character of the first occurrence of | |||
| 84 | .Sh STANDARDS | 81 | .Sh STANDARDS |
| 85 | The | 82 | The |
| 86 | .Fn strstr | 83 | .Fn strstr |
| 87 | function | 84 | function conforms to |
| 88 | conforms to | ||
| 89 | .St -ansiC . | 85 | .St -ansiC . |
diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c index 1ed59e357b..763c7e29d7 100644 --- a/src/lib/libc/string/strstr.c +++ b/src/lib/libc/string/strstr.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strstr.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strstr.c,v 1.2 1996/08/19 08:34:27 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 index 644bd10aed..b8dad8eff0 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 | |||
| @@ -33,29 +33,30 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strtok.3 5.8 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strtok.3,v 1.15 2001/08/06 10:42:26 mpech Exp $ |
| 37 | .\" $Id: strtok.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRTOK 3 | 39 | .Dt STRTOK 3 |
| 41 | .Os BSD 3 | 40 | .Os |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm strtok , | 42 | .Nm strtok , |
| 44 | .Nm strsep | 43 | .Nm strtok_r |
| 45 | .Nd string token operations | 44 | .Nd string token operations |
| 46 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 47 | .Fd #include <string.h> | 46 | .Fd #include <string.h> |
| 48 | .Ft char * | 47 | .Ft char * |
| 49 | .Fn strtok "char *str" "const char *sep" | 48 | .Fn strtok "char *str" "const char *sep" |
| 49 | .Ft char * | ||
| 50 | .Fn strtok_r "char *str" "const char *sep" "char **last" | ||
| 50 | .Sh DESCRIPTION | 51 | .Sh DESCRIPTION |
| 51 | .Bf -symbolic | 52 | .Bf -symbolic |
| 52 | This interface is obsoleted by strsep(3). | 53 | This interface is obsoleted by |
| 54 | .Xr strsep 3 . | ||
| 53 | .Ef | 55 | .Ef |
| 54 | .Pp | 56 | .Pp |
| 55 | The | 57 | The |
| 56 | .Fn strtok | 58 | .Fn strtok |
| 57 | function | 59 | 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 . | 60 | .Fa str . |
| 60 | These tokens are separated in the string by at least one of the | 61 | These tokens are separated in the string by at least one of the |
| 61 | characters in | 62 | characters in |
| @@ -71,17 +72,65 @@ The separator string, | |||
| 71 | must be supplied each time, and may change between calls. | 72 | must be supplied each time, and may change between calls. |
| 72 | .Pp | 73 | .Pp |
| 73 | The | 74 | The |
| 75 | .Fn strtok_r | ||
| 76 | function is a version of | ||
| 74 | .Fn strtok | 77 | .Fn strtok |
| 75 | function | 78 | that takes an explicit context argument and is reentrant. |
| 76 | returns a pointer to the beginning of each subsequent token in the string, | 79 | .Pp |
| 77 | after replacing the separator character itself with a | 80 | The |
| 78 | .Dv NUL | 81 | .Fn strtok |
| 82 | and | ||
| 83 | .Fn strtok_r | ||
| 84 | functions return a pointer to the beginning of each subsequent token | ||
| 85 | in the string, after replacing the separator character itself with an | ||
| 86 | .Tn ASCII NUL | ||
| 79 | character. | 87 | character. |
| 80 | When no more tokens remain, a null pointer is returned. | 88 | When no more tokens remain, a null pointer is returned. |
| 89 | .Pp | ||
| 90 | Since | ||
| 91 | .Fn strtok | ||
| 92 | and | ||
| 93 | .Fn strtok_r | ||
| 94 | modify the string, | ||
| 95 | .Fa str | ||
| 96 | should not point to an area in the initialized data segment. | ||
| 97 | .Sh EXAMPLES | ||
| 98 | The following will construct an array of pointers to each individual word in | ||
| 99 | the string | ||
| 100 | .Va s : | ||
| 101 | .Bd -literal -offset indent | ||
| 102 | #define MAXTOKENS 128 | ||
| 103 | |||
| 104 | char s[512], *p, *tokens[MAXTOKENS]; | ||
| 105 | char *last; | ||
| 106 | int i = 0; | ||
| 107 | |||
| 108 | snprintf(s, sizeof(s), "cat dog horse cow"); | ||
| 109 | |||
| 110 | for ((p = strtok_r(s, " ", &last)); p; | ||
| 111 | (p = strtok_r(NULL, " ", &last)), i++) { | ||
| 112 | if (i < MAXTOKENS - 1) | ||
| 113 | tokens[i] = p; | ||
| 114 | } | ||
| 115 | tokens[i] = NULL; | ||
| 116 | .Ed | ||
| 117 | .Pp | ||
| 118 | That is, | ||
| 119 | .Li tokens[0] | ||
| 120 | will point to | ||
| 121 | .Qq cat , | ||
| 122 | .Li tokens[1] | ||
| 123 | will point to | ||
| 124 | .Qq dog , | ||
| 125 | .Li tokens[2] | ||
| 126 | will point to | ||
| 127 | .Qq horse , | ||
| 128 | and | ||
| 129 | .Li tokens[3] | ||
| 130 | will point to | ||
| 131 | .Qq cow . | ||
| 81 | .Sh SEE ALSO | 132 | .Sh SEE ALSO |
| 82 | .Xr index 3 , | ||
| 83 | .Xr memchr 3 , | 133 | .Xr memchr 3 , |
| 84 | .Xr rindex 3 , | ||
| 85 | .Xr strchr 3 , | 134 | .Xr strchr 3 , |
| 86 | .Xr strcspn 3 , | 135 | .Xr strcspn 3 , |
| 87 | .Xr strpbrk 3 , | 136 | .Xr strpbrk 3 , |
| @@ -92,21 +141,16 @@ When no more tokens remain, a null pointer is returned. | |||
| 92 | .Sh STANDARDS | 141 | .Sh STANDARDS |
| 93 | The | 142 | The |
| 94 | .Fn strtok | 143 | .Fn strtok |
| 95 | function | 144 | function conforms to |
| 96 | conforms to | ||
| 97 | .St -ansiC . | 145 | .St -ansiC . |
| 98 | .Sh BUGS | 146 | .Sh BUGS |
| 99 | There is no way to get tokens from multiple strings simultaneously. | ||
| 100 | .Pp | ||
| 101 | The System V | 147 | The System V |
| 102 | .Fn strtok , | 148 | .Fn strtok , |
| 103 | if handed a string containing only delimiter characters, | 149 | if handed a string containing only delimiter characters, |
| 104 | will not alter the next starting point, so that a call to | 150 | will not alter the next starting point, so that a call to |
| 105 | .Fn strtok | 151 | .Fn strtok |
| 106 | with a different (or empty) delimiter string | 152 | with a different (or empty) delimiter string |
| 107 | may return a | 153 | may return a non-null value. |
| 108 | .Pf non- Dv NULL | ||
| 109 | value. | ||
| 110 | Since this implementation always alters the next starting point, | 154 | Since this implementation always alters the next starting point, |
| 111 | such a sequence of calls would always return | 155 | such a sequence of calls would always return |
| 112 | .Dv NULL . | 156 | .Dv NULL . |
diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c index 9f712579bf..d925dc75d0 100644 --- a/src/lib/libc/string/strtok.c +++ b/src/lib/libc/string/strtok.c | |||
| @@ -32,8 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | /*static char *sccsid = "from: @(#)strtok.c 5.8 (Berkeley) 2/24/91";*/ | 35 | static char *rcsid = "$OpenBSD: strtok.c,v 1.3 1999/11/09 11:19:46 art 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 38 | 37 | ||
| 39 | #include <string.h> | 38 | #include <string.h> |
| @@ -43,13 +42,23 @@ strtok(s, delim) | |||
| 43 | register char *s; | 42 | register char *s; |
| 44 | register const char *delim; | 43 | register const char *delim; |
| 45 | { | 44 | { |
| 45 | static char *last; | ||
| 46 | |||
| 47 | return strtok_r(s, delim, &last); | ||
| 48 | } | ||
| 49 | |||
| 50 | char * | ||
| 51 | strtok_r(s, delim, last) | ||
| 52 | register char *s; | ||
| 53 | register const char *delim; | ||
| 54 | char **last; | ||
| 55 | { | ||
| 46 | register char *spanp; | 56 | register char *spanp; |
| 47 | register int c, sc; | 57 | register int c, sc; |
| 48 | char *tok; | 58 | char *tok; |
| 49 | static char *last; | ||
| 50 | 59 | ||
| 51 | 60 | ||
| 52 | if (s == NULL && (s = last) == NULL) | 61 | if (s == NULL && (s = *last) == NULL) |
| 53 | return (NULL); | 62 | return (NULL); |
| 54 | 63 | ||
| 55 | /* | 64 | /* |
| @@ -63,7 +72,7 @@ cont: | |||
| 63 | } | 72 | } |
| 64 | 73 | ||
| 65 | if (c == 0) { /* no non-delimiter characters */ | 74 | if (c == 0) { /* no non-delimiter characters */ |
| 66 | last = NULL; | 75 | *last = NULL; |
| 67 | return (NULL); | 76 | return (NULL); |
| 68 | } | 77 | } |
| 69 | tok = s - 1; | 78 | tok = s - 1; |
| @@ -81,7 +90,7 @@ cont: | |||
| 81 | s = NULL; | 90 | s = NULL; |
| 82 | else | 91 | else |
| 83 | s[-1] = 0; | 92 | s[-1] = 0; |
| 84 | last = s; | 93 | *last = s; |
| 85 | return (tok); | 94 | return (tok); |
| 86 | } | 95 | } |
| 87 | } while (sc != 0); | 96 | } while (sc != 0); |
diff --git a/src/lib/libc/string/strxfrm.3 b/src/lib/libc/string/strxfrm.3 index 84fd945472..1e5338993a 100644 --- a/src/lib/libc/string/strxfrm.3 +++ b/src/lib/libc/string/strxfrm.3 | |||
| @@ -33,8 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strxfrm.3 5.4 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: strxfrm.3,v 1.3 2000/04/21 15:24:20 aaron Exp $ |
| 37 | .\" $Id: strxfrm.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
| 40 | .Dt STRXFRM 3 | 39 | .Dt STRXFRM 3 |
| @@ -49,8 +48,7 @@ | |||
| 49 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 50 | The | 49 | The |
| 51 | .Fn strxfrm | 50 | .Fn strxfrm |
| 52 | function | 51 | function does something horrible (see |
| 53 | does something horrible (see | ||
| 54 | .Tn ANSI | 52 | .Tn ANSI |
| 55 | standard). | 53 | standard). |
| 56 | In this implementation it just copies. | 54 | In this implementation it just copies. |
| @@ -64,6 +62,5 @@ In this implementation it just copies. | |||
| 64 | .Sh STANDARDS | 62 | .Sh STANDARDS |
| 65 | The | 63 | The |
| 66 | .Fn strxfrm | 64 | .Fn strxfrm |
| 67 | function | 65 | function conforms to |
| 68 | conforms to | ||
| 69 | .St -ansiC . | 66 | .St -ansiC . |
diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c index d9df77b957..6b258edecc 100644 --- a/src/lib/libc/string/strxfrm.c +++ b/src/lib/libc/string/strxfrm.c | |||
| @@ -35,8 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)strxfrm.c 5.2 (Berkeley) 1/26/91";*/ | 38 | static char *rcsid = "$OpenBSD: strxfrm.c,v 1.2 1996/08/19 08:34:29 tholo 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <string.h> |
diff --git a/src/lib/libc/string/swab.3 b/src/lib/libc/string/swab.3 index 133c487bbd..628eb6b15f 100644 --- a/src/lib/libc/string/swab.3 +++ b/src/lib/libc/string/swab.3 | |||
| @@ -29,8 +29,7 @@ | |||
| 29 | .\" 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 |
| 30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 31 | .\" | 31 | .\" |
| 32 | .\" from: @(#)swab.3 6.6 (Berkeley) 5/1/91 | 32 | .\" $OpenBSD: swab.3,v 1.4 2000/01/03 22:52:59 aaron Exp $ |
| 33 | .\" $Id: swab.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 34 | .\" | 33 | .\" |
| 35 | .Dd May 1, 1991 | 34 | .Dd May 1, 1991 |
| 36 | .Dt SWAB 3 | 35 | .Dt SWAB 3 |
| @@ -39,7 +38,7 @@ | |||
| 39 | .Nm swab | 38 | .Nm swab |
| 40 | .Nd swap adjacent bytes | 39 | .Nd swap adjacent bytes |
| 41 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 42 | .Fd #include <string.h> | 41 | .Fd #include <unistd.h> |
| 43 | .Ft void | 42 | .Ft void |
| 44 | .Fn swab "const void *src" "void *dst" "size_t len" | 43 | .Fn swab "const void *src" "void *dst" "size_t len" |
| 45 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| @@ -55,7 +54,7 @@ swapping adjacent bytes. | |||
| 55 | .Pp | 54 | .Pp |
| 56 | The argument | 55 | The argument |
| 57 | .Fa len | 56 | .Fa len |
| 58 | must be even number. | 57 | must be an even number. |
| 59 | .Sh SEE ALSO | 58 | .Sh SEE ALSO |
| 60 | .Xr bzero 3 , | 59 | .Xr bzero 3 , |
| 61 | .Xr memset 3 | 60 | .Xr memset 3 |
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c index f33fc53bd6..311cf13a53 100644 --- a/src/lib/libc/string/swab.c +++ b/src/lib/libc/string/swab.c | |||
| @@ -35,11 +35,10 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | /*static char *sccsid = "from: @(#)swab.c 5.10 (Berkeley) 3/6/91";*/ | 38 | static char *rcsid = "$OpenBSD: swab.c,v 1.3 1998/02/10 02:19:48 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 */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 41 | 40 | ||
| 42 | #include <string.h> | 41 | #include <unistd.h> |
| 43 | 42 | ||
| 44 | void | 43 | void |
| 45 | swab(from, to, len) | 44 | swab(from, to, len) |
