2009-05-23 06:31:50 +00:00
|
|
|
/*
|
|
|
|
** This file is in the public domain, so clarified as of
|
|
|
|
** 2006-07-17 by Arthur David Olson.
|
|
|
|
*/
|
|
|
|
|
1994-09-13 03:29:24 +00:00
|
|
|
#ifndef lint
|
|
|
|
#ifndef NOID
|
2009-05-23 06:31:50 +00:00
|
|
|
static const char elsieid[] = "@(#)ialloc.c 8.30";
|
1994-09-13 03:29:24 +00:00
|
|
|
#endif /* !defined NOID */
|
|
|
|
#endif /* !defined lint */
|
|
|
|
|
1997-10-29 07:27:56 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1997-10-29 07:27:56 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-09-13 03:29:24 +00:00
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
#define nonzero(n) (((n) == 0) ? 1 : (n))
|
|
|
|
|
|
|
|
char *
|
|
|
|
imalloc(n)
|
|
|
|
const int n;
|
|
|
|
{
|
1995-08-05 20:28:48 +00:00
|
|
|
return malloc((size_t) nonzero(n));
|
1994-09-13 03:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
icalloc(nelem, elsize)
|
|
|
|
int nelem;
|
|
|
|
int elsize;
|
|
|
|
{
|
|
|
|
if (nelem == 0 || elsize == 0)
|
|
|
|
nelem = elsize = 1;
|
1995-08-05 20:28:48 +00:00
|
|
|
return calloc((size_t) nelem, (size_t) elsize);
|
1994-09-13 03:29:24 +00:00
|
|
|
}
|
|
|
|
|
1995-08-05 20:28:48 +00:00
|
|
|
void *
|
1994-09-13 03:29:24 +00:00
|
|
|
irealloc(pointer, size)
|
1995-08-05 20:28:48 +00:00
|
|
|
void * const pointer;
|
1994-09-13 03:29:24 +00:00
|
|
|
const int size;
|
|
|
|
{
|
1995-08-05 20:28:48 +00:00
|
|
|
if (pointer == NULL)
|
1994-09-13 03:29:24 +00:00
|
|
|
return imalloc(size);
|
1995-08-05 20:28:48 +00:00
|
|
|
return realloc((void *) pointer, (size_t) nonzero(size));
|
1994-09-13 03:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
icatalloc(old, new)
|
|
|
|
char * const old;
|
|
|
|
const char * const new;
|
|
|
|
{
|
|
|
|
register char * result;
|
|
|
|
register int oldsize, newsize;
|
|
|
|
|
1995-08-05 20:28:48 +00:00
|
|
|
newsize = (new == NULL) ? 0 : strlen(new);
|
|
|
|
if (old == NULL)
|
1994-09-13 03:29:24 +00:00
|
|
|
oldsize = 0;
|
|
|
|
else if (newsize == 0)
|
|
|
|
return old;
|
|
|
|
else oldsize = strlen(old);
|
|
|
|
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
|
1995-08-05 20:28:48 +00:00
|
|
|
if (new != NULL)
|
1994-09-13 03:29:24 +00:00
|
|
|
(void) strcpy(result + oldsize, new);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
icpyalloc(string)
|
|
|
|
const char * const string;
|
|
|
|
{
|
|
|
|
return icatalloc((char *) NULL, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ifree(p)
|
|
|
|
char * const p;
|
|
|
|
{
|
1995-08-05 20:28:48 +00:00
|
|
|
if (p != NULL)
|
1994-09-13 03:29:24 +00:00
|
|
|
(void) free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
icfree(p)
|
|
|
|
char * const p;
|
|
|
|
{
|
1995-08-05 20:28:48 +00:00
|
|
|
if (p != NULL)
|
1994-09-13 03:29:24 +00:00
|
|
|
(void) free(p);
|
|
|
|
}
|