Files
codezero/loader/libs/c/src/realloc.c
Bahadir Balban 59f30a175a More progress on build scripts
Created a config directory for configuration files.
Moved all absolute path variables to a projpaths.py file
All scripts can now universally learn absolute paths via projpaths.py
Moved the config_symbols class to the configuration.py file.
Moved libs to loader since they are only referred by the loader
2009-09-12 13:42:30 +03:00

34 lines
568 B
C

/*
* K&R Malloc
*
* System specifc code should implement `more_core'
*/
#include "k_r_malloc.h"
#include <stdlib.h>
#include <string.h>
void *
realloc(void *ptr, size_t size)
{
Header *bp;
void *new_ptr;
size_t old_size;
if (ptr == NULL)
return malloc(size);
bp = (Header *) ptr - 1; /* point to block header */
old_size = sizeof(Header) * bp->s.size;
new_ptr = malloc(size);
if (new_ptr == NULL) {
return NULL;
}
if (old_size <= size) {
memcpy(new_ptr, ptr, old_size);
} else {
memcpy(new_ptr, ptr, size);
}
free(ptr);
return new_ptr;
}