]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/tzcode/zic/ialloc.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / tzcode / zic / ialloc.c
1 /*
2 ** This file is in the public domain, so clarified as of
3 ** 2006-07-17 by Arthur David Olson.
4 */
5
6 #ifndef lint
7 #ifndef NOID
8 static const char       elsieid[] = "@(#)ialloc.c       8.30";
9 #endif /* !defined NOID */
10 #endif /* !defined lint */
11
12 #ifndef lint
13 static const char rcsid[] =
14   "$FreeBSD$";
15 #endif /* not lint */
16
17 /*LINTLIBRARY*/
18
19 #include "private.h"
20
21 #define nonzero(n)      (((n) == 0) ? 1 : (n))
22
23 char *
24 imalloc(n)
25 const int       n;
26 {
27         return malloc((size_t) nonzero(n));
28 }
29
30 char *
31 icalloc(nelem, elsize)
32 int     nelem;
33 int     elsize;
34 {
35         if (nelem == 0 || elsize == 0)
36                 nelem = elsize = 1;
37         return calloc((size_t) nelem, (size_t) elsize);
38 }
39
40 void *
41 irealloc(pointer, size)
42 void * const    pointer;
43 const int       size;
44 {
45         if (pointer == NULL)
46                 return imalloc(size);
47         return realloc((void *) pointer, (size_t) nonzero(size));
48 }
49
50 char *
51 icatalloc(old, new)
52 char * const            old;
53 const char * const      new;
54 {
55         register char * result;
56         register int    oldsize, newsize;
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
70 char *
71 icpyalloc(string)
72 const char * const      string;
73 {
74         return icatalloc((char *) NULL, string);
75 }
76
77 void
78 ifree(p)
79 char * const    p;
80 {
81         if (p != NULL)
82                 (void) free(p);
83 }
84
85 void
86 icfree(p)
87 char * const    p;
88 {
89         if (p != NULL)
90                 (void) free(p);
91 }