sysdir.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. OSErrorWatch (RC);
  26. end;
  27. end;
  28. Procedure do_RmDir(s: rawbytestring);
  29. var
  30. Rc : word;
  31. begin
  32. if s = '.' then
  33. begin
  34. InOutRes := 16;
  35. exit;
  36. end;
  37. DoDirSeparators(s);
  38. Rc := DosDeleteDir(pchar(s));
  39. if Rc <> 0 then
  40. begin
  41. InOutRes := Rc;
  42. Errno2Inoutres;
  43. OSErrorWatch (RC);
  44. end;
  45. end;
  46. {$ASMMODE INTEL}
  47. Procedure do_ChDir(s: rawbytestring);
  48. var RC: cardinal;
  49. Len: Longint;
  50. begin
  51. Len := Length (S);
  52. if (Len >= 2) and (S[2] = ':') then
  53. begin
  54. RC := DosSetDefaultDisk ((Ord (S [1]) and not ($20)) - $40);
  55. if RC <> 0 then
  56. begin
  57. InOutRes := RC;
  58. OSErrorWatch (RC);
  59. end
  60. else
  61. if Len > 2 then
  62. begin
  63. DoDirSeparators (s);
  64. if (S [Len] = DirectorySeparator) and (Len <> 3) then
  65. S [Len] := #0;
  66. RC := DosSetCurrentDir (pchar (s));
  67. if RC <> 0 then
  68. begin
  69. InOutRes := RC;
  70. Errno2InOutRes;
  71. OSErrorWatch (RC);
  72. end;
  73. end;
  74. end else begin
  75. DoDirSeparators (s);
  76. if (Len > 1) and (S [Len] = DirectorySeparator) then
  77. S [Len] := #0;
  78. RC := DosSetCurrentDir (pchar (s));
  79. if RC <> 0 then
  80. begin
  81. InOutRes:= RC;
  82. Errno2InOutRes;
  83. OSErrorWatch (RC);
  84. end;
  85. end;
  86. end;
  87. {$ASMMODE ATT}
  88. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  89. {Written by Michael Van Canneyt.}
  90. var sof: Pchar;
  91. i:byte;
  92. l,l2:cardinal;
  93. RC: cardinal;
  94. begin
  95. setlength(Dir,255);
  96. Dir [4] := #0;
  97. { Used in case the specified drive isn't available }
  98. sof:=pchar(@dir[4]);
  99. { dir[1..3] will contain '[drivenr]:\', but is not }
  100. { supplied by DOS, so we let dos string start at }
  101. { dir[4] }
  102. { Get dir from drivenr : 0=default, 1=A etc... }
  103. { TODO: if max path length is > 255, increase the setlength parameter above and
  104. the 255 below }
  105. l:=255-3;
  106. RC := DosQueryCurrentDir(DriveNr, sof^, l);
  107. if RC <> 0 then
  108. begin
  109. InOutRes := longint (RC);
  110. Errno2Inoutres;
  111. OSErrorWatch (RC);
  112. end;
  113. {$WARNING Result code should be translated in some cases!}
  114. { Now Dir should be filled with directory in ASCIIZ, }
  115. { starting from dir[4] }
  116. dir[2]:=':';
  117. dir[3]:='\';
  118. i:=4;
  119. {Conversion to Pascal string }
  120. while (dir[i]<>#0) do
  121. begin
  122. { convert path name to DOS }
  123. if dir[i] in AllowDirectorySeparators then
  124. dir[i]:=DirectorySeparator;
  125. inc(i);
  126. end;
  127. setlength(dir,i-1);
  128. { upcase the string (FPC function) }
  129. if drivenr<>0 then { Drive was supplied. We know it }
  130. dir[1]:=chr(64+drivenr)
  131. else
  132. begin
  133. { We need to get the current drive from DOS function 19H }
  134. { because the drive was the default, which can be unknown }
  135. DosQueryCurrentDisk(l, l2);
  136. dir[1]:=chr(64+l);
  137. end;
  138. SetCodePage(dir,DefaultFileSystemCodePage,false);
  139. if not (FileNameCasePreserving) then dir:=upcase(dir);
  140. end;