sysdir.inc 3.6 KB

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