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