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:
parent
8a75e0399d
commit
ca42e1d1ce
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user