X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Frealloc.c;fp=functions%2Fstdlib%2Frealloc.c;h=df5fca1bc75904411404315cac347ea32f8d164c;hb=137bef7f4838fc430682213fa628e16b2237ed63;hp=0000000000000000000000000000000000000000;hpb=229d28866bf554e77928ccade55b06a7fdd47382;p=pdclib diff --git a/functions/stdlib/realloc.c b/functions/stdlib/realloc.c new file mode 100644 index 0000000..df5fca1 --- /dev/null +++ b/functions/stdlib/realloc.c @@ -0,0 +1,48 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* void * realloc( void *, size_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include +#include + +#ifndef REGTEST + +/* TODO: Primitive placeholder. Improve. */ + +void * realloc( void * ptr, size_t size ) +{ + struct _PDCLIB_memnode_t * baseptr = (struct _PDCLIB_memnode_t *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) ); + if ( baseptr->size >= size ) + { + return ptr; + } + else + { + void * newptr = malloc( size ); + memcpy( newptr, ptr, baseptr->size ); + free( ptr ); + return newptr; + } + return NULL; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + BEGIN_TESTS; + /* tests covered in malloc test driver */ + return TEST_RESULTS; +} + +#endif