intl/icu/source/tools/tzcode/ialloc.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/tzcode/ialloc.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/*
     1.5 +** This file is in the public domain, so clarified as of
     1.6 +** 2006-07-17 by Arthur David Olson.
     1.7 +*/
     1.8 +
     1.9 +#ifndef lint
    1.10 +#ifndef NOID
    1.11 +static char	elsieid[] = "@(#)ialloc.c	8.30";
    1.12 +#endif /* !defined NOID */
    1.13 +#endif /* !defined lint */
    1.14 +
    1.15 +/*LINTLIBRARY*/
    1.16 +
    1.17 +#include "private.h"
    1.18 +
    1.19 +#define nonzero(n)	(((n) == 0) ? 1 : (n))
    1.20 +
    1.21 +char *
    1.22 +imalloc(n)
    1.23 +const int	n;
    1.24 +{
    1.25 +	return malloc((size_t) nonzero(n));
    1.26 +}
    1.27 +
    1.28 +char *
    1.29 +icalloc(nelem, elsize)
    1.30 +int	nelem;
    1.31 +int	elsize;
    1.32 +{
    1.33 +	if (nelem == 0 || elsize == 0)
    1.34 +		nelem = elsize = 1;
    1.35 +	return calloc((size_t) nelem, (size_t) elsize);
    1.36 +}
    1.37 +
    1.38 +void *
    1.39 +irealloc(pointer, size)
    1.40 +void * const	pointer;
    1.41 +const int	size;
    1.42 +{
    1.43 +	if (pointer == NULL)
    1.44 +		return imalloc(size);
    1.45 +	return realloc((void *) pointer, (size_t) nonzero(size));
    1.46 +}
    1.47 +
    1.48 +char *
    1.49 +icatalloc(old, new)
    1.50 +char * const		old;
    1.51 +const char * const	new;
    1.52 +{
    1.53 +	register char *	result;
    1.54 +	register int	oldsize, newsize;
    1.55 +
    1.56 +	newsize = (new == NULL) ? 0 : strlen(new);
    1.57 +	if (old == NULL)
    1.58 +		oldsize = 0;
    1.59 +	else if (newsize == 0)
    1.60 +		return old;
    1.61 +	else	oldsize = strlen(old);
    1.62 +	if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
    1.63 +		if (new != NULL)
    1.64 +			(void) strcpy(result + oldsize, new);
    1.65 +	return result;
    1.66 +}
    1.67 +
    1.68 +char *
    1.69 +icpyalloc(string)
    1.70 +const char * const	string;
    1.71 +{
    1.72 +	return icatalloc((char *) NULL, string);
    1.73 +}
    1.74 +
    1.75 +void
    1.76 +ifree(p)
    1.77 +char * const	p;
    1.78 +{
    1.79 +	if (p != NULL)
    1.80 +		(void) free(p);
    1.81 +}
    1.82 +
    1.83 +void
    1.84 +icfree(p)
    1.85 +char * const	p;
    1.86 +{
    1.87 +	if (p != NULL)
    1.88 +		(void) free(p);
    1.89 +}

mercurial