1/* 2** This file is in the public domain, so clarified as of 3** 2006-07-17 by Arthur David Olson. 4*/ 5 6#ifndef lint 7#ifndef NOID 8static const char elsieid[] = "@(#)ialloc.c 8.30"; 9#endif /* !defined NOID */ 10#endif /* !defined lint */ 11 12#ifndef lint 13static const char rcsid[] = 14 "$FreeBSD$"; 15#endif /* not lint */ 16 17/*LINTLIBRARY*/ 18 19#include "private.h" 20 21#define nonzero(n) (((n) == 0) ? 1 : (n)) 22 23char * 24imalloc(n) 25const int n; 26{ 27 return malloc((size_t) nonzero(n)); 28} 29 30char * 31icalloc(nelem, elsize) 32int nelem; 33int elsize; 34{ 35 if (nelem == 0 || elsize == 0) 36 nelem = elsize = 1; 37 return calloc((size_t) nelem, (size_t) elsize); 38} 39 40void * 41irealloc(pointer, size) 42void * const pointer; 43const int size; 44{ 45 if (pointer == NULL) 46 return imalloc(size); 47 return realloc((void *) pointer, (size_t) nonzero(size)); 48} 49 50char * 51icatalloc(old, new) 52char * const old; 53const char * const new; 54{ 55 register char * result; 56 register int oldsize, newsize; 57 58 newsize = (new == NULL) ? 0 : strlen(new); 59 if (old == NULL) 60 oldsize = 0; 61 else if (newsize == 0) 62 return old; 63 else oldsize = strlen(old); 64 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL) 65 if (new != NULL) 66 (void) strcpy(result + oldsize, new); 67 return result; 68} 69 70char * 71icpyalloc(string) 72const char * const string; 73{ 74 return icatalloc((char *) NULL, string); 75} 76 77void 78ifree(p) 79char * const p; 80{ 81 if (p != NULL) 82 (void) free(p); 83} 84 85void 86icfree(p) 87char * const p; 88{ 89 if (p != NULL) 90 (void) free(p); 91} 92