1994-09-13 05:29:24 +02:00
|
|
|
#ifndef lint
|
|
|
|
#ifndef NOID
|
1995-08-05 22:28:48 +02:00
|
|
|
static char elsieid[] = "@(#)ialloc.c 8.28";
|
1994-09-13 05:29:24 +02:00
|
|
|
#endif /* !defined NOID */
|
|
|
|
#endif /* !defined lint */
|
|
|
|
|
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
#define nonzero(n) (((n) == 0) ? 1 : (n))
|
|
|
|
|
|
|
|
char * icalloc P((int nelem, int elsize));
|
|
|
|
char * icatalloc P((char * old, const char * new));
|
|
|
|
char * icpyalloc P((const char * string));
|
|
|
|
char * imalloc P((int n));
|
1995-08-05 22:28:48 +02:00
|
|
|
void * irealloc P((void * pointer, int size));
|
1994-09-13 05:29:24 +02:00
|
|
|
void ifree P((char * pointer));
|
|
|
|
|
|
|
|
char *
|
|
|
|
imalloc(n)
|
|
|
|
const int n;
|
|
|
|
{
|
1995-08-05 22:28:48 +02:00
|
|
|
return malloc((size_t) nonzero(n));
|
1994-09-13 05:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
icalloc(nelem, elsize)
|
|
|
|
int nelem;
|
|
|
|
int elsize;
|
|
|
|
{
|
|
|
|
if (nelem == 0 || elsize == 0)
|
|
|
|
nelem = elsize = 1;
|
1995-08-05 22:28:48 +02:00
|
|
|
return calloc((size_t) nelem, (size_t) elsize);
|
1994-09-13 05:29:24 +02:00
|
|
|
}
|
|
|
|
|
1995-08-05 22:28:48 +02:00
|
|
|
void *
|
1994-09-13 05:29:24 +02:00
|
|
|
irealloc(pointer, size)
|
1995-08-05 22:28:48 +02:00
|
|
|
void * const pointer;
|
1994-09-13 05:29:24 +02:00
|
|
|
const int size;
|
|
|
|
{
|
1995-08-05 22:28:48 +02:00
|
|
|
if (pointer == NULL)
|
1994-09-13 05:29:24 +02:00
|
|
|
return imalloc(size);
|
1995-08-05 22:28:48 +02:00
|
|
|
return realloc((void *) pointer, (size_t) nonzero(size));
|
1994-09-13 05:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
icatalloc(old, new)
|
|
|
|
char * const old;
|
|
|
|
const char * const new;
|
|
|
|
{
|
|
|
|
register char * result;
|
|
|
|
register int oldsize, newsize;
|
|
|
|
|
1995-08-05 22:28:48 +02:00
|
|
|
newsize = (new == NULL) ? 0 : strlen(new);
|
|
|
|
if (old == NULL)
|
1994-09-13 05:29:24 +02:00
|
|
|
oldsize = 0;
|
|
|
|
else if (newsize == 0)
|
|
|
|
return old;
|
|
|
|
else oldsize = strlen(old);
|
|
|
|
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
|
1995-08-05 22:28:48 +02:00
|
|
|
if (new != NULL)
|
1994-09-13 05:29:24 +02: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 22:28:48 +02:00
|
|
|
if (p != NULL)
|
1994-09-13 05:29:24 +02:00
|
|
|
(void) free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
icfree(p)
|
|
|
|
char * const p;
|
|
|
|
{
|
1995-08-05 22:28:48 +02:00
|
|
|
if (p != NULL)
|
1994-09-13 05:29:24 +02:00
|
|
|
(void) free(p);
|
|
|
|
}
|