]> git.saurik.com Git - apple/system_cmds.git/blame - zic.tproj/ialloc.c
system_cmds-805.250.2.tar.gz
[apple/system_cmds.git] / zic.tproj / ialloc.c
CommitLineData
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 8static const char elsieid[] = "@(#)ialloc.c 8.30";
2fc1e207
A
9#endif /* !defined NOID */
10#endif /* !defined lint */
11
12#ifndef lint
887d5eed
A
13static 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 23char *
887d5eed
A
24imalloc(n)
25const int n;
1815bff5 26{
887d5eed 27 return malloc((size_t) nonzero(n));
1815bff5
A
28}
29
30char *
887d5eed
A
31icalloc(nelem, elsize)
32int nelem;
33int 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
40void *
887d5eed
A
41irealloc(pointer, size)
42void * const pointer;
43const 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
50char *
887d5eed
A
51icatalloc(old, new)
52char * const old;
53const 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
70char *
887d5eed
A
71icpyalloc(string)
72const char * const string;
1815bff5
A
73{
74 return icatalloc((char *) NULL, string);
75}
76
77void
887d5eed
A
78ifree(p)
79char * const p;
1815bff5
A
80{
81 if (p != NULL)
82 (void) free(p);
83}
84
85void
887d5eed
A
86icfree(p)
87char * const p;
1815bff5
A
88{
89 if (p != NULL)
90 (void) free(p);
91}