123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- {
- System independent filecontrol interface for linux
- $Id$
- }
- uses
- Linux;
- function OpenFileStr(FName: PChar; Flags: Longint): TFileHandle; [ alias: 'OpenFile' ];
- var
- RC : longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- OpenFileStr:=fdOpen(FName, Flags, FilePerms);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, FName);
- until (RC <= 0) or (Todo <> errRetry);
- end;
- function CreateFileStr(FName: PChar): TFileHandle; [ alias: 'CreateFile' ];
- const
- O_RDONLY = 0;
- O_WRONLY = 1;
- O_RDWR = 2;
- O_CREATE = 64;
- O_EXCL = 128;
- O_NOCTTY = 256;
- O_TRUNC = 512;
- O_APPEND = 1024;
- begin
- CreateFileStr := OpenFileStr(FName, O_RDWR+O_CREATE+O_TRUNC);
- end;
- procedure CloseFile(Handle: TFileHandle);
- var
- RC: Longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- fdClose(Handle);
- RC := LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- end;
- function SeekFile(Handle: TFileHandle; Pos: TFileInt; SeekType: Word): TFileInt;
- var
- RC: Longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- RC := -fdSeek(Handle, Pos, SeekType);
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- SeekFile := -RC;
- end;
- procedure DeleteFileStr(FName: PChar); [ alias: 'DeleteFile' ];
- var
- RC: Longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- UnLink(FName);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- end;
- function ReadFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord;
- var
- RC: Longint;
- BytesRead: LongInt;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- BytesRead := fdRead(Handle, Buff, Count);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- if (RC > 0) then
- ReadFile := 0
- else
- ReadFile := BytesRead;
- end;
- function WriteFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord;
- var
- RC: Longint;
- BytesWritten: LongInt;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- BytesWritten := fdWrite(Handle, Buff, Count);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- if (RC > 0) then
- WriteFile := 0
- else
- WriteFile := BytesWritten;
- end;
- { The following two routines should go to syscalls... }
- procedure FlushFile(Handle: TFileHandle);
- var
- RC: Longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- fdFlush(Handle);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- end;
- procedure TruncateFile(Handle: TFileHandle);
- var
- RC: Longint;
- Todo: TErrorHandlerReturnValue;
- begin
- repeat
- fdTruncate(Handle,0);
- RC:=LinuxError;
- if (RC > 0) then
- Todo := ErrorHandler(RC, nil);
- until (RC <= 0) or (Todo <> errRetry);
- end;
- function EndOfFile(Handle: TFileHandle): Boolean;
- begin
- EndOfFile := FilePos(Handle) >= FileSize(Handle);
- end;
- function FilePos(Handle: TFileHandle): TFileInt;
- begin
- FilePos := SeekFile(Handle, 0, skCur);
- end;
- function FileSize(Handle: TFileHandle): TFileInt;
- var
- L: Longint;
- begin
- L := FilePos(Handle);
- FileSize := SeekFile(Handle, 0, skEnd);
- SeekFile(Handle, L, skBeg);
- end;
- {
- $Log$
- Revision 1.2 2000-07-13 11:32:24 michael
- + removed logs
-
- }
|