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