Implement strndup(3) using strnlen(3).

This makes the implementation a bit more consistent with strdup(3),
which uses strlen(3).
This commit is contained in:
ed 2010-02-02 19:02:08 +00:00
parent 8a75e0399d
commit ca42e1d1ce

View File

@ -42,9 +42,7 @@ strndup(const char *str, size_t n)
size_t len; size_t len;
char *copy; char *copy;
for (len = 0; len < n && str[len]; len++) len = strnlen(str, n);
continue;
if ((copy = malloc(len + 1)) == NULL) if ((copy = malloc(len + 1)) == NULL)
return (NULL); return (NULL);
memcpy(copy, str, len); memcpy(copy, str, len);