home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gzip-1.2.4.tar.gz / gzip-1.2.4.tar / gzip-1.2.4 / msdos / tailor.c < prev   
C/C++ Source or Header  |  1993-07-07  |  2KB  |  59 lines

  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.  */
  6.  
  7. /* tailor.c is a bunch of non portable routines.
  8.  * It should be kept to a minimum.
  9.  */
  10.  
  11. #include "tailor.h"
  12. #include "gzip.h"
  13.  
  14. #ifndef lint
  15. static char rcsid[] = "$Id: tailor.c,v 0.8 1993/02/24 18:24:54 jloup Exp $";
  16. #endif
  17.  
  18. #ifdef __TURBOC__
  19.  
  20. /************************/
  21. /*  Function fcalloc()  */
  22. /************************/
  23.  
  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).
  29.  */
  30. static ush ptr_offset = 0;
  31.  
  32. void * fcalloc(items, size)
  33.     unsigned items; /* number of items */
  34.     unsigned size;  /* item size */
  35. {
  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");
  43.     }
  44.     *((ush*)&buf+1) += (ptr_offset + 15) >> 4;
  45.     *(ush*)&buf = 0;
  46.     return buf;
  47. }
  48.  
  49. void fcfree(ptr)
  50.     void *ptr; /* region allocated with fcalloc() */
  51. {
  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);
  56.  }
  57.  
  58. #endif /* __TURBOC__ */
  59.