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*/
|
|
|
|
|
|
1988-02-18 08:58:56 -05:00
|
|
|
#include "string.h"
|
1988-02-15 15:17:37 -05:00
|
|
|
#include "stdlib.h"
|
1988-02-27 18:44:54 -05:00
|
|
|
#include "nonstd.h"
|
1988-02-18 11:33:47 -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
|
|
|
|
1988-02-18 08:58:56 -05:00
|
|
|
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));
|
|
|
|
|
char * irealloc P((char * pointer, int size));
|
|
|
|
|
void ifree P((char * pointer));
|
|
|
|
|
|
1986-03-12 12:58:41 -05:00
|
|
|
char *
|
|
|
|
|
imalloc(n)
|
1989-02-20 20:44:12 -05:00
|
|
|
const int 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-27 18:44:54 -05:00
|
|
|
result = malloc((alloc_size_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-27 18:44:54 -05:00
|
|
|
return malloc((alloc_size_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)
|
1989-02-20 20:44:12 -05:00
|
|
|
int nelem;
|
|
|
|
|
int elsize;
|
1986-03-12 12:58:41 -05:00
|
|
|
{
|
1986-12-26 22:38:04 -05:00
|
|
|
if (nelem == 0 || elsize == 0)
|
|
|
|
|
nelem = elsize = 1;
|
1988-02-27 18:44:54 -05:00
|
|
|
return calloc((alloc_size_t) nelem, (alloc_size_t) elsize);
|
1986-03-12 12:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
irealloc(pointer, size)
|
1989-02-20 20:44:12 -05:00
|
|
|
char * const pointer;
|
|
|
|
|
const int size;
|
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-27 18:44:54 -05:00
|
|
|
return realloc((genericptr_t) pointer, (alloc_size_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)
|
1989-02-20 20:44:12 -05:00
|
|
|
char * const old;
|
|
|
|
|
const char * const new;
|
1986-03-12 12:58:41 -05:00
|
|
|
{
|
|
|
|
|
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)
|
1989-02-20 20:44:12 -05:00
|
|
|
const char * const string;
|
1986-03-12 12:58:41 -05:00
|
|
|
{
|
|
|
|
|
return icatalloc((char *) NULL, string);
|
|
|
|
|
}
|
|
|
|
|
|
1988-02-15 15:17:37 -05:00
|
|
|
void
|
1986-03-12 13:36:34 -05:00
|
|
|
ifree(p)
|
1989-02-20 20:44:12 -05:00
|
|
|
char * const p;
|
1986-03-12 13:36:34 -05:00
|
|
|
{
|
|
|
|
|
if (!NULLMAL(p))
|
1988-02-27 18:44:54 -05:00
|
|
|
(void) free(p);
|
1986-03-12 13:36:34 -05:00
|
|
|
}
|
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)
|
1989-02-20 20:44:12 -05:00
|
|
|
char * const p;
|
1987-03-29 17:55:10 -05:00
|
|
|
{
|
|
|
|
|
if (!NULLMAL(p))
|
1988-02-27 18:44:54 -05:00
|
|
|
(void) free(p);
|
1987-03-29 17:55:10 -05:00
|
|
|
}
|