CVS commit: src/lib/libc/string

2021-04-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Apr 14 08:07:49 UTC 2021

Modified Files:
src/lib/libc/string: Makefile.inc

Log Message:
for GCC, built memset.c with -fno-builtin.  this avoids GCC 10 compiling
memset() and emitting calls to memset() where it seems code that looks
like what memset() does, which ends up recursing and blowing the stack.

this makes mips userland with GCC 10 work.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/lib/libc/string/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Makefile.inc
diff -u src/lib/libc/string/Makefile.inc:1.84 src/lib/libc/string/Makefile.inc:1.85
--- src/lib/libc/string/Makefile.inc:1.84	Wed Mar 25 18:45:42 2020
+++ src/lib/libc/string/Makefile.inc	Wed Apr 14 08:07:49 2021
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-#	$NetBSD: Makefile.inc,v 1.84 2020/03/25 18:45:42 kre Exp $
+#	$NetBSD: Makefile.inc,v 1.85 2021/04/14 08:07:49 mrg Exp $
 
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -34,6 +34,12 @@ CPPFLAGS.wcscmp.c+=	-I${LIBCDIR}/locale
 CPPFLAGS.wcsncmp.c+=	-I${LIBCDIR}/locale
 CPPFLAGS.wmemcmp.c+=	-I${LIBCDIR}/locale
 
+# Avoid memset() compilation generating calls to memset() via code
+# that appears to implement memset()-like semantics (similar to how
+# printf("foo") may be converted to puts("foo")), since that tends
+# to recurse and blow the stack.
+COPTS.memset.c+=	${${ACTIVE_CC} == "gcc":? -fno-builtin :}
+
 .include "${ARCHDIR}/string/Makefile.inc"
 
 MAN+=	bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 consttime_memequal.3 \



CVS commit: src/lib/libc/string

2020-11-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Nov 26 23:13:55 UTC 2020

Modified Files:
src/lib/libc/string: strchr.3

Log Message:
fix typo in manual page for strchrnul(3)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/strchr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strchr.3
diff -u src/lib/libc/string/strchr.3:1.13 src/lib/libc/string/strchr.3:1.14
--- src/lib/libc/string/strchr.3:1.13	Sun Oct 16 05:28:33 2016
+++ src/lib/libc/string/strchr.3	Thu Nov 26 23:13:55 2020
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strchr.3	8.2 (Berkeley) 4/19/94
-.\"	$NetBSD: strchr.3,v 1.13 2016/10/16 05:28:33 wiz Exp $
+.\"	$NetBSD: strchr.3,v 1.14 2020/11/26 23:13:55 rillig Exp $
 .\"
-.Dd October 12, 2016
+.Dd November 27, 2020
 .Dt STRCHR 3
 .Os
 .Sh NAME
@@ -76,7 +76,7 @@ if the character does not appear in the 
 The function
 .Fn strchrnul
 returns a pointer to the located character, or
-the a pointer to the
+a pointer to the
 .Dv NUL
 terminating character of the string if the character does not appear
 in the string.



CVS commit: src/lib/libc/string

2020-04-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Apr  4 21:29:54 UTC 2020

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Move the note about sys_errlist[] users to COMPATIBILITY, and strengthen it.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.23 src/lib/libc/string/strerror.3:1.24
--- src/lib/libc/string/strerror.3:1.23	Sat Apr  4 21:26:44 2020
+++ src/lib/libc/string/strerror.3	Sat Apr  4 21:29:54 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: strerror.3,v 1.23 2020/04/04 21:26:44 dholland Exp $
+.\" $NetBSD: strerror.3,v 1.24 2020/04/04 21:29:54 dholland Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -209,6 +209,13 @@ The use of these variables is deprecated
 one of the
 .Fn strerror
 family of functions should be used instead.
+.Sh COMPATIBILITY
+Programs that attempt to use the deprecated
+.Va sys_errlist
+variable often fail to compile because they provide their own,
+inconsistent, declaration of it.
+Such programs should be updated to use
+.Fn strerror .
 .Sh ERRORS
 These functions may fail if:
 .Bl -tag -width Er
@@ -280,8 +287,3 @@ and
 .Fn strerror_l
 use the same thread local storage; a call to either will destroy
 the result from an earlier call by the same thread of either of them.
-.Pp
-Programs that use the deprecated
-.Va sys_errlist
-variable often fail to compile because they declare it
-inconsistently.



CVS commit: src/lib/libc/string

2020-04-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Apr  4 21:26:44 UTC 2020

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Add missing ERRORS section.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.22 src/lib/libc/string/strerror.3:1.23
--- src/lib/libc/string/strerror.3:1.22	Sat Apr  4 21:20:39 2020
+++ src/lib/libc/string/strerror.3	Sat Apr  4 21:26:44 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: strerror.3,v 1.22 2020/04/04 21:20:39 dholland Exp $
+.\" $NetBSD: strerror.3,v 1.23 2020/04/04 21:26:44 dholland Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -209,6 +209,15 @@ The use of these variables is deprecated
 one of the
 .Fn strerror
 family of functions should be used instead.
+.Sh ERRORS
+These functions may fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The error number was out of range.
+.It Bq Er ERANGE
+The string buffer supplied was not large enough to hold the complete
+error message.
+.El
 .Sh SEE ALSO
 .Xr intro 2 ,
 .Xr err 3 ,



CVS commit: src/lib/libc/string

2020-04-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Apr  4 21:20:39 UTC 2020

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Minor clarification. And a typo. Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.21 src/lib/libc/string/strerror.3:1.22
--- src/lib/libc/string/strerror.3:1.21	Wed Mar 25 18:50:47 2020
+++ src/lib/libc/string/strerror.3	Sat Apr  4 21:20:39 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: strerror.3,v 1.21 2020/03/25 18:50:47 kre Exp $
+.\" $NetBSD: strerror.3,v 1.22 2020/04/04 21:20:39 dholland Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" @(#)strerror.3	8.1 (Berkeley) 6/9/93
-.Dd March 24, 2020
+.Dd April 4, 2020
 .Dt STRERROR 3
 .Os
 .Sh NAME
@@ -88,7 +88,7 @@ function renders the same result into
 .Fa strerrbuf
 for a maximum of
 .Fa buflen
-characters and returns 0 upon success.
+characters (including terminator) and returns 0 upon success.
 .Pp
 The
 .Fn strerror_l
@@ -269,7 +269,7 @@ Both
 .Fn strerror
 and
 .Fn strerror_l
-use the same thread local storage, a call to either will destroy
+use the same thread local storage; a call to either will destroy
 the result from an earlier call by the same thread of either of them.
 .Pp
 Programs that use the deprecated



CVS commit: src/lib/libc/string

2020-03-25 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 25 16:15:41 UTC 2020

Modified Files:
src/lib/libc/string: strerror_r.c

Log Message:
Arrange that strerror(-1) prints "Unknown error: -1" and not the
unsigned equivalent of -1.

While here, guarantee, even when !NLS, that nothing here (not even
snprintf deciding to complain about EILSEQ or something) can ever
alter errno (ie: always save and restore it, not only in the NLS case).
The functions here must never alter errno, whatever happens.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/strerror_r.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror_r.c
diff -u src/lib/libc/string/strerror_r.c:1.4 src/lib/libc/string/strerror_r.c:1.5
--- src/lib/libc/string/strerror_r.c:1.4	Tue Jan 10 20:25:48 2017
+++ src/lib/libc/string/strerror_r.c	Wed Mar 25 16:15:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror_r.c,v 1.4 2017/01/10 20:25:48 christos Exp $	*/
+/*	$NetBSD: strerror_r.c,v 1.5 2020/03/25 16:15:41 kre Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: strerror_r.c,v 1.4 2017/01/10 20:25:48 christos Exp $");
+__RCSID("$NetBSD: strerror_r.c,v 1.5 2020/03/25 16:15:41 kre Exp $");
 
 #include "namespace.h"
 #include 
@@ -53,12 +53,12 @@ __weak_alias(strerror_r, _strerror_r)
 int
 _strerror_lr(int num, char *buf, size_t buflen, locale_t loc)
 {
-#define	UPREFIX	"Unknown error: %u"
+#define	UPREFIX	"Unknown error: %d"
 	unsigned int errnum = num;
 	int retval = 0;
 	size_t slen;
-#ifdef NLS
 	int saved_errno = errno;
+#ifdef NLS
 	nl_catd catd;
 	catd = catopen_l("libc", NL_CAT_LOCALE, loc);
 #endif
@@ -66,7 +66,7 @@ _strerror_lr(int num, char *buf, size_t 
 
 	if (errnum < (unsigned int) sys_nerr) {
 #ifdef NLS
-		slen = strlcpy(buf, catgets(catd, 1, (int)errnum,
+		slen = strlcpy(buf, catgets(catd, 1, num,
 		sys_errlist[errnum]), buflen); 
 #else
 		slen = strlcpy(buf, sys_errlist[errnum], buflen); 
@@ -74,9 +74,9 @@ _strerror_lr(int num, char *buf, size_t 
 	} else {
 #ifdef NLS
 		slen = snprintf_l(buf, buflen, loc,
-		catgets(catd, 1, 0x, UPREFIX), errnum);
+		catgets(catd, 1, 0x, UPREFIX), num);
 #else
-		slen = snprintf(buf, buflen, UPREFIX, errnum);
+		slen = snprintf(buf, buflen, UPREFIX, num);
 #endif
 		retval = EINVAL;
 	}
@@ -86,8 +86,8 @@ _strerror_lr(int num, char *buf, size_t 
 
 #ifdef NLS
 	catclose(catd);
-	errno = saved_errno;
 #endif
+	errno = saved_errno;
 
 	return retval;
 }



CVS commit: src/lib/libc/string

2020-03-25 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 25 16:10:17 UTC 2020

Modified Files:
src/lib/libc/string: strerror.c

Log Message:
Protect against malloc failure corrupting errno, which is not
permitted of these functions.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/strerror.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.c
diff -u src/lib/libc/string/strerror.c:1.17 src/lib/libc/string/strerror.c:1.18
--- src/lib/libc/string/strerror.c:1.17	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/string/strerror.c	Wed Mar 25 16:10:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror.c,v 1.17 2015/01/20 18:31:25 christos Exp $	*/
+/*	$NetBSD: strerror.c,v 1.18 2020/03/25 16:10:17 kre Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: strerror.c,v 1.17 2015/01/20 18:31:25 christos Exp $");
+__RCSID("$NetBSD: strerror.c,v 1.18 2020/03/25 16:10:17 kre Exp $");
 
 #define __SETLOCALE_SOURCE__
 
@@ -78,7 +78,9 @@ strerror_l(int num, locale_t loc)
 	thr_once(_once, strerror_setup);
 	buf = thr_getspecific(strerror_key);
 	if (buf == NULL) {
+		error = errno;
 		buf = malloc(NL_TEXTMAX);
+		errno = error;
 		if (buf == NULL) {
 			static char fallback_buf[NL_TEXTMAX];
 			buf = fallback_buf;



CVS commit: src/lib/libc/string

2020-03-25 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 25 18:50:47 UTC 2020

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Delete the BUGS paragraph about the "missing" const qualifier for the
result type of strerror() (and strerror_l()).   While that once should
really have been present, when strerror() was invented, there was no
"const" qualifier in C to apply, and now the way the code is writtem
(really needs to be because of NLS support) the const is no longer
really appropriate.

Applications still shouldn't attempt to modify the result however.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.20 src/lib/libc/string/strerror.3:1.21
--- src/lib/libc/string/strerror.3:1.20	Wed Mar 25 18:45:42 2020
+++ src/lib/libc/string/strerror.3	Wed Mar 25 18:50:47 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: strerror.3,v 1.20 2020/03/25 18:45:42 kre Exp $
+.\" $NetBSD: strerror.3,v 1.21 2020/03/25 18:50:47 kre Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -271,22 +271,6 @@ and
 .Fn strerror_l
 use the same thread local storage, a call to either will destroy
 the result from an earlier call by the same thread of either of them.
-.\"
-.\" Is this following para really true any more?   All the strerror()
-.\" family of functions return the result in a malloc'd array (or if
-.\" ! _REENTRANT a static buffer in the function) or in a buffer
-.\" provided by the caller - nothing actually returns a pointer into
-.\" sys_errlist[] any more (strerror_ss() excepted, but we ignore that).
-.\" The POSIX (and historic) functions had no "const" qualifier.
-.\" POSIX does say that callers must not (attempt to) modify the result,
-.\" but for our implementation I see no defect that can cause.
-.Pp
-The return types for
-.Fn strerror
-and
-.Fn strerror_l
-are both missing a type-qualifier; it should actually be
-.Vt const char * .
 .Pp
 Programs that use the deprecated
 .Va sys_errlist



CVS commit: src/lib/libc/string

2019-03-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar 18 02:15:21 UTC 2019

Modified Files:
src/lib/libc/string: strxfrm.3

Log Message:
restore the removed "function does something horrible" description,
but leave the real description as well.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/strxfrm.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strxfrm.3
diff -u src/lib/libc/string/strxfrm.3:1.11 src/lib/libc/string/strxfrm.3:1.12
--- src/lib/libc/string/strxfrm.3:1.11	Sun Feb 18 00:46:47 2007
+++ src/lib/libc/string/strxfrm.3	Mon Mar 18 02:15:21 2019
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strxfrm.3	8.1 (Berkeley) 6/4/93
-.\"	$NetBSD: strxfrm.3,v 1.11 2007/02/18 00:46:47 wiz Exp $
+.\"	$NetBSD: strxfrm.3,v 1.12 2019/03/18 02:15:21 mrg Exp $
 .\"
-.Dd February 18, 2007
+.Dd March 6, 2019
 .Dt STRXFRM 3
 .Os
 .Sh NAME
@@ -45,9 +45,10 @@
 .Ft size_t
 .Fn strxfrm "char * restrict dst" "const char * restrict src" "size_t n"
 .Sh DESCRIPTION
-The idea of
+The
 .Fn strxfrm
-is to
+function does something horrible.
+The idea is to
 .Dq un-localize
 a string: the function transforms
 .Ar src ,



CVS commit: src/lib/libc/string

2018-07-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul  8 17:53:42 UTC 2018

Removed Files:
src/lib/libc/string: memmem.c

Log Message:
switch to FreeBSD's memmem


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r0 src/lib/libc/string/memmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/string

2017-08-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 23 10:27:41 UTC 2017

Modified Files:
src/lib/libc/string: stresep.c

Log Message:
PR/52499: Justin: stresep uses memmove with of-by-one length


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/stresep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/stresep.c
diff -u src/lib/libc/string/stresep.c:1.3 src/lib/libc/string/stresep.c:1.4
--- src/lib/libc/string/stresep.c:1.3	Sun Feb 12 12:19:00 2017
+++ src/lib/libc/string/stresep.c	Wed Aug 23 06:27:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $	*/
+/*	$NetBSD: stresep.c,v 1.4 2017/08/23 10:27:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)strsep.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $");
+__RCSID("$NetBSD: stresep.c,v 1.4 2017/08/23 10:27:41 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -66,6 +66,7 @@ stresep(char **stringp, const char *deli
 	char *s;
 	const char *spanp;
 	int c, sc;
+	size_t l;
 	char *tok;
 
 	_DIAGASSERT(stringp != NULL);
@@ -73,22 +74,25 @@ stresep(char **stringp, const char *deli
 
 	if ((s = *stringp) == NULL)
 		return NULL;
+	l = strlen(s) + 1;
 	for (tok = s;;) {
 		c = *s++;
+		l--;
 		while (esc != '\0' && c == esc) {
-			memmove(s - 1, s, strlen(s));
+			memmove(s - 1, s, l);
 			c = *s++;
+			l--;
 		}
 		spanp = delim;
 		do {
 			if ((sc = *spanp++) == c) {
-if (c == 0)
+if (c == '\0')
 	s = NULL;
 else
-	s[-1] = 0;
+	s[-1] = '\0';
 *stringp = s;
 return tok;
 			}
-		} while (sc != 0);
+		} while (sc != '\0');
 	}
 }



CVS commit: src/lib/libc/string

2017-06-17 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sat Jun 17 10:48:09 UTC 2017

Modified Files:
src/lib/libc/string: strings.3

Log Message:
Remove names from the NAME section which have their own man pages.
This is similar to the changes made in string(3) and memory(3) man pages 
previously.

The reasin being that, when you do `whatis ffs', an extra entry will be there in
the output for this page, which is confusing and unncessary.

Bump date for changes in the NAME section.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/strings.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strings.3
diff -u src/lib/libc/string/strings.3:1.2 src/lib/libc/string/strings.3:1.3
--- src/lib/libc/string/strings.3:1.2	Thu Jul 14 17:43:48 2016
+++ src/lib/libc/string/strings.3	Sat Jun 17 10:48:09 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: strings.3,v 1.2 2016/07/14 17:43:48 abhinav Exp $
+.\" $NetBSD: strings.3,v 1.3 2017/06/17 10:48:09 abhinav Exp $
 .\"
 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,18 +27,11 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 17, 2007
+.Dd June 17, 2017
 .Dt STRINGS 3
 .Os
 .Sh NAME
-.Nm bcmp ,
-.Nm bcopy ,
-.Nm bzero ,
-.Nm ffs ,
-.Nm index ,
-.Nm rindex ,
-.Nm strcasecmp ,
-.Nm strncasecmp
+.Nm strings
 .Nd string operations
 .Sh LIBRARY
 .Lb libc



CVS commit: src/lib/libc/string

2017-02-12 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Feb 12 17:19:00 UTC 2017

Modified Files:
src/lib/libc/string: stresep.c

Log Message:
overlapping strcpy is UB. use memmove
from asan+ubsan


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/stresep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/stresep.c
diff -u src/lib/libc/string/stresep.c:1.2 src/lib/libc/string/stresep.c:1.3
--- src/lib/libc/string/stresep.c:1.2	Thu Dec  6 22:07:07 2007
+++ src/lib/libc/string/stresep.c	Sun Feb 12 17:19:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stresep.c,v 1.2 2007/12/06 22:07:07 seb Exp $	*/
+/*	$NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)strsep.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: stresep.c,v 1.2 2007/12/06 22:07:07 seb Exp $");
+__RCSID("$NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -76,7 +76,7 @@ stresep(char **stringp, const char *deli
 	for (tok = s;;) {
 		c = *s++;
 		while (esc != '\0' && c == esc) {
-			(void)strcpy(s - 1, s);
+			memmove(s - 1, s, strlen(s));
 			c = *s++;
 		}
 		spanp = delim;



CVS commit: src/lib/libc/string

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 20:25:48 UTC 2017

Modified Files:
src/lib/libc/string: strerror_r.c

Log Message:
PR/51814: Ngie Cooper: add  since sys_nerr is declared there on
FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/strerror_r.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror_r.c
diff -u src/lib/libc/string/strerror_r.c:1.3 src/lib/libc/string/strerror_r.c:1.4
--- src/lib/libc/string/strerror_r.c:1.3	Mon Aug 19 09:03:12 2013
+++ src/lib/libc/string/strerror_r.c	Tue Jan 10 15:25:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror_r.c,v 1.3 2013/08/19 13:03:12 joerg Exp $	*/
+/*	$NetBSD: strerror_r.c,v 1.4 2017/01/10 20:25:48 christos Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,13 +30,14 @@
  */
 
 #include 
-__RCSID("$NetBSD: strerror_r.c,v 1.3 2013/08/19 13:03:12 joerg Exp $");
+__RCSID("$NetBSD: strerror_r.c,v 1.4 2017/01/10 20:25:48 christos Exp $");
 
 #include "namespace.h"
 #include 
 #include 
 #include 
 #include 
+#include 	/* for sys_nerr on FreeBSD */
 #ifdef NLS
 #include 
 #include 



CVS commit: src/lib/libc/string

2016-10-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Oct 16 05:28:33 UTC 2016

Modified Files:
src/lib/libc/string: strchr.3

Log Message:
Add missing word.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/strchr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strchr.3
diff -u src/lib/libc/string/strchr.3:1.12 src/lib/libc/string/strchr.3:1.13
--- src/lib/libc/string/strchr.3:1.12	Wed Oct 12 20:01:12 2016
+++ src/lib/libc/string/strchr.3	Sun Oct 16 05:28:33 2016
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strchr.3	8.2 (Berkeley) 4/19/94
-.\"	$NetBSD: strchr.3,v 1.12 2016/10/12 20:01:12 christos Exp $
+.\"	$NetBSD: strchr.3,v 1.13 2016/10/16 05:28:33 wiz Exp $
 .\"
 .Dd October 12, 2016
 .Dt STRCHR 3
@@ -111,5 +111,5 @@ conforms to
 .St -ansiC .
 .The
 .Fn strchrnul
-appeared in
+function appeared in
 .Nx 8 .



CVS commit: src/lib/libc/string

2016-10-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Oct 15 14:30:36 UTC 2016

Modified Files:
src/lib/libc/string: wcsnlen.c

Log Message:
Add NetBSD CVS Id on top of the wcsnlen.c file


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/wcsnlen.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcsnlen.c
diff -u src/lib/libc/string/wcsnlen.c:1.1 src/lib/libc/string/wcsnlen.c:1.2
--- src/lib/libc/string/wcsnlen.c:1.1	Sat Oct 15 14:22:00 2016
+++ src/lib/libc/string/wcsnlen.c	Sat Oct 15 14:30:36 2016
@@ -1,3 +1,5 @@
+/*	$NetBSD: wcsnlen.c,v 1.2 2016/10/15 14:30:36 kamil Exp $	*/
+
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: wcsnlen.c,v 1.1 2016/10/15 14:22:00 kamil Exp $");
+__RCSID("$NetBSD: wcsnlen.c,v 1.2 2016/10/15 14:30:36 kamil Exp $");
 
 #include 
 #include 



CVS commit: src/lib/libc/string

2016-10-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 12 20:01:12 UTC 2016

Modified Files:
src/lib/libc/string: Makefile.inc strchr.3

Log Message:
add strchrnul


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libc/string/Makefile.inc
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/strchr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Makefile.inc
diff -u src/lib/libc/string/Makefile.inc:1.80 src/lib/libc/string/Makefile.inc:1.81
--- src/lib/libc/string/Makefile.inc:1.80	Wed Sep 24 14:16:37 2014
+++ src/lib/libc/string/Makefile.inc	Wed Oct 12 16:01:12 2016
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-#	$NetBSD: Makefile.inc,v 1.80 2014/09/24 18:16:37 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.81 2016/10/12 20:01:12 christos Exp $
 
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -22,7 +22,7 @@ SRCS+=	strspn.c strstr.c swab.c strnstr.
 SRCS+=	explicit_memset.c consttime_memequal.c
 
 SRCS+=	memccpy.c memcpy.c memmem.c memmove.c
-SRCS+=	strchr.c strrchr.c
+SRCS+=	strchr.c strrchr.c strchrnul.c
 SRCS+=	popcount32.c popcount64.c
 
 # wide char
@@ -59,6 +59,7 @@ MLINKS+=strlcpy.3 strlcat.3
 MLINKS+=strlen.3 strnlen.3
 MLINKS+=strstr.3 strcasestr.3
 MLINKS+=strstr.3 strnstr.3
+MLINKS+=strchr.3 strchrnul.3
 MLINKS+=memchr.3 memrchr.3
 MLINKS+=strtok.3 strtok_r.3
 MLINKS+=strerror.3 strerror_r.3 strerror.3 perror.3 \

Index: src/lib/libc/string/strchr.3
diff -u src/lib/libc/string/strchr.3:1.11 src/lib/libc/string/strchr.3:1.12
--- src/lib/libc/string/strchr.3:1.11	Thu Aug  7 12:43:49 2003
+++ src/lib/libc/string/strchr.3	Wed Oct 12 16:01:12 2016
@@ -30,13 +30,13 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strchr.3	8.2 (Berkeley) 4/19/94
-.\"	$NetBSD: strchr.3,v 1.11 2003/08/07 16:43:49 agc Exp $
+.\"	$NetBSD: strchr.3,v 1.12 2016/10/12 20:01:12 christos Exp $
 .\"
-.Dd August 11, 2002
+.Dd October 12, 2016
 .Dt STRCHR 3
 .Os
 .Sh NAME
-.Nm strchr
+.Nm strchr, strchrnul
 .Nd locate character in string
 .Sh LIBRARY
 .Lb libc
@@ -44,10 +44,14 @@
 .In string.h
 .Ft char *
 .Fn strchr "const char *s" "int c"
+.Ft char *
+.Fn strchrnul "const char *s" "int c"
 .Sh DESCRIPTION
 The
 .Fn strchr
-function locates the first occurrence of
+and
+.Fn strchrnul
+functions locate the first occurrence of
 .Ar c
 in the string pointed to by
 .Ar s .
@@ -59,7 +63,9 @@ If
 is
 .Ql \e0 ,
 .Fn strchr
-locates the terminating
+and
+.Fn strchrnul
+locate the terminating
 .Ql \e0 .
 .Sh RETURN VALUES
 The function
@@ -67,6 +73,13 @@ The function
 returns a pointer to the located character, or
 .Dv NULL
 if the character does not appear in the string.
+The function
+.Fn strchrnul
+returns a pointer to the located character, or
+the a pointer to the
+.Dv NUL
+terminating character of the string if the character does not appear
+in the string.
 .Sh EXAMPLES
 After the following call to
 .Fn strchr ,
@@ -96,3 +109,7 @@ The
 function
 conforms to
 .St -ansiC .
+.The
+.Fn strchrnul
+appeared in
+.Nx 8 .



CVS commit: src/lib/libc/string

2016-08-04 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Thu Aug  4 16:36:46 UTC 2016

Modified Files:
src/lib/libc/string: memset.3

Log Message:
Grammar


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/memset.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/memset.3
diff -u src/lib/libc/string/memset.3:1.12 src/lib/libc/string/memset.3:1.13
--- src/lib/libc/string/memset.3:1.12	Mon Jun 24 07:56:49 2013
+++ src/lib/libc/string/memset.3	Thu Aug  4 16:36:45 2016
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)memset.3	8.1 (Berkeley) 6/4/93
-.\"	$NetBSD: memset.3,v 1.12 2013/06/24 07:56:49 wiz Exp $
+.\"	$NetBSD: memset.3,v 1.13 2016/08/04 16:36:45 sevan Exp $
 .\"
 .Dd June 23, 2013
 .Dt MEMSET 3
