objinc.inc 2.1 KB

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