sysdir.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 dosdir(func:byte;const s:string);
  16. var buffer:array[0..255] of char;
  17. begin
  18. move(s[1],buffer,length(s));
  19. buffer[length(s)]:=#0;
  20. DoDirSeparators(Pchar(@buffer));
  21. asm
  22. leal buffer,%edx
  23. movb func,%ah
  24. call syscall
  25. jnc .LDOS_DIRS1
  26. movw %ax,inoutres
  27. .LDOS_DIRS1:
  28. end ['eax', 'edx'];
  29. end;
  30. procedure MkDir (const S: string);[IOCHECK];
  31. var buffer:array[0..255] of char;
  32. Rc : word;
  33. begin
  34. If (s='') or (InOutRes <> 0) then
  35. exit;
  36. if os_mode = osOs2 then
  37. begin
  38. move(s[1],buffer,length(s));
  39. buffer[length(s)]:=#0;
  40. DoDirSeparators(Pchar(@buffer));
  41. Rc := DosCreateDir(buffer,nil);
  42. if Rc <> 0 then
  43. begin
  44. InOutRes := Rc;
  45. Errno2Inoutres;
  46. end;
  47. end
  48. else
  49. begin
  50. { Under EMX 0.9d DOS this routine call may sometimes fail }
  51. { The syscall documentation indicates clearly that this }
  52. { routine was NOT tested. }
  53. DosDir ($39, S);
  54. end;
  55. end;
  56. procedure rmdir(const s : string);[IOCHECK];
  57. var buffer:array[0..255] of char;
  58. Rc : word;
  59. begin
  60. if (s = '.' ) then
  61. InOutRes := 16;
  62. If (s='') or (InOutRes <> 0) then
  63. exit;
  64. if os_mode = osOs2 then
  65. begin
  66. move(s[1],buffer,length(s));
  67. buffer[length(s)]:=#0;
  68. DoDirSeparators(Pchar(@buffer));
  69. Rc := DosDeleteDir(buffer);
  70. if Rc <> 0 then
  71. begin
  72. InOutRes := Rc;
  73. Errno2Inoutres;
  74. end;
  75. end
  76. else
  77. begin
  78. { Under EMX 0.9d DOS this routine call may sometimes fail }
  79. { The syscall documentation indicates clearly that this }
  80. { routine was NOT tested. }
  81. DosDir ($3A, S);
  82. end;
  83. end;
  84. {$ASMMODE INTEL}
  85. procedure ChDir (const S: string);[IOCheck];
  86. var RC: cardinal;
  87. Buffer: array [0..255] of char;
  88. begin
  89. If (s='') or (InOutRes <> 0) then
  90. exit;
  91. (* According to EMX documentation, EMX has only one current directory
  92. for all processes, so we'll use native calls under OS/2. *)
  93. if os_Mode = osOS2 then
  94. begin
  95. if (Length (S) >= 2) and (S [2] = ':') then
  96. begin
  97. RC := DosSetDefaultDisk ((Ord (S [1]) and
  98. not ($20)) - $40);
  99. if RC <> 0 then
  100. InOutRes := RC
  101. else
  102. if Length (S) > 2 then
  103. begin
  104. Move (S [1], Buffer, Length (S));
  105. Buffer [Length (S)] := #0;
  106. DoDirSeparators (PChar (@Buffer));
  107. RC := DosSetCurrentDir (@Buffer);
  108. if RC <> 0 then
  109. begin
  110. InOutRes := RC;
  111. Errno2InOutRes;
  112. end;
  113. end;
  114. end
  115. else
  116. begin
  117. Move (S [1], Buffer, Length (S));
  118. Buffer [Length (S)] := #0;
  119. DoDirSeparators (PChar (@Buffer));
  120. RC := DosSetCurrentDir (@Buffer);
  121. if RC <> 0 then
  122. begin
  123. InOutRes:= RC;
  124. Errno2InOutRes;
  125. end;
  126. end;
  127. end
  128. else
  129. if (Length (S) >= 2) and (S [2] = ':') then
  130. begin
  131. asm
  132. mov esi, S
  133. mov al, [esi + 1]
  134. and al, not (20h)
  135. sub al, 41h
  136. mov edx, eax
  137. mov ah, 0Eh
  138. call syscall
  139. mov ah, 19h
  140. call syscall
  141. cmp al, dl
  142. jz @LCHDIR
  143. mov InOutRes, 15
  144. @LCHDIR:
  145. end ['eax','edx','esi'];
  146. if (Length (S) > 2) and (InOutRes <> 0) then
  147. { Under EMX 0.9d DOS this routine may sometime }
  148. { fail or crash the system. }
  149. DosDir ($3B, S);
  150. end
  151. else
  152. { Under EMX 0.9d DOS this routine may sometime }
  153. { fail or crash the system. }
  154. DosDir ($3B, S);
  155. end;
  156. {$ASMMODE ATT}
  157. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  158. {Written by Michael Van Canneyt.}
  159. var sof:Pchar;
  160. i:byte;
  161. begin
  162. Dir [4] := #0;
  163. { Used in case the specified drive isn't available }
  164. sof:=pchar(@dir[4]);
  165. { dir[1..3] will contain '[drivenr]:\', but is not }
  166. { supplied by DOS, so we let dos string start at }
  167. { dir[4] }
  168. { Get dir from drivenr : 0=default, 1=A etc... }
  169. asm
  170. movb drivenr,%dl
  171. movl sof,%esi
  172. mov $0x47,%ah
  173. call syscall
  174. jnc .LGetDir
  175. movw %ax, InOutRes
  176. .LGetDir:
  177. end [ 'eax','edx','esi'];
  178. { Now Dir should be filled with directory in ASCIIZ, }
  179. { starting from dir[4] }
  180. dir[0]:=#3;
  181. dir[2]:=':';
  182. dir[3]:='\';
  183. i:=4;
  184. {Conversion to Pascal string }
  185. while (dir[i]<>#0) do
  186. begin
  187. { convert path name to DOS }
  188. if dir[i] in AllowDirectorySeparators then
  189. dir[i]:=DirectorySeparator;
  190. dir[0]:=char(i);
  191. inc(i);
  192. end;
  193. { upcase the string (FPC function) }
  194. if drivenr<>0 then { Drive was supplied. We know it }
  195. dir[1]:=chr(64+drivenr)
  196. else
  197. begin
  198. { We need to get the current drive from DOS function 19H }
  199. { because the drive was the default, which can be unknown }
  200. asm
  201. movb $0x19,%ah
  202. call syscall
  203. addb $65,%al
  204. movb %al,i
  205. end ['eax'];
  206. dir[1]:=char(i);
  207. end;
  208. if not (FileNameCaseSensitive) then dir:=upcase(dir);
  209. end;