@@ -64,7 +64,7 @@ returns the original value of
 Note that the compiler may optimize away a call to
 .Fn memset
 if it can prove that the string will not be used by the program again,
-for example if it is allocated on the stack and about to out of scope.
+for example if it is allocated on the stack and about to go out of scope.
 If you want to guarantee that zeros are written to memory, for example
 to sanitize a buffer holding a cryptographic secret, use
 .Xr explicit_memset 3 .



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 18:36:57 UTC 2016

Modified Files:
src/lib/libc/string: string.3

Log Message:
Fix grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/string/string.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/string.3
diff -u src/lib/libc/string/string.3:1.16 src/lib/libc/string/string.3:1.17
--- src/lib/libc/string/string.3:1.16	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/string.3	Thu Jul 14 18:36:57 2016
@@ -28,7 +28,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)string.3	8.2 (Berkeley) 12/11/93
-.\"	$NetBSD: string.3,v 1.16 2009/05/01 17:27:01 perry Exp $
+.\"	$NetBSD: string.3,v 1.17 2016/07/14 18:36:57 abhinav Exp $
 .\"
 .Dd May 1, 2009
 .Dt STRING 3
@@ -196,5 +196,5 @@ function conforms to
 .Pp
 The
 .Fn strerror_r
-function conform to
+function conforms to
 .St -p1003.1-2001 .



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 18:21:31 UTC 2016

Modified Files:
src/lib/libc/string: popcount.3

Log Message:
Fix grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/string/popcount.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/popcount.3
diff -u src/lib/libc/string/popcount.3:1.5 src/lib/libc/string/popcount.3:1.6
--- src/lib/libc/string/popcount.3:1.5	Mon Aug 22 01:36:04 2011
+++ src/lib/libc/string/popcount.3	Thu Jul 14 18:21:31 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: popcount.3,v 1.5 2011/08/22 01:36:04 dholland Exp $
+.\"	$NetBSD: popcount.3,v 1.6 2016/07/14 18:21:31 abhinav Exp $
 .\"
 .\" Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -55,7 +55,7 @@
 .Sh DESCRIPTION
 The
 .Nm
-functions returns the number of bits set in
+functions return the number of bits set in
 .Fa value .
 .Sh SEE ALSO
 .Xr ffs 3



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 17:43:48 UTC 2016

Modified Files:
src/lib/libc/string: strings.3

Log Message:
Use .In for header file.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/strings.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strings.3
diff -u src/lib/libc/string/strings.3:1.1 src/lib/libc/string/strings.3:1.2
--- src/lib/libc/string/strings.3:1.1	Sat Feb 17 09:32:58 2007
+++ src/lib/libc/string/strings.3	Thu Jul 14 17:43:48 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: strings.3,v 1.1 2007/02/17 09:32:58 wiz Exp $
+.\" $NetBSD: strings.3,v 1.2 2016/07/14 17:43:48 abhinav Exp $
 .\"
 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -62,7 +62,7 @@
 .Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
 .Sh DESCRIPTION
 These functions all live in the
-.Pa strings.h
+.In strings.h
 header file.
 Except for
 .Fn ffs ,



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 17:17:58 UTC 2016

Modified Files:
src/lib/libc/string: wmemchr.3

Log Message:
Add comma to separate the Nm entries.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/string/wmemchr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wmemchr.3
diff -u src/lib/libc/string/wmemchr.3:1.15 src/lib/libc/string/wmemchr.3:1.16
--- src/lib/libc/string/wmemchr.3:1.15	Thu Dec 16 17:42:28 2010
+++ src/lib/libc/string/wmemchr.3	Thu Jul 14 17:17:58 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wmemchr.3,v 1.15 2010/12/16 17:42:28 wiz Exp $
+.\"	$NetBSD: wmemchr.3,v 1.16 2016/07/14 17:17:58 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -56,7 +56,7 @@
 .Nm wcspbrk ,
 .Nm wcsrchr ,
 .Nm wcsspn ,
-.Nm wcsstr
+.Nm wcsstr ,
 .Nm wcswcs
 .Nd wide-character string manipulation operations
 .Sh LIBRARY



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 17:09:03 UTC 2016

Modified Files:
src/lib/libc/string: strcmp.3

Log Message:
Add missing words and fix grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/strcmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcmp.3
diff -u src/lib/libc/string/strcmp.3:1.13 src/lib/libc/string/strcmp.3:1.14
--- src/lib/libc/string/strcmp.3:1.13	Mon Oct 16 08:48:45 2006
+++ src/lib/libc/string/strcmp.3	Thu Jul 14 17:09:03 2016
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strcmp.3	8.1 (Berkeley) 6/4/93
-.\"	$NetBSD: strcmp.3,v 1.13 2006/10/16 08:48:45 wiz Exp $
+.\"	$NetBSD: strcmp.3,v 1.14 2016/07/14 17:09:03 abhinav Exp $
 .\"
 .Dd June 4, 1993
 .Dt STRCMP 3
@@ -62,7 +62,7 @@ The
 .Fn strcmp
 and
 .Fn strncmp
-return an integer greater than, equal to, or less than 0, according
+functions return an integer greater than, equal to, or less than 0, according
 to whether the string
 .Fa s1
 is greater than, equal to, or less than the string
@@ -74,7 +74,7 @@ is greater than
 .Pp
 The
 .Fn strncmp
-compares not more than
+function compares not more than
 .Fa len
 characters.
 .Sh SEE ALSO
@@ -94,6 +94,6 @@ conform to
 .Sh NOTES
 If
 .Fa len
-is zero
+is 0,
 .Fn strncmp
-returns always 0.
+always returns 0.



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 16:09:56 UTC 2016

Modified Files:
src/lib/libc/string: wcscasecmp.3

Log Message:
Fix sentence.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/string/wcscasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscasecmp.3
diff -u src/lib/libc/string/wcscasecmp.3:1.5 src/lib/libc/string/wcscasecmp.3:1.6
--- src/lib/libc/string/wcscasecmp.3:1.5	Thu Jul 14 07:19:11 2016
+++ src/lib/libc/string/wcscasecmp.3	Thu Jul 14 16:09:56 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wcscasecmp.3,v 1.5 2016/07/14 07:19:11 abhinav Exp $
+.\"	$NetBSD: wcscasecmp.3,v 1.6 2016/07/14 16:09:56 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -66,7 +66,7 @@ The strings themselves are not modified.
 .Pp
 The
 .Fn wcsncasecmp
-compares at most
+function compares at most
 .Fa len
 characters.
 .Sh SEE ALSO



CVS commit: src/lib/libc/string

2016-07-14 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Thu Jul 14 07:19:11 UTC 2016

Modified Files:
src/lib/libc/string: wcscasecmp.3

