sysdir.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 DosDir(func:byte;s: rawbytestring);
  16. var
  17. regs : Registers;
  18. len : Integer;
  19. begin
  20. DoDirSeparators(s);
  21. { True DOS does not like backslashes at end
  22. Win95 DOS accepts this !!
  23. but "\" and "c:\" should still be kept and accepted hopefully PM }
  24. len:=length(s);
  25. if (len>0) and (s[len]='\') and
  26. Not ((len=1) or ((len=3) and (s[2]=':'))) then
  27. s[len]:=#0;
  28. ZeroSegRegs(regs);
  29. regs.DX:=Ofs(s[1]);
  30. regs.DS:=Seg(s[1]);
  31. if LFNSupport then
  32. regs.AX:=$7100+func
  33. else
  34. regs.AX:=func shl 8;
  35. MsDos(regs);
  36. if (regs.Flags and fCarry) <> 0 then
  37. GetInOutRes(regs.AX);
  38. end;
  39. Procedure do_MkDir(const s: rawbytestring);
  40. begin
  41. DosDir($39,s);
  42. end;
  43. Procedure do_RmDir(const s: rawbytestring);
  44. begin
  45. if s='.' then
  46. begin
  47. InOutRes:=16;
  48. exit;
  49. end;
  50. DosDir($3a,s);
  51. end;
  52. Procedure do_ChDir(const s: rawbytestring);
  53. var
  54. regs : Registers;
  55. len : Integer;
  56. begin
  57. len:=Length(s);
  58. { First handle Drive changes }
  59. if (len>=2) and (s[2]=':') then
  60. begin
  61. ZeroSegRegs(regs);
  62. regs.DX:=(ord(s[1]) and (not 32))-ord('A');
  63. regs.AX:=$0e00;
  64. MsDos(regs);
  65. ZeroSegRegs(regs);
  66. regs.AX:=$1900;
  67. MsDos(regs);
  68. if regs.AL<>regs.DL then
  69. begin
  70. Inoutres:=15;
  71. exit;
  72. end;
  73. { DosDir($3b,'c:') give Path not found error on
  74. pure DOS PM }
  75. if len=2 then
  76. exit;
  77. end;
  78. { do the normal dos chdir }
  79. DosDir($3b,s);
  80. end;
  81. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  82. var
  83. temp : array[0..260] of AnsiChar;
  84. i : integer;
  85. regs : Registers;
  86. begin
  87. ZeroSegRegs(regs);
  88. regs.DX:=drivenr;
  89. regs.SI:=Ofs(temp);
  90. regs.DS:=Seg(temp);
  91. if LFNSupport then
  92. regs.AX:=$7147
  93. else
  94. regs.AX:=$4700;
  95. MsDos(regs);
  96. if (regs.Flags and fCarry) <> 0 then
  97. Begin
  98. GetInOutRes (regs.AX);
  99. Dir := AnsiChar (DriveNr + 64) + ':\';
  100. SetCodePage (Dir,DefaultFileSystemCodePage,false);
  101. exit;
  102. end
  103. else
  104. temp[252] := #0; { to avoid shortstring buffer overflow }
  105. { conversion to Pascal string including slash conversion }
  106. i:=0;
  107. SetLength(dir,260);
  108. while (temp[i]<>#0) do
  109. begin
  110. if temp[i] in AllowDirectorySeparators then
  111. temp[i]:=DirectorySeparator;
  112. dir[i+4]:=temp[i];
  113. inc(i);
  114. end;
  115. dir[2]:=':';
  116. dir[3]:='\';
  117. SetLength(dir,i+3);
  118. SetCodePage (dir,DefaultFileSystemCodePage,false);
  119. { upcase the string }
  120. if not FileNameCasePreserving then
  121. dir:=upcase(dir);
  122. if drivenr<>0 then { Drive was supplied. We know it }
  123. dir[1]:=AnsiChar(65+drivenr-1)
  124. else
  125. begin
  126. { We need to get the current drive from DOS function 19H }
  127. { because the drive was the default, which can be unknown }
  128. ZeroSegRegs(regs);
  129. regs.AX:=$1900;
  130. MsDos(regs);
  131. i:= (regs.AX and $ff) + ord('A');
  132. dir[1]:=chr(i);
  133. end;
  134. end;