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