Files
amiga-tz/ialloc.c
T

100 lines
1.5 KiB
C
Raw Normal View History

1985-10-15 12:56:17 -04:00
#
1984-03-11 00:42:43 -05:00
1984-02-21 10:36:09 -05:00
/*LINTLIBRARY*/
1985-01-14 13:23:36 -05:00
#include "stdio.h"
1986-12-22 13:08:45 -05:00
#ifndef lint
#ifndef NOID
1985-10-15 12:56:17 -04:00
static char sccsid[] = "%W%";
1986-12-22 13:08:45 -05:00
#endif /* !NOID */
#endif /* !lint */
1985-10-15 12:56:17 -04:00
1986-02-03 11:16:38 -05:00
#ifndef alloc_t
#define alloc_t unsigned
1986-12-26 14:38:56 -05:00
#endif /* !alloc_t */
1984-02-21 10:36:09 -05:00
1986-03-12 13:36:34 -05:00
#ifdef MAL
#define NULLMAL(x) ((x) == NULL || (x) == MAL)
1986-12-26 14:38:56 -05:00
#else /* !MAL */
1986-03-12 13:36:34 -05:00
#define NULLMAL(x) ((x) == NULL)
1986-12-26 14:38:56 -05:00
#endif /* !MAL */
1986-03-12 13:36:34 -05:00
1986-02-03 11:16:38 -05:00
extern char * calloc();
1986-12-25 18:05:25 -05:00
extern char * malloc();
1986-02-03 11:16:38 -05:00
extern char * realloc();
extern char * strcpy();
1985-10-23 09:48:28 -04:00
1986-03-12 12:58:41 -05:00
char *
imalloc(n)
1985-10-23 09:48:28 -04:00
{
1986-03-12 12:58:41 -05:00
#ifdef MAL
register char * result;
if (n == 0)
n = 1;
1986-03-12 12:58:41 -05:00
result = malloc((alloc_t) n);
return (result == MAL) ? NULL : result;
1986-12-26 14:38:56 -05:00
#else /* !MAL */
if (n == 0)
n = 1;
1986-03-12 12:58:41 -05:00
return malloc((alloc_t) n);
1986-12-26 14:38:56 -05:00
#endif /* !MAL */
1986-03-12 12:58:41 -05:00
}
char *
icalloc(nelem, elsize)
{
1986-12-26 22:38:04 -05:00
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
1986-03-12 12:58:41 -05:00
return calloc((alloc_t) nelem, (alloc_t) elsize);
}
char *
irealloc(pointer, size)
char * pointer;
{
1986-03-12 13:36:34 -05:00
if (NULLMAL(pointer))
1986-03-12 12:58:41 -05:00
return imalloc(size);
1987-01-01 13:22:17 -05:00
if (size == 0)
size = 1;
return realloc(pointer, (alloc_t) size);
1986-03-12 12:58:41 -05:00
}
char *
icatalloc(old, new)
char * old;
char * new;
{
register char * result;
register oldsize, newsize;
1986-03-12 13:36:34 -05:00
oldsize = NULLMAL(old) ? 0 : strlen(old);
newsize = NULLMAL(new) ? 0 : strlen(new);
1986-03-12 12:58:41 -05:00
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
1986-03-12 13:36:34 -05:00
if (!NULLMAL(new))
1986-03-12 12:58:41 -05:00
(void) strcpy(result + oldsize, new);
return result;
}
char *
icpyalloc(string)
char * string;
{
return icatalloc((char *) NULL, string);
1985-10-23 09:48:28 -04:00
}
1986-03-12 13:36:34 -05:00
ifree(p)
char * p;
{
if (!NULLMAL(p))
free(p);
}
1987-03-29 17:55:10 -05:00
icfree(p)
char * p;
{
if (!NULLMAL(p))
free(p);
}