]> pd.if.org Git - pdclib/blob - functions/stdlib/free.c
Removed the header include guard 'optimization'.
[pdclib] / functions / stdlib / free.c
1 /* $Id$ */
2
3 /* void free( void * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdlib.h>
10
11 #ifndef REGTEST
12
13 #include <_PDCLIB_int.h>
14
15 /* TODO: Primitive placeholder. Much room for improvement. */
16
17 /* structure holding first and last element of free node list */
18 extern struct _PDCLIB_headnode_t _PDCLIB_memlist;
19
20 void free( void * ptr )
21 {
22     if ( ptr == NULL )
23     {
24         return;
25     }
26     ptr = (void *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) );
27     ( (struct _PDCLIB_memnode_t *)ptr )->next = NULL;
28     if ( _PDCLIB_memlist.last != NULL )
29     {
30         _PDCLIB_memlist.last->next = ptr;
31     }
32     else
33     {
34         _PDCLIB_memlist.first = ptr;
35     }
36     _PDCLIB_memlist.last = ptr;
37 }
38
39 #endif
40
41 #ifdef TEST
42 #include <_PDCLIB_test.h>
43 #include <stdbool.h>
44
45 int main( void )
46 {
47     free( NULL );
48     TESTCASE( true );
49     return TEST_RESULTS;
50 }
51
52 #endif