blob: 8b369edeb174e516c043175ffdd96f3a60b0db1c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
|
#include "memory.h"
char *strndup(char const *restrict string, size_t max_lenght)
{
size_t lenght = strnlen(string, max_lenght) + 1;
char *duplicate = reallocarray(NULL, lenght, sizeof *duplicate);
if (duplicate != NULL)
memcpy(duplicate, string, lenght);
return duplicate;
}
|