sysdir.inc 3.7 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 DosDir(func:byte;s:pchar;len:integer);
  16. var
  17. regs : trealregs;
  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. syscopytodos(longint(s),len+1);
  27. regs.realedx:=tb_offset;
  28. regs.realds:=tb_segment;
  29. if LFNSupport then
  30. regs.realeax:=$7100+func
  31. else
  32. regs.realeax:=func shl 8;
  33. sysrealintr($21,regs);
  34. if (regs.realflags and carryflag) <> 0 then
  35. GetInOutRes(lo(regs.realeax));
  36. end;
  37. Procedure MkDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
  38. begin
  39. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  40. exit;
  41. DosDir($39,s,len);
  42. end;
  43. Procedure RmDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
  44. begin
  45. if (len=1) and (s[0] = '.' ) then
  46. InOutRes := 16;
  47. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  48. exit;
  49. DosDir($3a,s,len);
  50. end;
  51. Procedure ChDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
  52. var
  53. regs : trealregs;
  54. begin
  55. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  56. exit;
  57. { First handle Drive changes }
  58. if (len>=2) and (s[1]=':') then
  59. begin
  60. regs.realedx:=(ord(s[0]) and (not 32))-ord('A');
  61. regs.realeax:=$0e00;
  62. sysrealintr($21,regs);
  63. regs.realeax:=$1900;
  64. sysrealintr($21,regs);
  65. if byte(regs.realeax)<>byte(regs.realedx) then
  66. begin
  67. Inoutres:=15;
  68. exit;
  69. end;
  70. { DosDir($3b,'c:') give Path not found error on
  71. pure DOS PM }
  72. if len=2 then
  73. exit;
  74. end;
  75. { do the normal dos chdir }
  76. DosDir($3b,s,len);
  77. end;
  78. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  79. var
  80. temp : array[0..255] of char;
  81. i : longint;
  82. regs : trealregs;
  83. begin
  84. regs.realedx:=drivenr;
  85. regs.realesi:=tb_offset;
  86. regs.realds:=tb_segment;
  87. if LFNSupport then
  88. regs.realeax:=$7147
  89. else
  90. regs.realeax:=$4700;
  91. sysrealintr($21,regs);
  92. if (regs.realflags and carryflag) <> 0 then
  93. Begin
  94. GetInOutRes (lo(regs.realeax));
  95. Dir := char (DriveNr + 64) + ':\';
  96. exit;
  97. end
  98. else
  99. syscopyfromdos(longint(@temp),251);
  100. { conversion to Pascal string including slash conversion }
  101. i:=0;
  102. while (temp[i]<>#0) do
  103. begin
  104. if temp[i] in AllowDirectorySeparators then
  105. temp[i]:=DirectorySeparator;
  106. dir[i+4]:=temp[i];
  107. inc(i);
  108. end;
  109. dir[2]:=':';
  110. dir[3]:='\';
  111. dir[0]:=char(i+3);
  112. { upcase the string }
  113. if not FileNameCaseSensitive then
  114. dir:=upcase(dir);
  115. if drivenr<>0 then { Drive was supplied. We know it }
  116. dir[1]:=char(65+drivenr-1)
  117. else
  118. begin
  119. { We need to get the current drive from DOS function 19H }
  120. { because the drive was the default, which can be unknown }
  121. regs.realeax:=$1900;
  122. sysrealintr($21,regs);
  123. i:= (regs.realeax and $ff) + ord('A');
  124. dir[1]:=chr(i);
  125. end;
  126. end;