Code: Select all
char *buf, *new_buf;
uint32 new_size;
***
new_buf = krealloc(buf, new_size);
if (!new_buf) sysfail("not enough memory");
else
{
kfree(buf);
buf = new_buf
}
***
Or perhaps krealloc DOES dispose the old block?
Cheers,
Adrian
Code: Select all
char *buf, *new_buf;
uint32 new_size;
***
new_buf = krealloc(buf, new_size);
if (!new_buf) sysfail("not enough memory");
else
{
kfree(buf);
buf = new_buf
}
***
Code: Select all
void *realloc(void *old_block, size_t new_size)
{
void *new_block;
size_t old_size;
new_block = malloc(new_size);
if (new_block == NULL)
{
/* leave old block intact */
return NULL;
}
if (old_block == NULL)
old_size = 0;
else
old_size = __msize(old_block);
memcpy(new_block, old_block, min(old_size, new_size));
free(old_block);
return new_block;
}