3 This file is part of the Free Pascal Run time library.
4 Copyright (c) 1999-2000 by the Free Pascal development team
6 See the file COPYING.FPC, included in this distribution,
7 for details about the copyright.
9 This program is distributed in the hope that it will be useful,
10 but WithOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 **********************************************************************}
15 {****************************************************************************
16 subroutines For UnTyped File handling
17 ****************************************************************************}
22 Procedure Assign(var f:File;const Name:string);
24 Assign Name to file f so it can be used with the file routines
27 FillChar(f,SizeOf(FileRec),0);
28 FileRec(f).Handle:=UnusedHandle;
29 FileRec(f).mode:=fmClosed;
30 Move(Name[1],FileRec(f).Name,Length(Name));
34 Procedure assign(var f:File;p:pchar);
36 Assign Name to file f so it can be used with the file routines
43 Procedure assign(var f:File;c:char);
45 Assign Name to file f so it can be used with the file routines
52 Procedure Rewrite(var f:File;l:Longint);[IOCheck];
54 Create file f with recordsize of l
59 Case FileRec(f).mode Of
60 fmInOut,fmInput,fmOutput : Close(f);
72 { Reopen with filemode 2, to be Tp compatible (PFV) }
73 Do_Open(f,PChar(@FileRec(f).Name),$1002);
74 FileRec(f).RecSize:=l;
79 Procedure Reset(var f:File;l:Longint);[IOCheck];
81 Open file f with recordsize of l and filemode
86 Case FileRec(f).mode Of
87 fmInOut,fmInput,fmOutput : Close(f);
99 Do_Open(f,PChar(@FileRec(f).Name),Filemode);
100 FileRec(f).RecSize:=l;
105 Procedure Rewrite(Var f:File);[IOCheck];
107 Create file with (default) 128 byte records
110 If InOutRes <> 0 then
116 Procedure Reset(Var f:File);[IOCheck];
118 Open file with (default) 128 byte records
121 If InOutRes <> 0 then
127 Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;var Result:Longint);[IOCheck];
129 Write Count records from Buf to file f, return written records in result
133 If InOutRes <> 0 then
135 case FileRec(f).Mode of
137 Result:=Do_Write(FileRec(f).Handle,Longint(@Buf),Count*FileRec(f).RecSize)
138 div FileRec(f).RecSize;
139 fmInPut: inOutRes := 105;
145 Procedure BlockWrite(Var f:File;Var Buf;Count:Word;var Result:Word);[IOCheck];
147 Write Count records from Buf to file f, return written records in Result
152 BlockWrite(f,Buf,Count,l);
157 Procedure BlockWrite(Var f:File;Var Buf;Count:Word;var Result:Integer);[IOCheck];
159 Write Count records from Buf to file f, return written records in Result
164 BlockWrite(f,Buf,Count,l);
169 Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);[IOCheck];
171 Write Count records from Buf to file f, if none a Read and Count>0 then
177 BlockWrite(f,Buf,Count,Result);
178 If (Result<Count) and (Count>0) Then
183 Procedure BlockRead(var f:File;var Buf;Count:Longint;var Result:Longint);[IOCheck];
185 Read Count records from file f ro Buf, return number of read records in
190 If InOutRes <> 0 then
192 case FileRec(f).Mode of
194 Result:=Do_Read(FileRec(f).Handle,Longint(@Buf),count*FileRec(f).RecSize)
195 div FileRec(f).RecSize;
196 fmOutput: inOutRes := 104;
202 Procedure BlockRead(var f:File;var Buf;count:Word;var Result:Word);[IOCheck];
204 Read Count records from file f to Buf, return number of read records in
210 BlockRead(f,Buf,Count,l);
215 Procedure BlockRead(var f:File;var Buf;count:Word;var Result:Integer);[IOCheck];
217 Read Count records from file f to Buf, return number of read records in
223 BlockRead(f,Buf,Count,l);
228 Procedure BlockRead(Var f:File;Var Buf;Count:Longint);[IOCheck];
230 Read Count records from file f to Buf, if none are read and Count>0 then
236 BlockRead(f,Buf,Count,Result);
237 If (Result<Count) and (Count>0) Then
242 Function FilePos(var f:File):Longint;[IOCheck];
244 Return current Position In file f in records
248 If InOutRes <> 0 then
250 case FileRec(f).Mode of
251 fmInOut,fmInput,fmOutput :
252 FilePos:=Do_FilePos(FileRec(f).Handle) div FileRec(f).RecSize;
259 Function FileSize(var f:File):Longint;[IOCheck];
261 Return the size of file f in records
265 If InOutRes <> 0 then
267 case FileRec(f).Mode of
268 fmInOut,fmInput,fmOutput :
270 if (FileRec(f).RecSize>0) then
271 FileSize:=Do_FileSize(FileRec(f).Handle) div FileRec(f).RecSize;
278 Function Eof(var f:File):Boolean;[IOCheck];
280 Return True if we're at the end of the file f, else False is returned
284 If InOutRes <> 0 then
286 case FileRec(f).Mode of
287 {Can't use do_ routines because we need record support}
288 fmInOut,fmInput,fmOutput : Eof:=(FileSize(f)<=FilePos(f));
294 Procedure Seek(var f:File;Pos:Longint);[IOCheck];
296 Goto record Pos in file f
299 If InOutRes <> 0 then
301 case FileRec(f).Mode of
302 fmInOut,fmInput,fmOutput :
303 Do_Seek(FileRec(f).Handle,Pos*FileRec(f).RecSize);
309 Procedure Truncate(Var f:File);[IOCheck];
311 Truncate/Cut file f at the current record Position
314 If InOutRes <> 0 then
316 case FileRec(f).Mode of
318 Do_Truncate(FileRec(f).Handle,FilePos(f)*FileRec(f).RecSize);
324 Procedure Close(var f:File);[IOCheck];
329 If InOutRes <> 0 then
331 case FileRec(f).Mode of
332 fmInOut,fmInput,fmOutput :
334 Do_Close(FileRec(f).Handle);
335 FileRec(f).mode:=fmClosed;
342 Procedure Erase(var f : File);[IOCheck];
344 If InOutRes <> 0 then
346 If FileRec(f).mode=fmClosed Then
347 Do_Erase(PChar(@FileRec(f).Name));
351 Procedure Rename(var f : File;p:pchar);[IOCheck];
353 If InOutRes <> 0 then
355 If FileRec(f).mode=fmClosed Then
357 Do_Rename(PChar(@FileRec(f).Name),p);
358 Move(p^,FileRec(f).Name,StrLen(p)+1);
363 Procedure Rename(var f : File;const s : string);[IOCheck];
365 p : array[0..255] Of Char;
367 If InOutRes <> 0 then
369 Move(s[1],p,Length(s));
375 Procedure Rename(var f : File;c : char);[IOCheck];
377 p : array[0..1] Of Char;
379 If InOutRes <> 0 then
388 Revision 1.1 2002/02/19 08:25:20 sasu
391 Revision 1.1 2000/07/13 06:30:44 michael
394 Revision 1.20 2000/03/24 10:26:18 jonas
395 * changed a lot of "if fm.mode = fmClosed then" to case statements,
396 because if f is not yet initialized, the mode is invalid and can
397 contain another value even though the file is closed
398 + check if a file is open in writeln_end (caused crash if used on
401 Revision 1.19 2000/02/09 16:59:29 peter
404 Revision 1.18 2000/01/17 20:02:30 peter
405 * open with mode 2 in rewrite
407 Revision 1.17 2000/01/16 22:25:38 peter
408 * check handle for file closing
410 Revision 1.16 2000/01/07 16:41:33 daniel
413 Revision 1.15 2000/01/07 16:32:24 daniel
414 * copyright 2000 added
416 Revision 1.14 1999/10/28 09:52:50 peter
417 * use filemode for rewrite instead of mode 1
419 Revision 1.13 1999/09/10 15:40:33 peter
420 * fixed do_open flags to be > $100, becuase filemode can be upto 255
422 Revision 1.12 1999/09/08 16:12:24 peter
423 * fixed inoutres for diskfull
425 Revision 1.11 1999/09/07 15:54:18 hajny
426 * fixed problem with Close under OS/2