src/allocator.c

changeset 414
81a4c3a63e65
parent 397
cfc1193b1e65
child 434
38ee262e8b94
equal deleted inserted replaced
413:0f4aa9fc75d9 414:81a4c3a63e65
27 */ 27 */
28 28
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <errno.h>
32 33
33 void *cx_malloc_stdlib(void *unused, size_t n) { 34 void *cx_malloc_stdlib(void *unused, size_t n) {
34 return malloc(n); 35 return malloc(n);
35 } 36 }
36 37
65 66
66 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) { 67 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) {
67 return allocator->cl->realloc(allocator->data, mem, n); 68 return allocator->cl->realloc(allocator->data, mem, n);
68 } 69 }
69 70
71 int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
72 if (mem == NULL) {
73 errno = EINVAL;
74 return 1;
75 }
76 void* nmem = allocator->cl->realloc(allocator->data, *mem, n);
77 if (nmem == NULL) {
78 return 1;
79 } else {
80 *mem = nmem;
81 return 0;
82 }
83 }
84
70 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) { 85 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) {
71 return allocator->cl->calloc(allocator->data, nelem, n); 86 return allocator->cl->calloc(allocator->data, nelem, n);
72 } 87 }
73 88
74 void cxFree(CxAllocator allocator, void *mem) { 89 void cxFree(CxAllocator allocator, void *mem) {

mercurial