From d6ce4d1def29ea75da5506bcc05c3011f9cb502b Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Wed, 24 Feb 1993 18:24:54 +0000 Subject: [PATCH] checked in with -k by eggert at 2006/11/05 06:57:40 --- msdos/tailor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 msdos/tailor.c diff --git a/msdos/tailor.c b/msdos/tailor.c new file mode 100644 index 0000000..94f4f9b --- /dev/null +++ b/msdos/tailor.c @@ -0,0 +1,58 @@ +/* tailor.c -- target dependent functions + * Copyright (C) 1992-1993 Jean-loup Gailly + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + +/* tailor.c is a bunch of non portable routines. + * It should be kept to a minimum. + */ + +#include "tailor.h" +#include "gzip.h" + +#ifndef lint +static char rcsid[] = "$Id$"; +#endif + +#ifdef __TURBOC__ + +/************************/ +/* Function fcalloc() */ +/************************/ + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use fcfree(). + * For MSC, use halloc instead of this function (see tailor.h). + */ +static ush ptr_offset = 0; + +void * fcalloc(items, size) + unsigned items; /* number of items */ + unsigned size; /* item size */ +{ + void * buf = farmalloc((ulg)items*size + 16L); + if (buf == NULL) return NULL; + /* Normalize the pointer to seg:0 */ + if (ptr_offset == 0) { + ptr_offset = (ush)((uch*)buf-0); + } else if (ptr_offset != (ush)((uch*)buf-0)) { + error("inconsistent ptr_offset"); + } + *((ush*)&buf+1) += (ptr_offset + 15) >> 4; + *(ush*)&buf = 0; + return buf; +} + +void fcfree(ptr) + void *ptr; /* region allocated with fcalloc() */ +{ + /* Put the pointer back to its original form: */ + *((ush*)&ptr+1) -= (ptr_offset + 15) >> 4; + *(ush*)&ptr = ptr_offset; + farfree(ptr); + } + +#endif /* __TURBOC__ */ -- 2.47.2