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