filutil.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. File utility calls
  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. {This is the correct way to call external assembler procedures.}
  13. procedure syscall;external name '___SYSCALL';
  14. const
  15. ofRead = $0000; {Open for reading}
  16. ofWrite = $0001; {Open for writing}
  17. ofReadWrite = $0002; {Open for reading/writing}
  18. faCreateNew = $00010000; {Create if file does not exist}
  19. faOpenReplace = $00040000; {Truncate if file exists}
  20. faCreate = $00050000; {Create if file does not exist, truncate otherwise}
  21. {$ASMMODE INTEL}
  22. function FileOpen (const FileName: string; Mode: integer): longint;
  23. {$IFOPT H+}
  24. assembler;
  25. {$ELSE}
  26. var FN: string;
  27. begin
  28. FN := FileName + #0;
  29. {$ENDIF}
  30. asm
  31. mov eax, 7F2Bh
  32. mov ecx, Mode
  33. {$IFOPT H+}
  34. mov edx, FileName
  35. {$ELSE}
  36. lea edx, FN
  37. inc edx
  38. {$ENDIF}
  39. call syscall
  40. {$IFOPT H-}
  41. mov [ebp - 4], eax
  42. end;
  43. {$ENDIF}
  44. end;
  45. function FileCreate (const FileName: string): longint;
  46. {$IFOPT H+}
  47. assembler;
  48. {$ELSE}
  49. var FN: string;
  50. begin
  51. FN := FileName + #0;
  52. {$ENDIF}
  53. asm
  54. mov eax, 7F2Bh
  55. mov ecx, ofReadWrite or faCreate
  56. {$IFOPT H+}
  57. mov edx, FileName
  58. {$ELSE}
  59. lea edx, FN
  60. inc edx
  61. {$ENDIF}
  62. call syscall
  63. {$IFOPT H-}
  64. mov [ebp - 4], eax
  65. end;
  66. {$ENDIF}
  67. end;
  68. function FileRead (Handle: longint; var Buffer; Count: longint): longint;
  69. assembler;
  70. asm
  71. mov eax, 3F00h
  72. mov ebx, Handle
  73. mov ecx, Count
  74. mov edx, Buffer
  75. call syscall
  76. jnc @FReadEnd
  77. mov eax, -1
  78. @FReadEnd:
  79. end;
  80. function FileWrite (Handle: longint; const Buffer; Count: longint): longint;
  81. assembler;
  82. asm
  83. mov eax, 4000h
  84. mov ebx, Handle
  85. mov ecx, Count
  86. mov edx, Buffer
  87. call syscall
  88. jnc @FWriteEnd
  89. mov eax, -1
  90. @FWriteEnd:
  91. end;
  92. function FileSeek (Handle, FOffset, Origin: longint): longint; assembler;
  93. asm
  94. mov eax, Origin
  95. mov ah, 42h
  96. mov ebx, Handle
  97. mov edx, FOffset
  98. call syscall
  99. jnc @FSeekEnd
  100. mov eax, -1
  101. @FSeekEnd:
  102. end;
  103. procedure FileClose (Handle: longint);
  104. begin
  105. if (Handle <= 4) or (os_mode = osOS2) and (Handle <= 2) then
  106. asm
  107. mov eax, 3E00h
  108. mov ebx, Handle
  109. call syscall
  110. end;
  111. end;
  112. function FileTruncate (Handle, Size: longint): boolean; assembler;
  113. asm
  114. mov eax, 7F25h
  115. mov ebx, Handle
  116. mov edx, Size
  117. call syscall
  118. jc @FTruncEnd
  119. mov eax, 4202h
  120. mov ebx, Handle
  121. mov edx, 0
  122. call syscall
  123. mov eax, 0
  124. jnc @FTruncEnd
  125. dec eax
  126. @FTruncEnd:
  127. end;
  128. function FileAge (const FileName: string): longint;
  129. var Handle: longint;
  130. begin
  131. Handle := FileOpen (FileName, 0);
  132. if Handle <> -1 then
  133. begin
  134. Result := FileGetDate (Handle);
  135. FileClose (Handle);
  136. end
  137. else
  138. Result := -1;
  139. end;
  140. function FileExists (const FileName: string): boolean;
  141. {$IFOPT H+}
  142. assembler;
  143. {$ELSE}
  144. var FN: string;
  145. begin
  146. FN := FileName + #0;
  147. {$ENDIF}
  148. asm
  149. mov ax, 4300h
  150. {$IFOPT H+}
  151. mov edx, FileName
  152. {$ELSE}
  153. lea edx, FN
  154. inc edx
  155. {$ENDIF}
  156. call syscall
  157. mov eax, 0
  158. jc @FExistsEnd
  159. test cx, 18h
  160. jnz @FExistsEnd
  161. inc eax
  162. @FExistsEnd:
  163. {$IFOPT H-}
  164. end;
  165. {$ENDIF}
  166. end;
  167. Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  168. begin
  169. //!! Needs implementing
  170. end;
  171. Function FindNext (Var Rslt : TSearchRec) : Longint;
  172. begin
  173. //!! Needs implementing
  174. end;
  175. procedure FindClose (var F: TSearchrec);
  176. begin
  177. if os_mode = osOS2 then
  178. begin
  179. DosCalls.DosFindClose (F.FindHandle);
  180. end;
  181. end;
  182. function FileGetDate (Handle: longint): longint; assembler;
  183. asm
  184. mov ax, 5700h
  185. mov ebx, Handle
  186. call syscall
  187. mov eax, -1
  188. jc @FGetDateEnd
  189. mov ax, dx
  190. shld eax, ecx, 16
  191. @FGetDateEnd:
  192. end;
  193. function FileSetDate (Handle, Age: longint): longint;
  194. begin
  195. if os_mode = osOS2 then
  196. begin
  197. {TODO: !!! Must be done differently for OS/2 !!!}
  198. end
  199. else
  200. asm
  201. mov ax, 5701h
  202. mov ebx, Handle
  203. mov cx, word ptr [Age]
  204. mov dx, word ptr [Age + 2]
  205. call syscall
  206. jnc @FSetDateEnd
  207. mov eax, -1
  208. @FSetDateEnd:
  209. mov [ebp - 4], eax
  210. end;
  211. end;
  212. function FileGetAttr (const FileName: string): longint;
  213. {$IFOPT H+}
  214. assembler;
  215. {$ELSE}
  216. var FN: string;
  217. begin
  218. FN := FileName + #0;
  219. {$ENDIF}
  220. asm
  221. mov ax, 4300h
  222. {$IFOPT H+}
  223. mov edx, FileName
  224. {$ELSE}
  225. lea edx, FN
  226. inc edx
  227. {$ENDIF}
  228. call syscall
  229. jnc @FGetAttrEnd
  230. mov eax, -1
  231. @FGetAttrEnd:
  232. {$IFOPT H-}
  233. mov [ebp - 4], eax
  234. end;
  235. {$ENDIF}
  236. end;
  237. function FileSetAttr (const Filename: string; Attr: longint): longint;
  238. {$IFOPT H+}
  239. assembler;
  240. {$ELSE}
  241. var FN: string;
  242. begin
  243. FN := FileName + #0;
  244. {$ENDIF}
  245. asm
  246. mov ax, 4301h
  247. mov ecx, Attr
  248. {$IFOPT H+}
  249. mov edx, FileName
  250. {$ELSE}
  251. lea edx, FN
  252. inc edx
  253. {$ENDIF}
  254. call syscall
  255. mov eax, 0
  256. jnc @FSetAttrEnd
  257. mov eax, -1
  258. @FSetAttrEnd:
  259. {$IFOPT H-}
  260. mov [ebp - 4], eax
  261. end;
  262. {$ENDIF}
  263. end;
  264. function DeleteFile (const FileName: string): boolean;
  265. {$IFOPT H+}
  266. assembler;
  267. {$ELSE}
  268. var FN: string;
  269. begin
  270. FN := FileName + #0;
  271. {$ENDIF}
  272. asm
  273. mov ax, 4100h
  274. {$IFOPT H+}
  275. mov edx, FileName
  276. {$ELSE}
  277. lea edx, FN
  278. inc edx
  279. {$ENDIF}
  280. call syscall
  281. mov eax, 0
  282. jc @FDeleteEnd
  283. inc eax
  284. @FDeleteEnd:
  285. {$IFOPT H-}
  286. mov [ebp - 4], eax
  287. end;
  288. {$ENDIF}
  289. end;
  290. function RenameFile (const OldName, NewName: string): boolean;
  291. {$IFOPT H+}
  292. assembler;
  293. {$ELSE}
  294. var FN1, FN2: string;
  295. begin
  296. FN1 := OldName + #0;
  297. FN2 := NewName + #0;
  298. {$ENDIF}
  299. asm
  300. mov ax, 5600h
  301. {$IFOPT H+}
  302. mov edx, OldName
  303. mov edi, NewName
  304. {$ELSE}
  305. lea edx, FN1
  306. inc edx
  307. lea edi, FN2
  308. inc edi
  309. {$ENDIF}
  310. call syscall
  311. mov eax, 0
  312. jc @FRenameEnd
  313. inc eax
  314. @FRenameEnd:
  315. {$IFOPT H-}
  316. mov [ebp - 4], eax
  317. end;
  318. {$ENDIF}
  319. end;
  320. function FileSearch (const Name, DirList: string): string;
  321. begin
  322. Result := Dos.FSearch (Name, DirList);
  323. end;
  324. Procedure GetLocalTime(var SystemTime: TSystemTime);
  325. begin
  326. //!! Needs implementing
  327. end ;
  328. Procedure InitAnsi;
  329. (* __nls_ctype ??? *)
  330. begin
  331. //!! Needs implementing
  332. end;
  333. Procedure InitInternational;
  334. begin
  335. InitAnsi;
  336. end;
  337. {
  338. $Log$
  339. Revision 1.12 2000-06-05 18:57:38 hajny
  340. * handle number check added to FileClose
  341. Revision 1.11 2000/06/04 15:04:22 hajny
  342. * another bunch of corrections
  343. Revision 1.10 2000/06/04 14:22:02 hajny
  344. * minor corrections
  345. Revision 1.9 2000/06/01 18:36:50 hajny
  346. * FileGetDate added
  347. Revision 1.8 2000/05/29 17:59:58 hajny
  348. * FindClose implemented
  349. Revision 1.7 2000/05/28 18:22:58 hajny
  350. + implementation started
  351. Revision 1.6 2000/02/17 22:16:05 sg
  352. * Changed the second argument of FileWrite from "var buffer" to
  353. "const buffer", like in Delphi.
  354. Revision 1.5 2000/02/09 16:59:33 peter
  355. * truncated log
  356. Revision 1.4 2000/01/07 16:41:47 daniel
  357. * copyright 2000
  358. Revision 1.3 1999/11/08 22:45:55 peter
  359. * updated
  360. }