typefile.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. See the File COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************
  12. subroutines for typed file handling
  13. ****************************************************************************}
  14. Procedure assign(var f:TypedFile;const Name:string);
  15. {
  16. Assign Name to file f so it can be used with the file routines
  17. }
  18. Begin
  19. FillChar(f,SizeOF(FileRec),0);
  20. FileRec(f).Handle:=UnusedHandle;
  21. FileRec(f).mode:=fmClosed;
  22. Move(Name[1],FileRec(f).Name,Length(Name));
  23. End;
  24. Procedure assign(var f:TypedFile;p:pchar);
  25. {
  26. Assign Name to file f so it can be used with the file routines
  27. }
  28. begin
  29. Assign(f,StrPas(p));
  30. end;
  31. Procedure assign(var f:TypedFile;c:char);
  32. {
  33. Assign Name to file f so it can be used with the file routines
  34. }
  35. begin
  36. Assign(f,string(c));
  37. end;
  38. Procedure Int_Typed_Reset(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED'];
  39. Begin
  40. If InOutRes <> 0 then
  41. exit;
  42. Reset(UnTypedFile(f),Size);
  43. End;
  44. Procedure Int_Typed_Rewrite(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED'];
  45. Begin
  46. If InOutRes <> 0 then
  47. exit;
  48. Rewrite(UnTypedFile(f),Size);
  49. End;
  50. Procedure Int_Typed_Write(TypeSize : Longint;var f : TypedFile;var Buf);[IOCheck, Public, Alias :'FPC_TYPED_WRITE'];
  51. Begin
  52. If InOutRes <> 0 then
  53. exit;
  54. case fileRec(f).mode of
  55. fmOutPut,fmInOut:
  56. Do_Write(FileRec(f).Handle,Longint(@Buf),TypeSize);
  57. fmInput: inOutRes := 105;
  58. else inOutRes := 103;
  59. end;
  60. End;
  61. Procedure Int_Typed_Read(TypeSize : Longint;var f : TypedFile;var Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ'];
  62. var
  63. Result : Longint;
  64. Begin
  65. If InOutRes <> 0 then
  66. exit;
  67. case FileRec(f).mode of
  68. fmInput,fmInOut:
  69. begin
  70. Result:=Do_Read(FileRec(f).Handle,Longint(@Buf),TypeSize);
  71. If Result<TypeSize Then
  72. InOutRes:=100
  73. end;
  74. fmOutPut: inOutRes := 104
  75. else inOutRes := 103;
  76. end;
  77. End;
  78. {
  79. $Log$
  80. Revision 1.2 2000-07-13 11:33:46 michael
  81. + removed logs
  82. }