X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Ffree.c;fp=functions%2Fstdlib%2Ffree.c;h=632f670a44501eb2fdd7410c7c5b2f8cf4808018;hb=137bef7f4838fc430682213fa628e16b2237ed63;hp=0000000000000000000000000000000000000000;hpb=229d28866bf554e77928ccade55b06a7fdd47382;p=pdclib diff --git a/functions/stdlib/free.c b/functions/stdlib/free.c new file mode 100644 index 0000000..632f670 --- /dev/null +++ b/functions/stdlib/free.c @@ -0,0 +1,52 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* void free( void * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif + +/* TODO: Primitive placeholder. Much room for improvement. */ + +/* structure holding first and last element of free node list */ +extern struct _PDCLIB_headnode_t _PDCLIB_memlist; + +void free( void * ptr ) +{ + ptr = (void *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) ); + ( (struct _PDCLIB_memnode_t *)ptr )->next = NULL; + if ( _PDCLIB_memlist.last != NULL ) + { + _PDCLIB_memlist.last->next = ptr; + } + else + { + _PDCLIB_memlist.first = ptr; + } + _PDCLIB_memlist.last = ptr; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + BEGIN_TESTS; + /* tests covered in malloc test driver */ + return TEST_RESULTS; +} + +#endif