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