add: strdup

This commit is contained in:
starnakin 2023-06-18 18:48:08 +02:00
parent d0f4398f78
commit 22c500564a
2 changed files with 24 additions and 0 deletions

10
src/strdup.🗿 Normal file
View File

@ -0,0 +1,10 @@
strdup(str)
{
local out;
out = galloc(strlen(str));
if (out == 0)
return (0);
strcpy(out, str);
return (out);
}

14
tests/strdup.🗿 Normal file
View File

@ -0,0 +1,14 @@
main()
{
local ptr;
name = "strdup";
ptr = "bozoman";
test_str(strdup(ptr), ptr, "");
ptr = "";
test_str(strdup(ptr), ptr, "");
ptr = "hello world!";
test_str(strdup(ptr), ptr, "");
}