typefile.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  14. Procedure Assign(out f:TypedFile;const Name: UnicodeString);
  15. {
  16. Assign Name to file f so it can be used with the file routines
  17. }
  18. Begin
  19. Assign(UnTypedFile(f),Name);
  20. End;
  21. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  22. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  23. Procedure Assign(out f:TypedFile;const Name: RawByteString);
  24. {
  25. Assign Name to file f so it can be used with the file routines
  26. }
  27. Begin
  28. Assign(UnTypedFile(f),Name);
  29. End;
  30. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  31. Procedure Assign(out f:TypedFile;const Name: ShortString);
  32. {
  33. Assign Name to file f so it can be used with the file routines
  34. }
  35. Begin
  36. Assign(UnTypedFile(f),Name);
  37. End;
  38. Procedure Assign(out f:TypedFile;const p:PAnsiChar);
  39. Begin
  40. Assign(UnTypedFile(f),p);
  41. end;
  42. Procedure Assign(out f:TypedFile;const c:AnsiChar);
  43. Begin
  44. Assign(UnTypedFile(f),c);
  45. end;
  46. Procedure fpc_reset_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED']; compilerproc;
  47. Begin
  48. Reset(UnTypedFile(f),Size);
  49. End;
  50. Procedure fpc_rewrite_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED']; compilerproc;
  51. Begin
  52. Rewrite(UnTypedFile(f),Size);
  53. End;
  54. {$ifdef FPC_HAS_FEATURE_RANDOM}
  55. { this code is duplicated in the iso7185 unit }
  56. Procedure DoAssign(var t : TypedFile);
  57. Begin
  58. Assign(t,'fpc_'+HexStr(random(1000000000),8)+'.tmp');
  59. End;
  60. {$else FPC_HAS_FEATURE_RANDOM}
  61. { this code is duplicated in the iso7185 unit }
  62. Procedure DoAssign(var t : TypedFile);
  63. const
  64. start : dword = 0;
  65. Begin
  66. Assign(t,'fpc_'+HexStr(start,8)+'.tmp');
  67. inc(start);
  68. End;
  69. {$endif FPC_HAS_FEATURE_RANDOM}
  70. Procedure fpc_reset_typed_iso(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED_ISO']; compilerproc;
  71. Begin
  72. If InOutRes <> 0 then
  73. exit;
  74. { create file name? }
  75. if FileRec(f).mode=0 then
  76. DoAssign(f);
  77. Reset(UnTypedFile(f),Size);
  78. End;
  79. Procedure fpc_rewrite_typed_iso(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED_ISO']; compilerproc;
  80. Begin
  81. If InOutRes <> 0 then
  82. exit;
  83. { create file name? }
  84. if FileRec(f).mode=0 then
  85. DoAssign(f);
  86. Rewrite(UnTypedFile(f),Size);
  87. End;
  88. Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf);[IOCheck, Public, Alias :'FPC_TYPED_WRITE']; compilerproc;
  89. Begin
  90. If InOutRes <> 0 then
  91. exit;
  92. case fileRec(f).mode of
  93. fmOutPut,fmInOut:
  94. Do_Write(FileRec(f).Handle,@Buf,TypeSize);
  95. fmInput: inOutRes := 105;
  96. else inOutRes := 103;
  97. end;
  98. End;
  99. Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ']; compilerproc;
  100. var
  101. Result : Longint;
  102. Begin
  103. If InOutRes <> 0 then
  104. exit;
  105. case FileRec(f).mode of
  106. fmInput,fmInOut:
  107. begin
  108. Result:=Do_Read(FileRec(f).Handle,@Buf,TypeSize);
  109. If Result<TypeSize Then
  110. InOutRes:=100
  111. end;
  112. fmOutPut: inOutRes := 104
  113. else inOutRes := 103;
  114. end;
  115. End;