ialloc.c revision 9937
1#ifndef lint
2#ifndef NOID
3static char	elsieid[] = "@(#)ialloc.c	8.28";
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
13char *	icalloc P((int nelem, int elsize));
14char *	icatalloc P((char * old, const char * new));
15char *	icpyalloc P((const char * string));
16char *	imalloc P((int n));
17void *	irealloc P((void * pointer, int size));
18void	ifree P((char * pointer));
19
20char *
21imalloc(n)
22const int	n;
23{
24	return malloc((size_t) nonzero(n));
25}
26
27char *
28icalloc(nelem, elsize)
29int	nelem;
30int	elsize;
31{
32	if (nelem == 0 || elsize == 0)
33		nelem = elsize = 1;
34	return calloc((size_t) nelem, (size_t) elsize);
35}
36
37void *
38irealloc(pointer, size)
39void * const	pointer;
40const int	size;
41{
42	if (pointer == NULL)
43		return imalloc(size);
44	return realloc((void *) pointer, (size_t) nonzero(size));
45}
46
47char *
48icatalloc(old, new)
49char * const		old;
50const char * const	new;
51{
52	register char *	result;
53	register int	oldsize, newsize;
54
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;
65}
66
67char *
68icpyalloc(string)
69const char * const	string;
70{
71	return icatalloc((char *) NULL, string);
72}
73
74void
75ifree(p)
76char * const	p;
77{
78	if (p != NULL)
79		(void) free(p);
80}
81
82void
83icfree(p)
84char * const	p;
85{
86	if (p != NULL)
87		(void) free(p);
88}
89