xref: /csrg-svn/share/zoneinfo/ialloc.c (revision 46793)
139982Sbostic #ifndef lint
239982Sbostic #ifndef NOID
339982Sbostic static char	elsieid[] = "@(#)ialloc.c	8.18";
439982Sbostic #endif /* !defined NOID */
539982Sbostic #endif /* !defined lint */
639982Sbostic 
739982Sbostic /*LINTLIBRARY*/
839982Sbostic 
9*46793Sbostic #include <string.h>
10*46793Sbostic #include <stdlib.h>
1139982Sbostic 
1239982Sbostic #ifdef MAL
1339982Sbostic #define NULLMAL(x)	((x) == NULL || (x) == MAL)
1439982Sbostic #else /* !defined MAL */
1539982Sbostic #define NULLMAL(x)	((x) == NULL)
1639982Sbostic #endif /* !defined MAL */
1739982Sbostic 
1839982Sbostic #define nonzero(n)	(((n) == 0) ? 1 : (n))
1939982Sbostic 
20*46793Sbostic char *	icalloc __P((int nelem, int elsize));
21*46793Sbostic char *	icatalloc __P((char * old, const char * new));
22*46793Sbostic char *	icpyalloc __P((const char * string));
23*46793Sbostic char *	imalloc __P((int n));
24*46793Sbostic char *	irealloc __P((char * pointer, int size));
25*46793Sbostic void	ifree __P((char * pointer));
2639982Sbostic 
2739982Sbostic char *
2839982Sbostic imalloc(n)
2939982Sbostic const int	n;
3039982Sbostic {
3139982Sbostic #ifdef MAL
3239982Sbostic 	register char *	result;
3339982Sbostic 
34*46793Sbostic 	result = malloc((size_t) nonzero(n));
3539982Sbostic 	return NULLMAL(result) ? NULL : result;
3639982Sbostic #else /* !defined MAL */
37*46793Sbostic 	return malloc((size_t) nonzero(n));
3839982Sbostic #endif /* !defined MAL */
3939982Sbostic }
4039982Sbostic 
4139982Sbostic char *
4239982Sbostic icalloc(nelem, elsize)
4339982Sbostic int	nelem;
4439982Sbostic int	elsize;
4539982Sbostic {
4639982Sbostic 	if (nelem == 0 || elsize == 0)
4739982Sbostic 		nelem = elsize = 1;
48*46793Sbostic 	return calloc((size_t) nelem, (size_t) elsize);
4939982Sbostic }
5039982Sbostic 
5139982Sbostic char *
5239982Sbostic irealloc(pointer, size)
5339982Sbostic char * const	pointer;
5439982Sbostic const int	size;
5539982Sbostic {
5639982Sbostic 	if (NULLMAL(pointer))
5739982Sbostic 		return imalloc(size);
58*46793Sbostic 	return realloc((void *) pointer, (size_t) nonzero(size));
5939982Sbostic }
6039982Sbostic 
6139982Sbostic char *
6239982Sbostic icatalloc(old, new)
6339982Sbostic char * const		old;
6439982Sbostic const char * const	new;
6539982Sbostic {
6639982Sbostic 	register char *	result;
6739982Sbostic 	register	oldsize, newsize;
6839982Sbostic 
6939982Sbostic 	newsize = NULLMAL(new) ? 0 : strlen(new);
7039982Sbostic 	if (NULLMAL(old))
7139982Sbostic 		oldsize = 0;
7239982Sbostic 	else if (newsize == 0)
7339982Sbostic 		return old;
7439982Sbostic 	else	oldsize = strlen(old);
7539982Sbostic 	if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
7639982Sbostic 		if (!NULLMAL(new))
7739982Sbostic 			(void) strcpy(result + oldsize, new);
7839982Sbostic 	return result;
7939982Sbostic }
8039982Sbostic 
8139982Sbostic char *
8239982Sbostic icpyalloc(string)
8339982Sbostic const char * const	string;
8439982Sbostic {
8539982Sbostic 	return icatalloc((char *) NULL, string);
8639982Sbostic }
8739982Sbostic 
8839982Sbostic void
8939982Sbostic ifree(p)
9039982Sbostic char * const	p;
9139982Sbostic {
9239982Sbostic 	if (!NULLMAL(p))
9339982Sbostic 		(void) free(p);
9439982Sbostic }
9539982Sbostic 
9639982Sbostic void
9739982Sbostic icfree(p)
9839982Sbostic char * const	p;
9939982Sbostic {
10039982Sbostic 	if (!NULLMAL(p))
10139982Sbostic 		(void) free(p);
10239982Sbostic }
103