1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2025-12-08 17:52:17 +00:00
Files
amiga-tz/ialloc.c
Arthur David Olson e81ba7fc9c boost sizes of zero to one to foil proposed ANSI idiocy
SCCS-file: ialloc.c
SCCS-SID: 7.8
2012-07-18 03:01:38 -04:00

144 lines
1.9 KiB
C

#
/*LINTLIBRARY*/
#include "stdio.h"
#ifdef OBJECTID
static char sccsid[] = "%W%";
#endif
#ifndef alloc_t
#define alloc_t unsigned
#endif
#ifdef MAL
#define NULLMAL(x) ((x) == NULL || (x) == MAL)
#endif
#ifndef MAL
#define NULLMAL(x) ((x) == NULL)
#endif
extern char * malloc();
extern char * calloc();
extern char * realloc();
extern char * strcpy();
char *
imalloc(n)
{
#ifdef MAL
register char * result;
if (n == 0)
n = 1;
result = malloc((alloc_t) n);
return (result == MAL) ? NULL : result;
#endif
#ifndef MAL
if (n == 0)
n = 1;
return malloc((alloc_t) n);
#endif
}
char *
icalloc(nelem, elsize)
{
if (nelem == 0)
nelem = 1;
if (elsize == 0)
elsize = 1;
return calloc((alloc_t) nelem, (alloc_t) elsize);
}
char *
irealloc(pointer, size)
char * pointer;
{
if (size == 0)
size = 1;
if (NULLMAL(pointer))
return imalloc(size);
else return realloc(pointer, (alloc_t) size);
}
char *
icatalloc(old, new)
char * old;
char * new;
{
register char * result;
register oldsize, newsize;
oldsize = NULLMAL(old) ? 0 : strlen(old);
newsize = NULLMAL(new) ? 0 : strlen(new);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (!NULLMAL(new))
(void) strcpy(result + oldsize, new);
return result;
}
char *
icpyalloc(string)
char * string;
{
return icatalloc((char *) NULL, string);
}
ifree(p)
char * p;
{
if (!NULLMAL(p))
free(p);
}
static char *
check(pointer)
char * pointer;
{
if (pointer == NULL)
wildrexit("allocating memory");
return pointer;
}
char *
emalloc(size)
{
return check(imalloc(size));
}
char *
ecalloc(nelem, elsize)
{
return check(icalloc(nelem, elsize));
}
char *
erealloc(ptr, size)
char * ptr;
{
return check(irealloc(ptr, size));
}
char *
ecatalloc(old, new)
char * old;
char * new;
{
return check(icatalloc(old, new));
}
char *
ecpyalloc(string)
char * string;
{
return check(icpyalloc(string));
}
efree(p)
char * p;
{
ifree(p);
}