From 61d38d61e269dbfdb47fb97870f8f88b473cb571 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Tue, 2 Feb 2010 19:02:08 +0000 Subject: [PATCH] Implement strndup(3) using strnlen(3). This makes the implementation a bit more consistent with strdup(3), which uses strlen(3). --- lib/libc/string/strndup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c index 56aa6a83a2e..abb1e030eee 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);