summaryrefslogtreecommitdiff
path: root/src/lib/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string')
-rw-r--r--src/lib/libc/string/Makefile.inc63
-rw-r--r--src/lib/libc/string/__strerror.c40
-rw-r--r--src/lib/libc/string/__strsignal.c30
-rw-r--r--src/lib/libc/string/bcmp.310
-rw-r--r--src/lib/libc/string/bcmp.c8
-rw-r--r--src/lib/libc/string/bcopy.310
-rw-r--r--src/lib/libc/string/bcopy.c3
-rw-r--r--src/lib/libc/string/bm.3109
-rw-r--r--src/lib/libc/string/bm.c7
-rw-r--r--src/lib/libc/string/bstring.320
-rw-r--r--src/lib/libc/string/bzero.311
-rw-r--r--src/lib/libc/string/bzero.c7
-rw-r--r--src/lib/libc/string/ffs.39
-rw-r--r--src/lib/libc/string/ffs.c70
-rw-r--r--src/lib/libc/string/index.383
-rw-r--r--src/lib/libc/string/index.c8
-rw-r--r--src/lib/libc/string/memccpy.325
-rw-r--r--src/lib/libc/string/memccpy.c13
-rw-r--r--src/lib/libc/string/memchr.320
-rw-r--r--src/lib/libc/string/memchr.c11
-rw-r--r--src/lib/libc/string/memcmp.316
-rw-r--r--src/lib/libc/string/memcmp.c3
-rw-r--r--src/lib/libc/string/memcpy.312
-rw-r--r--src/lib/libc/string/memmove.39
-rw-r--r--src/lib/libc/string/memset.318
-rw-r--r--src/lib/libc/string/memset.c3
-rw-r--r--src/lib/libc/string/rindex.381
-rw-r--r--src/lib/libc/string/rindex.c8
-rw-r--r--src/lib/libc/string/strcasecmp.322
-rw-r--r--src/lib/libc/string/strcasecmp.c17
-rw-r--r--src/lib/libc/string/strcat.369
-rw-r--r--src/lib/libc/string/strcat.c9
-rw-r--r--src/lib/libc/string/strchr.352
-rw-r--r--src/lib/libc/string/strcmp.315
-rw-r--r--src/lib/libc/string/strcmp.c7
-rw-r--r--src/lib/libc/string/strcoll.39
-rw-r--r--src/lib/libc/string/strcoll.c3
-rw-r--r--src/lib/libc/string/strcpy.374
-rw-r--r--src/lib/libc/string/strcpy.c9
-rw-r--r--src/lib/libc/string/strcspn.331
-rw-r--r--src/lib/libc/string/strcspn.c3
-rw-r--r--src/lib/libc/string/strdup.354
-rw-r--r--src/lib/libc/string/strdup.c26
-rw-r--r--src/lib/libc/string/strerror.311
-rw-r--r--src/lib/libc/string/strerror.c5
-rw-r--r--src/lib/libc/string/strftime.3202
-rw-r--r--src/lib/libc/string/strftime.c317
-rw-r--r--src/lib/libc/string/string.337
-rw-r--r--src/lib/libc/string/strlcat.c73
-rw-r--r--src/lib/libc/string/strlcpy.3190
-rw-r--r--src/lib/libc/string/strlcpy.c69
-rw-r--r--src/lib/libc/string/strlen.318
-rw-r--r--src/lib/libc/string/strlen.c20
-rw-r--r--src/lib/libc/string/strmode.370
-rw-r--r--src/lib/libc/string/strmode.c8
-rw-r--r--src/lib/libc/string/strncat.c3
-rw-r--r--src/lib/libc/string/strncmp.c7
-rw-r--r--src/lib/libc/string/strncpy.c3
-rw-r--r--src/lib/libc/string/strpbrk.316
-rw-r--r--src/lib/libc/string/strpbrk.c3
-rw-r--r--src/lib/libc/string/strrchr.353
-rw-r--r--src/lib/libc/string/strsep.384
-rw-r--r--src/lib/libc/string/strsep.c22
-rw-r--r--src/lib/libc/string/strsignal.35
-rw-r--r--src/lib/libc/string/strsignal.c5
-rw-r--r--src/lib/libc/string/strspn.330
-rw-r--r--src/lib/libc/string/strspn.c3
-rw-r--r--src/lib/libc/string/strstr.314
-rw-r--r--src/lib/libc/string/strstr.c3
-rw-r--r--src/lib/libc/string/strtok.384
-rw-r--r--src/lib/libc/string/strtok.c21
-rw-r--r--src/lib/libc/string/strxfrm.39
-rw-r--r--src/lib/libc/string/strxfrm.c3
-rw-r--r--src/lib/libc/string/swab.37
-rw-r--r--src/lib/libc/string/swab.c5
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
7SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ 6SRCS+= 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
29memmove.go: bcopy.c
30 ${CC} -g -DMEMMOVE ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
31 @${LD} -x -r ${.TARGET}
32 @mv a.out ${.TARGET}
33
30memmove.po: bcopy.c 34memmove.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
55memcpy.go: bcopy.c
56 ${CC} -g -DMEMCOPY ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
57 @${LD} -x -r ${.TARGET}
58 @mv a.out ${.TARGET}
59
51memcpy.po: bcopy.c 60memcpy.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
79strchr.go: index.c
80 ${CC} -g -DSTRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
81 @${LD} -x -r ${.TARGET}
82 @mv a.out ${.TARGET}
83
70strchr.po: index.c 84strchr.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
102strrchr.go: rindex.c
103 ${CC} -g -DSTRRCHR ${CFLAGS} ${CPPFLAGS} -c ${.ALLSRC} -o ${.TARGET}
104 @${LD} -x -r ${.TARGET}
105 @mv a.out ${.TARGET}
106
88strrchr.po: rindex.c 107strrchr.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
98MAN+= 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 \ 119LOBJS+= memmove.ln memcpy.ln strchr.ln strrchr.ln
120
121memmove.ln: bcopy.c
122 lint ${LINTFLAGS} -DMEMMOVE ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
123 ${LIBCSRCDIR}/string/bcopy.c
124
125memcpy.ln: bcopy.c
126 lint ${LINTFLAGS} -DMEMCOPY ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
127 ${LIBCSRCDIR}/string/bcopy.c
128
129strchr.ln: index.c
130 lint ${LINTFLAGS} -DSTRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
131 ${LIBCSRCDIR}/string/index.c
132
133strrchr.ln: rindex.c
134 lint ${LINTFLAGS} -DSTRRCHR ${CFLAGS:M-[IDU]*} -i -o ${.TARGET} \
135 ${LIBCSRCDIR}/string/rindex.c
136
137MAN+= 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
104MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 143MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3
144MLINKS+=strchr.3 index.3
145MLINKS+=strrchr.3 rindex.3
105MLINKS+=strcasecmp.3 strncasecmp.3 146MLINKS+=strcasecmp.3 strncasecmp.3
106MLINKS+=strcat.3 strncat.3 147MLINKS+=strcat.3 strncat.3
107MLINKS+=strcmp.3 strncmp.3 148MLINKS+=strcmp.3 strncmp.3
108MLINKS+=strcpy.3 strncpy.3 149MLINKS+=strcpy.3 strncpy.3
150MLINKS+=strlcpy.3 strlcat.3
151MLINKS+=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";*/ 35static char *rcsid = "$OpenBSD: __strerror.c,v 1.8 2001/12/08 20:37:32 deraadt Exp $";
36static 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
53static char *
54itoa(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";*/ 35static char *rcsid = "$OpenBSD: __strsignal.c,v 1.6 2001/06/27 00:58:56 lebel Exp $";
36static 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
52static 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
52char * 67char *
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
48The 47The
49.Fn bcmp 48.Fn bcmp
50function 49function compares byte string
51compares byte string
52.Fa b1 50.Fa b1
53against byte string 51against byte string
54.Fa b2 , 52.Fa b2 ,
@@ -68,5 +66,5 @@ The strings may overlap.
68.Sh HISTORY 66.Sh HISTORY
69A 67A
70.Fn bcmp 68.Fn bcmp
71function first appeared in 69function 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";*/ 35static char *rcsid = "$OpenBSD: bcmp.c,v 1.4 1996/08/19 08:33:57 tholo Exp $";
36static 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 */
47int
44bcmp(b1, b2, length) 48bcmp(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
49The 48The
50.Fn bcopy 49.Fn bcopy
51function 50function copies
52copies
53.Fa len 51.Fa len
54bytes from string 52bytes from string
55.Fa src 53.Fa src
@@ -68,5 +66,5 @@ is zero, no bytes are copied.
68.Sh HISTORY 66.Sh HISTORY
69A 67A
70.Fn bcopy 68.Fn bcopy
71function appeared in 69function 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";*/ 38static char *rcsid = "$OpenBSD: bcopy.c,v 1.2 1996/08/19 08:33:58 tholo Exp $";
39static 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
40bm_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
47bm_pat * 46.Fd #include <sys/types.h>
48.br 47.Fd #include <bm.h>
49bm_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]"
51u_char * 50.Ft u_char *
52.br 51.Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len"
53bm_exec(bm_pat *pdesc, u_char *text, size_t len); 52.Ft void
54.sp 53.Fn bm_free "bm_pat *pdesc"
55void 54.Sh DESCRIPTION
56.br
57bm_free(bm_pat *pdesc);
58.SH DESCRIPTION
59These routines implement an efficient mechanism to find an 55These routines implement an efficient mechanism to find an
60occurrence of a byte string within another byte string. 56occurrence of a byte string within another byte string.
61.PP 57.Pp
62.I Bm_comp 58.Fn bm_comp
63evaluates the 59evaluates
64.I patlen 60.Fa patlen
65bytes starting at 61bytes starting at
66.IR pattern , 62.Fa pattern
67and returns a pointer to a structure describing them. 63and returns a pointer to a structure describing them.
68The bytes referenced by 64The bytes referenced by
69.I pattern 65.Fa pattern
70may be of any value. 66may be of any value.
71.PP 67.Pp
72The search takes advantage of the frequency distribution of the 68The search takes advantage of the frequency distribution of the
73bytes in the text to be searched. 69bytes in the text to be searched.
74If specified, 70If specified,
75.I freq 71.Ar freq
76should be an array of 256 values, 72should be an array of 256 values,
77with higher values indicating that the corresponding character occurs 73with higher values indicating that the corresponding character occurs
78more frequently. 74more 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
80than optimal performance, not incorrect results.) 76than optimal performance, not incorrect results.)
81If 77If
82.I freq 78.Ar freq
83is NULL, 79is
80.Dv NULL ,
84a system default table is used. 81a system default table is used.
85.PP 82.Pp
86.I Bm_exec 83.Fn bm_exec
87returns a pointer to the leftmost occurrence of the string given to 84returns a pointer to the leftmost occurrence of the string given to
88.I bm_comp 85.Fn bm_comp
89within 86within
90.IR text , 87.Ar text ,
91or NULL if none occurs. 88or
89.Dv NULL
90if none occurs.
92The number of bytes in 91The number of bytes in
93.I text 92.Ar text
94must be specified by 93must be specified by
95.IR len . 94.Ar len .
96.PP 95.Pp
97Space allocated for the returned description is discarded 96Space allocated for the returned description is discarded
98by calling 97by calling
99.I bm_free 98.Fn bm_free
100with the returned description as an argument. 99with the returned description as an argument.
101.PP 100.Pp
102The asymptotic speed of 101The asymptotic speed of
103.I bm_exec 102.Fn bm_exec
104is 103is
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
112Hume and Sunday, 111.%A Daniel Sunday
113Software Practice and Experience, 112.%J "Software Practice and Experience"
114Vol. 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"; */ 38static char *rcsid = "$OpenBSD: bm.c,v 1.3 1996/08/19 08:33:59 tholo Exp $";
39static 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
97conform to 96conform to
98.St -ansiC . 97.St -ansiC .
99.Sh HISTORY 98.Sh HISTORY
100The functions 99The
101.Fn bzero 100.Fn bzero
102and 101and
103.Fn memccpy 102.Fn memccpy
104appeared in 103functions appeared in
105.Bx 4.3 ; 104.Bx 4.3 .
106the functions 105The
107.Fn bcmp , 106.Fn bcmp
108.Fn bcopy , 107and
109appeared in 108.Fn bcopy
109functions 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
48The 47The
49.Fn bzero 48.Fn bzero
50function 49function writes
51writes
52.Fa len 50.Fa len
53zero bytes to the string 51zero bytes to the string
54.Fa b . 52.Fa b .
@@ -63,6 +61,5 @@ does nothing.
63.Sh HISTORY 61.Sh HISTORY
64A 62A
65.Fn bzero 63.Fn bzero
66function 64function appeared in
67appeared 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";*/ 35static char *rcsid = "$OpenBSD: bzero.c,v 1.3 1996/08/19 08:34:00 tholo Exp $";
36static 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
48The 47The
49.Fn ffs 48.Fn ffs
50function 49function finds the first bit set in
51finds the first bit set in
52.Fa value 50.Fa value
53and returns the index of that bit. 51and returns the index of that bit.
54Bits are numbered starting from 1, starting at the right-most 52Bits are numbered starting from 1, starting at the rightmost bit.
55bit.
56A return value of 0 means that the argument was zero. 53A 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";*/ 9static char *rcsid = "$OpenBSD: ffs.c,v 1.5 2000/07/02 03:10:38 mickey Exp $";
36static 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
48The
49.Fn index
50function
51locates the first character matching
52.Fa c
53(converted to a
54.Em char )
55in the null-terminated string
56.Fa s .
57.Sh RETURN VALUES
58The character
59.Fa c
60is returned if it is found; otherwise
61.Dv NULL
62is returned.
63If
64.Fa c
65is '\e0',
66.Fn index
67locates 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
80A
81.Fn index
82function 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";*/ 35static char *rcsid = "$OpenBSD: index.c,v 1.3 2002/07/24 04:16:01 millert Exp $";
36static 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
41char * 40char *
42#ifdef STRCHR 41#ifdef STRCHR
43strchr(p, ch) 42strchr(const char *p, int ch)
44#else 43#else
45index(p, ch) 44index(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
45The 47The
46.Fn memccpy 48.Fn memccpy
47function 49function copies bytes from string
48copies bytes from string
49.Fa src 50.Fa src
50to string 51to string
51.Fa dst . 52.Fa dst .
52If the character 53If 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 )
57occurs in the string
55.Fa src , 58.Fa src ,
56the copy stops and a pointer to the byte after the copy of 59the 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
60is returned. 63is returned.
61Otherwise, 64Otherwise,
62.Fa len 65.Fa len
63bytes are copied, and a NULL pointer is returned. 66bytes 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
70The 73The
71.Fn memccpy 74.Fn memccpy
72function is 75function 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
36static char *rcsid = "$Id: memccpy.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; 38static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93";
39#else
40static 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
50The 49The
51.Fn memchr 50.Fn memchr
52function 51function locates the first occurrence of
53locates the first occurrence of
54.Fa c 52.Fa c
55(converted to an unsigned char) 53(converted to an
54.Li unsigned char )
56in string 55in string
57.Fa b . 56.Fa b .
58.Sh RETURN VALUES 57.Sh RETURN VALUES
59The 58The
60.Fn memchr 59.Fn memchr
61function 60function returns a pointer to the byte located, or
62returns a pointer to the byte located, 61.Dv NULL
63or NULL if no such byte exists within 62if no such byte exists within
64.Fa len 63.Fa len
65bytes. 64bytes.
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
78The 75The
79.Fn memchr 76.Fn memchr
80function 77function conforms to
81conforms 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";*/ 38static char *rcsid = "$OpenBSD: memchr.c,v 1.4 2001/09/07 08:09:31 espie Exp $";
39static 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 $"
44void * 43void *
45memchr(s, c, n) 44memchr(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
50The 49The
51.Fn memcmp 50.Fn memcmp
52function 51function compares byte string
53compares byte string
54.Fa b1 52.Fa b1
55against byte string 53against byte string
56.Fa b2 . 54.Fa b2 .
@@ -60,10 +58,11 @@ bytes long.
60.Sh RETURN VALUES 58.Sh RETURN VALUES
61The 59The
62.Fn memcmp 60.Fn memcmp
63function 61function returns zero if the two strings are identical,
64returns zero if the the two strings are identical,
65otherwise returns the difference between the first two differing bytes 62otherwise returns the difference between the first two differing bytes
66(treated as unsigned char values, so that 63(treated as
64.Li unsigned char
65values, so that
67.Sq Li \e200 66.Sq Li \e200
68is greater than 67is 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
79The 78The
80.Fn memcmp 79.Fn memcmp
81function 80function conforms to
82conforms 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";*/ 38static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo Exp $";
39static 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
50The 49The
51.Fn memcpy 50.Fn memcpy
52function 51function copies
53copies
54.Fa len 52.Fa len
55bytes from string 53bytes from string
56.Fa src 54.Fa src
@@ -59,8 +57,7 @@ to string
59.Sh RETURN VALUES 57.Sh RETURN VALUES
60The 58The
61.Fn memcpy 59.Fn memcpy
62function 60function returns the original value of
63returns 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
71The 68The
72.Fn memcpy 69.Fn memcpy
73function 70function conforms to
74conforms to
75.St -ansiC . 71.St -ansiC .
76.Sh BUGS 72.Sh BUGS
77In this implementation 73In 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
50The 49The
51.Fn memmove 50.Fn memmove
52function 51function copies
53copies
54.Fa len 52.Fa len
55bytes from string 53bytes from string
56.Fa src 54.Fa src
@@ -71,6 +69,5 @@ function returns the original value of
71.Sh STANDARDS 69.Sh STANDARDS
72The 70The
73.Fn memmove 71.Fn memmove
74function 72function conforms to
75conforms 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
50The 49The
51.Fn memset 50.Fn memset
52function 51function writes
53writes
54.Fa len 52.Fa len
55bytes of value 53bytes 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 )
57to the string
58.Fa b .
59.Sh RETURN VALUES
60The
61.Fn memset
62function 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
63The 68The
64.Fn memset 69.Fn memset
65function 70function conforms to
66conforms 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";*/ 38static char *rcsid = "$OpenBSD: memset.c,v 1.2 1996/08/19 08:34:07 tholo Exp $";
39static 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
48The
49.Fn rindex
50function
51locates the last character
52matching
53.Fa c
54(converted to a
55.Em char )
56in the null-terminated string
57.Fa s .
58The character c is returned if it is found; otherwise NULL is returned.
59If
60.Fa c
61is
62.Ql \e0 ,
63.Fn rindex
64locates 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
78A
79.Fn rindex
80function 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";*/ 35static char *rcsid = "$OpenBSD: rindex.c,v 1.3 2002/07/24 04:16:01 millert Exp $";
36static 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
41char * 40char *
42#ifdef STRRCHR 41#ifdef STRRCHR
43strrchr(p, ch) 42strrchr(const char *p, int ch)
44#else 43#else
45rindex(p, ch) 44rindex(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
52and 54and
53.Fn strncasecmp 55.Fn strncasecmp
54functions 56functions compare the null-terminated strings
55compare the null-terminated strings
56.Fa s1 57.Fa s1
57and 58and
58.Fa s2 59.Fa s2
@@ -68,7 +69,6 @@ The comparison is done using unsigned characters, so that
68is greater than 69is greater than
69.Ql \e0 . 70.Ql \e0 .
70.Pp 71.Pp
71The
72.Fn strncasecmp 72.Fn strncasecmp
73compares at most 73compares at most
74.Fa len 74.Fa len
@@ -84,5 +84,5 @@ The
84.Fn strcasecmp 84.Fn strcasecmp
85and 85and
86.Fn strncasecmp 86.Fn strncasecmp
87functions are 87functions 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
36static char *rcsid = "$Id: strcasecmp.c,v 1.1.1.1 1995/10/18 08:42:21 deraadt Exp $"; 40static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93";
41#else
42static 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
41typedef unsigned char u_char; 46typedef 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
54and 54and
55.Fn strncat 55.Fn strncat
56functions 56functions append a copy of the null-terminated string
57append a copy of the null-terminated string
58.Fa append 57.Fa append
59to the end of the null-terminated string 58to 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
67The 66The
68.Fn strncat 67.Fn strncat
69function 68function appends not more than
70appends not more than
71.Fa count 69.Fa count
72characters. 70characters where space for the terminating
71.Ql \e0
72should not be included in
73.Fa count .
73.Sh RETURN VALUES 74.Sh RETURN VALUES
74The 75The
75.Fn strcat 76.Fn strcat
76and 77and
77.Fn strncat 78.Fn strncat
78functions 79functions return the pointer
79return the pointer
80.Fa s . 80.Fa s .
81.Sh EXAMPLES
82The following appends
83.Dq Li abc
84to
85.Dq Li chararray :
86.Bd -literal -offset indent
87char *letters = "abcdefghi";
88
89(void)strncat(chararray, letters, 3);
90.Ed
91.Pp
92The following example shows how to use
93.Fn strncat
94safely in conjunction with
95.Xr strncpy 3 .
96.Bd -literal -offset indent
97char buf[BUFSIZ];
98char *input, *suffix;
99
100(void)strncpy(buf, input, sizeof(buf) - 1);
101buf[sizeof(buf) - 1] = '\e0';
102(void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf));
103.Ed
104.Pp
105The above will copy as many characters from
106.Dq Li input
107to
108.Dq Li buf
109as will fit.
110It then appends as many characters from suffix as will fit (or none
111if there is no space).
112For operations like this, the
113.Xr strlcpy 3
114and
115.Xr strlcat 3
116functions 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
88The 130The
89.Fn strcat 131.Fn strcat
90and 132and
91.Fn strncat 133.Fn strncat
92functions 134functions conform to
93conform 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";*/ 35static char *rcsid = "$OpenBSD: strcat.c,v 1.4 1996/08/19 08:34:10 tholo Exp $";
36static 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
41char * 44char *
42strcat(s, append) 45strcat(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
50The 52The
51.Fn strchr 53.Fn strchr
52function locates the first occurrence of 54function locates the first occurrence of the character
53.Ar c 55.Fa c
54in the string pointed to by 56in the string
55.Ar s . 57.Fa s .
56The terminating 58The terminating NUL character is considered part of the string.
57.Dv NULL
58character is considered part of the string.
59If 59If
60.Fa c 60.Fa c
61is 61is
@@ -63,16 +63,31 @@ is
63.Fn strchr 63.Fn strchr
64locates the terminating 64locates the terminating
65.Ql \e0 . 65.Ql \e0 .
66.Pp
67The
68.Fn index
69function is an old synonym for
70.Fn strchr .
66.Sh RETURN VALUES 71.Sh RETURN VALUES
67The function 72The
68.Fn strchr 73.Fn strchr
69returns a pointer to the located character, or 74function returns a pointer to the located character or
70.Dv NULL 75.Dv NULL
71if the character does not appear in the string. 76if the character does not appear in the string.
77.Sh EXAMPLES
78After the following call to
79.Fn strchr ,
80.Va p
81will point to the string
82.Qq oobar :
83.Bd -literal -offset indent
84char *p;
85char *s = "foobar";
86
87p = 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
84The 99The
85.Fn strchr 100.Fn strchr
86function 101function conforms to
87conforms to
88.St -ansiC . 102.St -ansiC .
103.Pp
104The
105.Fn index
106function 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
54and 54and
55.Fn strncmp 55.Fn strncmp
56functions 56functions lexicographically compare the null-terminated strings
57lexicographically compare the null-terminated strings
58.Fa s1 57.Fa s1
59and 58and
60.Fa s2 . 59.Fa s2 .
@@ -73,9 +72,8 @@ The comparison is done using unsigned characters, so that
73is greater than 72is greater than
74.Ql \e0 . 73.Ql \e0 .
75.Pp 74.Pp
76The
77.Fn strncmp 75.Fn strncmp
78compares not more than 76compares at most
79.Fa len 77.Fa len
80characters. 78characters.
81.Sh SEE ALSO 79.Sh SEE ALSO
@@ -89,6 +87,5 @@ The
89.Fn strcmp 87.Fn strcmp
90and 88and
91.Fn strncmp 89.Fn strncmp
92functions 90functions conform to
93conform 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";*/ 38static char *rcsid = "$OpenBSD: strcmp.c,v 1.3 1996/08/19 08:34:12 tholo Exp $";
39static 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
50The 49The
51.Fn strcoll 50.Fn strcoll
52function 51function lexicographically compares the null-terminated strings
53lexicographically compares the null-terminated strings
54.Fa s1 52.Fa s1
55and 53and
56.Fa s2 54.Fa s2
@@ -70,6 +68,5 @@ is greater than, equal to, or less than
70.Sh STANDARDS 68.Sh STANDARDS
71The 69The
72.Fn strcoll 70.Fn strcoll
73function 71function conforms to
74conforms 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";*/ 38static char *rcsid = "$OpenBSD: strcoll.c,v 1.2 1996/08/19 08:34:13 tholo Exp $";
39static 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
54and 54and
55.Fn strncpy 55.Fn strncpy
56functions 56functions copy the string
57copy the string
58.Fa src 57.Fa src
59to 58to
60.Fa dst 59.Fa dst
@@ -62,7 +61,6 @@ to
62.Ql \e0 61.Ql \e0
63character). 62character).
64.Pp 63.Pp
65The
66.Fn strncpy 64.Fn strncpy
67copies not more than 65copies not more than
68.Fa len 66.Fa len
@@ -78,45 +76,79 @@ characters long, and
78.Em not 76.Em not
79terminating 77terminating
80.Fa dst 78.Fa dst
81if 79if the length of
82.Fa src 80.Fa src
83is more than 81is greater than or equal to
84.Fa len 82.Fa len .
85characters long.
86.Sh RETURN VALUES 83.Sh RETURN VALUES
87The 84The
88.Fn strcpy 85.Fn strcpy
89and 86and
90.Fn strncpy 87.Fn strncpy
91functions 88functions return
92return
93.Fa dst . 89.Fa dst .
94.Sh EXAMPLES 90.Sh EXAMPLES
95The following sets 91The following sets
96.Dq Li chararray 92.Va chararray
97to 93to
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
103The following sets 99The following sets
104.Dq Li chararray 100.Va chararray
105to 101to
106.Dq Li abcdef : 102.Dq abcdef
103and does
104.Em not
105null terminate
106.Va chararray
107because the source string is >= the length parameter.
108.Fn strncpy
109.Em only
110null terminates the destination string when the length of the source
111string 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
116The following copies as many characters from
117.Va input
118to
119.Va buf
120as will fit and null terminates the result.
121Because
122.Fn strncpy
123does
124.Em not
125guarantee to null terminate the string itself, we must do this by hand.
126.Bd -literal -offset indent
127char buf[BUFSIZ];
128
129(void)strncpy(buf, input, sizeof(buf) - 1);
130buf[sizeof(buf) - 1] = '\e0';
131.Ed
132.Pp
133Note that
134.Xr strlcpy 3
135is a better choice for this kind of operation.
136The equivalent using
137.Xr strlcpy 3
138is 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
116The 149The
117.Fn strcpy 150.Fn strcpy
118and 151and
119.Fn strncpy 152.Fn strncpy
120functions 153functions conform to
121conform 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";*/ 35static char *rcsid = "$OpenBSD: strcpy.c,v 1.4 1996/08/19 08:34:14 tholo Exp $";
36static 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
41char * 44char *
42strcpy(to, from) 45strcpy(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
50The 49The
51.Fn strcspn 50.Fn strcspn
52function 51function spans the initial part of the null-terminated string
53spans the initial part of the null-terminated string
54.Fa s 52.Fa s
55as long as the characters from 53as long as the characters from
56.Fa s 54.Fa s
57do not occur in string 55do not occur in string
58.Fa charset 56.Fa charset
59(it 57(it spans the
60spans the
61.Em complement 58.Em complement
62of 59of
63.Fa charset ) . 60.Fa charset ) .
64.Sh RETURN VALUES 61.Sh RETURN VALUES
65The 62The
66.Fn strcspn 63.Fn strcspn
67function 64function returns the number of characters spanned.
68returns the number of characters spanned. 65.Sh EXAMPLES
66The following call to
67.Fn strcspn
68will return 3, since the first three characters of string
69.Fa s
70do not occur in string
71.Fa charset :
72.Bd -literal -offset indent
73char *s = "foobar";
74char *charset = "bar";
75size_t span;
76
77span = 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
81The 89The
82.Fn strcspn 90.Fn strcspn
83function 91function conforms to
84conforms 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";*/ 38static char *rcsid = "$OpenBSD: strcspn.c,v 1.2 1996/08/19 08:34:15 tholo Exp $";
39static 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
46The 47The
47.Fn strdup 48.Fn strdup
48function 49function allocates sufficient memory for a copy of the string
49allocates sufficient memory for a copy 50.Fa s ,
50of the string
51.Fa str ,
52does the copy, and returns a pointer to it. 51does the copy, and returns a pointer to it.
53The pointer may subsequently be used as an 52The pointer may subsequently be used as an argument to the function
54argument to the function
55.Xr free 3 . 53.Xr free 3 .
54.Pp
55If insufficient memory is available,
56.Dv NULL
57is returned.
58.Sh EXAMPLES
59The following will point
60.Va p
61to an allocated area of memory containing the null-terminated string
62.Qq foobar :
63.Bd -literal -offset indent
64char *p;
65
66if ((p = strdup("foobar")) == NULL) {
67 fprintf(stderr, "Out of memory.\en");
68 exit(1);
69}
70.Ed
71.Sh ERRORS
72The
73.Fn strdup
74function may fail and set the external variable
75.Va errno
76for 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
62The 84The
63.Fn strdup 85.Fn strdup
64function 86function 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
36static char *rcsid = "$Id: strdup.c,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $"; 38static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
39#else
40static 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 *
43strdup(str) 51strdup(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 @@
50The 49The
51.Fn strerror 50.Fn strerror
52function returns a pointer to the language-dependent error message 51function returns a pointer to the language-dependent error message
53string affiliated with an error number. 52string affiliated with the specified error number
53.Fa errnum .
54The returned string contains a maximum of
55.Dv NL_TEXTMAX
56characters, including the trailing NUL.
54.Pp 57.Pp
55The array pointed to is not to be modified by the program, but may be 58The array pointed to is not to be modified by the program, but may be
56overwritten by subsequent calls to 59overwritten 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";*/ 35static char *rcsid = "$OpenBSD: strerror.c,v 1.3 2002/02/16 21:27:24 millert Exp $";
36static 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
48extern char *__strerror __P((int, char *)); 47extern char *__strerror(int, char *);
49 48
50char * 49char *
51strerror(num) 50strerror(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
50The
51.Fn strftime
52function formats the information from
53.Fa timeptr
54into the buffer
55.Fa buf
56according to the string pointed to by
57.Fa format .
58.Pp
59The
60.Fa format
61string consists of zero or more conversion specifications and
62ordinary characters.
63All ordinary characters are copied directly into the buffer.
64A conversion specification consists of a percent sign
65.Ql %
66and one other character.
67.Pp
68No more than
69.Fa maxsize
70characters will be placed into the array.
71If the total number of resulting characters, including the terminating
72null character, is not more than
73.Fa maxsize ,
74.Fn strftime
75returns the number of characters in the array, not counting the
76terminating null.
77Otherwise, zero is returned.
78.Pp
79Each conversion specification is replaced by the characters as
80follows which are then copied into the buffer.
81.Bl -tag -width "xxxx"
82.It Cm \&%A
83is replaced by the locale's full weekday name.
84.It Cm %a
85is replaced by the locale's abbreviated weekday name.
86.It Cm \&%B
87is replaced by the locale's full month name.
88.It Cm \&%b No or Cm \&%h
89is replaced by the locale's abbreviated month name.
90.It Cm \&%C
91is replaced by the century (a year divided by 100 and truncated to an integer)
92as a decimal number (00-99).
93.It Cm \&%c
94is replaced by the locale's appropriate date and time representation.
95.It Cm \&%D
96is replaced by the date in the format
97.Dq Li %m/%d/%y .
98.It Cm \&%d
99is replaced by the day of the month as a decimal number (01-31).
100.It Cm \&%e
101is replaced by the day of month as a decimal number (1-31);
102single digits are preceded by a blank.
103.It Cm \&%H
104is replaced by the hour (24-hour clock) as a decimal number (00-23).
105.It Cm \&%I
106is replaced by the hour (12-hour clock) as a decimal number (01-12).
107.It Cm \&%j
108is replaced by the day of the year as a decimal number (001-366).
109.It Cm \&%k
110is replaced by the hour (24-hour clock) as a decimal number (0-23);
111single digits are preceded by a blank.
112.It Cm \&%l
113is replaced by the hour (12-hour clock) as a decimal number (1-12);
114single digits are preceded by a blank.
115.It Cm \&%M
116is replaced by the minute as a decimal number (00-59).
117.It Cm %m
118is replaced by the month as a decimal number (01-12).
119.It Cm %n
120is replaced by a newline.
121.It Cm %p
122is replaced by the locale's equivalent of either
123.Dq Tn AM
124or
125.Dq Tn PM .
126.It Cm \&%R
127is replaced by the time in the format
128.Dq Li %H:%M .
129.It Cm \&%r
130is replaced by the locale's representation of 12-hour clock time
131using AM/PM notation.
132.It Cm \&%T
133is replaced by the time in the format
134.Dq Li %H:%M:%S .
135.It Cm \&%t
136is replaced by a tab.
137.It Cm \&%S
138is replaced by the second as a decimal number (00-60).
139.It Cm %s
140is replaced by the number of seconds since the Epoch, UCT (see
141.Xr mktime 3 ) .
142.It Cm \&%U
143is replaced by the week number of the year (Sunday as the first day of
144the week) as a decimal number (00-53).
145.It Cm \&%u
146is replaced by the weekday (Monday as the first day of the week)
147as a decimal number (1-7).
148.It Cm \&%V
149is replaced by the week number of the year (Monday as the first day of
150the week) as a decimal number (01-53). If the week containing January
1511 has four or more days in the new year, then it is week 1; otherwise
152it is week 53 of the previous year, and the next week is week 1.
153.It Cm \&%W
154is replaced by the week number of the year (Monday as the first day of
155the week) as a decimal number (00-53).
156.It Cm \&%w
157is replaced by the weekday (Sunday as the first day of the week)
158as a decimal number (0-6).
159.It Cm \&%X
160is replaced by the locale's appropriate date representation.
161.It Cm \&%x
162is replaced by the locale's appropriate time representation.
163.It Cm \&%Y
164is replaced by the year with century as a decimal number.
165.It Cm \&%y
166is replaced by the year without century as a decimal number (00-99).
167.It Cm \&%Z
168is replaced by the time zone name.
169.It Cm %%
170is 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
179The
180.Fn strftime
181function
182conforms to
183.St -ansiC .
184The
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 ,
198and
199.Ql \&%V
200conversion specifications are extensions.
201.Sh BUGS
202There 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";*/
36static 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
45static size_t gsize;
46static char *pt;
47static int _add(), _conv(), _secs();
48static size_t _fmt();
49
50size_t
51strftime(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)
73static 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
275static
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
292static
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
307static
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
105The string functions 110The string functions
106functions manipulate strings terminated by a 111manipulate strings terminated by a
107null byte. 112null byte.
108.Pp 113.Pp
109See the specific manual pages for more information. 114See the specific manual pages for more information.
@@ -115,23 +120,25 @@ Except as noted in their specific manual pages,
115the string functions do not test the destination 120the string functions do not test the destination
116for size limitations. 121for 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
136The 143The
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 ,
152and 158and
153.Fn strtok 159.Fn strtok
154functions 160functions conform to
155conform 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)
31static 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 */
44size_t
45strlcat(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
42The
43.Fn strlcpy
44and
45.Fn strlcat
46functions copy and concatenate strings respectively.
47They are designed
48to be safer, more consistent, and less error prone replacements for
49.Xr strncpy 3
50and
51.Xr strncat 3 .
52Unlike those functions,
53.Fn strlcpy
54and
55.Fn strlcat
56take the full size of the buffer (not just the length) and guarantee to
57NUL-terminate the result (as long as
58.Fa size
59is larger than 0 or, in the case of
60.Fn strlcat ,
61as long as there is at least one byte free in
62.Fa dst ) .
63Note that you should include a byte for the NUL in
64.Fa size .
65Also note that
66.Fn strlcpy
67and
68.Fn strlcat
69only operate on true
70.Dq C
71strings.
72This means that for
73.Fn strlcpy
74.Fa src
75must be NUL-terminated and for
76.Fn strlcat
77both
78.Fa src
79and
80.Fa dst
81must be NUL-terminated.
82.Pp
83The
84.Fn strlcpy
85function copies up to
86.Fa size
87- 1 characters from the NUL-terminated string
88.Fa src
89to
90.Fa dst ,
91NUL-terminating the result.
92.Pp
93The
94.Fn strlcat
95function appends the NUL-terminated string
96.Fa src
97to the end of
98.Fa dst .
99It will append at most
100.Fa size
101- strlen(dst) - 1 bytes, NUL-terminating the result.
102.Sh RETURN VALUES
103The
104.Fn strlcpy
105and
106.Fn strlcat
107functions return the total length of the string they tried to create.
108For
109.Fn strlcpy
110that means the length of
111.Fa src .
112For
113.Fn strlcat
114that means the initial length of
115.Fa dst
116plus
117the length of
118.Fa src .
119While this may seem somewhat confusing it was done to make
120truncation detection simple.
121.Pp
122Note however, that if
123.Fn strlcat
124traverses
125.Fa size
126characters without finding a NUL, the length of the string is considered
127to be
128.Fa size
129and the destination string will not be NUL-terminated (since there was
130no space for the NUL).
131This keeps
132.Fn strlcat
133from running off the end of a string.
134In practice this should not happen (as it means that either
135.Fa size
136is incorrect or that
137.Fa dst
138is not a proper
139.Dq C
140string).
141The check exists to prevent potential security problems in incorrect code.
142.Sh EXAMPLES
143The following code fragment illustrates the simple case:
144.Bd -literal -offset indent
145char *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
153To detect truncation, perhaps while building a pathname, something
154like the following might be used:
155.Bd -literal -offset indent
156char *dir, *file, pname[MAXPATHLEN];
157
158\&...
159
160if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
161 goto toolong;
162if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
163 goto toolong;
164.Ed
165.Pp
166Since we know how many characters we copied the first time, we can
167speed things up a bit by using a copy instead of an append:
168.Bd -literal -offset indent
169char *dir, *file, pname[MAXPATHLEN];
170size_t n;
171
172\&...
173
174n = strlcpy(pname, dir, sizeof(pname));
175if (n >= sizeof(pname))
176 goto toolong;
177if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
178 goto toolong;
179.Ed
180.Pp
181However, one may question the validity of such optimizations, as they
182defeat the whole purpose of
183.Fn strlcpy
184and
185.Fn strlcat .
186As 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)
31static 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 */
42size_t
43strlcpy(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
50The 49The
51.Fn strlen 50.Fn strlen
52function 51function computes the length of the string
53computes the length of the string
54.Fa s . 52.Fa s .
55.Sh RETURN VALUES 53.Sh RETURN VALUES
56The 54The
57.Fn strlen 55.Fn strlen
58function 56function returns the number of characters that precede the terminating
59returns 57.Tn NUL
60the number of characters that precede the
61terminating
62.Dv NUL
63character. 58character.
64.Sh SEE ALSO 59.Sh SEE ALSO
65.Xr string 3 60.Xr string 3
66.Sh STANDARDS 61.Sh STANDARDS
67The 62The
68.Fn strlen 63.Fn strlen
69function 64function conforms to
70conforms 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";*/ 37static char *rcsid = "$OpenBSD: strlen.c,v 1.4 2001/07/29 21:15:23 millert Exp $";
36static 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
41size_t 46size_t
42strlen(str) 47strlen(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
46The 47The
47.Fn strmode 48.Fn strmode
48function 49function converts a file
49converts 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 )
53into a symbolic string which is stored in the location referenced by 53into a symbolic string which is stored in the location referenced by
54.Fa bp . 54.Fa bp .
55This stored string is eleven characters in length plus a trailing 55This stored string is eleven characters in length plus a trailing null byte.
56.Dv NULL .
57.Pp 56.Pp
58The first character is the inode type, and will be one of the following: 57The first character is the inode type, and will be one of the following:
59.Pp 58.Pp
@@ -72,6 +71,8 @@ symbolic link
72fifo 71fifo
73.It s 72.It s
74socket 73socket
74.It w
75whiteout
75.It ? 76.It ?
76unknown inode type 77unknown inode type
77.El 78.El
@@ -80,46 +81,58 @@ The next nine characters encode three sets of permissions, in three
80characters each. 81characters each.
81The first three characters are the permissions for the owner of the 82The first three characters are the permissions for the owner of the
82file, the second three for the group the file belongs to, and the 83file, the second three for the group the file belongs to, and the
83third for the ``other'', or default, set of users. 84third for the
85.Dq other ,
86or default, set of users.
84.Pp 87.Pp
85Permission checking is done as specifically as possible. 88Permission checking is done as specifically as possible.
86If read permission is denied to the owner of a file in the first set 89If read permission is denied to the owner of a file in the first set
87of permissions, the owner of the file will not be able to read the file. 90of permissions, the owner of the file will not be able to read the file.
88This is true even if the owner is in the file's group and the group 91This is true even if the owner is in the file's group and the group
89permissions allow reading or the ``other'' permissions allow reading. 92permissions allow reading or the
93.Dq other
94permissions allow reading.
90.Pp 95.Pp
91If the first character of the three character set is an ``r'', the file is 96If the first character of the three character set is an
92readable for that set of users; if a dash ``\-'', it is not readable. 97.Sq r ,
98the file is readable for that set of users; if a dash
99.Pq Ql - ,
100it is not readable.
93.Pp 101.Pp
94If the second character of the three character set is a ``w'', the file is 102If the second character of the three character set is a
95writable for that set of users; if a dash ``\-'', it is not writable. 103.Sq w ,
104the file is writable for that set of users; if a dash
105.Pq Ql - ,
106it is not writable.
96.Pp 107.Pp
97The third character is the first of the following characters that apply: 108The 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
100If the character is part of the owner permissions and the file is not 111If the character is part of the owner permissions and the file is not
101executable or the directory is not searchable, by the owner, and the 112executable or the directory is not searchable by the owner, and the
102set-user-id bit is set. 113set-user-ID bit is set.
103.It S 114.It S
104If the character is part of the group permissions and the file is not 115If the character is part of the group permissions and the file is not
105executable or the directory is not searchable, by the group, and the 116executable or the directory is not searchable by the group, and the
106set-group-id bit is set. 117set-group-ID bit is set.
107.It T 118.It T
108If the character is part of the other permissions and the file is not 119If the character is part of the other permissions and the file is not
109executable or the directory is not searchable, by others, and the ``sticky'' 120executable or the directory is not searchable by others, and the
121.Dq sticky
110.Pq Dv S_ISVTX 122.Pq Dv S_ISVTX
111bit is set. 123bit is set.
112.It s 124.It s
113If the character is part of the owner permissions and the file is 125If the character is part of the owner permissions and the file is
114executable or the directory searchable, by the owner, and the set-user-id 126executable or the directory searchable by the owner, and the set-user-ID
115bit is set. 127bit is set.
116.It s 128.It s
117If the character is part of the group permissions and the file is 129If the character is part of the group permissions and the file is
118executable or the directory searchable, by the group, and the set-group-id 130executable or the directory searchable by the group, and the set-group-ID
119bit is set. 131bit is set.
120.It t 132.It t
121If the character is part of the other permissions and the file is 133If the character is part of the other permissions and the file is
122executable or the directory searchable, by others, and the ``sticky'' 134executable or the directory searchable by others, and the
135.Dq sticky
123.Pq Dv S_ISVTX 136.Pq Dv S_ISVTX
124bit is set. 137bit is set.
125.It x 138.It x
@@ -128,14 +141,15 @@ The file is executable or the directory is searchable.
128None of the above apply. 141None of the above apply.
129.El 142.El
130.Pp 143.Pp
131The last character is a plus sign ``+'' if any there are any alternate 144The last character is a plus sign
145.Pq Ql +
146if there are any alternate
132or additional access control methods associated with the inode, otherwise 147or additional access control methods associated with the inode, otherwise
133it will be a space. 148it will be a space.
134.Sh RETURN VALUES 149.Sh RETURN VALUES
135The 150The
136.Fn strmode 151.Fn strmode
137function 152function always returns 0.
138always 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
146The 160The
147.Fn strmode 161.Fn strmode
148function 162function 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";*/ 35static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 deraadt Exp $";
36static 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";*/ 38static char *rcsid = "$OpenBSD: strncat.c,v 1.2 1996/08/19 08:34:21 tholo Exp $";
39static 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";*/ 35static char *rcsid = "$OpenBSD: strncmp.c,v 1.3 1996/08/19 08:34:21 tholo Exp $";
36static 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
41int 44int
42strncmp(s1, s2, n) 45strncmp(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";*/ 38static char *rcsid = "$OpenBSD: strncpy.c,v 1.2 1996/08/19 08:34:22 tholo Exp $";
39static 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
50The 49The
51.Fn strpbrk 50.Fn strpbrk
52function 51function locates in the null-terminated string
53locates in the null-terminated string
54.Fa s 52.Fa s
55the first occurrence of any character in the string 53the 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.
58If no characters from 56If no characters from
59.Fa charset 57.Fa charset
60occur anywhere in 58occur anywhere in
61.Fa s 59.Fa s ,
62.Fn strpbrk 60.Fn strpbrk
63returns NULL. 61returns
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
76The 73The
77.Fn strpbrk 74.Fn strpbrk
78function 75function conforms to
79conforms 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";*/ 35static char *rcsid = "$OpenBSD: strpbrk.c,v 1.2 1996/08/19 08:34:23 tholo Exp $";
36static 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
50The 52The
51.Fn strrchr 53.Fn strrchr
52function 54function locates the last occurrence of the character
53locates the last occurrence of
54.Fa c 55.Fa c
55(converted to a char)
56in the string 56in the string
57.Fa s . 57.Fa s .
58The terminating
59.Tn NUL
60character is considered part of the string.
58If 61If
59.Fa c 62.Fa c
60is 63is
@@ -62,20 +65,31 @@ is
62.Fn strrchr 65.Fn strrchr
63locates the terminating 66locates the terminating
64.Ql \e0 . 67.Ql \e0 .
68.Pp
69The
70.Fn rindex
71function is an old synonym for
72.Fn strrchr .
65.Sh RETURN VALUES 73.Sh RETURN VALUES
66The 74The
67.Fn strrchr 75.Fn strrchr
68function 76function returns a pointer to the located character or
69returns a pointer to the character, 77.Dv NULL
70or a null 78if the character does not appear in the string.
71pointer if 79.Sh EXAMPLES
72.Fa c 80After the following call to
73does not occur anywhere in 81.Fn strrchr ,
74.Fa s . 82.Va p
83will point to the string
84.Qq obar :
85.Bd -literal -offset indent
86char *p;
87char *s = "foobar";
88
89p = 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
87The 101The
88.Fn strrchr 102.Fn strrchr
89function 103function conforms to
90conforms to
91.St -ansiC . 104.St -ansiC .
105.Pp
106The
107.Fn rindex
108function 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
48The 50The
49.Fn strsep 51.Fn strsep
50locates in the null-terminated string at 52function locates, in the string referenced by
51.Fa *stringp
52the first occurrence of any character in
53.Fa delim
54and replaces this with a
55.Ql \e0 ,
56records the location of the immediate following character in
57.Fa *stringp , 53.Fa *stringp ,
58then returns the original value of 54the first occurrence of any character in the string
55.Fa delim
56(or the terminating
57.Ql \e0
58character) and replaces it with a
59.Ql \e0 .
60The location of the next character after the delimiter character
61(or
62.Dv NULL ,
63if the end of the string was reached) is stored in
59.Fa *stringp . 64.Fa *stringp .
60If no delimiter characters are found, 65The original value of
61.Fn strsep
62sets
63.Fa *stringp 66.Fa *stringp
67is returned.
68.Pp
69An
70.Dq empty
71field, i.e., one caused by two adjacent delimiter characters,
72can be detected by comparing the location referenced by the pointer returned
73by
74.Fn strsep
64to 75to
65.Dv NULL ; 76.Ql \e0 .
66if 77.Pp
78If
67.Fa *stringp 79.Fa *stringp
68is initially 80is initially
69.Dv NULL , 81.Dv NULL ,
@@ -73,20 +85,32 @@ returns
73.Sh EXAMPLES 85.Sh EXAMPLES
74The following uses 86The following uses
75.Fn strsep 87.Fn strsep
76to parse strings containing runs of white space, 88to parse a string, containing tokens delimited by whitespace, into an
77making up an argument vector: 89argument vector:
78.Bd -literal -offset indent 90.Bd -literal -offset indent
79char inputstring[100]; 91char **ap, *argv[10], *inputstring;
80char **argv[51], **ap = argv, *p, *val; 92
81/* set up inputstring */ 93for (ap = argv; ap < &argv[9] &&
82for (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
89The 101The
90.Fn strsep 102.Fn strsep
91function is 103function is intended as a replacement for the
92.Ud . 104.Fn strtok
105function.
106While the
107.Fn strtok
108function should be preferred for portability reasons (it conforms to
109.St -ansiC )
110it is unable to handle empty fields, i.e., detect fields delimited by
111two adjacent delimiter characters, or to be used for more than a single
112string at a time.
113The
114.Fn strsep
115function 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
36static char *rcsid = "$Id: strsep.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; 41static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
42#else
43static 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 */
52char * 58char *
53strsep(stringp, delim) 59strsep(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";*/ 35static char *rcsid = "$OpenBSD: strsignal.c,v 1.3 2002/02/16 21:27:24 millert Exp $";
36static 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
42extern char *__strsignal __P((int, char *)); 41extern char *__strsignal(int, char *);
43 42
44char * 43char *
45strsignal(sig) 44strsignal(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
50The 49The
51.Xr strcspn 50.Fn strspn
52function 51function spans the initial part of the null-terminated string
53spans the initial part of the null-terminated string
54.Fa s 52.Fa s
55as long as the characters from 53as 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
60The 58The
61.Fn strspn 59.Fn strspn
62function 60function returns the number of characters spanned.
63returns the number of characters spanned. 61.Sh EXAMPLES
62The following call to
63.Fn strspn
64will return 3, since the first three characters of string
65.Fa s
66are part of string
67.Fa charset :
68.Bd -literal -offset indent
69char *s = "foobar";
70char *charset = "of";
71size_t span;
72
73span = 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
76The 85The
77.Fn strspn 86.Fn strspn
78function 87function conforms to
79conforms 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";*/ 35static char *rcsid = "$OpenBSD: strspn.c,v 1.2 1996/08/19 08:34:26 tholo Exp $";
36static 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
50The 49The
51.Fn strstr 50.Fn strstr
52function 51function locates the first occurrence of the null-terminated string
53locates the first occurrence of the null-terminated string
54.Fa little 52.Fa little
55in the null-terminated string 53in the null-terminated string
56.Fa big . 54.Fa big .
@@ -65,15 +63,14 @@ if
65occurs nowhere in 63occurs nowhere in
66.Fa big , 64.Fa big ,
67.Fn strstr 65.Fn strstr
68returns NULL; 66returns
67.Dv NULL ;
69otherwise 68otherwise
70.Fn strstr 69.Fn strstr
71returns a pointer to the first character of the first occurrence of 70returns 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
85The 82The
86.Fn strstr 83.Fn strstr
87function 84function conforms to
88conforms 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";*/ 38static char *rcsid = "$OpenBSD: strstr.c,v 1.2 1996/08/19 08:34:27 tholo Exp $";
39static 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
52This interface is obsoleted by strsep(3). 53This interface is obsoleted by
54.Xr strsep 3 .
53.Ef 55.Ef
54.Pp 56.Pp
55The 57The
56.Fn strtok 58.Fn strtok
57function 59function is used to isolate sequential tokens in a null-terminated string,
58is used to isolate sequential tokens in a null-terminated string,
59.Fa str . 60.Fa str .
60These tokens are separated in the string by at least one of the 61These tokens are separated in the string by at least one of the
61characters in 62characters in
@@ -71,17 +72,65 @@ The separator string,
71must be supplied each time, and may change between calls. 72must be supplied each time, and may change between calls.
72.Pp 73.Pp
73The 74The
75.Fn strtok_r
76function is a version of
74.Fn strtok 77.Fn strtok
75function 78that takes an explicit context argument and is reentrant.
76returns a pointer to the beginning of each subsequent token in the string, 79.Pp
77after replacing the separator character itself with a 80The
78.Dv NUL 81.Fn strtok
82and
83.Fn strtok_r
84functions return a pointer to the beginning of each subsequent token
85in the string, after replacing the separator character itself with an
86.Tn ASCII NUL
79character. 87character.
80When no more tokens remain, a null pointer is returned. 88When no more tokens remain, a null pointer is returned.
89.Pp
90Since
91.Fn strtok
92and
93.Fn strtok_r
94modify the string,
95.Fa str
96should not point to an area in the initialized data segment.
97.Sh EXAMPLES
98The following will construct an array of pointers to each individual word in
99the string
100.Va s :
101.Bd -literal -offset indent
102#define MAXTOKENS 128
103
104char s[512], *p, *tokens[MAXTOKENS];
105char *last;
106int i = 0;
107
108snprintf(s, sizeof(s), "cat dog horse cow");
109
110for ((p = strtok_r(s, " ", &last)); p;
111 (p = strtok_r(NULL, " ", &last)), i++) {
112 if (i < MAXTOKENS - 1)
113 tokens[i] = p;
114}
115tokens[i] = NULL;
116.Ed
117.Pp
118That is,
119.Li tokens[0]
120will point to
121.Qq cat ,
122.Li tokens[1]
123will point to
124.Qq dog ,
125.Li tokens[2]
126will point to
127.Qq horse ,
128and
129.Li tokens[3]
130will 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
93The 142The
94.Fn strtok 143.Fn strtok
95function 144function conforms to
96conforms to
97.St -ansiC . 145.St -ansiC .
98.Sh BUGS 146.Sh BUGS
99There is no way to get tokens from multiple strings simultaneously.
100.Pp
101The System V 147The System V
102.Fn strtok , 148.Fn strtok ,
103if handed a string containing only delimiter characters, 149if handed a string containing only delimiter characters,
104will not alter the next starting point, so that a call to 150will not alter the next starting point, so that a call to
105.Fn strtok 151.Fn strtok
106with a different (or empty) delimiter string 152with a different (or empty) delimiter string
107may return a 153may return a non-null value.
108.Pf non- Dv NULL
109value.
110Since this implementation always alters the next starting point, 154Since this implementation always alters the next starting point,
111such a sequence of calls would always return 155such 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";*/ 35static char *rcsid = "$OpenBSD: strtok.c,v 1.3 1999/11/09 11:19:46 art Exp $";
36static 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
50char *
51strtok_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
50The 49The
51.Fn strxfrm 50.Fn strxfrm
52function 51function does something horrible (see
53does something horrible (see
54.Tn ANSI 52.Tn ANSI
55standard). 53standard).
56In this implementation it just copies. 54In this implementation it just copies.
@@ -64,6 +62,5 @@ In this implementation it just copies.
64.Sh STANDARDS 62.Sh STANDARDS
65The 63The
66.Fn strxfrm 64.Fn strxfrm
67function 65function conforms to
68conforms 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";*/ 38static char *rcsid = "$OpenBSD: strxfrm.c,v 1.2 1996/08/19 08:34:29 tholo Exp $";
39static 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
56The argument 55The argument
57.Fa len 56.Fa len
58must be even number. 57must 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";*/ 38static char *rcsid = "$OpenBSD: swab.c,v 1.3 1998/02/10 02:19:48 deraadt Exp $";
39static 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
44void 43void
45swab(from, to, len) 44swab(from, to, len)