blob: 126a17b460a96e9b5dafcb33a76890f8a48a155c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* 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 <stdlib.h>
#ifndef REGTEST
#include "pdclib/_PDCLIB_int.h"
/* 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 )
{
if ( ptr == NULL )
{
return;
}
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"
#include <stdbool.h>
int main( void )
{
free( NULL );
TESTCASE( true );
return TEST_RESULTS;
}
#endif
|