typefile.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {
  2. This file is part of the Free Pascal Run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the File COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {****************************************************************************
  11. subroutines for typed file handling
  12. ****************************************************************************}
  13. Procedure Assign(out f:TypedFile;const Name:string);
  14. {
  15. Assign Name to file f so it can be used with the file routines
  16. }
  17. Begin
  18. FillChar(f,SizeOF(FileRec),0);
  19. FileRec(f).Handle:=UnusedHandle;
  20. FileRec(f).mode:=fmClosed;
  21. Move(Name[1],FileRec(f).Name,Length(Name));
  22. End;
  23. Procedure Assign(out f:TypedFile;p:pchar);
  24. {
  25. Assign Name to file f so it can be used with the file routines
  26. }
  27. begin
  28. Assign(f,StrPas(p));
  29. end;
  30. Procedure Assign(out f:TypedFile;c:char);
  31. {
  32. Assign Name to file f so it can be used with the file routines
  33. }
  34. begin
  35. Assign(f,string(c));
  36. end;
  37. Procedure fpc_reset_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED']; compilerproc;
  38. Begin
  39. If InOutRes <> 0 then
  40. exit;
  41. Reset(UnTypedFile(f),Size);
  42. End;
  43. Procedure fpc_rewrite_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED']; compilerproc;
  44. Begin
  45. If InOutRes <> 0 then
  46. exit;
  47. Rewrite(UnTypedFile(f),Size);
  48. End;
  49. { this code is duplicated in the iso7185 unit }
  50. Procedure DoAssign(var t : TypedFile);
  51. Begin
  52. Assign(t,'fpc_'+HexStr(random(1000000000),8)+'.tmp');
  53. End;
  54. Procedure fpc_reset_typed_iso(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED_ISO']; compilerproc;
  55. Begin
  56. If InOutRes <> 0 then
  57. exit;
  58. { create file name? }
  59. if FileRec(f).mode=0 then
  60. DoAssign(f);
  61. Reset(UnTypedFile(f),Size);
  62. End;
  63. Procedure fpc_rewrite_typed_iso(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED_ISO']; compilerproc;
  64. Begin
  65. If InOutRes <> 0 then
  66. exit;
  67. { create file name? }
  68. if FileRec(f).mode=0 then
  69. DoAssign(f);
  70. Rewrite(UnTypedFile(f),Size);
  71. End;
  72. Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf);[IOCheck, Public, Alias :'FPC_TYPED_WRITE']; compilerproc;
  73. Begin
  74. If InOutRes <> 0 then
  75. exit;
  76. case fileRec(f).mode of
  77. fmOutPut,fmInOut:
  78. Do_Write(FileRec(f).Handle,@Buf,TypeSize);
  79. fmInput: inOutRes := 105;
  80. else inOutRes := 103;
  81. end;
  82. End;
  83. Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ']; compilerproc;
  84. var
  85. Result : Longint;
  86. Begin
  87. If InOutRes <> 0 then
  88. exit;
  89. case FileRec(f).mode of
  90. fmInput,fmInOut:
  91. begin
  92. Result:=Do_Read(FileRec(f).Handle,@Buf,TypeSize);
  93. If Result<TypeSize Then
  94. InOutRes:=100
  95. end;
  96. fmOutPut: inOutRes := 104
  97. else inOutRes := 103;
  98. end;
  99. End;