objinc.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 signal.inc}
  9. {$i syscalls.inc}
  10. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  11. Var LinuxMode : longint;
  12. BEGIN
  13. LinuxMode:=0;
  14. if Mode=stCreate then
  15. Begin
  16. LinuxMode:=Open_Creat;
  17. LinuxMode:=LinuxMode or Open_RdWr;
  18. end
  19. else
  20. Begin
  21. Case (Mode and 3) of
  22. 0 : LinuxMode:=LinuxMode or Open_RdOnly;
  23. 1 : LinuxMode:=LinuxMode or Open_WrOnly;
  24. 2 : LinuxMode:=LinuxMode or Open_RdWr;
  25. end;
  26. end;
  27. FileOpen:=SYS_Open (pchar(@FileName[0]),LinuxMode,438 {666 octal});
  28. If FileOpen=-1 then FileOpen:=0;
  29. DosStreamError:=Errno;
  30. END;
  31. FUNCTION FileRead (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  32. Var BytesMoved: Sw_Word): Word;
  33. BEGIN
  34. BytesMoved:=Sys_read (Handle,Pchar(@BufferArea),BufferLength);
  35. DosStreamError:=Errno;
  36. FileRead:=Errno;
  37. END;
  38. FUNCTION FileWrite (Handle: THandle; Var BufferArea; BufferLength: Sw_Word;
  39. Var BytesMoved: Sw_Word): Word;
  40. BEGIN
  41. BytesMoved:=Sys_Write (Handle,Pchar(@BufferArea),BufferLength);
  42. FileWrite:=Errno;
  43. DosStreamError:=Errno;
  44. END;
  45. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  46. VAR NewPos: LongInt): Word;
  47. BEGIN
  48. NewPos:=Sys_LSeek (Handle,Pos,MoveType);
  49. SetFilePos:=Errno;
  50. END;
  51. FUNCTION FileClose (Handle: THandle): Word;
  52. BEGIN
  53. Sys_Close (Handle);
  54. DosStreamError:=Errno;
  55. FileClose := Errno;
  56. END;
  57. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  58. {$IFNDEF BSD}
  59. Var sr : syscallregs;
  60. {$ENDIF}
  61. {$IFDEF DOSSETFILE1}
  62. Actual, Buf: LongInt;
  63. {$ENDIF}
  64. BEGIN
  65. {$IFDEF BSD}
  66. Do_Syscall(Syscall_Nr_ftruncate,handle,filesize,0); {0 -> offset =64 bit}
  67. {$ELSE}
  68. sr.reg2:=Handle;
  69. sr.reg3:=FileSize;
  70. Syscall(syscall_nr_fTruncate,sr);
  71. {$ENDIF}
  72. If Errno=0 then
  73. SetFileSize:=0
  74. else
  75. SetFileSize:=103;
  76. {$IFDEF DOSSETFILE1}
  77. If (Actual = FileSize) Then Begin { No position error }
  78. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  79. If (Actual <> -1) Then SetFileSize := 0 Else { No truncate error }
  80. SetFileSize := 103; { File truncate error }
  81. End Else SetFileSize := 103; { File truncate error }
  82. {$ENDIF}
  83. END;
  84. {
  85. $Log$
  86. Revision 1.3 2000-09-11 14:05:31 marco
  87. * FreeBSD support and removed old signalhandling
  88. Revision 1.2 2000/07/13 11:33:49 michael
  89. + removed logs
  90. }