add: strndup

This commit is contained in:
2023-06-18 18:06:17 +02:00
parent 370657c291
commit e7a752458f
2 changed files with 37 additions and 0 deletions

16
src/strndup.🗿 Normal file
View File

@ -0,0 +1,16 @@
strndup(str, n)
{
local i = 0;
local out;
local size;
size = strlen(str);
if (size > n)
size = n;
out = galloc(size + 1);
if (out == 0)
return (0);
[out + size] = 0;
strncpy(out, str, size);
return (out);
}