sysdir.inc 4.2 KB

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