1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-25 11:37:56 +00:00

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 Schouten 2010-02-02 19:02:08 +00:00
parent 62fd5fd625
commit 61d38d61e2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=203391

View File

@ -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);