sysdir.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 by Free Pascal development team
  4. Low level directory functions for Atari TOS
  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. Directory Handling
  13. *****************************************************************************}
  14. procedure do_mkdir(const s : rawbytestring);
  15. var
  16. dosResult: longint;
  17. ps: rawbytestring;
  18. begin
  19. ps:=s;
  20. DoDirSeparators(ps);
  21. dosResult:=gemdos_dcreate(pchar(ps));
  22. if dosResult < 0 then
  23. Error2InOutRes(dosResult);
  24. end;
  25. procedure do_rmdir(const s : rawbytestring);
  26. var
  27. dosResult: longint;
  28. ps: rawbytestring;
  29. begin
  30. ps:=s;
  31. DoDirSeparators(ps);
  32. if ps='.' then
  33. begin
  34. InOutRes:=16;
  35. exit;
  36. end;
  37. dosResult:=gemdos_ddelete(pchar(ps));
  38. if dosResult < 0 then
  39. Error2InOutRes(dosResult);
  40. end;
  41. procedure do_ChDir(const s: rawbytestring);
  42. var
  43. ps: rawbytestring;
  44. len: longint;
  45. drives: dword;
  46. curdrive: word;
  47. newdrive: word;
  48. dosResult: longint;
  49. begin
  50. ps:=s;
  51. DoDirSeparators(ps);
  52. len:=Length(ps);
  53. { first, handle drive changes }
  54. if (len>=2) and (ps[2]=':') then
  55. begin
  56. curdrive:=gemdos_dgetdrv;
  57. newdrive:=(ord(ps[1]) and (not 32))-ord('A');
  58. if (newdrive <> curdrive) then
  59. begin
  60. { verify if the drive we have to set actually exist.
  61. not doing so may corrupt TOS internal structures,
  62. according to docs. (KB) }
  63. drives:=gemdos_dsetdrv(curdrive);
  64. if (drives and (1 shl newdrive)) = 0 then
  65. begin
  66. InOutRes:=15;
  67. exit;
  68. end;
  69. gemdos_dsetdrv(newdrive);
  70. end;
  71. if len=2 then
  72. exit;
  73. end;
  74. { do normal setpath }
  75. dosResult:=gemdos_dsetpath(pchar(ps));
  76. if dosResult < 0 then
  77. Error2InOutRes(dosResult);
  78. end;
  79. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  80. var
  81. dosResult: longint;
  82. pathbuf: array[0..259] of char;
  83. begin
  84. Dir := '';
  85. dosResult:=gemdos_dgetpath(@pathbuf[2],DriveNr);
  86. if dosResult < 0 then
  87. begin
  88. Error2InOutRes(dosResult);
  89. exit;
  90. end;
  91. if DriveNr = 0 then
  92. DriveNr := gemdos_dgetdrv + 1;
  93. { return a full path, including drive }
  94. pathbuf[0]:=char(ord('A') + DriveNr - 1);
  95. pathbuf[1]:=DriveSeparator;
  96. Dir:=pathbuf;
  97. SetCodePage(Dir,DefaultSystemCodePage,false);
  98. end;