Home | History | Annotate | Download | only in zic
      1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
      2 
      3 /* static char	elsieid[] = "@(#)ialloc.c	8.29"; */
      4 
      5 /*LINTLIBRARY*/
      6 
      7 #include "private.h"
      8 
      9 #define	nonzero(n)	(((n) == 0) ? 1 : (n))
     10 
     11 char *
     12 imalloc(n)
     13 const int	n;
     14 {
     15 	return (malloc((size_t) nonzero(n)));
     16 }
     17 
     18 void *
     19 irealloc(pointer, size)
     20 void * const	pointer;
     21 const int	size;
     22 {
     23 	if (pointer == NULL)
     24 		return (imalloc(size));
     25 	return (realloc((void *) pointer, (size_t) nonzero(size)));
     26 }
     27 
     28 char *
     29 icatalloc(old, new)
     30 char * const		old;
     31 const char * const	new;
     32 {
     33 	register char *	result;
     34 	register int	oldsize, newsize;
     35 
     36 	newsize = (new == NULL) ? 0 : strlen(new);
     37 	if (old == NULL)
     38 		oldsize = 0;
     39 	else if (newsize == 0)
     40 		return (old);
     41 	else	oldsize = strlen(old);
     42 	if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
     43 		if (new != NULL)
     44 			(void) strcpy(result + oldsize, new);
     45 	return (result);
     46 }
     47 
     48 char *
     49 icpyalloc(string)
     50 const char * const	string;
     51 {
     52 	return (icatalloc((char *) NULL, string));
     53 }
     54 
     55 void
     56 ifree(p)
     57 char * const	p;
     58 {
     59 	if (p != NULL)
     60 		(void) free(p);
     61 }
     62