update from main archive 970203
[glibc/history.git] / time / ialloc.c
blob5631947d0718e15072d5d5c0c85486ddb5b84369
1 #ifndef lint
2 #ifndef NOID
3 static char elsieid[] = "@(#)ialloc.c 8.28";
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
7 /*LINTLIBRARY*/
9 #include "private.h"
11 #define nonzero(n) (((n) == 0) ? 1 : (n))
13 char * icalloc P((int nelem, int elsize));
14 char * icatalloc P((char * old, const char * new));
15 char * icpyalloc P((const char * string));
16 char * imalloc P((int n));
17 void * irealloc P((void * pointer, int size));
18 void ifree P((char * pointer));
20 char *
21 imalloc(n)
22 const int n;
24 return malloc((size_t) nonzero(n));
27 char *
28 icalloc(nelem, elsize)
29 int nelem;
30 int elsize;
32 if (nelem == 0 || elsize == 0)
33 nelem = elsize = 1;
34 return calloc((size_t) nelem, (size_t) elsize);
37 void *
38 irealloc(pointer, size)
39 void * const pointer;
40 const int size;
42 if (pointer == NULL)
43 return imalloc(size);
44 return realloc((void *) pointer, (size_t) nonzero(size));
47 char *
48 icatalloc(old, new)
49 char * const old;
50 const char * const new;
52 register char * result;
53 register int oldsize, newsize;
55 newsize = (new == NULL) ? 0 : strlen(new);
56 if (old == NULL)
57 oldsize = 0;
58 else if (newsize == 0)
59 return old;
60 else oldsize = strlen(old);
61 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
62 if (new != NULL)
63 (void) strcpy(result + oldsize, new);
64 return result;
67 char *
68 icpyalloc(string)
69 const char * const string;
71 return icatalloc((char *) NULL, string);
74 void
75 ifree(p)
76 char * const p;
78 if (p != NULL)
79 (void) free(p);
82 void
83 icfree(p)
84 char * const p;
86 if (p != NULL)
87 (void) free(p);