sysdir.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. RC := DosSetCurrentDir (s);
  61. if RC <> 0 then
  62. begin
  63. InOutRes := RC;
  64. Errno2InOutRes;
  65. end;
  66. end;
  67. end else begin
  68. DoDirSeparators (s);
  69. RC := DosSetCurrentDir (s);
  70. if RC <> 0 then
  71. begin
  72. InOutRes:= RC;
  73. Errno2InOutRes;
  74. end;
  75. end;
  76. end;
  77. {$ASMMODE ATT}
  78. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  79. {Written by Michael Van Canneyt.}
  80. var sof: Pchar;
  81. i:byte;
  82. l,l2:cardinal;
  83. begin
  84. Dir [4] := #0;
  85. { Used in case the specified drive isn't available }
  86. sof:=pchar(@dir[4]);
  87. { dir[1..3] will contain '[drivenr]:\', but is not }
  88. { supplied by DOS, so we let dos string start at }
  89. { dir[4] }
  90. { Get dir from drivenr : 0=default, 1=A etc... }
  91. l:=255-3;
  92. InOutRes:=longint (DosQueryCurrentDir(DriveNr, sof^, l));
  93. {$WARNING Result code should be translated in some cases!}
  94. { Now Dir should be filled with directory in ASCIIZ, }
  95. { starting from dir[4] }
  96. dir[0]:=#3;
  97. dir[2]:=':';
  98. dir[3]:='\';
  99. i:=4;
  100. {Conversion to Pascal string }
  101. while (dir[i]<>#0) do
  102. begin
  103. { convert path name to DOS }
  104. if dir[i] in AllowDirectorySeparators then
  105. dir[i]:=DirectorySeparator;
  106. dir[0]:=char(i);
  107. inc(i);
  108. end;
  109. { upcase the string (FPC function) }
  110. if drivenr<>0 then { Drive was supplied. We know it }
  111. dir[1]:=chr(64+drivenr)
  112. else
  113. begin
  114. { We need to get the current drive from DOS function 19H }
  115. { because the drive was the default, which can be unknown }
  116. DosQueryCurrentDisk(l, l2);
  117. dir[1]:=chr(64+l);
  118. end;
  119. if not (FileNameCaseSensitive) then dir:=upcase(dir);
  120. end;