summaryrefslogtreecommitdiff
path: root/Build/source/libs/libttf/arch/msdos/hugefile.c
blob: 901e0d6eae554676e84e98b91aa8abe58d910c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************
 *
 *  hugefile.c
 *
 *    File I/O Component (body) for dealing with "huge" objects under
 *    MS-DOS. Relies on the "default" version, with a small hook.
 *
 *  Written by Antoine Leca based on ideas from Dave Hoo.
 *  Copyright 1999 by Dave Hoo, Antoine Leca,
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used
 *  modified and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 *  NOTE
 *
 *    This file #includes the normal version, to avoid discrepancies
 *    between versions.  It uses only ANSI-mandated "tricks", so
 *    any ANSI-compliant compiler should be able to compile this file.
 *
 ******************************************************************/

#include "ttconfig.h"
#include "tttypes.h"

/* Here we include <stdio.h>, to have the proper definition of fread */
#include <stdio.h>

/* Then, we divert the use of fread to our version */
#undef  fread
#define fread(ptr, size, n, stream)  huge_fread(ptr, size, n, stream)

  LOCAL_FUNC
  Long huge_fread ( void *ptr, size_t size, Long n, FILE *stream );

/* Now, we include the "normal" version of ttfile.c                 */
/* The ANSI/ISO standard mandates that the include of <stdio.h>     */
/* there have no bad effects.                                       */
#include "ttfile.c"

/* Then, we define our implementation of fread that makes use of    */
/* "huge"-allocated memory.                                         */

/*******************************************************************
 *
 *  Function    : huge_fread
 *
 *  Description : replacement version of fread that handles
 *                "huge"-allocated memory.
 *
 *  Input  : See the reference for the runtime library function fread
 *
 *  Output : See the reference for the runtime library function fread
 *
 *  Notes  :
 *
 ******************************************************************/

  LOCAL_DEF
  Long huge_fread ( void *ptr, size_t size, Long n, FILE *stream )
  {
    char TT_HUGE_PTR * p = (char TT_HUGE_PTR *) ptr;
    ULong        left = (ULong)n * size;
    size_t       toRead;

    while ( left )
    {
      toRead = (left > 0x8000) ? 0x8000 : left;
      if ( (fread)( p, 1, toRead, stream ) != toRead)
        return -1;
      else
      {
        left -= (ULong) toRead;
        p    += toRead;
      }
    }
    return n * size;
  }


/* END */