sysdir.inc 5.7 KB

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