sysdir.inc 7.5 KB

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