typefile.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf);[IOCheck, Public, Alias :'FPC_TYPED_WRITE']; compilerproc;
  50. Begin
  51. If InOutRes <> 0 then
  52. exit;
  53. case fileRec(f).mode of
  54. fmOutPut,fmInOut:
  55. Do_Write(FileRec(f).Handle,@Buf,TypeSize);
  56. fmInput: inOutRes := 105;
  57. else inOutRes := 103;
  58. end;
  59. End;
  60. Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ']; compilerproc;
  61. var
  62. Result : Longint;
  63. Begin
  64. If InOutRes <> 0 then
  65. exit;
  66. case FileRec(f).mode of
  67. fmInput,fmInOut:
  68. begin
  69. Result:=Do_Read(FileRec(f).Handle,@Buf,TypeSize);
  70. If Result<TypeSize Then
  71. InOutRes:=100
  72. end;
  73. fmOutPut: inOutRes := 104
  74. else inOutRes := 103;
  75. end;
  76. End;