objinc.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 and stCreate)=stCreate then
  14. LinuxMode:=Open_Creat;
  15. Case (Mode and 3) of
  16. 0 : LinuxMode:=LinuxMode or Open_RdOnly;
  17. 1 : LinuxMode:=LinuxMode or Open_WrOnly;
  18. 2 : LinuxMode:=LinuxMode or Open_RdWr;
  19. end;
  20. FileOpen:=SYS_Open (pchar(@FileName[0]),LinuxMode,438 {666 octal});
  21. If FileOpen=-1 then FileOpen:=0;
  22. DosStreamError:=Errno;
  23. END;
  24. FUNCTION FileRead (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  25. Var BytesMoved: Sw_Word): Word;
  26. BEGIN
  27. BytesMoved:=Sys_read (Handle,Pchar(@BufferArea),BufferLength);
  28. DosStreamError:=Errno;
  29. FileRead:=Errno;
  30. END;
  31. FUNCTION FileWrite (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  32. Var BytesMoved: Sw_Word): Word;
  33. BEGIN
  34. BytesMoved:=Sys_Write (Handle,Pchar(@BufferArea),BufferLength);
  35. FileWrite:=Errno;
  36. DosStreamError:=Errno;
  37. END;
  38. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  39. VAR NewPos: LongInt): Word;
  40. BEGIN
  41. NewPos:=Sys_LSeek (Handle,Pos,MoveType);
  42. SetFilePos:=Errno;
  43. END;
  44. FUNCTION FileClose (Handle: THandle): Word;
  45. BEGIN
  46. Sys_Close (Handle);
  47. DosStreamError:=Errno;
  48. FileClose := Errno;
  49. END;
  50. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  51. Var sr : syscallregs;
  52. {$IFDEF DOSSETFILE1}
  53. Actual, Buf: LongInt;
  54. {$ENDIF}
  55. BEGIN
  56. sr.reg2:=Handle;
  57. sr.reg3:=FileSize;
  58. Syscall(syscall_nr_fTruncate,sr);
  59. If Errno=0 then
  60. SetFileSize:=0
  61. else
  62. SetFileSize:=103;
  63. {$IFDEF DOSSETFILE1}
  64. If (Actual = FileSize) Then Begin { No position error }
  65. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  66. If (Actual <> -1) Then SetFileSize := 0 Else { No truncate error }
  67. SetFileSize := 103; { File truncate error }
  68. End Else SetFileSize := 103; { File truncate error }
  69. {$ENDIF}
  70. END;