Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
26 | pmbaty | 1 | /* ACC -- Automatic Compiler Configuration |
2 | |||
3 | Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer |
||
4 | All Rights Reserved. |
||
5 | |||
6 | This software is a copyrighted work licensed under the terms of |
||
7 | the GNU General Public License. Please consult the file "ACC_LICENSE" |
||
8 | for details. |
||
9 | |||
10 | Markus F.X.J. Oberhumer |
||
11 | <markus@oberhumer.com> |
||
12 | http://www.oberhumer.com/ |
||
13 | */ |
||
14 | |||
15 | |||
16 | #define __ACCLIB_HFREAD_CH_INCLUDED 1 |
||
17 | #if !defined(ACCLIB_PUBLIC) |
||
18 | # define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f) |
||
19 | #endif |
||
20 | |||
21 | |||
22 | /*********************************************************************** |
||
23 | // huge pointer layer - stdio.h |
||
24 | ************************************************************************/ |
||
25 | |||
26 | ACCLIB_PUBLIC(acc_hsize_t, acc_hfread) (ACC_FILE_P fp, acc_hvoid_p buf, acc_hsize_t size) |
||
27 | { |
||
28 | #if (ACC_HAVE_MM_HUGE_PTR) |
||
29 | #if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM) |
||
30 | #define __ACCLIB_REQUIRE_HMEMCPY_CH 1 |
||
31 | unsigned char tmp[512]; |
||
32 | acc_hsize_t l = 0; |
||
33 | |||
34 | while (l < size) |
||
35 | { |
||
36 | size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l); |
||
37 | n = fread(tmp, 1, n, fp); |
||
38 | if (n == 0) |
||
39 | break; |
||
40 | __ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n); |
||
41 | l += n; |
||
42 | } |
||
43 | return l; |
||
44 | #elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) |
||
45 | acc_hbyte_p b = (acc_hbyte_p) buf; |
||
46 | acc_hsize_t l = 0; |
||
47 | |||
48 | while (l < size) |
||
49 | { |
||
50 | size_t n; |
||
51 | n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); |
||
52 | if ((acc_hsize_t) n > size - l) |
||
53 | n = (size_t) (size - l); |
||
54 | n = fread((void __far*)b, 1, n, fp); |
||
55 | if (n == 0) |
||
56 | break; |
||
57 | b += n; l += n; |
||
58 | } |
||
59 | return l; |
||
60 | #else |
||
61 | # error "unknown memory model" |
||
62 | #endif |
||
63 | #else |
||
64 | return fread(buf, 1, size, fp); |
||
65 | #endif |
||
66 | } |
||
67 | |||
68 | |||
69 | ACCLIB_PUBLIC(acc_hsize_t, acc_hfwrite) (ACC_FILE_P fp, const acc_hvoid_p buf, acc_hsize_t size) |
||
70 | { |
||
71 | #if (ACC_HAVE_MM_HUGE_PTR) |
||
72 | #if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM) |
||
73 | #define __ACCLIB_REQUIRE_HMEMCPY_CH 1 |
||
74 | unsigned char tmp[512]; |
||
75 | acc_hsize_t l = 0; |
||
76 | |||
77 | while (l < size) |
||
78 | { |
||
79 | size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l); |
||
80 | __ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n); |
||
81 | n = fwrite(tmp, 1, n, fp); |
||
82 | if (n == 0) |
||
83 | break; |
||
84 | l += n; |
||
85 | } |
||
86 | return l; |
||
87 | #elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) |
||
88 | const acc_hbyte_p b = (const acc_hbyte_p) buf; |
||
89 | acc_hsize_t l = 0; |
||
90 | |||
91 | while (l < size) |
||
92 | { |
||
93 | size_t n; |
||
94 | n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); |
||
95 | if ((acc_hsize_t) n > size - l) |
||
96 | n = (size_t) (size - l); |
||
97 | n = fwrite((void __far*)b, 1, n, fp); |
||
98 | if (n == 0) |
||
99 | break; |
||
100 | b += n; l += n; |
||
101 | } |
||
102 | return l; |
||
103 | #else |
||
104 | # error "unknown memory model" |
||
105 | #endif |
||
106 | #else |
||
107 | return fwrite(buf, 1, size, fp); |
||
108 | #endif |
||
109 | } |
||
110 | |||
111 | |||
112 | /* |
||
113 | vi:ts=4:et |
||
114 | */ |