sysdir.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2014 by Florian Klaempfl
  4. and other members of the Free Pascal development team.
  5. FPC Pascal system unit for OS/2.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {*****************************************************************************
  13. Directory Handling
  14. *****************************************************************************}
  15. Procedure do_MkDir(s: rawbytestring);
  16. var
  17. Rc : word;
  18. begin
  19. DoDirSeparators(s);
  20. Rc := DosCreateDir(pchar(s),nil);
  21. if Rc <> 0 then
  22. begin
  23. InOutRes := Rc;
  24. Errno2Inoutres;
  25. end;
  26. end;
  27. Procedure do_RmDir(s: rawbytestring);
  28. var
  29. Rc : word;
  30. begin
  31. if s = '.' then
  32. begin
  33. InOutRes := 16;
  34. exit;
  35. end;
  36. DoDirSeparators(s);
  37. Rc := DosDeleteDir(pchar(s));
  38. if Rc <> 0 then
  39. begin
  40. InOutRes := Rc;
  41. Errno2Inoutres;
  42. end;
  43. end;
  44. {$ASMMODE INTEL}
  45. Procedure do_ChDir(s: rawbytestring);
  46. var RC: cardinal;
  47. Len: Longint;
  48. begin
  49. Len := Length (S);
  50. if (Len >= 2) and (S[2] = ':') then
  51. begin
  52. RC := DosSetDefaultDisk ((Ord (S [1]) and not ($20)) - $40);
  53. if RC <> 0 then
  54. InOutRes := RC
  55. else
  56. if Len > 2 then
  57. begin
  58. DoDirSeparators (s);
  59. if (S [Len] = DirectorySeparator) and (Len <> 3) then
  60. S [Len] := #0;
  61. RC := DosSetCurrentDir (pchar (s));
  62. if RC <> 0 then
  63. begin
  64. InOutRes := RC;
  65. Errno2InOutRes;
  66. end;
  67. end;
  68. end else begin
  69. DoDirSeparators (s);
  70. if (Len > 1) and (S [Len] = DirectorySeparator) then
  71. S [Len] := #0;
  72. RC := DosSetCurrentDir (pchar (s));
  73. if RC <> 0 then
  74. begin
  75. InOutRes:= RC;
  76. Errno2InOutRes;
  77. end;
  78. end;
  79. end;
  80. {$ASMMODE ATT}
  81. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  82. {Written by Michael Van Canneyt.}
  83. var sof: Pchar;
  84. i:byte;
  85. l,l2:cardinal;
  86. begin
  87. setlength(Dir,255);
  88. Dir [4] := #0;
  89. { Used in case the specified drive isn't available }
  90. sof:=pchar(@dir[4]);
  91. { dir[1..3] will contain '[drivenr]:\', but is not }
  92. { supplied by DOS, so we let dos string start at }
  93. { dir[4] }
  94. { Get dir from drivenr : 0=default, 1=A etc... }
  95. { TODO: if max path length is > 255, increase the setlength parameter above and
  96. the 255 below }
  97. l:=255-3;
  98. InOutRes:=longint (DosQueryCurrentDir(DriveNr, sof^, l));
  99. {$WARNING Result code should be translated in some cases!}
  100. { Now Dir should be filled with directory in ASCIIZ, }
  101. { starting from dir[4] }
  102. dir[2]:=':';
  103. dir[3]:='\';
  104. i:=4;
  105. {Conversion to Pascal string }
  106. while (dir[i]<>#0) do
  107. begin
  108. { convert path name to DOS }
  109. if dir[i] in AllowDirectorySeparators then
  110. dir[i]:=DirectorySeparator;
  111. inc(i);
  112. end;
  113. setlength(dir,i-1);
  114. { upcase the string (FPC function) }
  115. if drivenr<>0 then { Drive was supplied. We know it }
  116. dir[1]:=chr(64+drivenr)
  117. else
  118. begin
  119. { We need to get the current drive from DOS function 19H }
  120. { because the drive was the default, which can be unknown }
  121. DosQueryCurrentDisk(l, l2);
  122. dir[1]:=chr(64+l);
  123. end;
  124. SetCodePage(dir,DefaultFileSystemCodePage,false);
  125. if not (FileNameCasePreserving) then dir:=upcase(dir);
  126. end;