1 /* ----------------------------------------------------------------------------
3 * ----------------------------------------------------------------------------
4 * Public Domain C Library - http://pdclib.sourceforge.net
5 * This code is Public Domain. Use, modify, and redistribute at will.
6 * --------------------------------------------------------------------------*/
8 void * realloc( void * ptr, size_t size ) { /* TODO */ };
10 /* PDPC code - assumes size_t of memory chunk at offset -4.
15 if ( ( newptr = malloc(size) ) != NULL )
19 // reading size information from hidden chunk header
20 oldsize = * (size_t *) ( (char *) ptr - 4 );
21 // correctly handle *down*sizing as well as *up*sizing
22 memcpy( newptr, ptr, ( oldsize < size ) ? oldsize : size );
30 /* Thomas "Beyond Infinity" Kreitner's code - unchecked, unoptimized
36 // searching the block to-be-allocated
37 chunk = used_mem.start;
38 while ( ! found && ( chunk->next != NULL )
40 if ( chunk->address == ptr )
51 length = chunk->length;
52 // allocate new memory area
53 if ( ( new = (void *) malloc( size ) ) != NULL )
56 memcpy( ptr, new, length );
57 // release the old memory