filutil.inc 6.5 KB

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