sysdir.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. RC := DosSetCurrentDir (pchar(S));
  96. if RC <> 0 then
  97. begin
  98. InOutRes := RC;
  99. Errno2InOutRes;
  100. end;
  101. end;
  102. end
  103. else
  104. begin
  105. DoDirSeparators (S);
  106. RC := DosSetCurrentDir (pchar(S));
  107. if RC <> 0 then
  108. begin
  109. InOutRes:= RC;
  110. Errno2InOutRes;
  111. end;
  112. end;
  113. end
  114. else
  115. if (Len >= 2) and (S [2] = ':') then
  116. begin
  117. asm
  118. mov esi, S
  119. mov al, [esi + 1]
  120. and al, not (20h)
  121. sub al, 41h
  122. mov edx, eax
  123. mov ah, 0Eh
  124. call syscall
  125. mov ah, 19h
  126. call syscall
  127. cmp al, dl
  128. jz @LCHDIR
  129. mov InOutRes, 15
  130. @LCHDIR:
  131. end ['eax','edx','esi'];
  132. if (Len > 2) and (InOutRes <> 0) then
  133. { Under EMX 0.9d DOS this routine may sometime }
  134. { fail or crash the system. }
  135. DosDir ($3B, S);
  136. end
  137. else
  138. { Under EMX 0.9d DOS this routine may sometime }
  139. { fail or crash the system. }
  140. DosDir ($3B, S);
  141. end;
  142. {$ASMMODE ATT}
  143. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  144. {Written by Michael Van Canneyt.}
  145. var sof:Pchar;
  146. i:byte;
  147. begin
  148. SetLength(Dir,260);
  149. Dir [4] := #0;
  150. { Used in case the specified drive isn't available }
  151. sof:=pchar(@dir[4]);
  152. { dir[1..3] will contain '[drivenr]:\', but is not }
  153. { supplied by DOS, so we let dos string start at }
  154. { dir[4] }
  155. { Get dir from drivenr : 0=default, 1=A etc... }
  156. asm
  157. movb drivenr,%dl
  158. movl sof,%esi
  159. mov $0x47,%ah
  160. call syscall
  161. jnc .LGetDir
  162. movw %ax, InOutRes
  163. .LGetDir:
  164. end [ 'eax','edx','esi'];
  165. { Now Dir should be filled with directory in ASCIIZ, }
  166. { starting from dir[4] }
  167. dir[2]:=':';
  168. dir[3]:='\';
  169. i:=4;
  170. {Conversion to Pascal string }
  171. while (dir[i]<>#0) do
  172. begin
  173. { convert path name to DOS }
  174. if dir[i] in AllowDirectorySeparators then
  175. dir[i]:=DirectorySeparator;
  176. inc(i);
  177. end;
  178. SetLength(dir,i-1);
  179. if drivenr<>0 then { Drive was supplied. We know it }
  180. dir[1]:=chr(64+drivenr)
  181. else
  182. begin
  183. { We need to get the current drive from DOS function 19H }
  184. { because the drive was the default, which can be unknown }
  185. asm
  186. movb $0x19,%ah
  187. call syscall
  188. addb $65,%al
  189. movb %al,i
  190. end ['eax'];
  191. dir[1]:=char(i);
  192. end;
  193. SetCodePage(dir,DefaultFileSystemCodePage,false);
  194. { upcase the string (FPC function) }
  195. if not (FileNameCasePreserving) then dir:=upcase(dir);
  196. end;