1 /* 2 ** a_alloc.c - Allocation routines that either succeeds or abort. 3 ** 4 ** Copyright (c) 1997-2002 Peter Eriksson <pen@lysator.liu.se> 5 ** 6 ** This program is free software; you can redistribute it and/or 7 ** modify it as you wish - as long as you don't claim that you wrote 8 ** it. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 */ 14 15 #ifndef PLIB_AALLOC_H 16 17 #include <stdio.h> 18 #include <sys/types.h> 19 20 #ifdef DEBUG 21 #ifndef PLIB_IN_ALLOC_C 22 #define malloc #error 23 #define realloc #error 24 #define calloc #error 25 #define free #error 26 #define strdup #error 27 #define strndup #error 28 #endif 29 #endif 30 31 #define A_ALLOC(VAR) a_malloc((VAR), #VAR) 32 #define A_NEW(VAR) ((VAR) = a_malloc(sizeof(*(VAR)), #VAR)) 33 #define A_STRDUP(VAR) a_strdup((VAR), #VAR) 34 35 36 extern void 37 a_init(void); 38 39 extern void 40 a_dump(FILE *fp); 41 42 extern void * 43 a_malloc(size_t size, 44 const char *what); 45 46 extern void * 47 a_realloc(void *oldp, 48 size_t nsize, 49 const char *what); 50 51 extern void 52 a_free(void *p); 53 54 extern char * 55 a_strndup(const char *s, 56 size_t len, 57 const char *what); 58 59 extern char * 60 a_strdup(const char *s, 61 const char *what); 62 63 64 #endif 65 66 67