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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2005 by Free Pascal development team
Low level file functions for Nintendo Wii
Copyright (c) 2011 by Francesco Lombardi
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{****************************************************************************
Low level File Routines
All these functions can set InOutRes on errors
****************************************************************************}
{ close a file from the handle value }
procedure do_close(handle: THandle);
begin
if FileIODevice.FileIO.DoClose <> nil then
FileIODevice.FileIO.DoClose(handle);
//_fclose (_PFILE(pointer(handle))^);
end;
procedure do_erase(p: pchar);
begin
if FileIODevice.FileIO.DoErase <> nil then
FileIODevice.FileIO.DoErase(p);
// _unlink(p);
end;
procedure do_rename(p1, p2: pchar);
begin
// _rename(p1, p2);
if FileIODevice.FileIO.DoRename <> nil then
FileIODevice.FileIO.DoRename(p1, p2);
end;
function do_write(h: THandle; addr: pointer; len: longint) : longint;
begin
// result := _fwrite(addr, 1, len, _PFILE(pointer(h))^);
if FileIODevice.FileIO.DoWrite <> nil then
result := FileIODevice.FileIO.DoWrite(h, addr, len);
end;
function do_read(h: THandle; addr: pointer; len: longint) : longint;
begin
// result := _fread(addr, 1, len, _PFILE(pointer(h))^);
if FileIODevice.FileIO.DoRead <> nil then
result := FileIODevice.FileIO.DoRead(h, addr, len);
end;
function do_filepos(handle: THandle): longint;
begin
// result := _ftell(_PFILE(pointer(handle))^);
if FileIODevice.FileIO.DoFilePos <> nil then
result := FileIODevice.FileIO.DoFilePos(handle);
end;
procedure do_seek(handle: THandle; pos: longint);
begin
//_fseek(_PFILE(pointer(handle))^, pos, SEEK_SET);
if FileIODevice.FileIO.DoSeek <> nil then
FileIODevice.FileIO.DoSeek(handle, pos);
end;
function do_seekend(handle: THandle): longint;
begin
// result := _fseek(_PFILE(pointer(handle))^, 0, SEEK_END);
if FileIODevice.FileIO.DoSeekend <> nil then
result := FileIODevice.FileIO.DoSeekend(handle);
end;
function do_filesize(handle: THandle): longint;
begin
// result := -1;
if FileIODevice.FileIO.DoFilesize <> nil then
result := FileIODevice.FileIO.DoFilesize(handle);
end;
{ truncate at a given position }
procedure do_truncate(handle: THandle; pos: longint);
begin
// _ftruncate(_fileno(_PFILE(pointer(handle))^), pos);
if FileIODevice.FileIO.DoTruncate <> nil then
FileIODevice.FileIO.DoTruncate(handle, pos);
end;
procedure do_open(var f; p: pchar; flags: longint);
begin
(*
{ close first if opened }
if ((flags and $10000) = 0) then
begin
case FileRec(f).mode of
fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
fmclosed : ;
else
begin
// inoutres:=102; {not assigned}
exit;
end;
end;
end;
{ reset file Handle }
FileRec(f).Handle:=UnusedHandle;
{ We do the conversion of filemodes here, concentrated on 1 place }
case (flags and 3) of
0 : begin
oflags := 'rb'#0;
filerec(f).mode := fminput;
end;
1 : begin
if (flags and $1000)=$1000 then
oflags := 'w+b' else
oflags := 'wb';
filerec(f).mode := fmoutput;
end;
2 : begin
if (flags and $1000)=$1000 then
oflags := 'w+' else
oflags := 'r+';
filerec(f).mode := fminout;
end;
end;
{if (flags and $1000)=$1000 then
oflags:=oflags or (O_CREAT or O_TRUNC)
else
if (flags and $100)=$100 then
oflags:=oflags or (O_APPEND);}
{ empty name is special }
if p[0]=#0 then
begin
case FileRec(f).mode of
fminput: FileRec(f).Handle:=StdInputHandle;
fminout, { this is set by rewrite }
fmoutput: FileRec(f).Handle:=StdOutputHandle;
fmappend:
begin
FileRec(f).Handle:=StdOutputHandle;
FileRec(f).mode:=fmoutput; {fool fmappend}
end;
end;
exit;
end;
{ real open call }
FileRec(f).Handle := longint(fopen(p, @oflags[1]));//_open(p,oflags,438);
// errno does not seem to be set on succsess ??
{
if FileRec(f).Handle = 0 then
Errno2Inoutres
else
InOutRes := 0;
}
*)
// FileRec(f).Handle := THandle (_fopen(p, @oflags[1]));
if FileIODevice.FileIO.DoOpen <> nil then
FileIODevice.FileIO.DoOpen(f, p, flags);
end;
function do_isdevice(handle: THandle): boolean;
begin
// result := (_isatty(_fileno(_PFILE(pointer(handle))^)) > 0);
if FileIODevice.FileIO.DoIsdevice <> nil then
result := FileIODevice.FileIO.DoIsdevice(handle);
end;
|