]> git.saurik.com Git - apple/system_cmds.git/blame - zic.tproj/ialloc.c
system_cmds-735.20.1.tar.gz
[apple/system_cmds.git] / zic.tproj / ialloc.c
CommitLineData
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 19char *
cf37c299 20imalloc(const size_t n)
1815bff5 21{
cf37c299 22 return malloc(nonzero(n));
1815bff5
A
23}
24
25char *
cf37c299 26icalloc(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
33void *
cf37c299 34irealloc(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
41char *
cf37c299 42icatalloc(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
59char *
cf37c299 60icpyalloc(const char * const string)
1815bff5
A
61{
62 return icatalloc((char *) NULL, string);
63}
64
65void
cf37c299 66ifree(char * const p)
1815bff5
A
67{
68 if (p != NULL)
69 (void) free(p);
70}
71
72void
cf37c299 73icfree(char * const p)
1815bff5
A
74{
75 if (p != NULL)
76 (void) free(p);
77}