typefile.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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({$ifdef PARAOUTFILE}out{$else}var{$endif} f:TypedFile;const Name:RtlString);
  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. StrLCopy(FileRec(f).Name, PRtlChar(Name), SizeOf(FileRec(f).Name) div SizeOf(RtlChar));
  22. End;
  23. Procedure fpc_reset_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_RESET_TYPED']; compilerproc;
  24. Begin
  25. If InOutRes <> 0 then
  26. exit;
  27. Reset(UnTypedFile(f),Size);
  28. End;
  29. Procedure fpc_rewrite_typed(var f : TypedFile;Size : Longint);[Public,IOCheck, Alias:'FPC_REWRITE_TYPED']; compilerproc;
  30. Begin
  31. If InOutRes <> 0 then
  32. exit;
  33. Rewrite(UnTypedFile(f),Size);
  34. End;
  35. Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf);[IOCheck, Public, Alias :'FPC_TYPED_WRITE']; compilerproc;
  36. Begin
  37. If InOutRes <> 0 then
  38. exit;
  39. case fileRec(f).mode of
  40. fmOutPut,fmInOut:
  41. Do_Write(FileRec(f).Handle,@Buf,TypeSize);
  42. fmInput: inOutRes := 105;
  43. else inOutRes := 103;
  44. end;
  45. End;
  46. Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf);[IOCheck, Public, Alias :'FPC_TYPED_READ']; compilerproc;
  47. var
  48. Result : Longint;
  49. Begin
  50. If InOutRes <> 0 then
  51. exit;
  52. case FileRec(f).mode of
  53. fmInput,fmInOut:
  54. begin
  55. Result:=Do_Read(FileRec(f).Handle,@Buf,TypeSize);
  56. If Result<TypeSize Then
  57. InOutRes:=100
  58. end;
  59. fmOutPut: inOutRes := 104
  60. else inOutRes := 103;
  61. end;
  62. End;