Implemented realloc().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28454 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2ef4a8b524
commit
f68fa9d364
@ -237,12 +237,33 @@ dump_chunks(void)
|
||||
|
||||
|
||||
void *
|
||||
realloc(void *buffer, size_t newSize)
|
||||
realloc(void *allocation, size_t newSize)
|
||||
{
|
||||
// not implemented
|
||||
// free, if new size is 0
|
||||
if (newSize == 0) {
|
||||
free(allocation);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// just malloc(), if no previous allocation
|
||||
if (allocation == NULL)
|
||||
return malloc(newSize);
|
||||
|
||||
// we're lazy and don't shrink allocations
|
||||
free_chunk* chunk = free_chunk::SetToAllocated(allocation);
|
||||
if (chunk->Size() >= newSize)
|
||||
return allocation;
|
||||
|
||||
// the allocation needs to grow -- allocate a new one and memcpy()
|
||||
void* newAllocation = malloc(newSize);
|
||||
if (newAllocation != NULL) {
|
||||
memcpy(newAllocation, allocation, chunk->Size());
|
||||
free(allocation);
|
||||
}
|
||||
|
||||
return newAllocation;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
malloc(size_t size)
|
||||
|
Loading…
Reference in New Issue
Block a user