sysdir.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 MkDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
  16. var
  17. Rc : word;
  18. begin
  19. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  20. exit;
  21. DoDirSeparators(s);
  22. Rc := DosCreateDir(s,nil);
  23. if Rc <> 0 then
  24. begin
  25. InOutRes := Rc;
  26. Errno2Inoutres;
  27. end;
  28. end;
  29. Procedure RmDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
  30. var
  31. Rc : word;
  32. begin
  33. if (len=1) and (s^ = '.' ) then
  34. InOutRes := 16;
  35. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  36. exit;
  37. DoDirSeparators(s);
  38. Rc := DosDeleteDir(s);
  39. if Rc <> 0 then
  40. begin
  41. InOutRes := Rc;
  42. Errno2Inoutres;
  43. end;
  44. end;
  45. {$ASMMODE INTEL}
  46. Procedure ChDir(s: pchar;len:sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
  47. var RC: cardinal;
  48. begin
  49. If not assigned(s) or (len=0) or (InOutRes <> 0) then
  50. exit;
  51. if (Len >= 2) and (S[1] = ':') then
  52. begin
  53. RC := DosSetDefaultDisk ((Ord (S [0]) and not ($20)) - $40);
  54. if RC <> 0 then
  55. InOutRes := RC
  56. else
  57. if Len > 2 then
  58. begin
  59. DoDirSeparators (s);
  60. if (S [Pred (Len)] = DirectorySeparator) and (Len <> 3) then
  61. S [Pred (Len)] := #0;
  62. RC := DosSetCurrentDir (s);
  63. if RC <> 0 then
  64. begin
  65. InOutRes := RC;
  66. Errno2InOutRes;
  67. end;
  68. end;
  69. end else begin
  70. DoDirSeparators (s);
  71. if (Len > 1) and (S [Pred (Len)] = DirectorySeparator) then
  72. S [Pred (Len)] := #0;
  73. RC := DosSetCurrentDir (s);
  74. if RC <> 0 then
  75. begin
  76. InOutRes:= RC;
  77. Errno2InOutRes;
  78. end;
  79. end;
  80. end;
  81. {$ASMMODE ATT}
  82. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  83. {Written by Michael Van Canneyt.}
  84. var sof: Pchar;
  85. i:byte;
  86. l,l2:cardinal;
  87. begin
  88. Dir [4] := #0;
  89. { Used in case the specified drive isn't available }
  90. sof:=pchar(@dir[4]);
  91. { dir[1..3] will contain '[drivenr]:\', but is not }
  92. { supplied by DOS, so we let dos string start at }
  93. { dir[4] }
  94. { Get dir from drivenr : 0=default, 1=A etc... }
  95. l:=255-3;
  96. InOutRes:=longint (DosQueryCurrentDir(DriveNr, sof^, l));
  97. {$WARNING Result code should be translated in some cases!}
  98. { Now Dir should be filled with directory in ASCIIZ, }
  99. { starting from dir[4] }
  100. dir[0]:=#3;
  101. dir[2]:=':';
  102. dir[3]:='\';
  103. i:=4;
  104. {Conversion to Pascal string }
  105. while (dir[i]<>#0) do
  106. begin
  107. { convert path name to DOS }
  108. if dir[i] in AllowDirectorySeparators then
  109. dir[i]:=DirectorySeparator;
  110. dir[0]:=char(i);
  111. inc(i);
  112. end;
  113. { upcase the string (FPC function) }
  114. if drivenr<>0 then { Drive was supplied. We know it }
  115. dir[1]:=chr(64+drivenr)
  116. else
  117. begin
  118. { We need to get the current drive from DOS function 19H }
  119. { because the drive was the default, which can be unknown }
  120. DosQueryCurrentDisk(l, l2);
  121. dir[1]:=chr(64+l);
  122. end;
  123. if not (FileNameCaseSensitive) then dir:=upcase(dir);
  124. end;