]> git.saurik.com Git - apple/system_cmds.git/blame_incremental - zic.tproj/ialloc.c
system_cmds-735.20.1.tar.gz
[apple/system_cmds.git] / zic.tproj / ialloc.c
... / ...
CommitLineData
1#include <sys/cdefs.h>
2#ifndef lint
3#ifndef NOID
4__unused static const char elsieid[] = "@(#)ialloc.c 8.29";
5#endif /* !defined NOID */
6#endif /* !defined lint */
7
8#ifndef lint
9__unused static const char rcsid[] =
10 "$FreeBSD: src/usr.sbin/zic/ialloc.c,v 1.6 2000/11/28 18:18:56 charnier Exp $";
11#endif /* not lint */
12
13/*LINTLIBRARY*/
14
15#include "private.h"
16
17#define nonzero(n) (((n) == 0) ? 1 : (n))
18
19char *
20imalloc(const size_t n)
21{
22 return malloc(nonzero(n));
23}
24
25char *
26icalloc(size_t nelem, size_t elsize)
27{
28 if (nelem == 0 || elsize == 0)
29 nelem = elsize = 1;
30 return calloc(nelem, elsize);
31}
32
33void *
34irealloc(void * const pointer, const size_t size)
35{
36 if (pointer == NULL)
37 return imalloc(size);
38 return realloc((void *) pointer, nonzero(size));
39}
40
41char *
42icatalloc(char * const old, const char * const new)
43{
44 char * result;
45 size_t oldsize, newsize;
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 *
60icpyalloc(const char * const string)
61{
62 return icatalloc((char *) NULL, string);
63}
64
65void
66ifree(char * const p)
67{
68 if (p != NULL)
69 (void) free(p);
70}
71
72void
73icfree(char * const p)
74{
75 if (p != NULL)
76 (void) free(p);
77}