filutil.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2012 by the Free Pascal development team
  4. File utility calls
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifndef SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  12. Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
  13. begin
  14. Result:=FileOpen(ToSingleByteFileSystemEncodedFileName(FileName),Mode);
  15. end;
  16. Function FileCreate (Const FileName : UnicodeString) : THandle;
  17. begin
  18. Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName));
  19. end;
  20. Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
  21. begin
  22. Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName),Rights);
  23. end;
  24. Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
  25. begin
  26. Result:=FileCreate(ToSingleByteFileSystemEncodedFileName(FileName),ShareMode,Rights);
  27. end;
  28. Function FileAge (Const FileName : UnicodeString): Longint;
  29. begin
  30. Result:=FileAge(ToSingleByteFileSystemEncodedFileName(FileName));
  31. end;
  32. Function FileExists (Const FileName : UnicodeString; FollowLink : Boolean) : Boolean;
  33. begin
  34. Result:=FileExists(ToSingleByteFileSystemEncodedFileName(FileName), FollowLink);
  35. end;
  36. Function DirectoryExists (Const Directory : UnicodeString; FollowLink : Boolean) : Boolean;
  37. begin
  38. Result:=DirectoryExists(ToSingleByteFileSystemEncodedFileName(Directory), FollowLink);
  39. end;
  40. Function FileGetAttr (Const FileName : UnicodeString) : Longint;
  41. begin
  42. Result:=FileGetAttr(ToSingleByteFileSystemEncodedFileName(FileName));
  43. end;
  44. Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
  45. begin
  46. Result:=FileSetAttr(ToSingleByteFileSystemEncodedFileName(FileName),Attr);
  47. end;
  48. Function DeleteFile (Const FileName : UnicodeString) : Boolean;
  49. begin
  50. Result:=DeleteFile(ToSingleByteFileSystemEncodedFileName(FileName));
  51. end;
  52. Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
  53. begin
  54. Result:=RenameFile(ToSingleByteFileSystemEncodedFileName(OldName),
  55. ToSingleByteFileSystemEncodedFileName(NewName));
  56. end;
  57. {$ifdef OS_FILEISREADONLY}
  58. Function FileIsReadOnly(const FileName: UnicodeString): Boolean;
  59. begin
  60. Result:=FileIsReadOnly(ToSingleByteFileSystemEncodedFileName(FileName));
  61. end;
  62. {$endif}
  63. {$ifdef OS_FILESETDATEBYNAME}
  64. Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
  65. begin
  66. Result:=FileSetDate(ToSingleByteFileSystemEncodedFileName(FileName),Age);
  67. end;
  68. {$endif}
  69. function FileAge(const FileName: RawByteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  70. Var
  71. Info : TRawByteSearchRec;
  72. A : Integer;
  73. begin
  74. for A:=1 to Length(FileName) do
  75. if CharInSet(FileName[A],['?','*']) then
  76. Exit(False);
  77. A:=0;
  78. if not FollowLink then
  79. A:=A or faSymLink;
  80. Result:=FindFirst(FileName,A,Info)=0;
  81. if Result then
  82. begin
  83. FileDateTime:=FileDatetoDateTime(Info.Time);
  84. FindClose(Info);
  85. end;
  86. end;
  87. Function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  88. begin
  89. Result:=FileAge(ToSingleByteFileSystemEncodedFileName(FileName),FileDateTime,FollowLink);
  90. end;
  91. function FileGetSymLinkTarget(const FileName: UnicodeString; out SymLinkRec: TUnicodeSymLinkRec): Boolean;
  92. var
  93. sr: TRawbyteSymLinkRec;
  94. begin
  95. Result := FileGetSymLinkTarget(ToSingleByteFileSystemEncodedFileName(FileName), sr);
  96. if Result then
  97. begin
  98. SymLinkRec.TargetName := UnicodeString(sr.TargetName);
  99. SymLinkRec.Size := sr.Size;
  100. SymLinkRec.Attr := sr.Attr;
  101. {$ifdef SYMLINKREC_USEFINDDATA}
  102. SymLinkRec.FindData := sr.FindData;
  103. {$endif}
  104. {$ifdef unix}
  105. SymLinkRec.Mode := sr.Mode;
  106. {$endif}
  107. end;
  108. end;
  109. Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
  110. begin
  111. Result:=UnicodeString(FileSearch(ToSingleByteFileSystemEncodedFileName(Name),
  112. ToSingleByteFileSystemEncodedFileName(Dirlist),Options));
  113. end;
  114. Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
  115. begin
  116. Result:=UnicodeString(FileSearch(ToSingleByteFileSystemEncodedFileName(Name),
  117. ToSingleByteFileSystemEncodedFileName(DirList),ImplicitCurrentDir));
  118. end;
  119. Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
  120. begin
  121. Result:=UnicodeString(ExeSearch(ToSingleByteFileSystemEncodedFileName(Name),
  122. ToSingleByteFileSystemEncodedFileName(Dirlist)));
  123. end;
  124. Function FileSearch (Const Name, DirList : RawByteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
  125. Var
  126. I : longint;
  127. Temp : RawByteString;
  128. begin
  129. Result:=Name;
  130. temp:=SetDirSeparators(DirList);
  131. // Start with checking the file in the current directory
  132. If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
  133. exit;
  134. while True do begin
  135. If Temp = '' then
  136. Break; // No more directories to search - fail
  137. I:=pos(PathSeparator,Temp);
  138. If I<>0 then
  139. begin
  140. Result:=Copy (Temp,1,i-1);
  141. system.Delete(Temp,1,I);
  142. end
  143. else
  144. begin
  145. Result:=Temp;
  146. Temp:='';
  147. end;
  148. If Result<>'' then
  149. begin
  150. If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
  151. Result:=Copy(Result,2,Length(Result)-2);
  152. if (Result<>'') then
  153. Result:=IncludeTrailingPathDelimiter(Result)+name;
  154. end;
  155. If (Result <> '') and FileExists(Result) Then
  156. exit;
  157. end;
  158. Result:='';
  159. end;
  160. Function FileSearch (Const Name, DirList : RawByteString; ImplicitCurrentDir : Boolean) : RawByteString;
  161. begin
  162. if ImplicitCurrentDir then
  163. Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
  164. else
  165. Result:=FileSearch(Name,DirList,[]);
  166. end;
  167. Function ExeSearch (Const Name : RawByteString; Const DirList : RawByteString ='' ) : RawByteString;
  168. Var
  169. D : RawByteString;
  170. O : TFileSearchOptions;
  171. begin
  172. D:=DirList;
  173. if (D='') then
  174. D:=GetEnvironmentVariable('PATH');
  175. {$ifdef unix}
  176. O:=[];
  177. {$else unix}
  178. O:=[sfoImplicitCurrentDir,sfoStripQuotes];
  179. {$endif unix}
  180. Result := FileSearch(Name, D, O);
  181. end;
  182. {$endif}
  183. {$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  184. Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
  185. begin
  186. Result:=FileOpen(UnicodeString(FileName),Mode);
  187. end;
  188. Function FileCreate (Const FileName : RawByteString) : THandle;
  189. begin
  190. Result:=FileCreate(UnicodeString(FileName));
  191. end;
  192. Function FileCreate (Const FileName : RawByteString; Rights : Integer) : THandle;
  193. begin
  194. Result:=FileCreate(UnicodeString(FileName),Rights);
  195. end;
  196. Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
  197. begin
  198. Result:=FileCreate(UnicodeString(FileName),ShareMode,Rights);
  199. end;
  200. Function FileAge (Const FileName : RawByteString): Longint;
  201. begin
  202. Result:=FileAge(UnicodeString(FileName));
  203. end;
  204. Function FileExists (Const FileName : RawByteString; FollowLink : Boolean) : Boolean;
  205. begin
  206. Result:=FileExists(UnicodeString(FileName), FollowLink);
  207. end;
  208. Function DirectoryExists (Const Directory : RawByteString; FollowLink : Boolean) : Boolean;
  209. begin
  210. Result:=DirectoryExists(UnicodeString(Directory), FollowLink);
  211. end;
  212. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  213. begin
  214. Result:=FileGetAttr(unicodestring(FileName));
  215. end;
  216. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  217. begin
  218. Result:=FileSetAttr(unicodestring(FileName),Attr);
  219. end;
  220. Function DeleteFile (Const FileName : RawByteString) : Boolean;
  221. begin
  222. Result:=DeleteFile(UnicodeString(FileName));
  223. end;
  224. Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
  225. begin
  226. Result:=RenameFile(UnicodeString(OldName),UnicodeString(NewName));
  227. end;
  228. {$ifdef OS_FILEISREADONLY}
  229. Function FileIsReadOnly(const FileName: RawByteString): Boolean;
  230. begin
  231. Result:=FileIsReadOnly(UnicodeString(FileName));
  232. end;
  233. {$endif}
  234. {$ifdef OS_FILESETDATEBYNAME}
  235. Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
  236. begin
  237. Result:=FileSetDate(UnicodeString(FileName),Age);
  238. end;
  239. {$endif}
  240. function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  241. Var
  242. Info : TUnicodeSearchRec;
  243. A : Integer;
  244. begin
  245. for A:=1 to Length(FileName) do
  246. if CharInSet(FileName[A],['?','*']) then
  247. Exit(False);
  248. A:=0;
  249. if not FollowLink then
  250. A:=A or faSymLink;
  251. Result:=FindFirst(FileName,A,Info)=0;
  252. if Result then
  253. begin
  254. FileDateTime:=FileDatetoDateTime(Info.Time);
  255. FindClose(Info);
  256. end;
  257. end;
  258. Function FileAge(const FileName: RawbyteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  259. begin
  260. Result:=FileAge(UnicodeString(FileName),FileDateTime,FollowLink);
  261. end;
  262. function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
  263. var
  264. sr: TUnicodeSymLinkRec;
  265. begin
  266. Result := FileGetSymLinkTarget(UnicodeString(FileName), sr);
  267. if Result then
  268. begin
  269. SymLinkRec.TargetName := ToSingleByteFileSystemEncodedFileName(sr.TargetName);
  270. SymLinkRec.Size := sr.Size;
  271. SymLinkRec.Attr := sr.Attr;
  272. {$ifdef SYMLINKREC_USEFINDDATA}
  273. SymLinkRec.FindData := sr.FindData;
  274. {$endif}
  275. {$ifdef unix}
  276. SymLinkRec.Mode := sr.Mode;
  277. {$endif}
  278. end;
  279. end;
  280. Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
  281. Var
  282. I : longint;
  283. Temp : UnicodeString;
  284. begin
  285. Result:=Name;
  286. temp:=SetDirSeparators(DirList);
  287. // Start with checking the file in the current directory
  288. If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
  289. exit;
  290. while True do begin
  291. If Temp = '' then
  292. Break; // No more directories to search - fail
  293. I:=pos(PathSeparator,Temp);
  294. If I<>0 then
  295. begin
  296. Result:=Copy (Temp,1,i-1);
  297. system.Delete(Temp,1,I);
  298. end
  299. else
  300. begin
  301. Result:=Temp;
  302. Temp:='';
  303. end;
  304. If Result<>'' then
  305. begin
  306. If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
  307. Result:=Copy(Result,2,Length(Result)-2);
  308. if (Result<>'') then
  309. Result:=IncludeTrailingPathDelimiter(Result)+name;
  310. end;
  311. If (Result <> '') and FileExists(Result) Then
  312. exit;
  313. end;
  314. Result:='';
  315. end;
  316. Function FileSearch (Const Name, DirList : RawbyteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
  317. begin
  318. Result:=ToSingleByteFileSystemEncodedFileName(FileSearch(unicodestring(name),unicodestring(dirlist),options));
  319. end;
  320. Function FileSearch (Const Name, DirList : RawbyteString; ImplicitCurrentDir : Boolean) : RawByteString;
  321. begin
  322. Result:=ToSingleByteFileSystemEncodedFileName(FileSearch(unicodestring(name),unicodestring(dirlist),ImplicitCurrentDir));
  323. end;
  324. Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
  325. begin
  326. if ImplicitCurrentDir then
  327. Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
  328. else
  329. Result:=FileSearch(Name,DirList,[]);
  330. end;
  331. Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString ='' ) : UnicodeString;
  332. Var
  333. D : UnicodeString;
  334. O : TFileSearchOptions;
  335. begin
  336. D:=DirList;
  337. if (D='') then
  338. D:=UnicodeString(GetEnvironmentVariable('PATH'));
  339. {$ifdef unix}
  340. O:=[];
  341. {$else unix}
  342. O:=[sfoImplicitCurrentDir,sfoStripQuotes];
  343. {$endif unix}
  344. Result := FileSearch(Name, D, O);
  345. end;
  346. Function ExeSearch (Const Name : RawbyteString; Const DirList : RawbyteString ='' ) : RawByteString;
  347. begin
  348. Result:=ToSingleByteFileSystemEncodedFileName(ExeSearch(unicodestring(name),unicodestring(dirlist)));
  349. end;
  350. {$endif}
  351. function FileGetSymLinkTarget(const FileName: UnicodeString; out TargetName: UnicodeString): Boolean;
  352. var
  353. sr: TUnicodeSymLinkRec;
  354. begin
  355. Result := FileGetSymLinkTarget(FileName, sr);
  356. if Result then
  357. TargetName := sr.TargetName;
  358. end;
  359. function FileGetSymLinkTarget(const FileName: RawByteString; out TargetName: RawByteString): Boolean;
  360. var
  361. sr: TRawbyteSymLinkRec;
  362. begin
  363. Result := FileGetSymLinkTarget(FileName, sr);
  364. if Result then
  365. TargetName := sr.TargetName;
  366. end;
  367. Function GetFileHandle(var f : File):THandle;
  368. begin
  369. Result:=filerec(f).handle;
  370. end;
  371. Function GetFileHandle(var f : Text):THandle;
  372. begin
  373. Result:=textrec(f).handle;
  374. end;
  375. { FindFirst/FindNext. In order to avoid having to duplicate most code in th
  376. OS-specific implementations, we let those implementations fill in all
  377. fields of TRawbyte/UnicodeSearchRec, except for the name. That field is
  378. filled in by the OS-indepedent wrappers, which also takes care of setting
  379. the appropriate code page if applicable.
  380. }
  381. type
  382. TAbstractSearchRec = Record
  383. Time : Longint;
  384. Size : Int64;
  385. Attr : Longint;
  386. { this will be assigned by the generic code; it is actually either a
  387. rawbytestring or unicodestring; keep it a reference-counted type
  388. so that -gt doesn't overwrite it, the field name should be
  389. indication enough that you should not touch it }
  390. Name_do_not_touch : RawByteString;
  391. ExcludeAttr : Longint;
  392. FindHandle : {$ifdef FINDHANDLE_IS_POINTER}Pointer{$else}THandle{$endif};
  393. {$ifdef unix}
  394. Mode : TMode;
  395. {$endif unix}
  396. {$ifdef SEARCHREC_USEFINDDATA}
  397. FindData : TFindData;
  398. {$endif}
  399. end;
  400. {$ifdef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  401. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint; forward;
  402. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint; forward;
  403. {$endif SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  404. {$ifdef SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  405. Function InternalFindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: UnicodeString) : Longint; forward;
  406. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : UnicodeString) : Longint; forward;
  407. {$endif SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  408. procedure InternalFindClose(var Handle: {$ifdef FINDHANDLE_IS_POINTER}Pointer{$else}THandle{$endif}{$ifdef SEARCHREC_USEFINDDATA};var FindData: TFindData{$endif}); forward;
  409. {$ifndef SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  410. Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
  411. var
  412. Name: UnicodeString;
  413. begin
  414. Result:=InternalFindFirst(UnicodeString(Path),Attr,TAbstractSearchRec(Rslt),Name);
  415. if Result=0 then
  416. widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Name),Rslt.Name,DefaultRTLFileSystemCodePage,length(Name));
  417. end;
  418. Function FindNext (Var Rslt : TRawByteSearchRec) : Longint;
  419. var
  420. Name: UnicodeString;
  421. begin
  422. Result:=InternalFindNext(TAbstractSearchRec(Rslt),Name);
  423. if Result=0 then
  424. widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Name),Rslt.Name,DefaultRTLFileSystemCodePage,length(Name));
  425. end;
  426. {$else not SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  427. Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
  428. begin
  429. Result:=InternalFindFirst(Path,Attr,TAbstractSearchRec(Rslt),Rslt.Name);
  430. if Result=0 then
  431. SetCodePage(Rslt.Name,DefaultRTLFileSystemCodePage);
  432. end;
  433. Function FindNext (Var Rslt : TRawByteSearchRec) : Longint;
  434. begin
  435. Result:=InternalFindNext(TAbstractSearchRec(Rslt),Rslt.Name);
  436. if Result=0 then
  437. SetCodePage(Rslt.Name,DefaultRTLFileSystemCodePage);
  438. end;
  439. {$endif not SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  440. {$ifndef SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  441. Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
  442. var
  443. Name: RawByteString;
  444. begin
  445. Result:=InternalFindFirst(ToSingleByteFileSystemEncodedFileName(Path),Attr,TAbstractSearchRec(Rslt),Name);
  446. if Result=0 then
  447. Rslt.Name:=UnicodeString(Name);
  448. end;
  449. Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
  450. var
  451. Name: RawByteString;
  452. begin
  453. Result:=InternalFindNext(TAbstractSearchRec(Rslt),Name);
  454. if Result=0 then
  455. Rslt.Name:=UnicodeString(Name);
  456. end;
  457. {$else not SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  458. Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
  459. begin
  460. Result:=InternalFindFirst(Path,Attr,TAbstractSearchRec(Rslt),Rslt.Name);
  461. end;
  462. Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
  463. begin
  464. Result:=InternalFindNext(TAbstractSearchRec(Rslt),Rslt.Name);
  465. end;
  466. {$endif not SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
  467. Procedure FindClose(Var f: TRawByteSearchRec);
  468. begin
  469. InternalFindClose(f.FindHandle{$ifdef SEARCHREC_USEFINDDATA},f.FindData{$endif});
  470. end;
  471. Procedure FindClose(Var f: TUnicodeSearchRec);
  472. begin
  473. InternalFindClose(f.FindHandle{$ifdef SEARCHREC_USEFINDDATA},f.FindData{$endif});
  474. end;
  475. {$if defined(windows) and not defined(win16)}
  476. function FindDataTimeToDateTime(constref aFileTime: FILETIME; out aResult: TDateTime): Boolean;
  477. var
  478. st, lt: TSystemTime;
  479. begin
  480. Result := FileTimeToSystemTime(aFileTime, st);
  481. if Result then begin
  482. {$ifndef wince}
  483. if SystemTimeToTzSpecificLocalTime(Nil, st, lt) then
  484. aResult := SystemTimeToDateTime(lt)
  485. else
  486. {$endif}
  487. aResult := SystemTimeToDateTime(st);
  488. end;
  489. end;
  490. {$endif}
  491. { TUnicodeSearchRec }
  492. function TUnicodeSearchRec.GetTimeStamp: TDateTime;
  493. begin
  494. {$if declared(FindDataTimeToDateTime)}
  495. if not FindDataTimeToDateTime(FindData.ftLastWriteTime, Result) then
  496. {$else}
  497. Result := FileDateToDateTime(Time);
  498. {$endif}
  499. end;
  500. { TRawbyteSearchRec }
  501. function TRawbyteSearchRec.GetTimeStamp: TDateTime;
  502. begin
  503. {$if declared(FindDataTimeToDateTime)}
  504. if not FindDataTimeToDateTime(FindData.ftLastWriteTime, Result) then
  505. {$else}
  506. Result := FileDateToDateTime(Time);
  507. {$endif}
  508. end;
  509. { TUnicodeSymLinkRec }
  510. function TUnicodeSymLinkRec.GetTimeStamp: TDateTime;
  511. begin
  512. {$if declared(FindDataTimeToDateTime)}
  513. if not FindDataTimeToDateTime(FindData.ftLastWriteTime, Result) then
  514. {$else}
  515. Result := 0;
  516. {$endif}
  517. end;
  518. { TRawbyteSymLinkRec }
  519. function TRawbyteSymLinkRec.GetTimeStamp: TDateTime;
  520. begin
  521. {$if declared(FindDataTimeToDateTime)}
  522. if not FindDataTimeToDateTime(FindData.ftLastWriteTime, Result) then
  523. {$else}
  524. Result := 0;
  525. {$endif}
  526. end;
  527. {$ifndef SYSUTILS_HAS_FILEFLUSH_IMPL}
  528. function FileFlush(Handle: THandle): Boolean;
  529. begin
  530. Result:= False;
  531. end;
  532. {$endif}