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"
|
|
|
|
|
|
1987-10-14 15:58:10 -04:00
|
|
|
#if !defined lint && !defined NOID
|
1987-11-04 11:19:47 -05:00
|
|
|
static char elsieid[] = "%W%";
|
1987-10-14 15:58:10 -04:00
|
|
|
#endif /* !defined lint && !defined NOID */
|
1985-10-15 12:56:17 -04:00
|
|
|
|
1988-02-15 15:17:37 -05:00
|
|
|
#if defined __STDC__ || defined __TURBOC__
|
|
|
|
|
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
|
|
#define alloc_t size_t
|
|
|
|
|
|
|
|
|
|
#else /* !defined __STDC__ || defined __TURBOC__ */
|
|
|
|
|
|
|
|
|
|
extern char * calloc();
|
|
|
|
|
extern char * malloc();
|
|
|
|
|
extern char * realloc();
|
|
|
|
|
extern char * strcpy();
|
|
|
|
|
|
1987-10-14 15:58:10 -04:00
|
|
|
#if !defined 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-15 15:17:37 -05:00
|
|
|
#endif /* !defined __STDC__ || defined __TURBOC__ */
|
|
|
|
|
|
1987-10-14 15:58:10 -04:00
|
|
|
#if defined 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-15 15:17:37 -05:00
|
|
|
/*
|
|
|
|
|
** Beat a know TurboC 1.0 bug.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined __TURBOC__ && __TURBOC__ == 1
|
|
|
|
|
#define roundup(n) (((n) + 1) & ~1)
|
|
|
|
|
#else /* !(defined __TURBOC__ && __TURBOC__ == 1) */
|
|
|
|
|
#if !defined roundup
|
|
|
|
|
#define roundup(n) (n)
|
|
|
|
|
#endif /* !defined roundup */
|
|
|
|
|
#endif /* !(defined __TURBOC__ && __TURBOC__ == 1) */
|
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
|
|
|
{
|
1987-10-14 15:58:10 -04:00
|
|
|
#if defined MAL
|
1986-03-12 12:58:41 -05:00
|
|
|
register char * result;
|
|
|
|
|
|
1986-08-26 11:23:33 -04:00
|
|
|
if (n == 0)
|
|
|
|
|
n = 1;
|
1986-03-12 12:58:41 -05:00
|
|
|
result = malloc((alloc_t) 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 */
|
1986-08-26 11:23:33 -04:00
|
|
|
if (n == 0)
|
|
|
|
|
n = 1;
|
1988-02-15 15:17:37 -05:00
|
|
|
return malloc((alloc_t) roundup(n));
|
1987-10-14 15:58:10 -04:00
|
|
|
#endif /* !defined 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;
|
1988-02-15 15:17:37 -05:00
|
|
|
return calloc((alloc_t) nelem, (alloc_t) roundup(elsize));
|
1986-03-12 12:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
1988-02-15 15:17:37 -05:00
|
|
|
return realloc(pointer, (alloc_t) roundup(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
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|