~ubuntu-branches/ubuntu/vivid/gzip/vivid

« back to all changes in this revision

Viewing changes to msdos/tailor.c

  • Committer: Steve Langasek
  • Date: 2012-06-29 02:07:40 UTC
  • mfrom: (4.1.9 sid)
  • Revision ID: steve.langasek@canonical.com-20120629020740-qqikrblzana08v2y
Merge version 1.5-1.1 from Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <config.h>
12
 
#include "tailor.h"
13
 
#include "gzip.h"
14
 
 
15
 
#ifdef __TURBOC__
16
 
 
17
 
/************************/
18
 
/*  Function fcalloc()  */
19
 
/************************/
20
 
 
21
 
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
22
 
 * and farmalloc(64K) returns a pointer with an offset of 8, so we
23
 
 * must fix the pointer. Warning: the pointer must be put back to its
24
 
 * original form in order to free it, use fcfree().
25
 
 * For MSC, use halloc instead of this function (see tailor.h).
26
 
 */
27
 
static ush ptr_offset = 0;
28
 
 
29
 
void * fcalloc(items, size)
30
 
    unsigned items; /* number of items */
31
 
    unsigned size;  /* item size */
32
 
{
33
 
    void * buf = farmalloc((ulg)items*size + 16L);
34
 
    if (buf == NULL) return NULL;
35
 
    /* Normalize the pointer to seg:0 */
36
 
    if (ptr_offset == 0) {
37
 
        ptr_offset = (ush)((uch*)buf-0);
38
 
    } else if (ptr_offset != (ush)((uch*)buf-0)) {
39
 
        error("inconsistent ptr_offset");
40
 
    }
41
 
    *((ush*)&buf+1) += (ptr_offset + 15) >> 4;
42
 
    *(ush*)&buf = 0;
43
 
    return buf;
44
 
}
45
 
 
46
 
void fcfree(ptr)
47
 
    void *ptr; /* region allocated with fcalloc() */
48
 
{
49
 
    /* Put the pointer back to its original form: */
50
 
    *((ush*)&ptr+1) -= (ptr_offset + 15) >> 4;
51
 
    *(ush*)&ptr = ptr_offset;
52
 
    farfree(ptr);
53
 
 }
54
 
 
55
 
#endif /* __TURBOC__ */