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_HREAD_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 - read/write |
||
24 | ************************************************************************/ |
||
25 | |||
26 | #if (ACC_HAVE_MM_HUGE_PTR) |
||
27 | |||
28 | ACCLIB_PUBLIC(long, acc_hread) (int fd, acc_hvoid_p buf, long size) |
||
29 | { |
||
30 | #if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM) |
||
31 | #define __ACCLIB_REQUIRE_HMEMCPY_CH 1 |
||
32 | unsigned char tmp[512]; |
||
33 | long l = 0; |
||
34 | |||
35 | while (l < size) |
||
36 | { |
||
37 | int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l); |
||
38 | n = read(fd, tmp, n); |
||
39 | if (n == 0) |
||
40 | break; |
||
41 | if (n < 0) |
||
42 | return -1; |
||
43 | __ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n); |
||
44 | l += n; |
||
45 | } |
||
46 | return l; |
||
47 | #elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) |
||
48 | acc_hbyte_p b = (acc_hbyte_p) buf; |
||
49 | long l = 0; |
||
50 | |||
51 | while (l < size) |
||
52 | { |
||
53 | unsigned n; |
||
54 | n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); |
||
55 | if ((long) n > size - l) |
||
56 | n = (unsigned) (size - l); |
||
57 | n = read(fd, (void __far*)b, n); |
||
58 | if (n == 0) |
||
59 | break; |
||
60 | if (n == (unsigned)-1) |
||
61 | return -1; |
||
62 | b += n; l += n; |
||
63 | } |
||
64 | return l; |
||
65 | #else |
||
66 | # error "unknown memory model" |
||
67 | #endif |
||
68 | } |
||
69 | |||
70 | |||
71 | ACCLIB_PUBLIC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size) |
||
72 | { |
||
73 | #if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM) |
||
74 | #define __ACCLIB_REQUIRE_HMEMCPY_CH 1 |
||
75 | unsigned char tmp[512]; |
||
76 | long l = 0; |
||
77 | |||
78 | while (l < size) |
||
79 | { |
||
80 | int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l); |
||
81 | __ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n); |
||
82 | n = write(fd, tmp, n); |
||
83 | if (n == 0) |
||
84 | break; |
||
85 | if (n < 0) |
||
86 | return -1; |
||
87 | l += n; |
||
88 | } |
||
89 | return l; |
||
90 | #elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) |
||
91 | const acc_hbyte_p b = (const acc_hbyte_p) buf; |
||
92 | long l = 0; |
||
93 | |||
94 | while (l < size) |
||
95 | { |
||
96 | unsigned n; |
||
97 | n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); |
||
98 | if ((long) n > size - l) |
||
99 | n = (unsigned) (size - l); |
||
100 | n = write(fd, (void __far*)b, n); |
||
101 | if (n == 0) |
||
102 | break; |
||
103 | if (n == (unsigned)-1) |
||
104 | return -1; |
||
105 | b += n; l += n; |
||
106 | } |
||
107 | return l; |
||
108 | #else |
||
109 | # error "unknown memory model" |
||
110 | #endif |
||
111 | } |
||
112 | |||
113 | #endif /* #if (ACC_HAVE_MM_HUGE_PTR) */ |
||
114 | |||
115 | |||
116 | /* |
||
117 | vi:ts=4:et |
||
118 | */ |