Fixed license declaration at spec file
[platform/upstream/tzdata.git] / 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 /*LINTLIBRARY*/
7
8 #include "private.h"
9
10 #define nonzero(n)      (((n) == 0) ? 1 : (n))
11
12 char *
13 imalloc(n)
14 const int       n;
15 {
16         return malloc((size_t) nonzero(n));
17 }
18
19 char *
20 icalloc(nelem, elsize)
21 int     nelem;
22 int     elsize;
23 {
24         if (nelem == 0 || elsize == 0)
25                 nelem = elsize = 1;
26         return calloc((size_t) nelem, (size_t) elsize);
27 }
28
29 void *
30 irealloc(pointer, size)
31 void * const    pointer;
32 const int       size;
33 {
34         if (pointer == NULL)
35                 return imalloc(size);
36         return realloc((void *) pointer, (size_t) nonzero(size));
37 }
38
39 char *
40 icatalloc(old, new)
41 char * const            old;
42 const char * const      new;
43 {
44         register char * result;
45         register int    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
59 char *
60 icpyalloc(string)
61 const char * const      string;
62 {
63         return icatalloc((char *) NULL, string);
64 }
65
66 void
67 ifree(p)
68 char * const    p;
69 {
70         if (p != NULL)
71                 (void) free(p);
72 }
73
74 void
75 icfree(p)
76 char * const    p;
77 {
78         if (p != NULL)
79                 (void) free(p);
80 }