diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 19:55:29 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 19:55:29 +0000 |
commit | 03f37879ef167dba6f5944716c06da81902e436e (patch) | |
tree | 46a70f3d85f8de8a8a1b648a53754531b86198a6 /src/libstddjb/alloc.c | |
parent | 90c1f3c1580d8e699c2788262a614a930a33e13e (diff) | |
download | skalibs-03f37879ef167dba6f5944716c06da81902e436e.tar.xz |
We're down to ONE rogue sysdep, boys. ONE.
Diffstat (limited to 'src/libstddjb/alloc.c')
-rw-r--r-- | src/libstddjb/alloc.c | 44 |
1 files changed, 2 insertions, 42 deletions
diff --git a/src/libstddjb/alloc.c b/src/libstddjb/alloc.c index 95a5df9..d223a56 100644 --- a/src/libstddjb/alloc.c +++ b/src/libstddjb/alloc.c @@ -1,49 +1,9 @@ /* ISC license. */ -#include <skalibs/sysdeps.h> -#include <errno.h> #include <stdlib.h> #include <skalibs/alloc.h> -#include "alloc-internal.h" -#ifdef DEBUG_ALLOC -# include "buffer.h" -# include "strerr2.h" -# include "lolstdio.h" -# define PLM(...) (bprintf(buffer_2, "%s: debug_alloc: ", PROG), bprintf(buffer_2, __VA_ARGS__), buffer_putflush(buffer_2, "\n", 1)) -#endif - -aligned_char *alloc (size_t n) -{ - aligned_char *p = n ? (aligned_char *)malloc(n) : (aligned_char *)alloc_0 ; -#ifdef DEBUG_ALLOC - static unsigned int counter = 0 ; - PLM("alloc(%u): %p. Allocated: %u", n, p, ++counter) ; -#endif - return p ; -} - -void alloc_free (void *p) -{ - int e = errno ; -#ifdef DEBUG_ALLOC - static unsigned int counter = 0 ; - PLM("alloc_free(%p). Freed: %u", p, ++counter) ; -#endif -#ifndef SKALIBS_HASMALLOC0 - if (p != alloc_0) -#endif - free(p) ; - errno = e ; -} - -int alloc_realloc (aligned_char **x, size_t n) +void *alloc (size_t n) { - aligned_char *y = n ? (aligned_char *)realloc(*x, n) : (free(*x), alloc_0) ; -#ifdef DEBUG_ALLOC - PLM("alloc_realloc(&%p) -> new address = %p", *x, y) ; -#endif - if (!y) return 0 ; - *x = y ; - return 1 ; + return malloc(n ? n : 1) ; } |