1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2026-05-07 03:27:35 +00:00

more turbo/BSD work

SCCS-file: ialloc.c
SCCS-SID: 8.8
This commit is contained in:
Arthur David Olson
1988-02-15 15:17:37 -05:00
committed by Paul Eggert
parent 34aa5b8c0a
commit 26958ab815

View File

@@ -8,25 +8,43 @@
static char elsieid[] = "%W%"; static char elsieid[] = "%W%";
#endif /* !defined lint && !defined NOID */ #endif /* !defined lint && !defined NOID */
#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();
#if !defined alloc_t #if !defined alloc_t
#define alloc_t unsigned #define alloc_t unsigned
#endif /* !defined alloc_t */ #endif /* !defined alloc_t */
#endif /* !defined __STDC__ || defined __TURBOC__ */
#if defined MAL #if defined MAL
#define NULLMAL(x) ((x) == NULL || (x) == MAL) #define NULLMAL(x) ((x) == NULL || (x) == MAL)
#else /* !defined MAL */ #else /* !defined MAL */
#define NULLMAL(x) ((x) == NULL) #define NULLMAL(x) ((x) == NULL)
#endif /* !defined MAL */ #endif /* !defined MAL */
#if defined __STDC__ || defined __TURBOC__ /*
#include "alloc.h" ** Beat a know TurboC 1.0 bug.
#include "string.h" */
#else /* !defined __STDC__ || defined __TURBOC__ */
extern char * calloc(); #if defined __TURBOC__ && __TURBOC__ == 1
extern char * malloc(); #define roundup(n) (((n) + 1) & ~1)
extern char * realloc(); #else /* !(defined __TURBOC__ && __TURBOC__ == 1) */
extern char * strcpy(); #if !defined roundup
#endif /* !defined __STDC__ || defined __TURBOC__ */ #define roundup(n) (n)
#endif /* !defined roundup */
#endif /* !(defined __TURBOC__ && __TURBOC__ == 1) */
char * char *
imalloc(n) imalloc(n)
@@ -37,18 +55,11 @@ imalloc(n)
if (n == 0) if (n == 0)
n = 1; n = 1;
result = malloc((alloc_t) n); result = malloc((alloc_t) n);
return (result == MAL) ? NULL : result; return NULLMAL(result) ? NULL : result;
#else /* !defined MAL */ #else /* !defined MAL */
if (n == 0) if (n == 0)
n = 1; n = 1;
#if defined __TURBOC__ && __TURBOC__ == 1 return malloc((alloc_t) roundup(n));
/*
** Beat a TURBOC 1.0 bug.
*/
if ((n & 1) != 0)
++n;
#endif /* defined __TURBOC__ && __TURBOC__ == 1 */
return malloc((alloc_t) n);
#endif /* !defined MAL */ #endif /* !defined MAL */
} }
@@ -57,11 +68,7 @@ icalloc(nelem, elsize)
{ {
if (nelem == 0 || elsize == 0) if (nelem == 0 || elsize == 0)
nelem = elsize = 1; nelem = elsize = 1;
#if defined __TURBOC__ && __TURBOC__ == 1 return calloc((alloc_t) nelem, (alloc_t) roundup(elsize));
if ((nelem & 1) != 0 && (elsize & 1) != 0)
++nelem;
#endif /* defined __TURBOC__ && __TURBOC__ == 1 */
return calloc((alloc_t) nelem, (alloc_t) elsize);
} }
char * char *
@@ -72,11 +79,7 @@ char * pointer;
return imalloc(size); return imalloc(size);
if (size == 0) if (size == 0)
size = 1; size = 1;
#if defined __TURBOC__ && __TURBOC__ == 1 return realloc(pointer, (alloc_t) roundup(size));
if ((size & 1) != 0)
++size;
#endif /* defined __TURBOC__ && __TURBOC__ == 1 */
return realloc(pointer, (alloc_t) size);
} }
char * char *
@@ -106,6 +109,7 @@ char * string;
return icatalloc((char *) NULL, string); return icatalloc((char *) NULL, string);
} }
void
ifree(p) ifree(p)
char * p; char * p;
{ {
@@ -113,6 +117,7 @@ char * p;
free(p); free(p);
} }
void
icfree(p) icfree(p)
char * p; char * p;
{ {