sysdir.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit for the Win32 API.
  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. RC := DosSetCurrentDir (pchar (s));
  60. if RC <> 0 then
  61. begin
  62. InOutRes := RC;
  63. Errno2InOutRes;
  64. end;
  65. end;
  66. end else begin
  67. DoDirSeparators (s);
  68. RC := DosSetCurrentDir (pchar (s));
  69. if RC <> 0 then
  70. begin
  71. InOutRes:= RC;
  72. Errno2InOutRes;
  73. end;
  74. end;
  75. end;
  76. {$ASMMODE ATT}
  77. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  78. {Written by Michael Van Canneyt.}
  79. var sof: Pchar;
  80. i:byte;
  81. l,l2:cardinal;
  82. begin
  83. setlength(Dir,255);
  84. Dir [4] := #0;
  85. { Used in case the specified drive isn't available }
  86. sof:=pchar(@dir[4]);
  87. { dir[1..3] will contain '[drivenr]:\', but is not }
  88. { supplied by DOS, so we let dos string start at }
  89. { dir[4] }
  90. { Get dir from drivenr : 0=default, 1=A etc... }
  91. { TODO: if max path length is > 255, increase the setlength parameter above and
  92. the 255 below }
  93. l:=255-3;
  94. InOutRes:=longint (DosQueryCurrentDir(DriveNr, sof^, l));
  95. {$WARNING Result code should be translated in some cases!}
  96. { Now Dir should be filled with directory in ASCIIZ, }
  97. { starting from dir[4] }
  98. dir[2]:=':';
  99. dir[3]:='\';
  100. i:=4;
  101. {Conversion to Pascal string }
  102. while (dir[i]<>#0) do
  103. begin
  104. { convert path name to DOS }
  105. if dir[i] in AllowDirectorySeparators then
  106. dir[i]:=DirectorySeparator;
  107. inc(i);
  108. end;
  109. setlength(dir,i-1);
  110. { upcase the string (FPC function) }
  111. if drivenr<>0 then { Drive was supplied. We know it }
  112. dir[1]:=chr(64+drivenr)
  113. else
  114. begin
  115. { We need to get the current drive from DOS function 19H }
  116. { because the drive was the default, which can be unknown }
  117. DosQueryCurrentDisk(l, l2);
  118. dir[1]:=chr(64+l);
  119. end;
  120. SetCodePage(dir,DefaultFileSystemCodePage,false);
  121. if not (FileNameCasePreserving) then dir:=upcase(dir);
  122. end;