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