1988-02-17 20:01:54 -05:00
|
|
|
#ifndef lint
|
|
|
|
|
#ifndef NOID
|
1987-11-04 11:19:47 -05:00
|
|
|
static char elsieid[] = "%W%";
|
1988-02-17 20:01:54 -05:00
|
|
|
#endif /* !defined NOID */
|
|
|
|
|
#endif /* !defined lint */
|
1985-10-15 12:56:17 -04:00
|
|
|
|
1988-02-17 22:22:32 -05:00
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#ifdef __STDC__
|
|
|
|
|
#define HAVEHEADS
|
|
|
|
|
#endif /* defined __STDC__ */
|
|
|
|
|
|
|
|
|
|
#ifdef __TURBOC__
|
|
|
|
|
#define HAVEHEADS
|
|
|
|
|
#endif /* defined __TURBOC__ */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVEHEADS
|
1988-02-15 15:17:37 -05:00
|
|
|
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
|
|
#define alloc_t size_t
|
|
|
|
|
|
1988-02-18 04:55:09 -05:00
|
|
|
char * icalloc(int nelem, int elsize);
|
|
|
|
|
char * icatalloc(char * old, char * new);
|
|
|
|
|
char * icpyalloc(char * string);
|
|
|
|
|
char * imalloc(int n);
|
|
|
|
|
char * irealloc(char * pointer, int size);
|
|
|
|
|
void ifree(char * pointer);
|
|
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#else /* !defined HAVEHEADS */
|
1988-02-15 15:17:37 -05:00
|
|
|
|
|
|
|
|
extern char * calloc();
|
|
|
|
|
extern char * malloc();
|
|
|
|
|
extern char * realloc();
|
|
|
|
|
extern char * strcpy();
|
|
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#ifndef alloc_t
|
1986-02-03 11:16:38 -05:00
|
|
|
#define alloc_t unsigned
|
1987-10-14 15:58:10 -04:00
|
|
|
#endif /* !defined alloc_t */
|
1984-02-21 10:36:09 -05:00
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#endif /* !defined HAVEHEADS */
|
1988-02-15 15:17:37 -05:00
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#ifdef MAL
|
1986-03-12 13:36:34 -05:00
|
|
|
#define NULLMAL(x) ((x) == NULL || (x) == MAL)
|
1987-10-14 15:58:10 -04:00
|
|
|
#else /* !defined MAL */
|
1986-03-12 13:36:34 -05:00
|
|
|
#define NULLMAL(x) ((x) == NULL)
|
1987-10-14 15:58:10 -04:00
|
|
|
#endif /* !defined MAL */
|
1986-03-12 13:36:34 -05:00
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
#define nonzero(n) (((n) == 0) ? 1 : (n))
|
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
|
|
|
{
|
1988-02-17 20:01:54 -05:00
|
|
|
#ifdef MAL
|
1986-03-12 12:58:41 -05:00
|
|
|
register char * result;
|
|
|
|
|
|
1988-02-17 20:01:54 -05:00
|
|
|
result = malloc((alloc_t) nonzero(n));
|
1988-02-15 15:17:37 -05:00
|
|
|
return NULLMAL(result) ? NULL : result;
|
1987-10-14 15:58:10 -04:00
|
|
|
#else /* !defined MAL */
|
1988-02-17 20:01:54 -05:00
|
|
|
return malloc((alloc_t) nonzero(n));
|
1987-10-14 15:58:10 -04:00
|
|
|
#endif /* !defined MAL */
|
1985-10-23 09:48:28 -04:00
|
|
|
}
|
|
|
|
|
|
1986-02-03 11:16:38 -05:00
|
|
|
char *
|
1986-03-12 12:58:41 -05:00
|
|
|
icalloc(nelem, elsize)
|
|
|
|
|
{
|
1986-12-26 22:38:04 -05:00
|
|
|
if (nelem == 0 || elsize == 0)
|
|
|
|
|
nelem = elsize = 1;
|
1988-02-17 20:01:54 -05:00
|
|
|
return calloc((alloc_t) nelem, (alloc_t) elsize);
|
1986-03-12 12:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
irealloc(pointer, size)
|
|
|
|
|
char * pointer;
|
1985-10-23 09:48:28 -04:00
|
|
|
{
|
1986-03-12 13:36:34 -05:00
|
|
|
if (NULLMAL(pointer))
|
1986-03-12 12:58:41 -05:00
|
|
|
return imalloc(size);
|
1988-02-17 20:01:54 -05:00
|
|
|
return realloc(pointer, (alloc_t) nonzero(size));
|
1986-03-12 12:58:41 -05:00
|
|
|
}
|
1985-10-23 09:48:28 -04:00
|
|
|
|
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
|
|
|
newsize = NULLMAL(new) ? 0 : strlen(new);
|
1988-02-05 14:50:09 -05:00
|
|
|
if (NULLMAL(old))
|
|
|
|
|
oldsize = 0;
|
|
|
|
|
else if (newsize == 0)
|
|
|
|
|
return old;
|
|
|
|
|
else oldsize = strlen(old);
|
1988-02-17 21:40:56 -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);
|
|
|
|
|
}
|
|
|
|
|
|
1988-02-15 15:17:37 -05:00
|
|
|
void
|
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
|
|
|
|
1988-02-15 15:17:37 -05:00
|
|
|
void
|
1987-03-29 17:55:10 -05:00
|
|
|
icfree(p)
|
|
|
|
|
char * p;
|
|
|
|
|
{
|
|
|
|
|
if (!NULLMAL(p))
|
|
|
|
|
free(p);
|
|
|
|
|
}
|