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