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