Files
amiga-tz/ialloc.c
T

104 lines
1.8 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
#ifdef MAL
#define NULLMAL(x) ((x) == NULL || (x) == MAL)
1993-11-22 12:58:12 -05:00
#endif /* defined MAL */
#ifndef MAL
1992-11-23 11:25:20 -05:00
#define NULLMAL(x) ((x) == NULL)
#endif /* !defined MAL */
1986-03-12 13:36:34 -05:00
1992-11-23 11:25:20 -05:00
#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));
1994-06-07 16:05:15 -04:00
void * irealloc P((void * pointer, int size));
1992-11-23 11:25:20 -05:00
void ifree P((char * pointer));
char *
imalloc(n)
const int n;
1985-10-23 09:48:28 -04:00
{
1992-11-23 11:25:20 -05:00
#ifdef MAL
register char * result;
1986-03-12 12:58:41 -05:00
1994-08-20 13:17:28 -04:00
result = malloc((alloc_size_T) nonzero(n));
1992-11-23 11:25:20 -05:00
return NULLMAL(result) ? NULL : result;
1993-11-22 12:58:12 -05:00
#endif /* defined MAL */
#ifndef MAL
1994-08-20 13:17:28 -04:00
return malloc((alloc_size_T) nonzero(n));
1992-11-23 11:25:20 -05:00
#endif /* !defined MAL */
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;
1994-08-20 13:17:28 -04:00
return calloc((alloc_size_T) nelem, (alloc_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;
{
if (NULLMAL(pointer))
return imalloc(size);
1995-01-02 12:05:51 -05:00
return realloc((generic_T *) pointer, (alloc_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;
newsize = NULLMAL(new) ? 0 : strlen(new);
if (NULLMAL(old))
oldsize = 0;
else if (newsize == 0)
return old;
else oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (!NULLMAL(new))
(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;
{
if (!NULLMAL(p))
(void) free(p);
}
void
icfree(p)
char * const p;
{
if (!NULLMAL(p))
(void) free(p);
1987-03-29 17:55:10 -05:00
}