Files
amiga-tz/ialloc.c
T

82 lines
1.2 KiB
C
Raw Normal View History

1992-11-23 11:25:20 -05:00
#ifndef lint
#ifndef NOID
static char elsieid[] = "%W%";
#endif /* !defined NOID */
#endif /* !defined lint */
1985-10-15 12:56:17 -04:00
1988-02-17 22:22:32 -05:00
/*LINTLIBRARY*/
1992-11-23 11:25:20 -05:00
#include "private.h"
1988-02-18 11:33:47 -05:00
1992-11-23 11:25:20 -05:00
#define nonzero(n) (((n) == 0) ? 1 : (n))
char *
imalloc(n)
const int n;
1985-10-23 09:48:28 -04:00
{
1995-01-06 17:11:13 -05:00
return malloc((size_t) nonzero(n));
1986-03-12 12:58:41 -05:00
}
1992-11-23 11:25:20 -05:00
char *
icalloc(nelem, elsize)
int nelem;
int elsize;
1986-03-12 12:58:41 -05:00
{
1992-11-23 11:25:20 -05:00
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
1995-01-06 17:11:13 -05:00
return calloc((size_t) nelem, (size_t) elsize);
1992-11-23 11:25:20 -05:00
}
1994-06-07 16:05:15 -04:00
void *
1992-11-23 11:25:20 -05:00
irealloc(pointer, size)
1994-06-07 16:05:15 -04:00
void * const pointer;
1992-11-23 11:25:20 -05:00
const int size;
{
1995-01-06 17:55:30 -05:00
if (pointer == NULL)
1992-11-23 11:25:20 -05:00
return imalloc(size);
1995-01-06 17:11:13 -05:00
return realloc((void *) pointer, (size_t) nonzero(size));
1992-11-23 11:25:20 -05:00
}
char *
icatalloc(old, new)
char * const old;
const char * const new;
{
register char * result;
register int oldsize, newsize;
1995-01-06 17:55:30 -05:00
newsize = (new == NULL) ? 0 : strlen(new);
if (old == NULL)
1992-11-23 11:25:20 -05:00
oldsize = 0;
else if (newsize == 0)
return old;
else oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
1995-01-06 17:55:30 -05:00
if (new != NULL)
1992-11-23 11:25:20 -05: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-01-06 17:55:30 -05:00
if (p != NULL)
1992-11-23 11:25:20 -05:00
(void) free(p);
}
void
icfree(p)
char * const p;
{
1995-01-06 17:55:30 -05:00
if (p != NULL)
1992-11-23 11:25:20 -05:00
(void) free(p);
1987-03-29 17:55:10 -05:00
}