avoid silent data loss e.g., on NFS, due to unchecked close of stdout
[gzip.git] / msdos / tailor.c
blob94f4f9bffc8126a8b5ad92bfec5bc2db9c6bdc93
1 /* tailor.c -- target dependent functions
2 * Copyright (C) 1992-1993 Jean-loup Gailly
3 * This is free software; you can redistribute it and/or modify it under the
4 * terms of the GNU General Public License, see the file COPYING.
5 */
7 /* tailor.c is a bunch of non portable routines.
8 * It should be kept to a minimum.
9 */
11 #include "tailor.h"
12 #include "gzip.h"
14 #ifndef lint
15 static char rcsid[] = "$Id$";
16 #endif
18 #ifdef __TURBOC__
20 /************************/
21 /* Function fcalloc() */
22 /************************/
24 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
25 * and farmalloc(64K) returns a pointer with an offset of 8, so we
26 * must fix the pointer. Warning: the pointer must be put back to its
27 * original form in order to free it, use fcfree().
28 * For MSC, use halloc instead of this function (see tailor.h).
30 static ush ptr_offset = 0;
32 void * fcalloc(items, size)
33 unsigned items; /* number of items */
34 unsigned size; /* item size */
36 void * buf = farmalloc((ulg)items*size + 16L);
37 if (buf == NULL) return NULL;
38 /* Normalize the pointer to seg:0 */
39 if (ptr_offset == 0) {
40 ptr_offset = (ush)((uch*)buf-0);
41 } else if (ptr_offset != (ush)((uch*)buf-0)) {
42 error("inconsistent ptr_offset");
44 *((ush*)&buf+1) += (ptr_offset + 15) >> 4;
45 *(ush*)&buf = 0;
46 return buf;
49 void fcfree(ptr)
50 void *ptr; /* region allocated with fcalloc() */
52 /* Put the pointer back to its original form: */
53 *((ush*)&ptr+1) -= (ptr_offset + 15) >> 4;
54 *(ush*)&ptr = ptr_offset;
55 farfree(ptr);
58 #endif /* __TURBOC__ */