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
|
{
System independent filecontrol interface for linux
$Id: filectrl.inc,v 1.1 1998/12/04 12:48:30 peter Exp $
}
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: filectrl.inc,v $
Revision 1.1 1998/12/04 12:48:30 peter
* moved some dirs
Revision 1.1 1998/10/26 11:31:47 peter
+ inital include files
}
|