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