Log Message:
Fix grammar and be consistent between using 0 and zero.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/wcscasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscasecmp.3
diff -u src/lib/libc/string/wcscasecmp.3:1.4 src/lib/libc/string/wcscasecmp.3:1.5
--- src/lib/libc/string/wcscasecmp.3:1.4	Wed Jul 13 06:50:02 2016
+++ src/lib/libc/string/wcscasecmp.3	Thu Jul 14 07:19:11 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wcscasecmp.3,v 1.4 2016/07/13 06:50:02 abhinav Exp $
+.\"	$NetBSD: wcscasecmp.3,v 1.5 2016/07/14 07:19:11 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -88,6 +88,6 @@ functions first appeared in
 .Sh NOTES
 If
 .Fa len
-is zero,
+is 0,
 .Fn wcsncasecmp
-returns always 0.
+always returns 0.



CVS commit: src/lib/libc/string

2016-07-13 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Jul 13 09:05:16 UTC 2016

Modified Files:
src/lib/libc/string: strcasecmp.3

Log Message:
Fix grammar and be consistent between using zero and 0.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/string/strcasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcasecmp.3
diff -u src/lib/libc/string/strcasecmp.3:1.20 src/lib/libc/string/strcasecmp.3:1.21
--- src/lib/libc/string/strcasecmp.3:1.20	Tue Jul 12 21:45:41 2016
+++ src/lib/libc/string/strcasecmp.3	Wed Jul 13 09:05:16 2016
@@ -28,7 +28,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strcasecmp.3	8.1 (Berkeley) 6/9/93
-.\"	$NetBSD: strcasecmp.3,v 1.20 2016/07/12 21:45:41 wiz Exp $
+.\"	$NetBSD: strcasecmp.3,v 1.21 2016/07/13 09:05:16 abhinav Exp $
 .\"
 .Dd July 11, 2016
 .Dt STRCASECMP 3
@@ -96,6 +96,6 @@ functions first appeared in
 .Sh NOTES
 If
 .Fa len
-is zero
+is 0
 .Fn strncasecmp
-returns always 0.
+always returns 0.



CVS commit: src/lib/libc/string

2016-07-13 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Jul 13 06:50:02 UTC 2016

Modified Files:
src/lib/libc/string: wcscasecmp.3

Log Message:
Add STANDARDS section, referencing IEEE std 1003.1-2008
ok wiz@


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcscasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscasecmp.3
diff -u src/lib/libc/string/wcscasecmp.3:1.3 src/lib/libc/string/wcscasecmp.3:1.4
--- src/lib/libc/string/wcscasecmp.3:1.3	Thu Dec 16 17:42:28 2010
+++ src/lib/libc/string/wcscasecmp.3	Wed Jul 13 06:50:02 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wcscasecmp.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
+.\"	$NetBSD: wcscasecmp.3,v 1.4 2016/07/13 06:50:02 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -31,7 +31,7 @@
 .\"
 .\" from: @(#)wcscasecmp.3	8.1 (Berkeley) 6/9/93
 .\"
-.Dd August 26, 2006
+.Dd July 13, 2016
 .Dt WCSCASECMP 3
 .Os
 .Sh NAME
@@ -71,6 +71,13 @@ compares at most
 characters.
 .Sh SEE ALSO
 .Xr wcscmp 3
+.Sh STANDARDS
+The
+.Fn wcscasecmp
+and
+.Fn wcsncasecmp
+functions conform to
+.St -p1003.1-2008 .
 .Sh HISTORY
 The
 .Fn wcscasecmp



CVS commit: src/lib/libc/string

2016-07-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jul 12 21:45:42 UTC 2016

Modified Files:
src/lib/libc/string: strcasecmp.3

Log Message:
Add missing word.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/string/strcasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcasecmp.3
diff -u src/lib/libc/string/strcasecmp.3:1.19 src/lib/libc/string/strcasecmp.3:1.20
--- src/lib/libc/string/strcasecmp.3:1.19	Tue Jul 12 16:43:53 2016
+++ src/lib/libc/string/strcasecmp.3	Tue Jul 12 21:45:41 2016
@@ -28,7 +28,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strcasecmp.3	8.1 (Berkeley) 6/9/93
-.\"	$NetBSD: strcasecmp.3,v 1.19 2016/07/12 16:43:53 abhinav Exp $
+.\"	$NetBSD: strcasecmp.3,v 1.20 2016/07/12 21:45:41 wiz Exp $
 .\"
 .Dd July 11, 2016
 .Dt STRCASECMP 3
@@ -84,7 +84,7 @@ The
 .Fn strcasecmp
 and
 .Fn strncasecmp
-conform to
+functions conform to
 .St -p1003.1-2001 .
 .Sh HISTORY
 The



CVS commit: src/lib/libc/string

2016-07-12 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Tue Jul 12 16:43:53 UTC 2016

Modified Files:
src/lib/libc/string: strcasecmp.3

Log Message:
Fix sentence


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/string/strcasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcasecmp.3
diff -u src/lib/libc/string/strcasecmp.3:1.18 src/lib/libc/string/strcasecmp.3:1.19
--- src/lib/libc/string/strcasecmp.3:1.18	Tue Jul 12 15:45:24 2016
+++ src/lib/libc/string/strcasecmp.3	Tue Jul 12 16:43:53 2016
@@ -28,7 +28,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strcasecmp.3	8.1 (Berkeley) 6/9/93
-.\"	$NetBSD: strcasecmp.3,v 1.18 2016/07/12 15:45:24 abhinav Exp $
+.\"	$NetBSD: strcasecmp.3,v 1.19 2016/07/12 16:43:53 abhinav Exp $
 .\"
 .Dd July 11, 2016
 .Dt STRCASECMP 3
@@ -69,6 +69,7 @@ is greater than
 .Pp
 The
 .Fn strncasecmp
+function
 compares at most
 .Fa len
 characters.



CVS commit: src/lib/libc/string

2016-07-12 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Tue Jul 12 15:45:24 UTC 2016

Modified Files:
src/lib/libc/string: strcasecmp.3

Log Message:
Add STANDARDS section.
It is part of IEEE Std 1003.1-2001 and 2008, both, but there doesn't seem to be
any difference between the two versions, therefore referencing the older 
standard.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/strcasecmp.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcasecmp.3
diff -u src/lib/libc/string/strcasecmp.3:1.17 src/lib/libc/string/strcasecmp.3:1.18
--- src/lib/libc/string/strcasecmp.3:1.17	Mon Oct 16 08:48:45 2006
+++ src/lib/libc/string/strcasecmp.3	Tue Jul 12 15:45:24 2016
@@ -28,9 +28,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\" from: @(#)strcasecmp.3	8.1 (Berkeley) 6/9/93
-.\"	$NetBSD: strcasecmp.3,v 1.17 2006/10/16 08:48:45 wiz Exp $
+.\"	$NetBSD: strcasecmp.3,v 1.18 2016/07/12 15:45:24 abhinav Exp $
 .\"
-.Dd June 9, 1993
+.Dd July 11, 2016
 .Dt STRCASECMP 3
 .Os
 .Sh NAME
@@ -78,6 +78,13 @@ characters.
 .Xr strcmp 3 ,
 .Xr strcoll 3 ,
 .Xr strxfrm 3
+.Sh STANDARDS
+The
+.Fn strcasecmp
+and
+.Fn strncasecmp
+conform to
+.St -p1003.1-2001 .
 .Sh HISTORY
 The
 .Fn strcasecmp



CVS commit: src/lib/libc/string

2015-06-19 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Jun 20 04:18:00 UTC 2015

Modified Files:
src/lib/libc/string: bcopy.3

Log Message:
PR 49988 Kamil Rytarowski: fix pasto


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/string/bcopy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/bcopy.3
diff -u src/lib/libc/string/bcopy.3:1.14 src/lib/libc/string/bcopy.3:1.15
--- src/lib/libc/string/bcopy.3:1.14	Sat May  5 21:24:19 2012
+++ src/lib/libc/string/bcopy.3	Sat Jun 20 04:18:00 2015
@@ -29,7 +29,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)bcopy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: bcopy.3,v 1.14 2012/05/05 21:24:19 dholland Exp $
+.\	$NetBSD: bcopy.3,v 1.15 2015/06/20 04:18:00 dholland Exp $
 .\
 .Dd May 5, 2012
 .Dt BCOPY 3
@@ -79,7 +79,7 @@ arguments in the opposite order from the
 .Xr strncpy 3
 .Sh STANDARDS
 The
-.Fn bcmp
+.Fn bcopy
 function conforms to
 .St -p1003.1-2001 .
 The



CVS commit: src/lib/libc/string

2015-05-09 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat May  9 19:01:53 UTC 2015

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Update HISTORY from OpenBSD: strerror from 4.3 Reno, perror from v4.
(this page was claiming both were from 4.4, which is clearly rubbish)


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.17 src/lib/libc/string/strerror.3:1.18
--- src/lib/libc/string/strerror.3:1.17	Mon Oct 25 07:37:11 2010
+++ src/lib/libc/string/strerror.3	Sat May  9 19:01:53 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: strerror.3,v 1.17 2010/10/25 07:37:11 wiz Exp $
+.\ $NetBSD: strerror.3,v 1.18 2015/05/09 19:01:53 dholland Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ @(#)strerror.3	8.1 (Berkeley) 6/9/93
-.Dd October 24, 2010
+.Dd May 9, 2015
 .Dt STRERROR 3
 .Os
 .Sh NAME
@@ -171,11 +171,13 @@ function conforms to
 .St -p1003.1-2001 .
 .Sh HISTORY
 The
-.Fn strerror
-and
 .Fn perror
-functions first appeared in
-.Bx 4.4 .
+function first appeared in
+.At v4 .
+The
+.Fn strerror
+function first appeared in
+.Bx 4.3 Reno .
 The
 .Fn strerror_r
 function first appeared in



CVS commit: src/lib/libc/string

2015-04-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Apr  1 15:20:58 UTC 2015

Modified Files:
src/lib/libc/string: strcpy.3

Log Message:
clarify what happens when strings overlap.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/string/strcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcpy.3
diff -u src/lib/libc/string/strcpy.3:1.20 src/lib/libc/string/strcpy.3:1.21
--- src/lib/libc/string/strcpy.3:1.20	Sat May  2 05:37:32 2009
+++ src/lib/libc/string/strcpy.3	Wed Apr  1 11:20:58 2015
@@ -30,9 +30,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strcpy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strcpy.3,v 1.20 2009/05/02 09:37:32 wiz Exp $
+.\	$NetBSD: strcpy.3,v 1.21 2015/04/01 15:20:58 christos Exp $
 .\
-.Dd May 1, 2009
+.Dd April 1, 2015
 .Dt STRCPY 3
 .Os
 .Sh NAME
@@ -92,6 +92,10 @@ Otherwise,
 is
 .Em not
 terminated.
+.Pp
+For portability the source and destination strings should not overlap, because
+implementations are allowed to optimize character movement and the standard
+specify that the results are undefined if they do.
 .Sh RETURN VALUES
 The
 .Fn strcpy



CVS commit: src/lib/libc/string

2015-04-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Apr  1 15:45:00 UTC 2015

Modified Files:
src/lib/libc/string: strcpy.3

Log Message:
grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/string/strcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcpy.3
diff -u src/lib/libc/string/strcpy.3:1.21 src/lib/libc/string/strcpy.3:1.22
--- src/lib/libc/string/strcpy.3:1.21	Wed Apr  1 11:20:58 2015
+++ src/lib/libc/string/strcpy.3	Wed Apr  1 11:45:00 2015
@@ -30,7 +30,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strcpy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strcpy.3,v 1.21 2015/04/01 15:20:58 christos Exp $
+.\	$NetBSD: strcpy.3,v 1.22 2015/04/01 15:45:00 christos Exp $
 .\
 .Dd April 1, 2015
 .Dt STRCPY 3
@@ -95,7 +95,7 @@ terminated.
 .Pp
 For portability the source and destination strings should not overlap, because
 implementations are allowed to optimize character movement and the standard
-specify that the results are undefined if they do.
+specifies that the results are undefined if they do.
 .Sh RETURN VALUES
 The
 .Fn strcpy



CVS commit: src/lib/libc/string

2015-04-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Apr  1 20:18:17 UTC 2015

Modified Files:
src/lib/libc/string: strcpy.3

Log Message:
Strengthen prohibition against overlapping in strcpy(3).


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/string/strcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcpy.3
diff -u src/lib/libc/string/strcpy.3:1.22 src/lib/libc/string/strcpy.3:1.23
--- src/lib/libc/string/strcpy.3:1.22	Wed Apr  1 15:45:00 2015
+++ src/lib/libc/string/strcpy.3	Wed Apr  1 20:18:17 2015
@@ -30,7 +30,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strcpy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strcpy.3,v 1.22 2015/04/01 15:45:00 christos Exp $
+.\	$NetBSD: strcpy.3,v 1.23 2015/04/01 20:18:17 riastradh Exp $
 .\
 .Dd April 1, 2015
 .Dt STRCPY 3
@@ -93,9 +93,11 @@ is
 .Em not
 terminated.
 .Pp
-For portability the source and destination strings should not overlap, because
-implementations are allowed to optimize character movement and the standard
-specifies that the results are undefined if they do.
+The strings
+.Fa src
+and
+.Fa dst
+may not overlap.
 .Sh RETURN VALUES
 The
 .Fn strcpy



CVS commit: src/lib/libc/string

2015-03-23 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Mon Mar 23 07:41:16 UTC 2015

Modified Files:
src/lib/libc/string: consttime_memequal.3

Log Message:
Explain why there is no consttime_memcmp().

Inspired by a patch from Kamil Rytarowski.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/consttime_memequal.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/consttime_memequal.3
diff -u src/lib/libc/string/consttime_memequal.3:1.4 src/lib/libc/string/consttime_memequal.3:1.5
--- src/lib/libc/string/consttime_memequal.3:1.4	Fri Nov 14 22:46:34 2014
+++ src/lib/libc/string/consttime_memequal.3	Mon Mar 23 07:41:16 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: consttime_memequal.3,v 1.4 2014/11/14 22:46:34 wiz Exp $
+.\	$NetBSD: consttime_memequal.3,v 1.5 2015/03/23 07:41:16 apb Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd November 14, 2014
+.Dd March 23, 2015
 .Dt CONSTTIME_MEMEQUAL 3
 .Os
 .Sh NAME
@@ -78,6 +78,13 @@ does not return a lexicographic ordering
 and
 .Fa b2 ;
 it tells only whether they are equal.
+.Nx
+does not provide a
+.Fn consttime_memcmp
+function, because all known use cases that require
+.Sq constant time
+memory comparison also require only comparison for equality,
+not lexicographic ordering.
 .Sh SEE ALSO
 .Xr explicit_memset 3 ,
 .Xr memcmp 3



CVS commit: src/lib/libc/string

2014-11-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov 14 16:43:57 UTC 2014

Modified Files:
src/lib/libc/string: consttime_memequal.3

Log Message:
Commit to returning 1, not any nonzero value.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/consttime_memequal.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/consttime_memequal.3
diff -u src/lib/libc/string/consttime_memequal.3:1.2 src/lib/libc/string/consttime_memequal.3:1.3
--- src/lib/libc/string/consttime_memequal.3:1.2	Wed Aug 28 15:24:41 2013
+++ src/lib/libc/string/consttime_memequal.3	Fri Nov 14 16:43:57 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: consttime_memequal.3,v 1.2 2013/08/28 15:24:41 riastradh Exp $
+.\	$NetBSD: consttime_memequal.3,v 1.3 2014/11/14 16:43:57 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd August 28, 2013
+.Dd November 14, 2013
 .Dt CONSTTIME_MEMEQUAL 3
 .Os
 .Sh NAME
@@ -48,8 +48,8 @@ bytes of memory at
 .Fa b1
 and
 .Fa b2
-for equality, returning zero if they are distinct and nonzero if they
-are identical.
+for equality, returning 0 if they are distinct and 1 if they are
+identical.
 .Pp
 The time taken by
 .Fn consttime_memequal



CVS commit: src/lib/libc/string

2014-11-14 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Nov 14 22:46:34 UTC 2014

Modified Files:
src/lib/libc/string: consttime_memequal.3

Log Message:
bump year


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/consttime_memequal.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/consttime_memequal.3
diff -u src/lib/libc/string/consttime_memequal.3:1.3 src/lib/libc/string/consttime_memequal.3:1.4
--- src/lib/libc/string/consttime_memequal.3:1.3	Fri Nov 14 16:43:57 2014
+++ src/lib/libc/string/consttime_memequal.3	Fri Nov 14 22:46:34 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: consttime_memequal.3,v 1.3 2014/11/14 16:43:57 riastradh Exp $
+.\	$NetBSD: consttime_memequal.3,v 1.4 2014/11/14 22:46:34 wiz Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd November 14, 2013
+.Dd November 14, 2014
 .Dt CONSTTIME_MEMEQUAL 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/string

2014-09-24 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Sep 24 18:43:21 UTC 2014

Modified Files:
src/lib/libc/string: strstr.3

Log Message:
NUL byte instead of null byte.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/strstr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strstr.3
diff -u src/lib/libc/string/strstr.3:1.11 src/lib/libc/string/strstr.3:1.12
--- src/lib/libc/string/strstr.3:1.11	Wed Sep 24 18:16:37 2014
+++ src/lib/libc/string/strstr.3	Wed Sep 24 18:43:21 2014
@@ -31,7 +31,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strstr.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strstr.3,v 1.11 2014/09/24 18:16:37 christos Exp $
+.\	$NetBSD: strstr.3,v 1.12 2014/09/24 18:43:21 wiz Exp $
 .\
 .Dd September 24, 2014
 .Dt STRSTR 3
@@ -66,7 +66,7 @@ but ignores the case of both strings.
 The
 .Fn strnstr
 function
-locates the first occurrence of the null-terminated string
+locates the first occurrence of the NUL-terminated string
 .Fa little
 in the string
 .Fa big ,



CVS commit: src/lib/libc/string

2014-09-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 24 22:21:33 UTC 2014

Added Files:
src/lib/libc/string: strnstr.c

Log Message:
add strnstr.c from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/libc/string/strnstr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/libc/string/strnstr.c
diff -u /dev/null src/lib/libc/string/strnstr.c:1.1
--- /dev/null	Wed Sep 24 18:21:33 2014
+++ src/lib/libc/string/strnstr.c	Wed Sep 24 18:21:33 2014
@@ -0,0 +1,71 @@
+/*	$NetBSD: strnstr.c,v 1.1 2014/09/24 22:21:33 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2001 Mike Barcroft m...@freebsd.org
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+#if defined(LIBC_SCCS)  !defined(lint)
+#if 0
+static char sccsid[] = @(#)strstr.c	8.1 (Berkeley) 6/4/93;
+#else
+__RCSID($NetBSD: strnstr.c,v 1.1 2014/09/24 22:21:33 christos Exp $);
+#endif
+#endif /* LIBC_SCCS and not lint */
+/* FreeBSD: head/lib/libc/string/strnstr.c 251069 2013-05-28 20:57:40Z emaste */
+
+#include string.h
+
+/*
+ * Find the first occurrence of find in s, where the search is limited to the
+ * first slen characters of s.
+ */
+char *
+strnstr(const char *s, const char *find, size_t slen)
+{
+	char c, sc;
+	size_t len;
+
+	if ((c = *find++) != '\0') {
+		len = strlen(find);
+		do {
+			do {
+if (slen--  1 || (sc = *s++) == '\0')
+	return NULL;
+			} while (sc != c);
+			if (len  slen)
+return NULL;
+		} while (strncmp(s, find, len) != 0);
+		s--;
+	}
+	return __UNCONST(s);
+}



CVS commit: src/lib/libc/string

2014-06-23 Thread Mateusz Kocielski
Module Name:src
Committed By:   shm
Date:   Mon Jun 23 10:43:25 UTC 2014

Modified Files:
src/lib/libc/string: bm.c

Log Message:
PR/42032 fixed overrun in bm_exec(), free(3) clean ups


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/bm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/bm.c
diff -u src/lib/libc/string/bm.c:1.12 src/lib/libc/string/bm.c:1.13
--- src/lib/libc/string/bm.c:1.12	Mon Jun 25 22:32:46 2012
+++ src/lib/libc/string/bm.c	Mon Jun 23 10:43:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bm.c,v 1.12 2012/06/25 22:32:46 abs Exp $	*/
+/*	$NetBSD: bm.c,v 1.13 2014/06/23 10:43:25 shm Exp $	*/
 
 /*-
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)bm.c	8.7 (Berkeley) 6/21/94;
 #else
-__RCSID($NetBSD: bm.c,v 1.12 2012/06/25 22:32:46 abs Exp $);
+__RCSID($NetBSD: bm.c,v 1.13 2014/06/23 10:43:25 shm Exp $);
 #endif
 #endif /* LIBC_SCCS  not lint */
 
@@ -162,10 +162,8 @@ bm_free(bm_pat *pat)
 
 	_DIAGASSERT(pat != NULL);
 
-	if (pat-pat != NULL)
-		free(pat-pat);
-	if (pat-delta != NULL)
-		free(pat-delta);
+	free(pat-pat);
+	free(pat-delta);
 	free(pat);
 }
 
