]> pd.if.org Git - pdclib/blob - functions/stdlib/free.c
43de1299846b9f66162560e733996be060f8495e
[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 #ifndef _PDCLIB_INT_H
14 #define _PDCLIB_INT_H _PDCLIB_INT_H
15 #include <_PDCLIB_int.h>
16 #endif
17
18 /* TODO: Primitive placeholder. Much room for improvement. */
19
20 /* structure holding first and last element of free node list */
21 extern struct _PDCLIB_headnode_t _PDCLIB_memlist;
22
23 void free( void * ptr )
24 {
25     ptr = (void *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) );
26     ( (struct _PDCLIB_memnode_t *)ptr )->next = NULL;
27     if ( _PDCLIB_memlist.last != NULL )
28     {
29         _PDCLIB_memlist.last->next = ptr;
30     }
31     else
32     {
33         _PDCLIB_memlist.first = ptr;
34     }
35     _PDCLIB_memlist.last = ptr;
36 }
37
38 #endif
39
40 #ifdef TEST
41 #include <_PDCLIB_test.h>
42
43 int main( void )
44 {
45     /* tests covered in malloc test driver */
46     return TEST_RESULTS;
47 }
48
49 #endif