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.
7 /* tailor.c is a bunch of non portable routines.
8 * It should be kept to a minimum.
15 static char rcsid
[] = "$Id$";
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;
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
;
58 #endif /* __TURBOC__ */