objinc.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Includefile for objects.pp implementing OS-dependent file routines
  6. for Go32V2
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************
  13. }
  14. {---------------------------------------------------------------------------}
  15. { FileClose -> Platforms DOS - Not checked }
  16. {---------------------------------------------------------------------------}
  17. FUNCTION FileClose (Handle: THandle): Word;
  18. var
  19. regs : trealregs;
  20. begin
  21. regs.realebx:=handle;
  22. regs.realeax:=$3e00;
  23. sysrealintr($21,regs);
  24. FileClose := 0;
  25. end;
  26. {---------------------------------------------------------------------------}
  27. { FileOpen -> Platforms DOS - Checked 05May1998 CEC }
  28. { Returns 0 on failure }
  29. {---------------------------------------------------------------------------}
  30. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  31. Var
  32. regs : trealregs;
  33. BEGIN
  34. DosStreamError:=0;
  35. syscopytodos(longint(@FileName),256);
  36. { get linear address from system unit }
  37. regs.realedx:=tb mod 16;
  38. regs.realds:=tb div 16;
  39. regs.realeax := Mode;
  40. regs.realecx:=0;
  41. sysrealintr($21,regs);
  42. if (regs.realflags and 1) <> 0 then
  43. begin
  44. InOutRes:=lo(regs.realeax);
  45. FileOpen:=$0;
  46. exit;
  47. end
  48. else
  49. { word handle (under DOS) }
  50. FileOpen:=regs.realeax and $ffff;
  51. END;
  52. {---------------------------------------------------------------------------}
  53. { SetFilePos -> Platforms DOS - Checked 05May1998 CEC }
  54. {---------------------------------------------------------------------------}
  55. {
  56. Calls the operating system to move the file denoted by the handle to
  57. to the requested position. The move method can be: 0 = absolute offset;
  58. 1 = offset from present location; 2 = offset from end of file;
  59. Any error is held in DosErrorStream and returned from the call.
  60. If the return is zero (ie no error) NewPos contains the new absolute
  61. file position.
  62. }
  63. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;Var Actual: LongInt): Word;
  64. Var
  65. regs: Trealregs;
  66. const
  67. CarryFlag = $001;
  68. BEGIN
  69. regs.realeax := ($42 shl 8) + Byte(MoveType);
  70. regs.realedx := pos and $ffff; { keep low word }
  71. regs.realecx := pos shr 16;
  72. regs.realebx := longint(Handle);
  73. sysrealintr($21,regs);
  74. if (regs.RealFlags and CarryFlag = 0) then { no error }
  75. Actual:=(regs.realeax and $ffff) + ((regs.realedx and $ffff) shl 16)
  76. else
  77. DosStreamError:=word(regs.realeax);
  78. SetFilePos := DosStreamError; { Return any error }
  79. END;
  80. {---------------------------------------------------------------------------}
  81. { FileRead -> Platforms DOS - Checked 05May1998 CEC }
  82. {---------------------------------------------------------------------------}
  83. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  84. Var Actual: Sw_Word): Word;
  85. BEGIN
  86. Actual:=system.do_read(longint(Handle),longint(@Buf),Count);
  87. FileRead:=InOutRes;
  88. End;
  89. {---------------------------------------------------------------------------}
  90. { FileWrite -> Platforms DOS - Checked 05May1998 CEC }
  91. {---------------------------------------------------------------------------}
  92. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  93. BEGIN
  94. system.do_write(longint(Handle),longint(@Buf),Count);
  95. Actual:=Count;
  96. FileWrite:=InOutRes;
  97. End;
  98. {---------------------------------------------------------------------------}
  99. { SetFileSize -> Platforms DOS - Not Checked }
  100. {---------------------------------------------------------------------------}
  101. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  102. VAR Actual, Buf: LongInt;
  103. BEGIN
  104. SetFilePos(Handle,FileSize,0,Actual);
  105. If (Actual = FileSize) Then
  106. Begin
  107. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  108. If (Actual <> -1) Then
  109. SetFileSize := 0
  110. Else
  111. SetFileSize := 103; { File truncate error }
  112. End
  113. Else
  114. SetFileSize := 103; { File truncate error }
  115. END;
  116. {
  117. $Log$
  118. Revision 1.4 2000-02-09 16:59:29 peter
  119. * truncated log
  120. Revision 1.3 2000/01/07 16:41:32 daniel
  121. * copyright 2000
  122. Revision 1.2 2000/01/07 16:32:23 daniel
  123. * copyright 2000 added
  124. }