summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2010-02-02 19:02:08 +0000
committered <ed@FreeBSD.org>2010-02-02 19:02:08 +0000
commitca42e1d1ceb9cfd3924a389a273d173d25ae7523 (patch)
treed2c5eb034b46dc31e531d9ca155da6fdf887c00e /lib
parent8a75e0399dc0ea366e99c69d9e95b89a9929f87f (diff)
downloadFreeBSD-src-ca42e1d1ceb9cfd3924a389a273d173d25ae7523.zip
FreeBSD-src-ca42e1d1ceb9cfd3924a389a273d173d25ae7523.tar.gz
Implement strndup(3) using strnlen(3).
This makes the implementation a bit more consistent with strdup(3), which uses strlen(3).
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/string/strndup.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c
index 56aa6a8..abb1e03 100644
--- a/lib/libc/string/strndup.c
+++ b/lib/libc/string/strndup.c
@@ -42,9 +42,7 @@ strndup(const char *str, size_t n)
size_t len;
char *copy;
- for (len = 0; len < n && str[len]; len++)
- continue;
-
+ len = strnlen(str, n);
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
OpenPOWER on IntegriCloud