@@ -194,7 +192,7 @@ bm_exec(bm_pat *pat, u_char *base, size_
 	e = base + n - 3 * pat-patlen;
 	while (s  e) {
 		k = d0[*s];		/* ufast skip loop */
-		while (k) {
+		while (k  s  e) {
 			k = d0[*(s += k)];
 			k = d0[*(s += k)];
 		}



CVS commit: src/lib/libc/string

2013-12-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 27 20:25:11 UTC 2013

Removed Files:
src/lib/libc/string: strncat.c

Log Message:
moved to common


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r0 src/lib/libc/string/strncat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/string

2013-11-06 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Wed Nov  6 21:05:27 UTC 2013

Modified Files:
src/lib/libc/string: stpcpy.c stpncpy.c

Log Message:
Fix build problems.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/stpcpy.c \
src/lib/libc/string/stpncpy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/stpcpy.c
diff -u src/lib/libc/string/stpcpy.c:1.1 src/lib/libc/string/stpcpy.c:1.2
--- src/lib/libc/string/stpcpy.c:1.1	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/stpcpy.c	Wed Nov  6 21:05:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: stpcpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $	*/
+/*	$NetBSD: stpcpy.c,v 1.2 2013/11/06 21:05:27 tron Exp $	*/
 
 /*
  * Copyright (c) 1999
@@ -36,13 +36,17 @@
 #if 0
 static char sccsid[] = @(#)strcpy.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: stpcpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $);
+__RCSID($NetBSD: stpcpy.c,v 1.2 2013/11/06 21:05:27 tron Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 /* FreeBSD: src/lib/libc/string/stpcpy.c,v 1.2 2009/02/28 06:05:37 das Exp */
 
 #include string.h
 
+#ifdef _FORTIFY_SOURCE
+#undef stpcpy
+#endif
+
 char *
 stpcpy(char * __restrict to, const char * __restrict from)
 {
Index: src/lib/libc/string/stpncpy.c
diff -u src/lib/libc/string/stpncpy.c:1.1 src/lib/libc/string/stpncpy.c:1.2
--- src/lib/libc/string/stpncpy.c:1.1	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/stpncpy.c	Wed Nov  6 21:05:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: stpncpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $	*/
+/*	$NetBSD: stpncpy.c,v 1.2 2013/11/06 21:05:27 tron Exp $	*/
 
 /*-
  * Copyright (c) 2009 David Schultz d...@freebsd.org
@@ -28,12 +28,16 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: stpncpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $);
+__RCSID($NetBSD: stpncpy.c,v 1.2 2013/11/06 21:05:27 tron Exp $);
 #endif /* LIBC_SCCS and not lint */
 /* FreeBSD: src/lib/libc/string/stpncpy.c,v 1.1 2009/02/28 06:00:58 das Exp */
 
 #include string.h
 
+#ifdef _FORTIFY_SOURCE
+#undef stpncpy
+#endif
+
 char *
 stpncpy(char * __restrict dst, const char * __restrict src, size_t n)
 {



CVS commit: src/lib/libc/string

2013-09-02 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Sep  2 07:59:32 UTC 2013

Modified Files:
src/lib/libc/string: strerror.c

Log Message:
Missing alias for strerror_l.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/string/strerror.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.c
diff -u src/lib/libc/string/strerror.c:1.15 src/lib/libc/string/strerror.c:1.16
--- src/lib/libc/string/strerror.c:1.15	Mon Aug 19 13:03:12 2013
+++ src/lib/libc/string/strerror.c	Mon Sep  2 07:59:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror.c,v 1.15 2013/08/19 13:03:12 joerg Exp $	*/
+/*	$NetBSD: strerror.c,v 1.16 2013/09/02 07:59:32 joerg Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strerror.c,v 1.15 2013/08/19 13:03:12 joerg Exp $);
+__RCSID($NetBSD: strerror.c,v 1.16 2013/09/02 07:59:32 joerg Exp $);
 
 #define __SETLOCALE_SOURCE__
 
@@ -47,6 +47,8 @@ __RCSID($NetBSD: strerror.c,v 1.15 2013
 #endif
 #include setlocale_local.h
 
+__weak_alias(strerror_l, _strerror_l)
+
 __aconst char *
 strerror(int num)
 {



CVS commit: src/lib/libc/string

2013-08-19 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Aug 19 10:59:39 UTC 2013

Modified Files:
src/lib/libc/string: Makefile.inc
Removed Files:
src/lib/libc/string: _strerror_r.c _strlcat.c _strlcpy.c

Log Message:
GC __indr_reference wrappers.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/lib/libc/string/Makefile.inc
cvs rdiff -u -r1.3 -r0 src/lib/libc/string/_strerror_r.c
cvs rdiff -u -r1.5 -r0 src/lib/libc/string/_strlcat.c \
src/lib/libc/string/_strlcpy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Makefile.inc
diff -u src/lib/libc/string/Makefile.inc:1.78 src/lib/libc/string/Makefile.inc:1.79
--- src/lib/libc/string/Makefile.inc:1.78	Mon Jun 24 04:21:20 2013
+++ src/lib/libc/string/Makefile.inc	Mon Aug 19 10:59:39 2013
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-#	$NetBSD: Makefile.inc,v 1.78 2013/06/24 04:21:20 riastradh Exp $
+#	$NetBSD: Makefile.inc,v 1.79 2013/08/19 10:59:39 joerg Exp $
 
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -34,9 +34,6 @@ CPPFLAGS.wcscmp.c+=	-I${LIBCDIR}/locale
 CPPFLAGS.wcsncmp.c+=	-I${LIBCDIR}/locale
 CPPFLAGS.wmemcmp.c+=	-I${LIBCDIR}/locale
 
-# namespace protection wrappers
-SRCS+=	_strlcat.c _strlcpy.c _strerror_r.c
-
 .include ${ARCHDIR}/string/Makefile.inc
 
 MAN+=	bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 consttime_memequal.3 \



CVS commit: src/lib/libc/string

2013-06-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 23 16:44:06 UTC 2013

Modified Files:
src/lib/libc/string: memcmp.3 memset.3
Added Files:
src/lib/libc/string: consttime_bcmp.3 explicit_bzero.3

Log Message:
Add man pages and xrefs for consttime_bcmp and explicit_bzero.

ok wiz


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/libc/string/consttime_bcmp.3 \
src/lib/libc/string/explicit_bzero.3
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/string/memcmp.3 \
src/lib/libc/string/memset.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/memcmp.3
diff -u src/lib/libc/string/memcmp.3:1.9 src/lib/libc/string/memcmp.3:1.10
--- src/lib/libc/string/memcmp.3:1.9	Thu Aug  7 16:43:48 2003
+++ src/lib/libc/string/memcmp.3	Sun Jun 23 16:44:06 2013
@@ -30,9 +30,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)memcmp.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: memcmp.3,v 1.9 2003/08/07 16:43:48 agc Exp $
+.\	$NetBSD: memcmp.3,v 1.10 2013/06/23 16:44:06 riastradh Exp $
 .\
-.Dd June 4, 1993
+.Dd June 23, 2013
 .Dt MEMCMP 3
 .Os
 .Sh NAME
@@ -67,8 +67,18 @@ is greater than
 .Sq Li \\e0 ,
 for example).
 Zero-length strings are always identical.
+.Pp
+Do not use
+.Fn memcmp
+to compare cryptographic secrets, because the time it takes varies
+depending on how many bytes are the same, and thus leaks information
+about the two strings by a timing side channel.
+To compare secrets, hashes, message authentication codes, etc., use
+.Xr consttime_bcmp 3
+instead.
 .Sh SEE ALSO
 .Xr bcmp 3 ,
+.Xr consttime_bcmp 3 ,
 .Xr strcasecmp 3 ,
 .Xr strcmp 3 ,
 .Xr strcoll 3 ,
Index: src/lib/libc/string/memset.3
diff -u src/lib/libc/string/memset.3:1.9 src/lib/libc/string/memset.3:1.10
--- src/lib/libc/string/memset.3:1.9	Thu Aug  7 16:43:49 2003
+++ src/lib/libc/string/memset.3	Sun Jun 23 16:44:06 2013
@@ -30,9 +30,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)memset.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: memset.3,v 1.9 2003/08/07 16:43:49 agc Exp $
+.\	$NetBSD: memset.3,v 1.10 2013/06/23 16:44:06 riastradh Exp $
 .\
-.Dd June 4, 1993
+.Dd June 23, 2013
 .Dt MEMSET 3
 .Os
 .Sh NAME
@@ -60,8 +60,17 @@ The
 function
 returns the original value of
 .Fa b .
+.Pp
+Note that the compiler may optimize away a call to
+.Fn memset
+if it can prove that the string will not be used by the program again,
+for example if it is allocated on the stack and about to out of scope.
+If you want to guarantee that zeros are written to memory, for example
+to sanitize a buffer holding a cryptographic secret, use
+.Xr explicit_bzero .
 .Sh SEE ALSO
 .Xr bzero 3 ,
+.Xr explicit_bzero 3 ,
 .Xr swab 3
 .Sh STANDARDS
 The

Added files:

Index: src/lib/libc/string/consttime_bcmp.3
diff -u /dev/null src/lib/libc/string/consttime_bcmp.3:1.1
--- /dev/null	Sun Jun 23 16:44:06 2013
+++ src/lib/libc/string/consttime_bcmp.3	Sun Jun 23 16:44:06 2013
@@ -0,0 +1,88 @@
+.\	$NetBSD: consttime_bcmp.3,v 1.1 2013/06/23 16:44:06 riastradh Exp $
+.\
+.\ Copyright (c) 2013 The NetBSD Foundation, Inc.
+.\ All rights reserved.
+.\
+.\ This documentation is derived from text contributed to The NetBSD
+.\ Foundation by Taylor R. Campbell.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\ PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\ POSSIBILITY OF SUCH DAMAGE.
+.\
+.Dd June 23, 2013
+.Dt CONSTTIME_BCMP 3
+.Os
+.Sh NAME
+.Nm consttime_bcmp
+.Nd compare byte strings for equality without timing leaks
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In string.h
+.Ft int
+.Fn consttime_bcmp void *b1 void *b2 size_t len
+.Sh DESCRIPTION
+The
+.Fn consttime_bcmp
+function compares
+.Fa len
+bytes of memory at
+.Fa b1
+and
+.Fa b2
+for equality, returning zero if they are identical 

CVS commit: src/lib/libc/string

2012-12-28 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Dec 28 13:53:12 UTC 2012

Modified Files:
src/lib/libc/string: wcsdup.3

Log Message:
Add wide to description. From OpenBSD via Ingo Schwarze.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcsdup.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcsdup.3
diff -u src/lib/libc/string/wcsdup.3:1.3 src/lib/libc/string/wcsdup.3:1.4
--- src/lib/libc/string/wcsdup.3:1.3	Thu Dec 16 17:42:28 2010
+++ src/lib/libc/string/wcsdup.3	Fri Dec 28 13:53:12 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
+.\	$NetBSD: wcsdup.3,v 1.4 2012/12/28 13:53:12 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .Os
 .Sh NAME
 .Nm wcsdup
-.Nd save a copy of a string
+.Nd save a copy of a wide string
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS



CVS commit: src/lib/libc/string

2012-05-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat May  5 21:14:55 UTC 2012

Modified Files:
src/lib/libc/string: index.3 rindex.3

Log Message:
Describe these as obsolete.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/index.3
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/rindex.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/index.3
diff -u src/lib/libc/string/index.3:1.13 src/lib/libc/string/index.3:1.14
--- src/lib/libc/string/index.3:1.13	Thu Apr 29 06:54:26 2010
+++ src/lib/libc/string/index.3	Sat May  5 21:14:55 2012
@@ -28,7 +28,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)index.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: index.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $
+.\	$NetBSD: index.3,v 1.14 2012/05/05 21:14:55 dholland Exp $
 .\
 .Dd April 29, 2010
 .Dt INDEX 3
@@ -52,6 +52,11 @@ locates the first character matching
 .Em char )
 in the nul-terminated string
 .Fa s .
+.Pp
+This function is obsolete.
+The equivalent function
+.Xr strchr 3
+should be used instead.
 .Sh RETURN VALUES
 A pointer to the character is returned if it is found; otherwise
 .Dv NULL

Index: src/lib/libc/string/rindex.3
diff -u src/lib/libc/string/rindex.3:1.12 src/lib/libc/string/rindex.3:1.13
--- src/lib/libc/string/rindex.3:1.12	Thu Apr 29 06:54:26 2010
+++ src/lib/libc/string/rindex.3	Sat May  5 21:14:55 2012
@@ -28,7 +28,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)rindex.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: rindex.3,v 1.12 2010/04/29 06:54:26 jruoho Exp $
+.\	$NetBSD: rindex.3,v 1.13 2012/05/05 21:14:55 dholland Exp $
 .\
 .Dd April 29, 2010
 .Dt RINDEX 3
@@ -53,6 +53,11 @@ matching
 .Em char )
 in the nul-terminated string
 .Fa s .
+.Pp
+This function is obsolete.
+The equivalent function
+.Xr strrchr 3
+should be used instead.
 .Sh RETURN VALUES
 A pointer to the character is returned if it is found; otherwise
 .Dv NULL



CVS commit: src/lib/libc/string

2012-05-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat May  5 21:18:43 UTC 2012

Modified Files:
src/lib/libc/string: index.3 rindex.3

Log Message:
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/string/index.3
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/rindex.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/index.3
diff -u src/lib/libc/string/index.3:1.14 src/lib/libc/string/index.3:1.15
--- src/lib/libc/string/index.3:1.14	Sat May  5 21:14:55 2012
+++ src/lib/libc/string/index.3	Sat May  5 21:18:43 2012
@@ -28,9 +28,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)index.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: index.3,v 1.14 2012/05/05 21:14:55 dholland Exp $
+.\	$NetBSD: index.3,v 1.15 2012/05/05 21:18:43 dholland Exp $
 .\
-.Dd April 29, 2010
+.Dd May 5, 2012
 .Dt INDEX 3
 .Os
 .Sh NAME

Index: src/lib/libc/string/rindex.3
diff -u src/lib/libc/string/rindex.3:1.13 src/lib/libc/string/rindex.3:1.14
--- src/lib/libc/string/rindex.3:1.13	Sat May  5 21:14:55 2012
+++ src/lib/libc/string/rindex.3	Sat May  5 21:18:43 2012
@@ -28,9 +28,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)rindex.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: rindex.3,v 1.13 2012/05/05 21:14:55 dholland Exp $
+.\	$NetBSD: rindex.3,v 1.14 2012/05/05 21:18:43 dholland Exp $
 .\
-.Dd April 29, 2010
+.Dd May 5, 2012
 .Dt RINDEX 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/string

2012-05-05 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat May  5 21:24:19 UTC 2012

Modified Files:
src/lib/libc/string: bcmp.3 bcopy.3

Log Message:
Mark these obsolete as well.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/bcmp.3 \
src/lib/libc/string/bcopy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/bcmp.3
diff -u src/lib/libc/string/bcmp.3:1.13 src/lib/libc/string/bcmp.3:1.14
--- src/lib/libc/string/bcmp.3:1.13	Thu Apr 29 06:54:26 2010
+++ src/lib/libc/string/bcmp.3	Sat May  5 21:24:19 2012
@@ -28,9 +28,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)bcmp.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: bcmp.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $
+.\	$NetBSD: bcmp.3,v 1.14 2012/05/05 21:24:19 dholland Exp $
 .\
-.Dd April 29, 2010
+.Dd May 5, 2012
 .Dt BCMP 3
 .Os
 .Sh NAME
@@ -57,6 +57,11 @@ bytes long.
 Zero-length strings are always identical.
 .Pp
 The strings may overlap.
+.Pp
+This function is obsolete.
+The equivalent function
+.Xr memcmp 3
+should be used instead.
 .Sh SEE ALSO
 .Xr memcmp 3 ,
 .Xr strcasecmp 3 ,
Index: src/lib/libc/string/bcopy.3
diff -u src/lib/libc/string/bcopy.3:1.13 src/lib/libc/string/bcopy.3:1.14
--- src/lib/libc/string/bcopy.3:1.13	Thu Apr 29 07:27:30 2010
+++ src/lib/libc/string/bcopy.3	Sat May  5 21:24:19 2012
@@ -29,9 +29,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)bcopy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: bcopy.3,v 1.13 2010/04/29 07:27:30 wiz Exp $
+.\	$NetBSD: bcopy.3,v 1.14 2012/05/05 21:24:19 dholland Exp $
 .\
-.Dd April 29, 2010
+.Dd May 5, 2012
 .Dt BCOPY 3
 .Os
 .Sh NAME
@@ -57,6 +57,20 @@ The two strings may overlap.
 If
 .Fa len
 is zero, no bytes are copied.
+.Pp
+This function is obsolete.
+The functions
+.Xr memcpy 3
+and/or
+.Xr memmove 3
+should be used instead.
+Note that
+.Fn bcopy
+takes its
+.Fa src
+and
+.Fa dst
+arguments in the opposite order from these.
 .Sh SEE ALSO
 .Xr memccpy 3 ,
 .Xr memcpy 3 ,



CVS commit: src/lib/libc/string

2012-03-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 21 00:35:50 UTC 2012

Modified Files:
src/lib/libc/string: strcspn.c strspn.c

Log Message:
size_t - uint8_t


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/strcspn.c \
src/lib/libc/string/strspn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcspn.c
diff -u src/lib/libc/string/strcspn.c:1.17 src/lib/libc/string/strcspn.c:1.18
--- src/lib/libc/string/strcspn.c:1.17	Thu Jul 30 17:42:06 2009
+++ src/lib/libc/string/strcspn.c	Tue Mar 20 20:35:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $	*/
+/*	$NetBSD: strcspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $);
+__RCSID($NetBSD: strcspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $);
 
 #include assert.h
 #include inttypes.h
@@ -39,7 +39,7 @@ __RCSID($NetBSD: strcspn.c,v 1.17 2009/
 size_t
 strcspn(const char *s, const char *charset)
 {
-	static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+	static const uint8_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
 	const char *t;
 	uint8_t set[32];
 #define UC(a) ((unsigned int)(unsigned char)(a))
Index: src/lib/libc/string/strspn.c
diff -u src/lib/libc/string/strspn.c:1.17 src/lib/libc/string/strspn.c:1.18
--- src/lib/libc/string/strspn.c:1.17	Thu Jul 30 17:42:06 2009
+++ src/lib/libc/string/strspn.c	Tue Mar 20 20:35:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $	*/
+/*	$NetBSD: strspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $);
+__RCSID($NetBSD: strspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $);
 
 #include assert.h
 #include inttypes.h
@@ -38,7 +38,7 @@ __RCSID($NetBSD: strspn.c,v 1.17 2009/0
 size_t
 strspn(const char *s, const char *charset)
 {
-	static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+	static const uint8_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
 	uint8_t set[32];
 	const char *t;
 #define UC(a) ((unsigned int)(unsigned char)(a))



CVS commit: src/lib/libc/string

2011-11-25 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Fri Nov 25 09:00:51 UTC 2011

Modified Files:
src/lib/libc/string: wcscspn_bloom.h

Log Message:
Add explicit casts to make lint happy and fix the NetBSD/i386 build.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/wcscspn_bloom.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscspn_bloom.h
diff -u src/lib/libc/string/wcscspn_bloom.h:1.1 src/lib/libc/string/wcscspn_bloom.h:1.2
--- src/lib/libc/string/wcscspn_bloom.h:1.1	Thu Nov 24 18:44:25 2011
+++ src/lib/libc/string/wcscspn_bloom.h	Fri Nov 25 09:00:51 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcscspn_bloom.h,v 1.1 2011/11/24 18:44:25 joerg Exp $	*/
+/*	$NetBSD: wcscspn_bloom.h,v 1.2 2011/11/25 09:00:51 tron Exp $	*/
 
 /*-
  * Copyright (c) 2011 Joerg Sonnenberger,
@@ -50,8 +50,8 @@ wcscspn_bloom1(size_t x)
 static inline size_t
 wcscspn_bloom2(size_t x)
 {
-	return (uint32_t)(x * 2654435761U) /
-	(0x1ULL / (BLOOM_MASK + 1));
+	return (size_t)((uint32_t)(x * 2654435761U) /
+	(0x1ULL / (BLOOM_MASK + 1)));
 }
 
 static inline void
@@ -62,9 +62,9 @@ wcsspn_bloom_init(size_t *bloom, const w
 	memset(bloom, 0, BLOOM_SIZE);
 	do {
 		val = wcscspn_bloom1((size_t)*charset);
-		bloom[val / BLOOM_DIV] |= 1ULL  (val % BLOOM_DIV);
+		bloom[val / BLOOM_DIV] |= (size_t)(1ULL  (val % BLOOM_DIV));
 		val = wcscspn_bloom2((size_t)*charset);
-		bloom[val / BLOOM_DIV] |= 1ULL  (val % BLOOM_DIV);
+		bloom[val / BLOOM_DIV] |= (size_t)(1ULL  (val % BLOOM_DIV));
 	}
 	while (*++charset);
 }



CVS commit: src/lib/libc/string

2011-11-25 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Nov 25 16:46:56 UTC 2011

Modified Files:
src/lib/libc/string: wcscspn_bloom.h

Log Message:
Use CHAR_BIT; don't hardwire 8. Fix logic slightly to work with arbitrary
CHAR_BIT. Compiler output unchanged (on amd64).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/wcscspn_bloom.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscspn_bloom.h
diff -u src/lib/libc/string/wcscspn_bloom.h:1.2 src/lib/libc/string/wcscspn_bloom.h:1.3
--- src/lib/libc/string/wcscspn_bloom.h:1.2	Fri Nov 25 09:00:51 2011
+++ src/lib/libc/string/wcscspn_bloom.h	Fri Nov 25 16:46:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcscspn_bloom.h,v 1.2 2011/11/25 09:00:51 tron Exp $	*/
+/*	$NetBSD: wcscspn_bloom.h,v 1.3 2011/11/25 16:46:56 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2011 Joerg Sonnenberger,
@@ -36,22 +36,24 @@
  * multiplication.
  */
 
+#include limits.h
+
 #define	BLOOM_SIZE		64
 #define	BLOOM_ARRAY_SIZE	(BLOOM_SIZE / sizeof(size_t))
-#define	BLOOM_MASK		(BLOOM_SIZE * 8 - 1)
-#define	BLOOM_DIV		(sizeof(size_t) * 8)
+#define	BLOOM_BITS		(BLOOM_SIZE * CHAR_BIT)
+#define	BLOOM_DIV		(sizeof(size_t) * CHAR_BIT)
 
 static inline size_t
 wcscspn_bloom1(size_t x)
 {
-	return x  BLOOM_MASK;
+	return x % BLOOM_BITS;
 }
 
 static inline size_t
 wcscspn_bloom2(size_t x)
 {
 	return (size_t)((uint32_t)(x * 2654435761U) /
-	(0x1ULL / (BLOOM_MASK + 1)));
+	(0x1ULL / BLOOM_BITS));
 }
 
 static inline void



CVS commit: src/lib/libc/string

2011-11-25 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Nov 25 17:48:23 UTC 2011

Modified Files:
src/lib/libc/string: wcscspn_bloom.h

Log Message:
If we have to cast, do it properly.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcscspn_bloom.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscspn_bloom.h
diff -u src/lib/libc/string/wcscspn_bloom.h:1.3 src/lib/libc/string/wcscspn_bloom.h:1.4
--- src/lib/libc/string/wcscspn_bloom.h:1.3	Fri Nov 25 16:46:56 2011
+++ src/lib/libc/string/wcscspn_bloom.h	Fri Nov 25 17:48:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcscspn_bloom.h,v 1.3 2011/11/25 16:46:56 dholland Exp $	*/
+/*	$NetBSD: wcscspn_bloom.h,v 1.4 2011/11/25 17:48:22 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2011 Joerg Sonnenberger,
@@ -64,9 +64,9 @@ wcsspn_bloom_init(size_t *bloom, const w
 	memset(bloom, 0, BLOOM_SIZE);
 	do {
 		val = wcscspn_bloom1((size_t)*charset);
-		bloom[val / BLOOM_DIV] |= (size_t)(1ULL  (val % BLOOM_DIV));
+		bloom[val / BLOOM_DIV] |= (size_t)1  (val % BLOOM_DIV);
 		val = wcscspn_bloom2((size_t)*charset);
-		bloom[val / BLOOM_DIV] |= (size_t)(1ULL  (val % BLOOM_DIV));
+		bloom[val / BLOOM_DIV] |= (size_t)1  (val % BLOOM_DIV);
 	}
 	while (*++charset);
 }
@@ -77,10 +77,10 @@ wcsspn_in_bloom(const size_t *bloom, wch
 	size_t val;
 
 	val = wcscspn_bloom1((size_t)ch);
-	if (bloom[val / BLOOM_DIV]  (1ULL  (val % BLOOM_DIV)))
+	if (bloom[val / BLOOM_DIV]  ((size_t)1  (val % BLOOM_DIV)))
 		return 1;
 	val = wcscspn_bloom2((size_t)ch);
-	if (bloom[val / BLOOM_DIV]  (1ULL  (val % BLOOM_DIV)))
+	if (bloom[val / BLOOM_DIV]  ((size_t)1  (val % BLOOM_DIV)))
 		return 1;
 	return 0;
 }



CVS commit: src/lib/libc/string

2011-11-24 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Nov 24 18:44:25 UTC 2011

Modified Files:
src/lib/libc/string: wcscspn.c wcspbrk.c
Added Files:
src/lib/libc/string: wcscspn_bloom.h

Log Message:
In wcscspn and wcspbrk, handle set size of 0 and 1 explicitly.
For larger sets, use a bloom filter to avoid the inner loop for most of
the input. The current implementation uses a simple modular hash as
first function (well suited for input e.g. in ISO Latin character sets)
and a more complex multiplicative hash as second function with a filter
size of 512 Bit. This reduces the typical run time to O(n+m).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcscspn.c
cvs rdiff -u -r0 -r1.1 src/lib/libc/string/wcscspn_bloom.h
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/wcspbrk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscspn.c
diff -u src/lib/libc/string/wcscspn.c:1.3 src/lib/libc/string/wcscspn.c:1.4
--- src/lib/libc/string/wcscspn.c:1.3	Mon Nov 21 15:02:48 2011
+++ src/lib/libc/string/wcscspn.c	Thu Nov 24 18:44:25 2011
@@ -1,7 +1,8 @@
-/*	$NetBSD: wcscspn.c,v 1.3 2011/11/21 15:02:48 joerg Exp $	*/
+/*	$NetBSD: wcscspn.c,v 1.4 2011/11/24 18:44:25 joerg Exp $	*/
 
 /*-
- * Copyright (c)1999 Citrus Project,
+ * Copyright (c) 1999 Citrus Project,
+ * Copyright (c) 2011 Joerg Sonnenberger,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,25 +30,45 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: wcscspn.c,v 1.3 2011/11/21 15:02:48 joerg Exp $);
+__RCSID($NetBSD: wcscspn.c,v 1.4 2011/11/24 18:44:25 joerg Exp $);
 
 #include assert.h
+#include inttypes.h
+#include string.h
 #include wchar.h
 
+#include wcscspn_bloom.h
+
 size_t
 wcscspn(const wchar_t *s, const wchar_t *set)
 {
+	size_t bloom[BLOOM_ARRAY_SIZE];
 	const wchar_t *p;
 	const wchar_t *q;
 
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(set != NULL);
 
+	if (set[0] == '\0')
+		return wcslen(s);
+	if (set[1] == '\0') {
+		for (p = s; *p; ++p)
+			if (*p == set[0])
+break;
+		return p - s;
+	}
+
+	wcsspn_bloom_init(bloom, set);
+
 	for (p = s; *p; ++p) {
-		for (q = set; *q; ++q) {
+		if (!wcsspn_in_bloom(bloom, *p))
+			continue;
+
+		q = set;
+		do {
 			if (*p == *q)
 goto done;
-		}
+		} while (*++q);
 	}
 
 done:

Index: src/lib/libc/string/wcspbrk.c
diff -u src/lib/libc/string/wcspbrk.c:1.4 src/lib/libc/string/wcspbrk.c:1.5
--- src/lib/libc/string/wcspbrk.c:1.4	Mon Nov 21 15:02:48 2011
+++ src/lib/libc/string/wcspbrk.c	Thu Nov 24 18:44:25 2011
@@ -1,7 +1,8 @@
-/*	$NetBSD: wcspbrk.c,v 1.4 2011/11/21 15:02:48 joerg Exp $	*/
+/*	$NetBSD: wcspbrk.c,v 1.5 2011/11/24 18:44:25 joerg Exp $	*/
 
 /*-
- * Copyright (c)1999 Citrus Project,
+ * Copyright (c) 1999 Citrus Project,
+ * Copyright (c) 2011 Joerg Sonnenberger,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,25 +30,41 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: wcspbrk.c,v 1.4 2011/11/21 15:02:48 joerg Exp $);
+__RCSID($NetBSD: wcspbrk.c,v 1.5 2011/11/24 18:44:25 joerg Exp $);
 
 #include assert.h
+#include inttypes.h
+#include string.h
 #include wchar.h
 
+#include wcscspn_bloom.h
+
 wchar_t *
 wcspbrk(const wchar_t *s, const wchar_t *set)
 {
+	size_t bloom[BLOOM_ARRAY_SIZE];
 	const wchar_t *p;
 	const wchar_t *q;
 
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(set != NULL);
 
+	if (set[0] == '\0')
+		return NULL;
+	if (set[1] == '\0')
+		return wcschr(s, set[0]);
+
+	wcsspn_bloom_init(bloom, set);
+
 	for (p = s; *p; ++p) {
-		for (q = set; *q; ++q) {
+		if (!wcsspn_in_bloom(bloom, *p))
+			continue;
+
+		q = set;
+		do {
 			if (*p == *q)
 return __UNCONST(p);
-		}
+		} while (*++q);
 	}
 	return NULL;
 }

Added files:

Index: src/lib/libc/string/wcscspn_bloom.h
diff -u /dev/null src/lib/libc/string/wcscspn_bloom.h:1.1
--- /dev/null	Thu Nov 24 18:44:25 2011
+++ src/lib/libc/string/wcscspn_bloom.h	Thu Nov 24 18:44:25 2011
@@ -0,0 +1,84 @@
+/*	$NetBSD: wcscspn_bloom.h,v 1.1 2011/11/24 18:44:25 joerg Exp $	*/
+
+/*-
+ * Copyright (c) 2011 Joerg Sonnenberger,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 

CVS commit: src/lib/libc/string

2011-11-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov 21 15:02:48 UTC 2011

Modified Files:
src/lib/libc/string: wcscspn.c wcspbrk.c wcsspn.c

Log Message:
Clean up a bit in preparation for more serious changes


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/wcscspn.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcspbrk.c \
src/lib/libc/string/wcsspn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wcscspn.c
diff -u src/lib/libc/string/wcscspn.c:1.2 src/lib/libc/string/wcscspn.c:1.3
--- src/lib/libc/string/wcscspn.c:1.2	Wed Jan  3 14:29:36 2001
+++ src/lib/libc/string/wcscspn.c	Mon Nov 21 15:02:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $	*/
+/*	$NetBSD: wcscspn.c,v 1.3 2011/11/21 15:02:48 joerg Exp $	*/
 
 /*-
  * Copyright (c)1999 Citrus Project,
@@ -29,17 +29,13 @@
  */
 
 #include sys/cdefs.h
-#if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $);
-#endif /* LIBC_SCCS and not lint */
+__RCSID($NetBSD: wcscspn.c,v 1.3 2011/11/21 15:02:48 joerg Exp $);
 
 #include assert.h
 #include wchar.h
 
 size_t
-wcscspn(s, set)
-	const wchar_t *s;
-	const wchar_t *set;
+wcscspn(const wchar_t *s, const wchar_t *set)
 {
 	const wchar_t *p;
 	const wchar_t *q;
@@ -47,15 +43,11 @@ wcscspn(s, set)
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(set != NULL);
 
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
+	for (p = s; *p; ++p) {
+		for (q = set; *q; ++q) {
 			if (*p == *q)
 goto done;
-			q++;
 		}
-		p++;
 	}
 
 done:

Index: src/lib/libc/string/wcspbrk.c
diff -u src/lib/libc/string/wcspbrk.c:1.3 src/lib/libc/string/wcspbrk.c:1.4
--- src/lib/libc/string/wcspbrk.c:1.3	Tue Nov 29 03:12:00 2005
+++ src/lib/libc/string/wcspbrk.c	Mon Nov 21 15:02:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcspbrk.c,v 1.3 2005/11/29 03:12:00 christos Exp $	*/
+/*	$NetBSD: wcspbrk.c,v 1.4 2011/11/21 15:02:48 joerg Exp $	*/
 
 /*-
  * Copyright (c)1999 Citrus Project,
@@ -29,17 +29,13 @@
  */
 
 #include sys/cdefs.h
-#if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: wcspbrk.c,v 1.3 2005/11/29 03:12:00 christos Exp $);
-#endif /* LIBC_SCCS and not lint */
+__RCSID($NetBSD: wcspbrk.c,v 1.4 2011/11/21 15:02:48 joerg Exp $);
 
 #include assert.h
 #include wchar.h
 
 wchar_t *
-wcspbrk(s, set)
-	const wchar_t *s;
-	const wchar_t *set;
+wcspbrk(const wchar_t *s, const wchar_t *set)
 {
 	const wchar_t *p;
 	const wchar_t *q;
@@ -47,15 +43,11 @@ wcspbrk(s, set)
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(set != NULL);
 
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
+	for (p = s; *p; ++p) {
+		for (q = set; *q; ++q) {
 			if (*p == *q)
 return __UNCONST(p);
-			q++;
 		}
-		p++;
 	}
 	return NULL;
 }
Index: src/lib/libc/string/wcsspn.c
diff -u src/lib/libc/string/wcsspn.c:1.3 src/lib/libc/string/wcsspn.c:1.4
--- src/lib/libc/string/wcsspn.c:1.3	Fri Sep 21 16:09:15 2001
+++ src/lib/libc/string/wcsspn.c	Mon Nov 21 15:02:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $	*/
+/*	$NetBSD: wcsspn.c,v 1.4 2011/11/21 15:02:48 joerg Exp $	*/
 
 /*-
  * Copyright (c)1999,2001 Citrus Project,
@@ -29,17 +29,13 @@
  */
 
 #include sys/cdefs.h
-#if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $);
-#endif /* LIBC_SCCS and not lint */
+__RCSID($NetBSD: wcsspn.c,v 1.4 2011/11/21 15:02:48 joerg Exp $);
 
 #include assert.h
 #include wchar.h
 
 size_t
-wcsspn(s, set)
-	const wchar_t *s;
-	const wchar_t *set;
+wcsspn(const wchar_t *s, const wchar_t *set)
 {
 	const wchar_t *p;
 	const wchar_t *q;
@@ -47,19 +43,14 @@ wcsspn(s, set)
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(set != NULL);
 
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
+	for (p = s; *p; ++p) {
+		for (q = set; *q; ++q) {
 			if (*p == *q)
 break;
-			q++;
 		}
 		if (!*q)
-			goto done;
-		p++;
+			break;
 	}
 
-done:
 	return (p - s);
 }



CVS commit: src/lib/libc/string

2011-11-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Nov 22 00:37:10 UTC 2011

Modified Files:
src/lib/libc/string: strpbrk.c

Log Message:
Handle simple cases (strlen(charset) = 1) more efficiently.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/string/strpbrk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strpbrk.c
diff -u src/lib/libc/string/strpbrk.c:1.19 src/lib/libc/string/strpbrk.c:1.20
--- src/lib/libc/string/strpbrk.c:1.19	Wed Sep 24 16:58:53 2008
+++ src/lib/libc/string/strpbrk.c	Tue Nov 22 00:37:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $	*/
+/*	$NetBSD: strpbrk.c,v 1.20 2011/11/22 00:37:09 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $);
+__RCSID($NetBSD: strpbrk.c,v 1.20 2011/11/22 00:37:09 joerg Exp $);
 
 #include assert.h
 #include inttypes.h
@@ -60,6 +60,11 @@ strpbrk(const char *s, const char *chars
 	_DIAGASSERT(s != NULL);
 	_DIAGASSERT(charset != NULL);
 
+	if (charset[0] == '\0')
+		return NULL;
+	if (charset[1] == '\0')
+		return strchr(s, charset[0]);
+
 	for (; *charset != '\0'; ++charset)
 		ADD_TO_SET(UC(*charset));
 



CVS commit: src/lib/libc/string

2011-08-21 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 22 01:36:04 UTC 2011

Modified Files:
src/lib/libc/string: popcount.3

Log Message:
Add patch from Klaus Klein in PR 45258 to note that popcount32/64
require stdint.h.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/popcount.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/popcount.3
diff -u src/lib/libc/string/popcount.3:1.4 src/lib/libc/string/popcount.3:1.5
--- src/lib/libc/string/popcount.3:1.4	Wed Jul 22 07:07:27 2009
+++ src/lib/libc/string/popcount.3	Mon Aug 22 01:36:04 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: popcount.3,v 1.4 2009/07/22 07:07:27 wiz Exp $
+.\	$NetBSD: popcount.3,v 1.5 2011/08/22 01:36:04 dholland Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd July 13, 2009
+.Dd August 22, 2011
 .Dt POPCOUNT 3
 .Os
 .Sh NAME
@@ -47,6 +47,7 @@
 .Fn popcountl unsigned long value
 .Ft unsigned int
 .Fn popcountll unsigned long long value
+.In stdint.h
 .Ft unsigned int
 .Fn popcount32 uint32_t value
 .Ft unsigned int



CVS commit: src/lib/libc/string

2011-01-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan  4 17:14:07 UTC 2011

Modified Files:
src/lib/libc/string: swab.c

Log Message:
Special-case the (unlikely in practice) call with len = 2 - previously
the code would not have swapped anything. Problem pointed out by
sparc64 automatic test run.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.17 src/lib/libc/string/swab.c:1.18
--- src/lib/libc/string/swab.c:1.17	Sun Apr 18 11:39:39 2010
+++ src/lib/libc/string/swab.c	Tue Jan  4 17:14:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $	*/
+/*	$NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)swab.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $);
+__RCSID($NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -61,6 +61,12 @@
 	fp = (const char *)from;
 	tp = (char *)to;
 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
+
+	if (__predict_false(len == 1)) {
+		STEP;
+		return;
+	}
+
 	/* round to multiple of 8 */
 	while ((--len % 8) != 0)
 		STEP;



CVS commit: src/lib/libc/string

2010-10-25 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Oct 25 07:37:11 UTC 2010

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.16 src/lib/libc/string/strerror.3:1.17
--- src/lib/libc/string/strerror.3:1.16	Sun Oct 24 23:10:51 2010
+++ src/lib/libc/string/strerror.3	Mon Oct 25 07:37:11 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: strerror.3,v 1.16 2010/10/24 23:10:51 dholland Exp $
+.\ $NetBSD: strerror.3,v 1.17 2010/10/25 07:37:11 wiz Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ @(#)strerror.3	8.1 (Berkeley) 6/9/93
-.Dd May 22, 2006
+.Dd October 24, 2010
 .Dt STRERROR 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/string

2010-10-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Oct 24 23:10:51 UTC 2010

Modified Files:
src/lib/libc/string: strerror.3

Log Message:
Mention err/warn. Note that they're generally preferred to perror().
Might want to strengthen the wording.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/string/strerror.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strerror.3
diff -u src/lib/libc/string/strerror.3:1.15 src/lib/libc/string/strerror.3:1.16
--- src/lib/libc/string/strerror.3:1.15	Mon Oct 16 08:48:45 2006
+++ src/lib/libc/string/strerror.3	Sun Oct 24 23:10:51 2010
@@ -1,4 +1,4 @@
-.\ $NetBSD: strerror.3,v 1.15 2006/10/16 08:48:45 wiz Exp $
+.\ $NetBSD: strerror.3,v 1.16 2010/10/24 23:10:51 dholland Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -98,6 +98,13 @@
 a colon and space
 .Pq Dq Li :\  ;
 otherwise, only the error message string is printed.
+Note that in most cases the
+.Xr err 3
+and
+.Xr warn 3
+family of functions is preferable to
+.Fn perror ;
+they are more flexible and also print the program name.
 .Pp
 If the error number is not recognized, these functions pass an error message
 string containing
@@ -148,7 +155,9 @@
 should be used instead.
 .Sh SEE ALSO
 .Xr intro 2 ,
-.Xr psignal 3
+.Xr err 3 ,
+.Xr psignal 3 ,
+.Xr warn 3
 .Sh STANDARDS
 The
 .Fn perror



CVS commit: src/lib/libc/string

2010-07-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  5 00:45:19 UTC 2010

Modified Files:
src/lib/libc/string: Lint_swab.c

Log Message:
consistency with c source


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/Lint_swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Lint_swab.c
diff -u src/lib/libc/string/Lint_swab.c:1.2 src/lib/libc/string/Lint_swab.c:1.3
--- src/lib/libc/string/Lint_swab.c:1.2	Wed Jun 14 02:49:10 2000
+++ src/lib/libc/string/Lint_swab.c	Sun Jul  4 20:45:19 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: Lint_swab.c,v 1.2 2000/06/14 06:49:10 cgd Exp $ */
+/* $NetBSD: Lint_swab.c,v 1.3 2010/07/05 00:45:19 christos Exp $ */
 
 /*
  * This file placed in the public domain.
@@ -9,9 +9,6 @@
 
 /*ARGSUSED*/
 void
-swab(src, dst, len)
-	const void *src;
-	void *dst;
-	size_t len;
+swab(const void *src, void *dst, ssize_t len)
 {
 }



CVS commit: src/lib/libc/string

2010-04-29 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Apr 29 07:27:30 UTC 2010

Modified Files:
src/lib/libc/string: bcopy.3

Log Message:
Add punctuation.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/bcopy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/bcopy.3
diff -u src/lib/libc/string/bcopy.3:1.12 src/lib/libc/string/bcopy.3:1.13
--- src/lib/libc/string/bcopy.3:1.12	Thu Apr 29 06:54:26 2010
+++ src/lib/libc/string/bcopy.3	Thu Apr 29 07:27:30 2010
@@ -29,7 +29,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)bcopy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: bcopy.3,v 1.12 2010/04/29 06:54:26 jruoho Exp $
+.\	$NetBSD: bcopy.3,v 1.13 2010/04/29 07:27:30 wiz Exp $
 .\
 .Dd April 29, 2010
 .Dt BCOPY 3
@@ -70,7 +70,7 @@
 .St -p1003.1-2001 .
 The
 .St -p1003.1-2004
-revision marked it as legacy the
+revision marked it as legacy; the
 .St -p1003.1-2008
 revision removed it from the specification.
 .Sh HISTORY



CVS commit: src/lib/libc/string

2010-04-29 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Apr 29 17:17:18 UTC 2010

Modified Files:
src/lib/libc/string: swab.3

Log Message:
Fix markup.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/swab.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.13 src/lib/libc/string/swab.3:1.14
--- src/lib/libc/string/swab.3:1.13	Thu Apr 29 05:42:04 2010
+++ src/lib/libc/string/swab.3	Thu Apr 29 17:17:18 2010
@@ -26,7 +26,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.13 2010/04/29 05:42:04 jruoho Exp $
+.\	$NetBSD: swab.3,v 1.14 2010/04/29 17:17:18 jruoho Exp $
 .\
 .Dd April 29, 2010
 .Dt SWAB 3
@@ -59,7 +59,8 @@
 If
 .Fa len
 is odd,
-.Nm copies
+.Nm
+copies
 .Fa len - 1
 bytes and the disposition of the last byte is unspecified.
 .Sh SEE ALSO



CVS commit: src/lib/libc/string

2010-04-29 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Fri Apr 30 03:52:13 UTC 2010

Modified Files:
src/lib/libc/string: swab.3

Log Message:
.Nm - .Fn.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/string/swab.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.14 src/lib/libc/string/swab.3:1.15
--- src/lib/libc/string/swab.3:1.14	Thu Apr 29 17:17:18 2010
+++ src/lib/libc/string/swab.3	Fri Apr 30 03:52:13 2010
@@ -26,9 +26,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.14 2010/04/29 17:17:18 jruoho Exp $
+.\	$NetBSD: swab.3,v 1.15 2010/04/30 03:52:13 jruoho Exp $
 .\
-.Dd April 29, 2010
+.Dd April 30, 2010
 .Dt SWAB 3
 .Os
 .Sh NAME
@@ -53,13 +53,13 @@
 .Pp
 If
 .Fa len
-is negative or zero
-.Nm
+is negative or zero,
+.Fn swab
 does nothing.
 If
 .Fa len
 is odd,
-.Nm
+.Fn swab
 copies
 .Fa len - 1
 bytes and the disposition of the last byte is unspecified.



CVS commit: src/lib/libc/string

2010-04-28 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Wed Apr 28 07:44:05 UTC 2010

Modified Files:
src/lib/libc/string: ffs.3

Log Message:
Reference ffs32(3). Also note POSIX compliance and the movement of the
header from string.h to strings.h.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/ffs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/ffs.3
diff -u src/lib/libc/string/ffs.3:1.11 src/lib/libc/string/ffs.3:1.12
--- src/lib/libc/string/ffs.3:1.11	Tue Jul 21 13:22:15 2009
+++ src/lib/libc/string/ffs.3	Wed Apr 28 07:44:04 2010
@@ -28,9 +28,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)ffs.3	8.2 (Berkeley) 4/19/94
-.\	$NetBSD: ffs.3,v 1.11 2009/07/21 13:22:15 wiz Exp $
+.\	$NetBSD: ffs.3,v 1.12 2010/04/28 07:44:04 jruoho Exp $
 .\
-.Dd July 21, 2009
+.Dd April 28, 2010
 .Dt FFS 3
 .Os
 .Sh NAME
@@ -53,9 +53,22 @@
 A return value of 0 means that the argument was zero.
 .Sh SEE ALSO
 .Xr bitstring 3 ,
+.Xr ffs32 3 ,
 .Xr popcount 3
+.Sh STANDARDS
+The
+.Fn ffs
+function conforms to
+.St -p1003.1-2001 .
 .Sh HISTORY
 The
 .Fn ffs
 function appeared in
 .Bx 4.3 .
+The prototype for it existed previously in the
+.In string.h header
+before it was moved to
+.In strings.h
+for
+.Tn POSIX
+compliance.



CVS commit: src/lib/libc/string

2010-04-28 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Wed Apr 28 07:47:09 UTC 2010

Modified Files:
src/lib/libc/string: ffs.3

Log Message:
Only put the actual header for the .In line.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/ffs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/ffs.3
diff -u src/lib/libc/string/ffs.3:1.12 src/lib/libc/string/ffs.3:1.13
--- src/lib/libc/string/ffs.3:1.12	Wed Apr 28 07:44:04 2010
+++ src/lib/libc/string/ffs.3	Wed Apr 28 07:47:09 2010
@@ -28,7 +28,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)ffs.3	8.2 (Berkeley) 4/19/94
-.\	$NetBSD: ffs.3,v 1.12 2010/04/28 07:44:04 jruoho Exp $
+.\	$NetBSD: ffs.3,v 1.13 2010/04/28 07:47:09 jruoho Exp $
 .\
 .Dd April 28, 2010
 .Dt FFS 3
@@ -66,8 +66,8 @@
 function appeared in
 .Bx 4.3 .
 The prototype for it existed previously in the
-.In string.h header
-before it was moved to
+.In string.h
+header before it was moved to
 .In strings.h
 for
 .Tn POSIX



CVS commit: src/lib/libc/string

2010-04-28 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Apr 29 05:42:04 UTC 2010

Modified Files:
src/lib/libc/string: swab.3

Log Message:
Note the recent changes.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/swab.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.12 src/lib/libc/string/swab.3:1.13
--- src/lib/libc/string/swab.3:1.12	Sat Apr 17 20:29:20 2010
+++ src/lib/libc/string/swab.3	Thu Apr 29 05:42:04 2010
@@ -26,9 +26,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.12 2010/04/17 20:29:20 wiz Exp $
+.\	$NetBSD: swab.3,v 1.13 2010/04/29 05:42:04 jruoho Exp $
 .\
-.Dd April 17, 2010
+.Dd April 29, 2010
 .Dt SWAB 3
 .Os
 .Sh NAME
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .In unistd.h
 .Ft void
-.Fn swab const void * restrict src void * restrict dst size_t len
+.Fn swab const void * restrict src void * restrict dst ssize_t len
 .Sh DESCRIPTION
 The function
 .Fn swab
@@ -65,8 +65,27 @@
 .Sh SEE ALSO
 .Xr bzero 3 ,
 .Xr memset 3
+.Sh STANDARDS
+The
+.Fn swab
+function conforms to
+.St -p1003.1-2001 .
 .Sh HISTORY
 A
 .Fn swab
 function appeared in
 .At v7 .
+It was originally documented to be
+.Dq useful for carrying binary data between PDP11's and other machines .
+.Pp
+In
+.Nx 6.0
+the type of
+.Fa len
+was changed from
+.Vt size_t
+to
+.Vt ssize_t
+for
+.Tn POSIX
+compliance.



CVS commit: src/lib/libc/string

2010-04-18 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sun Apr 18 10:51:34 UTC 2010

Modified Files:
src/lib/libc/string: swab.c

Log Message:
Bitwise operations on signed types are well-defined if the values
happen to be positive, and indeed the values here were guaranteed
to be positive, but some compilers complained anyway, so convert
the bitwise operations to arithmetic operations.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.15 src/lib/libc/string/swab.c:1.16
--- src/lib/libc/string/swab.c:1.15	Sun Apr 18 04:54:33 2010
+++ src/lib/libc/string/swab.c	Sun Apr 18 10:51:33 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.15 2010/04/18 04:54:33 christos Exp $	*/
+/*	$NetBSD: swab.c,v 1.16 2010/04/18 10:51:33 apb Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)swab.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: swab.c,v 1.15 2010/04/18 04:54:33 christos Exp $);
+__RCSID($NetBSD: swab.c,v 1.16 2010/04/18 10:51:33 apb Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -62,9 +62,9 @@
 	tp = (char *)to;
 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
 	/* round to multiple of 8 */
-	while ((--len  07) != 0)
+	while ((--len % 8) != 0)
 		STEP;
-	len = 3;
+	len /= 8;
 	if (len == 0)
 		return;
 	while (len-- != 0) {



CVS commit: src/lib/libc/string

2010-04-18 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sun Apr 18 11:39:39 UTC 2010

Modified Files:
src/lib/libc/string: swab.c

Log Message:
The number of byte pairs to swap is len/2, not len/2+1.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.16 src/lib/libc/string/swab.c:1.17
--- src/lib/libc/string/swab.c:1.16	Sun Apr 18 10:51:33 2010
+++ src/lib/libc/string/swab.c	Sun Apr 18 11:39:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.16 2010/04/18 10:51:33 apb Exp $	*/
+/*	$NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)swab.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: swab.c,v 1.16 2010/04/18 10:51:33 apb Exp $);
+__RCSID($NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -57,7 +57,7 @@
 	_DIAGASSERT(from != NULL);
 	_DIAGASSERT(to != NULL);
 
-	len = (len / 2) + 1;
+	len /= 2;
 	fp = (const char *)from;
 	tp = (char *)to;
 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp



CVS commit: src/lib/libc/string

2010-04-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 17 17:50:13 UTC 2010

Modified Files:
src/lib/libc/string: swab.3

Log Message:
add restrict


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/string/swab.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.9 src/lib/libc/string/swab.3:1.10
--- src/lib/libc/string/swab.3:1.9	Thu Aug  7 12:43:53 2003
+++ src/lib/libc/string/swab.3	Sat Apr 17 13:50:13 2010
@@ -26,9 +26,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.9 2003/08/07 16:43:53 agc Exp $
+.\	$NetBSD: swab.3,v 1.10 2010/04/17 17:50:13 christos Exp $
 .\
-.Dd June 4, 1993
+.Dd April 17, 2010
 .Dt SWAB 3
 .Os
 .Sh NAME
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .In unistd.h
 .Ft void
-.Fn swab const void *src void *dst size_t len
+.Fn swab const void * restrict src void * restrict dst size_t len
 .Sh DESCRIPTION
 The function
 .Fn swab



CVS commit: src/lib/libc/string

2010-04-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 17 17:57:39 UTC 2010

Modified Files:
src/lib/libc/string: swab.3 swab.c

Log Message:
Change and document for POSIX compliance.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/string/swab.3
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.10 src/lib/libc/string/swab.3:1.11
--- src/lib/libc/string/swab.3:1.10	Sat Apr 17 13:50:13 2010
+++ src/lib/libc/string/swab.3	Sat Apr 17 13:57:39 2010
@@ -26,7 +26,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.10 2010/04/17 17:50:13 christos Exp $
+.\	$NetBSD: swab.3,v 1.11 2010/04/17 17:57:39 christos Exp $
 .\
 .Dd April 17, 2010
 .Dt SWAB 3
@@ -51,9 +51,17 @@
 .Fa dst ,
 swapping adjacent bytes.
 .Pp
-The argument
+If 
 .Fa len
-must be even number.
+is negative or zero
+.Nm
+does nothing.
+If
+.Fa len
+is odd,
+.Nm copies
+.Fa len - 1
+bytes and the disposition of the last byte is unspecified.
 .Sh SEE ALSO
 .Xr bzero 3 ,
 .Xr memset 3

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.12 src/lib/libc/string/swab.c:1.13
--- src/lib/libc/string/swab.c:1.12	Thu Aug  7 12:43:53 2003
+++ src/lib/libc/string/swab.c	Sat Apr 17 13:57:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.12 2003/08/07 16:43:53 agc Exp $	*/
+/*	$NetBSD: swab.c,v 1.13 2010/04/17 17:57:39 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)swab.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: swab.c,v 1.12 2003/08/07 16:43:53 agc Exp $);
+__RCSID($NetBSD: swab.c,v 1.13 2010/04/17 17:57:39 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,12 +45,17 @@
 #include unistd.h
 
 void
-swab(const void *from, void *to, size_t len)
+swab(const void * __restrict from, void * __restrict to, ssize_t len)
 {
 	char temp;
 	const char *fp;
 	char *tp;
 
+	if (len  1)
+		len--;
+	if (len = 0)
+		return;
+
 	_DIAGASSERT(from != NULL);
 	_DIAGASSERT(to != NULL);
 



CVS commit: src/lib/libc/string

2010-04-17 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Apr 17 20:29:20 UTC 2010

Modified Files:
src/lib/libc/string: swab.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/swab.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.11 src/lib/libc/string/swab.3:1.12
--- src/lib/libc/string/swab.3:1.11	Sat Apr 17 17:57:39 2010
+++ src/lib/libc/string/swab.3	Sat Apr 17 20:29:20 2010
@@ -26,7 +26,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: swab.3,v 1.11 2010/04/17 17:57:39 christos Exp $
+.\	$NetBSD: swab.3,v 1.12 2010/04/17 20:29:20 wiz Exp $
 .\
 .Dd April 17, 2010
 .Dt SWAB 3
@@ -51,7 +51,7 @@
 .Fa dst ,
 swapping adjacent bytes.
 .Pp
-If 
+If
 .Fa len
 is negative or zero
 .Nm



CVS commit: src/lib/libc/string

2010-04-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 18 04:54:34 UTC 2010

Modified Files:
src/lib/libc/string: swab.c

Log Message:
simplify


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.14 src/lib/libc/string/swab.c:1.15
--- src/lib/libc/string/swab.c:1.14	Sat Apr 17 17:42:43 2010
+++ src/lib/libc/string/swab.c	Sun Apr 18 00:54:33 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.14 2010/04/17 21:42:43 christos Exp $	*/
+/*	$NetBSD: swab.c,v 1.15 2010/04/18 04:54:33 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)swab.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: swab.c,v 1.14 2010/04/17 21:42:43 christos Exp $);
+__RCSID($NetBSD: swab.c,v 1.15 2010/04/18 04:54:33 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -51,10 +51,7 @@
 	const char *fp;
 	char *tp;
 
-	/*LINTED: unportable */
-	if (len  1)
-		len--;
-	if (len = 0)
+	if (len = 1)
 		return;
 
 	_DIAGASSERT(from != NULL);



CVS commit: src/lib/libc/string

2010-04-14 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Wed Apr 14 11:07:20 UTC 2010

Modified Files:
src/lib/libc/string: strlcpy.3

Log Message:
Add the USENIX paper of Miller and de Raadt to SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/string/strlcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strlcpy.3
diff -u src/lib/libc/string/strlcpy.3:1.11 src/lib/libc/string/strlcpy.3:1.12
--- src/lib/libc/string/strlcpy.3:1.11	Thu Jun 26 12:25:22 2003
+++ src/lib/libc/string/strlcpy.3	Wed Apr 14 11:07:20 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: strlcpy.3,v 1.11 2003/06/26 12:25:22 wiz Exp $
+.\	$NetBSD: strlcpy.3,v 1.12 2010/04/14 11:07:20 jruoho Exp $
 .\ from OpenBSD: strlcpy.3,v 1.11 2000/11/16 23:27:41 angelos Exp
 .\
 .\ Copyright (c) 1998, 2000 Todd C. Miller todd.mil...@courtesan.com
@@ -190,11 +190,22 @@
 .Xr snprintf 3 ,
 .Xr strncat 3 ,
 .Xr strncpy 3
+.Rs
+.%A Todd C. Miller
+.%A Theo de Raadt
+.%T strlcpy and strlcat -- Consistent, Safe, String Copy and Concatenation
+.%I USENIX Association
+.%B Proceedings of the FREENIX Track: 1999 USENIX Annual Technical Conference
+.%D June 6-11, 1999
+.%U http://www.usenix.org/publications/library/proceedings/usenix99/
+.%U full_papers/millert/millert.pdf
+.Re
 .Sh HISTORY
+The
 .Fn strlcpy
 and
 .Fn strlcat
-first appeared in
+functions first appeared in
 .Ox 2.4 ,
 then in
 .Nx 1.4.3



CVS commit: src/lib/libc/string

2010-04-14 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Apr 14 13:07:51 UTC 2010

Modified Files:
src/lib/libc/string: strlcpy.3

Log Message:
Join URL.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/strlcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strlcpy.3
diff -u src/lib/libc/string/strlcpy.3:1.12 src/lib/libc/string/strlcpy.3:1.13
--- src/lib/libc/string/strlcpy.3:1.12	Wed Apr 14 11:07:20 2010
+++ src/lib/libc/string/strlcpy.3	Wed Apr 14 13:07:51 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: strlcpy.3,v 1.12 2010/04/14 11:07:20 jruoho Exp $
+.\	$NetBSD: strlcpy.3,v 1.13 2010/04/14 13:07:51 wiz Exp $
 .\ from OpenBSD: strlcpy.3,v 1.11 2000/11/16 23:27:41 angelos Exp
 .\
 .\ Copyright (c) 1998, 2000 Todd C. Miller todd.mil...@courtesan.com
@@ -197,8 +197,7 @@
 .%I USENIX Association
 .%B Proceedings of the FREENIX Track: 1999 USENIX Annual Technical Conference
 .%D June 6-11, 1999
-.%U http://www.usenix.org/publications/library/proceedings/usenix99/
-.%U full_papers/millert/millert.pdf
+.%U http://www.usenix.org/publications/library/proceedings/usenix99/full_papers/millert/millert.pdf
 .Re
 .Sh HISTORY
 The



CVS commit: src/lib/libc/string

2009-08-05 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Aug  5 16:08:00 UTC 2009

Modified Files:
src/lib/libc/string: Lint_ffs.c

Log Message:
ffs(3) lives in strings.h, so include the correct header. ANSIfy.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/Lint_ffs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Lint_ffs.c
diff -u src/lib/libc/string/Lint_ffs.c:1.2 src/lib/libc/string/Lint_ffs.c:1.3
--- src/lib/libc/string/Lint_ffs.c:1.2	Wed Jun 14 06:49:07 2000
+++ src/lib/libc/string/Lint_ffs.c	Wed Aug  5 16:08:00 2009
@@ -1,16 +1,15 @@
-/* $NetBSD: Lint_ffs.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
+/* $NetBSD: Lint_ffs.c,v 1.3 2009/08/05 16:08:00 joerg Exp $ */
 
 /*
  * This file placed in the public domain.
  * Chris Demetriou, November 5, 1997.
  */
 
-#include string.h
+#include strings.h
 
 /*ARGSUSED*/
 int
-ffs(value)
-	int value;
+ffs(int value)
 {
 	return(0);
 }



CVS commit: src/lib/libc/string

2009-07-30 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Jul 30 21:42:06 UTC 2009

Modified Files:
src/lib/libc/string: strcspn.c strspn.c

Log Message:
Use a 'register only' str[c]spn() on 64 bit systems.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/string/strcspn.c \
src/lib/libc/string/strspn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcspn.c
diff -u src/lib/libc/string/strcspn.c:1.16 src/lib/libc/string/strcspn.c:1.17
--- src/lib/libc/string/strcspn.c:1.16	Wed Jul 30 16:13:59 2008
+++ src/lib/libc/string/strcspn.c	Thu Jul 30 21:42:06 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcspn.c,v 1.16 2008/07/30 16:13:59 joerg Exp $	*/
+/*	$NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger
@@ -26,12 +26,16 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strcspn.c,v 1.16 2008/07/30 16:13:59 joerg Exp $);
+__RCSID($NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $);
 
 #include assert.h
 #include inttypes.h
+#include limits.h
 #include string.h
 
+/* 64bit version is in strspn.c */
+#if ULONG_MAX != 0xull
+
 size_t
 strcspn(const char *s, const char *charset)
 {
@@ -62,3 +66,5 @@
 			break;
 	return t - s;
 }
+
+#endif
Index: src/lib/libc/string/strspn.c
diff -u src/lib/libc/string/strspn.c:1.16 src/lib/libc/string/strspn.c:1.17
--- src/lib/libc/string/strspn.c:1.16	Wed Jul 30 16:13:59 2008
+++ src/lib/libc/string/strspn.c	Thu Jul 30 21:42:06 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: strspn.c,v 1.16 2008/07/30 16:13:59 joerg Exp $	*/
+/*	$NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger
@@ -26,13 +26,15 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strspn.c,v 1.16 2008/07/30 16:13:59 joerg Exp $);
+__RCSID($NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $);
 
 #include assert.h
 #include inttypes.h
 #include limits.h
 #include string.h
 
+#if ULONG_MAX != 0xull
+
 size_t
 strspn(const char *s, const char *charset)
 {
@@ -64,3 +66,86 @@
 			break;
 	return t - s;
 }
+
+#else
+
+/* 64 bit system, use four 64 bits registers for bitmask */
+
+static size_t
+strspn_x(const char *s_s, const char *charset_s, unsigned long invert)
+{
+	const unsigned char *s = (const unsigned char *)s_s;
+	const unsigned char *charset = (const unsigned char *)charset_s;
+	unsigned long m_0, m_4, m_8, m_c;
+	unsigned char ch, next_ch;
+	unsigned long bit;
+	unsigned long check;
+	size_t count;
+
+	/* Four 64bit registers have one bit for each character value */
+	m_0 = 0;
+	m_4 = 0;
+	m_8 = 0;
+	m_c = 0;
+
+	for (ch = *charset; ch != 0; ch = next_ch) {
+		next_ch = *++charset;
+		bit = 1ul  (ch  0x3f);
+		if (__predict_true(ch  0x80)) {
+			if (ch  0x40)
+m_0 |= bit;
+			else
+m_4 |= bit;
+		} else {
+			if (ch  0xc0)
+m_8 |= bit;
+			else
+m_c |= bit;
+		}
+	}
+
+	/* For strcspn() we just invert the validity set */
+	m_0 ^= invert;
+	m_4 ^= invert;
+	m_8 ^= invert;
+	m_c ^= invert;
+
+	/*
+	 * We could do remove the lsb from m_0 to terminate at the
+	 * end of the input string.
+	 * However prefetching the next char is benifitial and we must
+	 * not read the byte after the \0 - as it might fault!
+	 * So we take the 'hit' of the compare against 0.
+	 */
+
+	ch = *s++;
+	for (count = 0; ch != 0; ch = next_ch) {
+		next_ch = s[count];
+		if (__predict_true(ch  0x80)) {
+			check = m_0;
+			if (ch = 0x40)
+check = m_4;
+		} else {
+			check = m_8;
+			if (ch = 0xc0)
+check = m_c;
+		}
+		if (!((check  (ch  0x3f))  1))
+			break;
+		count++;
+	}
+	return count;
+}
+
+size_t
+strspn(const char *s, const char *charset)
+{
+	return strspn_x(s, charset, 0);
+}
+
+size_t
+strcspn(const char *s, const char *charset)
+{
+	return strspn_x(s, charset, ~0ul);
+}
+#endif



CVS commit: src/lib/libc/string

2009-07-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jul 22 07:07:27 UTC 2009

Modified Files:
src/lib/libc/string: popcount.3

Log Message:
Add comma in enumeration.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/popcount.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/popcount.3
diff -u src/lib/libc/string/popcount.3:1.3 src/lib/libc/string/popcount.3:1.4
--- src/lib/libc/string/popcount.3:1.3	Tue Jul 21 14:55:33 2009
+++ src/lib/libc/string/popcount.3	Wed Jul 22 07:07:27 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: popcount.3,v 1.3 2009/07/21 14:55:33 joerg Exp $
+.\	$NetBSD: popcount.3,v 1.4 2009/07/22 07:07:27 wiz Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -63,7 +63,7 @@
 .Fn popcount ,
 .Fn popcountl ,
 .Fn popcountll ,
-.Fn popcount32
+.Fn popcount32 ,
 and
 .Fn popcount64
 functions appeared in



CVS commit: src/lib/libc/string

2009-07-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jul 21 13:21:42 UTC 2009

Modified Files:
src/lib/libc/string: popcount.3

Log Message:
Fix typo, add comma in enumeration.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/popcount.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/popcount.3
diff -u src/lib/libc/string/popcount.3:1.1 src/lib/libc/string/popcount.3:1.2
--- src/lib/libc/string/popcount.3:1.1	Tue Jul 21 13:18:44 2009
+++ src/lib/libc/string/popcount.3	Tue Jul 21 13:21:41 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: popcount.3,v 1.1 2009/07/21 13:18:44 joerg Exp $
+.\	$NetBSD: popcount.3,v 1.2 2009/07/21 13:21:41 wiz Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -44,7 +44,7 @@
 .Ft unsigned int
 .Fn popcountl unsigned long value
 .Ft unsigned int
-.Fn popcountl unsigned long long value
+.Fn popcountll unsigned long long value
 .Sh DESCRIPTION
 The
 .Nm
@@ -55,7 +55,7 @@
 .Sh HISTORY
 The
 .Fn popcount ,
-.Fn popcountl
+.Fn popcountl ,
 and
 .Fn popcountll
 functions appeared in



CVS commit: src/lib/libc/string

2009-07-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jul 21 13:22:15 UTC 2009

Modified Files:
src/lib/libc/string: ffs.3

Log Message:
Xref popcount(3).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/string/ffs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/ffs.3
diff -u src/lib/libc/string/ffs.3:1.10 src/lib/libc/string/ffs.3:1.11
--- src/lib/libc/string/ffs.3:1.10	Thu Aug  7 16:43:47 2003
+++ src/lib/libc/string/ffs.3	Tue Jul 21 13:22:15 2009
@@ -28,9 +28,9 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)ffs.3	8.2 (Berkeley) 4/19/94
-.\	$NetBSD: ffs.3,v 1.10 2003/08/07 16:43:47 agc Exp $
+.\	$NetBSD: ffs.3,v 1.11 2009/07/21 13:22:15 wiz Exp $
 .\
-.Dd April 19, 1994
+.Dd July 21, 2009
 .Dt FFS 3
 .Os
 .Sh NAME
@@ -52,7 +52,8 @@
 bit.
 A return value of 0 means that the argument was zero.
 .Sh SEE ALSO
-.Xr bitstring 3
+.Xr bitstring 3 ,
+.Xr popcount 3
 .Sh HISTORY
 The
 .Fn ffs



CVS commit: src/lib/libc/string

2009-07-18 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sat Jul 18 09:41:23 UTC 2009

Modified Files:
src/lib/libc/string: Makefile.inc

Log Message:
Remove index() and rindex() from the list (in comment)


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/lib/libc/string/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Makefile.inc
diff -u src/lib/libc/string/Makefile.inc:1.71 src/lib/libc/string/Makefile.inc:1.72
--- src/lib/libc/string/Makefile.inc:1.71	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/Makefile.inc	Sat Jul 18 09:41:23 2009
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-#	$NetBSD: Makefile.inc,v 1.71 2009/05/01 17:27:01 perry Exp $
+#	$NetBSD: Makefile.inc,v 1.72 2009/07/18 09:41:23 dsl Exp $
 
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -25,8 +25,8 @@
 
 # machine-dependent net sources
 # m-d Makefile.inc must include sources for:
-#	bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset()
-#	rindex() strcat() strcmp() strcpy() strcspn() strlen()
+#	bcmp() bcopy() bzero() ffs() memchr() memcmp() memset()
+#	strcat() strcmp() strcpy() strcspn() strlen()
 #	strncat() strncmp() strncpy() strpbrk() strsep()
 #	strspn() strstr() swav()
 # m-d Makefile.inc may include sources for:



CVS commit: src/lib/libc/string

2009-05-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat May  2 09:31:01 UTC 2009

Modified Files:
src/lib/libc/string: wmemchr.3

Log Message:
Remove duplicate entry.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/string/wmemchr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/wmemchr.3
diff -u src/lib/libc/string/wmemchr.3:1.13 src/lib/libc/string/wmemchr.3:1.14
--- src/lib/libc/string/wmemchr.3:1.13	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/wmemchr.3	Sat May  2 09:31:01 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: wmemchr.3,v 1.13 2009/05/01 17:27:01 perry Exp $
+.\	$NetBSD: wmemchr.3,v 1.14 2009/05/02 09:31:01 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -138,7 +138,6 @@
 .Xr strlcat 3 ,
 .Xr strlcpy 3 ,
 .Xr strlen 3 ,
-.Xr strnlen 3 ,
 .Xr strncat 3 ,
 .Xr strncmp 3 ,
 .Xr strncpy 3 ,



CVS commit: src/lib/libc/string

2009-05-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat May  2 09:31:08 UTC 2009

Modified Files:
src/lib/libc/string: strcpy.3

Log Message:
Sort sections.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/string/strcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcpy.3
diff -u src/lib/libc/string/strcpy.3:1.18 src/lib/libc/string/strcpy.3:1.19
--- src/lib/libc/string/strcpy.3:1.18	Fri May  1 17:27:01 2009
+++ src/lib/libc/string/strcpy.3	Sat May  2 09:31:08 2009
@@ -30,7 +30,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strcpy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strcpy.3,v 1.18 2009/05/01 17:27:01 perry Exp $
+.\	$NetBSD: strcpy.3,v 1.19 2009/05/02 09:31:08 wiz Exp $
 .\
 .Dd May 1, 2009
 .Dt STRCPY 3
@@ -184,14 +184,6 @@
 .Xr strlcpy 3
 is not defined in any standards, it should
 only be used when portability is not a concern.
-.Sh SECURITY CONSIDERATIONS
-The
-.Fn strcpy
-and
-.Fn stpcpy
-functions are easily misused in a manner which enables malicious users
-to arbitrarily change a running program's functionality through a
-buffer overflow attack.
 .Sh SEE ALSO
 .Xr bcopy 3 ,
 .Xr memccpy 3 ,
@@ -220,3 +212,11 @@
 .Fn stpncpy
 functions first appeared in
 .Nx 6.0 .
+.Sh SECURITY CONSIDERATIONS
+The
+.Fn strcpy
+and
+.Fn stpcpy
+functions are easily misused in a manner which enables malicious users
+to arbitrarily change a running program's functionality through a
+buffer overflow attack.



CVS commit: src/lib/libc/string

2009-05-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat May  2 09:37:33 UTC 2009

Modified Files:
src/lib/libc/string: strcpy.3

Log Message:
Improve formatting and punctuation for NUL-terminate.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/string/strcpy.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/strcpy.3
diff -u src/lib/libc/string/strcpy.3:1.19 src/lib/libc/string/strcpy.3:1.20
--- src/lib/libc/string/strcpy.3:1.19	Sat May  2 09:31:08 2009
+++ src/lib/libc/string/strcpy.3	Sat May  2 09:37:32 2009
@@ -30,7 +30,7 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)strcpy.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: strcpy.3,v 1.19 2009/05/02 09:31:08 wiz Exp $
+.\	$NetBSD: strcpy.3,v 1.20 2009/05/02 09:37:32 wiz Exp $
 .\
 .Dd May 1, 2009
 .Dt STRCPY 3
@@ -140,15 +140,13 @@
 .Pp
 Note that it does
 .Em not
-.Tn NUL
-terminate
+.Dv NUL Ns No -terminate
 .Va chararray
 because the length of the source string is greater than or equal
 to the length parameter.
 .Fn strncpy
 .Em only
-.Tn NUL
-terminates
+.Dv NUL Ns No -terminates
 the destination string when the length of the source
 string is less than the length parameter.
 .Pp
@@ -157,15 +155,15 @@
 to
 .Va buf
 as will fit and
-.Tn NUL
-terminates the result.
+.Dv NUL Ns No -terminates
+the result.
 Because
 .Fn strncpy
 does
 .Em not
 guarantee to
-.Tn NUL
-terminate the string itself, this must be done explicitly.
+.Dv NUL Ns No -terminate
+the string itself, this must be done explicitly.
 .Bd -literal -offset indent
 char buf[1024];
 



CVS commit: src/lib/libc/string

2009-04-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 10 23:13:38 UTC 2009

Modified Files:
src/lib/libc/string: Makefile.inc memchr.3
Added Files:
src/lib/libc/string: memrchr.c

Log Message:
add memrchr


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/lib/libc/string/Makefile.inc
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/string/memchr.3
cvs rdiff -u -r0 -r1.1 src/lib/libc/string/memrchr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/Makefile.inc
diff -u src/lib/libc/string/Makefile.inc:1.69 src/lib/libc/string/Makefile.inc:1.70
--- src/lib/libc/string/Makefile.inc:1.69	Sat Jan 10 21:46:30 2009
+++ src/lib/libc/string/Makefile.inc	Fri Apr 10 19:13:38 2009
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-#	$NetBSD: Makefile.inc,v 1.69 2009/01/11 02:46:30 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.70 2009/04/10 23:13:38 christos Exp $
 
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -7,7 +7,7 @@
 SRCS+=	bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
 	strerror.c strlcat.c strlcpy.c strmode.c strsignal.c strtok.c \
 	strtok_r.c strxfrm.c __strsignal.c strerror_r.c strndup.c \
-	stresep.c
+	stresep.c memrchr.c
 
 # wide char
 SRCS+=	wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \
@@ -69,6 +69,7 @@
 MLINKS+=strcpy.3 strncpy.3
 MLINKS+=strlcpy.3 strlcat.3
 MLINKS+=strstr.3 strcasestr.3
+MLINKS+=memchr.3 memrchr.3
 MLINKS+=strtok.3 strtok_r.3
 MLINKS+=strerror.3 strerror_r.3 strerror.3 perror.3 \
 	strerror.3 sys_errlist.3 strerror.3 sys_nerr.3

Index: src/lib/libc/string/memchr.3
diff -u src/lib/libc/string/memchr.3:1.9 src/lib/libc/string/memchr.3:1.10
--- src/lib/libc/string/memchr.3:1.9	Mon Oct 16 04:48:45 2006
+++ src/lib/libc/string/memchr.3	Fri Apr 10 19:13:38 2009
@@ -30,13 +30,13 @@
 .\ SUCH DAMAGE.
 .\
 .\ from: @(#)memchr.3	8.1 (Berkeley) 6/4/93
-.\	$NetBSD: memchr.3,v 1.9 2006/10/16 08:48:45 wiz Exp $
+.\	$NetBSD: memchr.3,v 1.10 2009/04/10 23:13:38 christos Exp $
 .\
-.Dd June 4, 1993
+.Dd April 10, 2009
 .Dt MEMCHR 3
 .Os
 .Sh NAME
-.Nm memchr
+.Nm memchr, memrchr
 .Nd locate byte in byte string
 .Sh LIBRARY
 .Lb libc
@@ -44,6 +44,8 @@
 .In string.h
 .Ft void *
 .Fn memchr const void *b int c size_t len
+.Ft void *
+.Fn memrchr const void *b int c size_t len
 .Sh DESCRIPTION
 The
 .Fn memchr
@@ -53,11 +55,21 @@
 (converted to an unsigned char)
 in string
 .Fa b .
+The
+.Fn memrchr
+function
+locates the last occurrence of
+.Fa c
+(converted to an unsigned char)
+in string
+.Fa b .
 .Sh RETURN VALUES
 The
 .Fn memchr
-function
-returns a pointer to the byte located, or
+and
+.Fn memrchr
+functions
+return a pointer to the byte located, or
 .Dv NULL
 if no such byte exists within
 .Fa len

Added files:

Index: src/lib/libc/string/memrchr.c
diff -u /dev/null src/lib/libc/string/memrchr.c:1.1
--- /dev/null	Fri Apr 10 19:13:38 2009
+++ src/lib/libc/string/memrchr.c	Fri Apr 10 19:13:38 2009
@@ -0,0 +1,61 @@
+/*	$NetBSD: memrchr.c,v 1.1 2009/04/10 23:13:38 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ *This product includes software developed by the NetBSD
+ *Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING