sysdir.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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;const s:string);
  16. var
  17. buffer : array[0..255] of char;
  18. regs : trealregs;
  19. begin
  20. move(s[1],buffer,length(s));
  21. buffer[length(s)]:=#0;
  22. DoDirSeparators(pchar(@buffer));
  23. { True DOS does not like backslashes at end
  24. Win95 DOS accepts this !!
  25. but "\" and "c:\" should still be kept and accepted hopefully PM }
  26. if (length(s)>0) and (buffer[length(s)-1]='\') and
  27. Not ((length(s)=1) or ((length(s)=3) and (s[2]=':'))) then
  28. buffer[length(s)-1]:=#0;
  29. syscopytodos(longint(@buffer),length(s)+1);
  30. regs.realedx:=tb_offset;
  31. regs.realds:=tb_segment;
  32. if LFNSupport then
  33. regs.realeax:=$7100+func
  34. else
  35. regs.realeax:=func shl 8;
  36. sysrealintr($21,regs);
  37. if (regs.realflags and carryflag) <> 0 then
  38. GetInOutRes(lo(regs.realeax));
  39. end;
  40. procedure mkdir(const s : string);[IOCheck];
  41. begin
  42. If (s='') or (InOutRes <> 0) then
  43. exit;
  44. DosDir($39,s);
  45. end;
  46. procedure rmdir(const s : string);[IOCheck];
  47. begin
  48. if (s = '.' ) then
  49. InOutRes := 16;
  50. If (s='') or (InOutRes <> 0) then
  51. exit;
  52. DosDir($3a,s);
  53. end;
  54. procedure chdir(const s : string);[IOCheck];
  55. var
  56. regs : trealregs;
  57. begin
  58. If (s='') or (InOutRes <> 0) then
  59. exit;
  60. { First handle Drive changes }
  61. if (length(s)>=2) and (s[2]=':') then
  62. begin
  63. regs.realedx:=(ord(s[1]) and (not 32))-ord('A');
  64. regs.realeax:=$0e00;
  65. sysrealintr($21,regs);
  66. regs.realeax:=$1900;
  67. sysrealintr($21,regs);
  68. if byte(regs.realeax)<>byte(regs.realedx) 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 length(s)=2 then
  76. exit;
  77. end;
  78. { do the normal dos chdir }
  79. DosDir($3b,s);
  80. end;
  81. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  82. var
  83. temp : array[0..255] of char;
  84. i : longint;
  85. regs : trealregs;
  86. begin
  87. regs.realedx:=drivenr;
  88. regs.realesi:=tb_offset;
  89. regs.realds:=tb_segment;
  90. if LFNSupport then
  91. regs.realeax:=$7147
  92. else
  93. regs.realeax:=$4700;
  94. sysrealintr($21,regs);
  95. if (regs.realflags and carryflag) <> 0 then
  96. Begin
  97. GetInOutRes (lo(regs.realeax));
  98. Dir := char (DriveNr + 64) + ':\';
  99. exit;
  100. end
  101. else
  102. syscopyfromdos(longint(@temp),251);
  103. { conversion to Pascal string including slash conversion }
  104. i:=0;
  105. while (temp[i]<>#0) do
  106. begin
  107. if temp[i] in AllowDirectorySeparators then
  108. temp[i]:=DirectorySeparator;
  109. dir[i+4]:=temp[i];
  110. inc(i);
  111. end;
  112. dir[2]:=':';
  113. dir[3]:='\';
  114. dir[0]:=char(i+3);
  115. { upcase the string }
  116. if not FileNameCaseSensitive then
  117. dir:=upcase(dir);
  118. if drivenr<>0 then { Drive was supplied. We know it }
  119. dir[1]:=char(65+drivenr-1)
  120. else
  121. begin
  122. { We need to get the current drive from DOS function 19H }
  123. { because the drive was the default, which can be unknown }
  124. regs.realeax:=$1900;
  125. sysrealintr($21,regs);
  126. i:= (regs.realeax and $ff) + ord('A');
  127. dir[1]:=chr(i);
  128. end;
  129. end;