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