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
|
{ For linux we 'steal' the following from system unit, this way
we don't need to change the system unit interface. }
Var errno : Longint;
{$i sysnr.inc}
{$i errno.inc}
{$i sysconst.inc}
{$i systypes.inc}
{$i syscalls.inc}
FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
Var LinuxMode : longint;
BEGIN
LinuxMode:=0;
if Mode=stCreate then
Begin
LinuxMode:=Open_Creat;
LinuxMode:=LinuxMode or Open_RdWr;
end
else
Begin
Case (Mode and 3) of
0 : LinuxMode:=LinuxMode or Open_RdOnly;
1 : LinuxMode:=LinuxMode or Open_WrOnly;
2 : LinuxMode:=LinuxMode or Open_RdWr;
end;
end;
FileOpen:=SYS_Open (pchar(@FileName[0]),LinuxMode,438 {666 octal});
If FileOpen=-1 then FileOpen:=0;
DosStreamError:=Errno;
END;
FUNCTION FileRead (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
Var BytesMoved: Sw_Word): Word;
BEGIN
BytesMoved:=Sys_read (Handle,Pchar(@BufferArea),BufferLength);
DosStreamError:=Errno;
FileRead:=Errno;
END;
FUNCTION FileWrite (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
Var BytesMoved: Sw_Word): Word;
BEGIN
BytesMoved:=Sys_Write (Handle,Pchar(@BufferArea),BufferLength);
FileWrite:=Errno;
DosStreamError:=Errno;
END;
FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
VAR NewPos: LongInt): Word;
BEGIN
NewPos:=Sys_LSeek (Handle,Pos,MoveType);
SetFilePos:=Errno;
END;
FUNCTION FileClose (Handle: THandle): Word;
BEGIN
Sys_Close (Handle);
DosStreamError:=Errno;
FileClose := Errno;
END;
FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
Var sr : syscallregs;
{$IFDEF DOSSETFILE1}
Actual, Buf: LongInt;
{$ENDIF}
BEGIN
sr.reg2:=Handle;
sr.reg3:=FileSize;
Syscall(syscall_nr_fTruncate,sr);
If Errno=0 then
SetFileSize:=0
else
SetFileSize:=103;
{$IFDEF DOSSETFILE1}
If (Actual = FileSize) Then Begin { No position error }
Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
If (Actual <> -1) Then SetFileSize := 0 Else { No truncate error }
SetFileSize := 103; { File truncate error }
End Else SetFileSize := 103; { File truncate error }
{$ENDIF}
END;
|