sysfile.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2020 by Free Pascal development team
  4. Low level file functions for the Sinclair QL
  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. Low level File Routines
  13. All these functions can set InOutRes on errors
  14. ****************************************************************************}
  15. { close a file from the handle value }
  16. procedure do_close(handle : longint);
  17. begin
  18. Error2InOutRes(io_close(handle));
  19. end;
  20. procedure do_erase(p : pchar; pchangeable: boolean);
  21. begin
  22. end;
  23. procedure do_rename(p1,p2 : pchar; p1changeable, p2changeable: boolean);
  24. begin
  25. end;
  26. function do_write(h: longint; addr: pointer; len: longint) : longint;
  27. var
  28. res: longint;
  29. begin
  30. do_write:=0;
  31. res:=io_sstrg(h, -1, addr, len);
  32. if res < 0 then
  33. Error2InOutRes(res)
  34. else
  35. do_write:=res;
  36. end;
  37. function do_read(h: longint; addr: pointer; len: longint) : longint;
  38. begin
  39. do_read:=-1;
  40. end;
  41. function do_filepos(handle: longint) : longint;
  42. begin
  43. do_filepos:=-1;
  44. end;
  45. procedure do_seek(handle, pos: longint);
  46. begin
  47. end;
  48. function do_seekend(handle: longint):longint;
  49. begin
  50. do_seekend:=-1;
  51. end;
  52. function do_filesize(handle : THandle) : longint;
  53. begin
  54. do_filesize:=-1;
  55. end;
  56. { truncate at a given position }
  57. procedure do_truncate(handle, pos: longint);
  58. begin
  59. end;
  60. procedure do_open(var f;p:pchar;flags:longint; pchangeable: boolean);
  61. {
  62. filerec and textrec have both handle and mode as the first items so
  63. they could use the same routine for opening/creating.
  64. when (flags and $100) the file will be append
  65. when (flags and $1000) the file will be truncate/rewritten
  66. when (flags and $10000) there is no check for close (needed for textfiles)
  67. }
  68. var
  69. res: longint;
  70. openMode: longint;
  71. begin
  72. openMode:=Q_OPEN;
  73. { close first if opened }
  74. if ((flags and $10000)=0) then
  75. begin
  76. case filerec(f).mode of
  77. fmInput, fmOutput, fmInout:
  78. do_close(filerec(f).handle);
  79. fmClosed: ;
  80. else
  81. begin
  82. InOutRes:=102; {not assigned}
  83. exit;
  84. end;
  85. end;
  86. end;
  87. { reset file handle }
  88. filerec(f).handle:=UnusedHandle;
  89. { convert filemode to filerec modes }
  90. case (flags and 3) of
  91. 0 : filerec(f).mode:=fmInput;
  92. 1 : filerec(f).mode:=fmOutput;
  93. 2 : filerec(f).mode:=fmInout;
  94. end;
  95. { empty name is special }
  96. if p[0]=#0 then begin
  97. case filerec(f).mode of
  98. fminput :
  99. filerec(f).handle:=StdInputHandle;
  100. fmappend,
  101. fmoutput : begin
  102. filerec(f).handle:=StdOutputHandle;
  103. filerec(f).mode:=fmOutput; {fool fmappend}
  104. end;
  105. end;
  106. exit;
  107. end;
  108. { rewrite (create a new file) }
  109. { FIX ME: this will just create a new file, actual overwriting
  110. seems to be a more complex endeavor... }
  111. if (flags and $1000)<>0 then openMode:=Q_OPEN_NEW;
  112. res:=io_open(p,openMode);
  113. if res < 0 then
  114. begin
  115. Error2InOutRes(res);
  116. filerec(f).mode:=fmClosed;
  117. exit;
  118. end
  119. else
  120. filerec(f).handle:=res;
  121. { append mode }
  122. if ((Flags and $100)<>0) and
  123. (FileRec(F).Handle<>UnusedHandle) then begin
  124. do_seekend(filerec(f).handle);
  125. filerec(f).mode:=fmOutput; {fool fmappend}
  126. end;
  127. end;
  128. function do_isdevice(handle: thandle): boolean;
  129. begin
  130. do_isdevice:=false;
  131. end;