Update.
[platform/upstream/linaro-glibc.git] / time / ialloc.c
1 #ifndef lint
2 #ifndef NOID
3 static char     elsieid[] = "@(#)ialloc.c       8.29";
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
6
7 /*LINTLIBRARY*/
8
9 #include "private.h"
10
11 #define nonzero(n)      (((n) == 0) ? 1 : (n))
12
13 char *
14 imalloc(n)
15 const int       n;
16 {
17         return malloc((size_t) nonzero(n));
18 }
19
20 char *
21 icalloc(nelem, elsize)
22 int     nelem;
23 int     elsize;
24 {
25         if (nelem == 0 || elsize == 0)
26                 nelem = elsize = 1;
27         return calloc((size_t) nelem, (size_t) elsize);
28 }
29
30 void *
31 irealloc(pointer, size)
32 void * const    pointer;
33 const int       size;
34 {
35         if (pointer == NULL)
36                 return imalloc(size);
37         return realloc((void *) pointer, (size_t) nonzero(size));
38 }
39
40 char *
41 icatalloc(old, new)
42 char * const            old;
43 const char * const      new;
44 {
45         register char * result;
46         register int    oldsize, newsize;
47
48         newsize = (new == NULL) ? 0 : strlen(new);
49         if (old == NULL)
50                 oldsize = 0;
51         else if (newsize == 0)
52                 return old;
53         else    oldsize = strlen(old);
54         if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
55                 if (new != NULL)
56                         (void) strcpy(result + oldsize, new);
57         return result;
58 }
59
60 char *
61 icpyalloc(string)
62 const char * const      string;
63 {
64         return icatalloc((char *) NULL, string);
65 }
66
67 void
68 ifree(p)
69 char * const    p;
70 {
71         if (p != NULL)
72                 (void) free(p);
73 }
74
75 void
76 icfree(p)
77 char * const    p;
78 {
79         if (p != NULL)
80                 (void) free(p);
81 }