src/allocator.c

changeset 414
81a4c3a63e65
parent 397
cfc1193b1e65
child 434
38ee262e8b94
     1.1 --- a/src/allocator.c	Sun Feb 14 15:37:12 2021 +0100
     1.2 +++ b/src/allocator.c	Mon Mar 01 22:19:06 2021 +0100
     1.3 @@ -29,6 +29,7 @@
     1.4  #include "cx/allocator.h"
     1.5  
     1.6  #include <stdlib.h>
     1.7 +#include <errno.h>
     1.8  
     1.9  void *cx_malloc_stdlib(void *unused, size_t n) {
    1.10      return malloc(n);
    1.11 @@ -67,6 +68,20 @@
    1.12      return allocator->cl->realloc(allocator->data, mem, n);
    1.13  }
    1.14  
    1.15 +int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
    1.16 +    if (mem == NULL) {
    1.17 +        errno = EINVAL;
    1.18 +        return 1;
    1.19 +    }
    1.20 +    void* nmem = allocator->cl->realloc(allocator->data, *mem, n);
    1.21 +    if (nmem == NULL) {
    1.22 +        return 1;
    1.23 +    } else {
    1.24 +        *mem = nmem;
    1.25 +        return 0;
    1.26 +    }
    1.27 +}
    1.28 +
    1.29  void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) {
    1.30      return allocator->cl->calloc(allocator->data, nelem, n);
    1.31  }

mercurial