summaryrefslogtreecommitdiff
path: root/common/lib/libc/string
diff options
context:
space:
mode:
authormatt <matt@NetBSD.org>2013-01-23 07:57:27 +0000
committermatt <matt@NetBSD.org>2013-01-23 07:57:27 +0000
commit28f05f2ec8d4d4c157593dcc62bec7f63587491a (patch)
tree065e452fab3921f55cd1b5dba66f7e8b0b5051f4 /common/lib/libc/string
parent3e0c7e0aac793f4821648a9bb5adeb83d51495c8 (diff)
Add a (unused) variant of strlcat that uses strnlen and strlcpy to do the work.
Diffstat (limited to 'common/lib/libc/string')
-rw-r--r--common/lib/libc/string/strlcat.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/common/lib/libc/string/strlcat.c b/common/lib/libc/string/strlcat.c
index d4a8d7eba02..909dc9b29d0 100644
--- a/common/lib/libc/string/strlcat.c
+++ b/common/lib/libc/string/strlcat.c
@@ -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_t siz)
*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