add: realloc

This commit is contained in:
2023-07-23 15:35:32 +02:00
parent c6608ad4eb
commit f9fa2a5a12
2 changed files with 32 additions and 0 deletions

21
src/realloc.🗿 Normal file
View File

@ -0,0 +1,21 @@
reallocarray(ptr, nmemb, size)
{
local tmp;
local start;
start = ptr;
tmp = galloc(size);
if (tmp == NULL)
return NULL;
if (ptr == NULL)
return tmp;
loop
{
if (start - ptr == nmemb)
break;
[tmp + start - ptr] = [start];
start++;
}
free(ptr);
return tmp;
}