Module Name:    src
Committed By:   matt
Date:           Wed Jan 23 07:57:27 UTC 2013

Modified Files:
        src/common/lib/libc/string: strlcat.c

Log Message:
Add a (unused) variant of strlcat that uses strnlen and strlcpy to do the work.


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

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

Modified files:

Index: src/common/lib/libc/string/strlcat.c
diff -u src/common/lib/libc/string/strlcat.c:1.3 src/common/lib/libc/string/strlcat.c:1.4
--- src/common/lib/libc/string/strlcat.c:1.3	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/strlcat.c	Wed Jan 23 07:57:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $	*/
 /*	$OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $	*/
 
 /*
@@ -24,7 +24,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $");
+__RCSID("$NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef _LIBC
@@ -55,6 +55,7 @@ __weak_alias(strlcat, _strlcat)
 size_t
 strlcat(char *dst, const char *src, size_t siz)
 {
+#if 1
 	char *d = dst;
 	const char *s = src;
 	size_t n = siz;
@@ -81,5 +82,20 @@ strlcat(char *dst, const char *src, size
 	*d = '\0';
 
 	return(dlen + (s - src));	/* count does not include NUL */
+#else
+	_DIAGASSERT(dst != NULL);
+	_DIAGASSERT(src != NULL);
+
+	/*
+	 * Find length of string in dst (maxing out at siz).
+	 */
+	size_t dlen = strnlen(dst, siz);
+
+	/*
+	 * Copy src into any remaining space in dst (truncating if needed).
+	 * Note strlcpy(dst, src, 0) returns strlen(src).
+	 */
+	return dlen + strlcpy(dst + dlen, src, siz - dlen);
+#endif
 }
 #endif

Reply via email to