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