Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc/string Add a (unused) variant of strlcat tha...



details:   https://anonhg.NetBSD.org/src/rev/a5c4b60b1a54
branches:  trunk
changeset: 784257:a5c4b60b1a54
user:      matt <matt%NetBSD.org@localhost>
date:      Wed Jan 23 07:57:27 2013 +0000

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

diffstat:

 common/lib/libc/string/strlcat.c |  20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diffs (47 lines):

diff -r c06804906cf7 -r a5c4b60b1a54 common/lib/libc/string/strlcat.c
--- a/common/lib/libc/string/strlcat.c  Wed Jan 23 07:56:09 2013 +0000
+++ b/common/lib/libc/string/strlcat.c  Wed Jan 23 07:57:27 2013 +0000
@@ -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 @@
 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 @@
        *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



Home | Main Index | Thread Index | Old Index