objinc.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. { For linux we 'steal' the following from system unit, this way
  2. we don't need to change the system unit interface. }
  3. Var errno : Longint;
  4. {$i sysnr.inc}
  5. {$i errno.inc}
  6. {$i sysconst.inc}
  7. {$i systypes.inc}
  8. {$i syscalls.inc}
  9. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  10. Var LinuxMode : longint;
  11. BEGIN
  12. LinuxMode:=0;
  13. if Mode=stCreate then
  14. Begin
  15. LinuxMode:=Open_Creat;
  16. LinuxMode:=LinuxMode or Open_RdWr;
  17. end
  18. else
  19. Begin
  20. Case (Mode and 3) of
  21. 0 : LinuxMode:=LinuxMode or Open_RdOnly;
  22. 1 : LinuxMode:=LinuxMode or Open_WrOnly;
  23. 2 : LinuxMode:=LinuxMode or Open_RdWr;
  24. end;
  25. end;
  26. FileOpen:=SYS_Open (pchar(@FileName[0]),LinuxMode,438 {666 octal});
  27. If FileOpen=-1 then FileOpen:=0;
  28. DosStreamError:=Errno;
  29. END;
  30. FUNCTION FileRead (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  31. Var BytesMoved: Sw_Word): Word;
  32. BEGIN
  33. BytesMoved:=Sys_read (Handle,Pchar(@BufferArea),BufferLength);
  34. DosStreamError:=Errno;
  35. FileRead:=Errno;
  36. END;
  37. FUNCTION FileWrite (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  38. Var BytesMoved: Sw_Word): Word;
  39. BEGIN
  40. BytesMoved:=Sys_Write (Handle,Pchar(@BufferArea),BufferLength);
  41. FileWrite:=Errno;
  42. DosStreamError:=Errno;
  43. END;
  44. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  45. VAR NewPos: LongInt): Word;
  46. BEGIN
  47. NewPos:=Sys_LSeek (Handle,Pos,MoveType);
  48. SetFilePos:=Errno;
  49. END;
  50. FUNCTION FileClose (Handle: THandle): Word;
  51. BEGIN
  52. Sys_Close (Handle);
  53. DosStreamError:=Errno;
  54. FileClose := Errno;
  55. END;
  56. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  57. Var sr : syscallregs;
  58. {$IFDEF DOSSETFILE1}
  59. Actual, Buf: LongInt;
  60. {$ENDIF}
  61. BEGIN
  62. sr.reg2:=Handle;
  63. sr.reg3:=FileSize;
  64. Syscall(syscall_nr_fTruncate,sr);
  65. If Errno=0 then
  66. SetFileSize:=0
  67. else
  68. SetFileSize:=103;
  69. {$IFDEF DOSSETFILE1}
  70. If (Actual = FileSize) Then Begin { No position error }
  71. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  72. If (Actual <> -1) Then SetFileSize := 0 Else { No truncate error }
  73. SetFileSize := 103; { File truncate error }
  74. End Else SetFileSize := 103; { File truncate error }
  75. {$ENDIF}
  76. END;