sysdir.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  5. member of the Free Pascal development team.
  6. FPC Pascal system unit for the Win32 API.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {*****************************************************************************
  14. Directory Handling
  15. *****************************************************************************}
  16. procedure DosDir(func:byte;const s:string);
  17. var
  18. buffer : array[0..255] of char;
  19. regs : trealregs;
  20. begin
  21. move(s[1],buffer,length(s));
  22. buffer[length(s)]:=#0;
  23. AllowSlash(pchar(@buffer));
  24. { True DOS does not like backslashes at end
  25. Win95 DOS accepts this !!
  26. but "\" and "c:\" should still be kept and accepted hopefully PM }
  27. if (length(s)>0) and (buffer[length(s)-1]='\') and
  28. Not ((length(s)=1) or ((length(s)=3) and (s[2]=':'))) then
  29. buffer[length(s)-1]:=#0;
  30. syscopytodos(longint(@buffer),length(s)+1);
  31. regs.realedx:=tb_offset;
  32. regs.realds:=tb_segment;
  33. if LFNSupport then
  34. regs.realeax:=$7100+func
  35. else
  36. regs.realeax:=func shl 8;
  37. sysrealintr($21,regs);
  38. if (regs.realflags and carryflag) <> 0 then
  39. GetInOutRes(lo(regs.realeax));
  40. end;
  41. procedure mkdir(const s : string);[IOCheck];
  42. begin
  43. If (s='') or (InOutRes <> 0) then
  44. exit;
  45. DosDir($39,s);
  46. end;
  47. procedure rmdir(const s : string);[IOCheck];
  48. begin
  49. if (s = '.' ) then
  50. InOutRes := 16;
  51. If (s='') or (InOutRes <> 0) then
  52. exit;
  53. DosDir($3a,s);
  54. end;
  55. procedure chdir(const s : string);[IOCheck];
  56. var
  57. regs : trealregs;
  58. begin
  59. If (s='') or (InOutRes <> 0) then
  60. exit;
  61. { First handle Drive changes }
  62. if (length(s)>=2) and (s[2]=':') then
  63. begin
  64. regs.realedx:=(ord(s[1]) and (not 32))-ord('A');
  65. regs.realeax:=$0e00;
  66. sysrealintr($21,regs);
  67. regs.realeax:=$1900;
  68. sysrealintr($21,regs);
  69. if byte(regs.realeax)<>byte(regs.realedx) then
  70. begin
  71. Inoutres:=15;
  72. exit;
  73. end;
  74. { DosDir($3b,'c:') give Path not found error on
  75. pure DOS PM }
  76. if length(s)=2 then
  77. exit;
  78. end;
  79. { do the normal dos chdir }
  80. DosDir($3b,s);
  81. end;
  82. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  83. var
  84. temp : array[0..255] of char;
  85. i : longint;
  86. regs : trealregs;
  87. begin
  88. regs.realedx:=drivenr;
  89. regs.realesi:=tb_offset;
  90. regs.realds:=tb_segment;
  91. if LFNSupport then
  92. regs.realeax:=$7147
  93. else
  94. regs.realeax:=$4700;
  95. sysrealintr($21,regs);
  96. if (regs.realflags and carryflag) <> 0 then
  97. Begin
  98. GetInOutRes (lo(regs.realeax));
  99. Dir := char (DriveNr + 64) + ':\';
  100. exit;
  101. end
  102. else
  103. syscopyfromdos(longint(@temp),251);
  104. { conversion to Pascal string including slash conversion }
  105. i:=0;
  106. while (temp[i]<>#0) do
  107. begin
  108. if temp[i]='/' then
  109. temp[i]:='\';
  110. dir[i+4]:=temp[i];
  111. inc(i);
  112. end;
  113. dir[2]:=':';
  114. dir[3]:='\';
  115. dir[0]:=char(i+3);
  116. { upcase the string }
  117. if not FileNameCaseSensitive then
  118. dir:=upcase(dir);
  119. if drivenr<>0 then { Drive was supplied. We know it }
  120. dir[1]:=char(65+drivenr-1)
  121. else
  122. begin
  123. { We need to get the current drive from DOS function 19H }
  124. { because the drive was the default, which can be unknown }
  125. regs.realeax:=$1900;
  126. sysrealintr($21,regs);
  127. i:= (regs.realeax and $ff) + ord('A');
  128. dir[1]:=chr(i);
  129. end;
  130. end;
  131. {
  132. $Log$
  133. Revision 1.1 2005-02-06 16:57:18 peter
  134. * threads for go32v2,os,emx,netware
  135. Revision 1.1 2005/02/06 13:06:20 peter
  136. * moved file and dir functions to sysfile/sysdir
  137. * win32 thread in systemunit
  138. }