filutilh.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 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. Type
  12. // Some operating systems need extra find data.
  13. {$if defined(Win32) or defined(WinCE) or defined(Win64)}
  14. TUnicodeSearchFindData = TWin32FindDataW;
  15. {$ENDIF}
  16. {$ifdef netware_clib}
  17. TUnicodeSearchFindData = TNetwareFindData;
  18. {$endif}
  19. {$ifdef netware_libc}
  20. TUnicodeSearchFindData = TNetwareLibcFindData;
  21. {$endif}
  22. {$ifdef MacOS}
  23. TUnicodeSearchFindData = TMacOSFindData;
  24. {$endif}
  25. {$ifdef nativent}
  26. TUnicodeSearchFindData = TNativeNTFindData;
  27. {$endif}
  28. // USEFINDDATA is only defined here.
  29. {$if defined(Win32) or defined(Win64)}
  30. {$DEFINE USEFINDDATA}
  31. TRawByteSearchFindData = TWin32FindDataA;
  32. {$ENDIF}
  33. {$if defined(Wince)}
  34. {$DEFINE USEFINDDATA}
  35. TRawByteSearchFindData = TWin32FindDataW;
  36. {$ENDIF}
  37. {$ifdef netware_clib}
  38. TRawByteSearchFindData = TNetwareFindData;
  39. {$DEFINE USEFINDDATA}
  40. {$endif}
  41. {$ifdef netware_libc}
  42. TRawByteSearchFindData = TNetwareLibcFindData;
  43. {$DEFINE USEFINDDATA}
  44. {$endif}
  45. {$ifdef MacOS}
  46. TRawByteSearchFindData = TMacOSFindData;
  47. {$DEFINE USEFINDDATA}
  48. {$endif}
  49. {$ifdef nativent}
  50. TRawByteSearchFindData = TNativeNTFindData;
  51. {$DEFINE USEFINDDATA}
  52. {$endif}
  53. // The actual unicode search record
  54. TUnicodeSearchRec = Record
  55. Time : Longint;
  56. Size : Int64;
  57. Attr : Longint;
  58. Name : UnicodeString;
  59. ExcludeAttr : Longint;
  60. {$ifdef unix}
  61. FindHandle : Pointer;
  62. Mode : TMode;
  63. {$else unix}
  64. FindHandle : THandle;
  65. {$endif unix}
  66. {$IFDEF USEFINDDATA}
  67. FindData : TUnicodeSearchFindData;
  68. {$ENDIF}
  69. end;
  70. TRawbyteSearchRec = Record
  71. Time : Longint;
  72. Size : Int64;
  73. Attr : Longint;
  74. Name : RawByteString;
  75. ExcludeAttr : Longint;
  76. {$ifdef unix}
  77. FindHandle : Pointer;
  78. Mode : TMode;
  79. {$else unix}
  80. FindHandle : THandle;
  81. {$endif unix}
  82. {$IFDEF USEFINDDATA}
  83. FindData : TRawByteSearchFindData;
  84. {$ENDIF}
  85. end;
  86. {$IFDEF FPC_UNICODE_RTL}
  87. TSearchRec = TUnicodeSearchRec;
  88. {$ELSE}
  89. TSearchRec = TRawbyteSearchRec;
  90. {$ENDIF}
  91. Const
  92. { File attributes }
  93. faReadOnly = $00000001;
  94. faHidden = $00000002;
  95. faSysFile = $00000004;
  96. faVolumeId = $00000008;
  97. faDirectory = $00000010;
  98. faArchive = $00000020;
  99. faSymLink = $00000040;
  100. faAnyFile = $0000003f;
  101. { File open modes }
  102. fmOpenRead = $0000;
  103. fmOpenWrite = $0001;
  104. fmOpenReadWrite = $0002;
  105. { Share modes}
  106. fmShareCompat = $0000;
  107. fmShareExclusive = $0010;
  108. fmShareDenyWrite = $0020;
  109. fmShareDenyRead = $0030;
  110. fmShareDenyNone = $0040;
  111. { File seek origins }
  112. fsFromBeginning = 0;
  113. fsFromCurrent = 1;
  114. fsFromEnd = 2;
  115. { File errors }
  116. feInvalidHandle : THandle = THandle(-1); //return value on FileOpen error
  117. Type
  118. TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
  119. TFileSearchOptions = set of TFileSearchOption;
  120. Function FileOpen (Const FileName : unicodestring; Mode : Integer) : THandle;
  121. Function FileCreate (Const FileName : UnicodeString) : THandle;
  122. Function FileCreate (Const FileName : UnicodeString; Rights : Integer) : THandle;
  123. Function FileCreate (Const FileName : UnicodeString; ShareMode : Integer; Rights : Integer) : THandle;
  124. {$IFNDEF FPUNONE}
  125. Function FileAge (Const FileName : UnicodeString): Longint;
  126. {$ENDIF}
  127. Function FileExists (Const FileName : UnicodeString) : Boolean;
  128. Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
  129. Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
  130. Function FileGetAttr (Const FileName : UnicodeString) : Longint;
  131. Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
  132. Function DeleteFile (Const FileName : UnicodeString) : Boolean;
  133. Function RenameFile (Const OldName, NewName : UnicodeString) : Boolean;
  134. Function FindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TUnicodeSearchRec) : Longint;
  135. Function FindNext (Var Rslt : TUnicodeSearchRec) : Longint;
  136. Procedure FindClose (Var F : TUnicodeSearchrec);
  137. Function FileSearch (Const Name, DirList : UnicodeString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : UnicodeString;
  138. Function FileSearch (Const Name, DirList : UnicodeString; ImplicitCurrentDir : Boolean) : UnicodeString;
  139. Function ExeSearch (Const Name : UnicodeString; Const DirList : UnicodeString = '') : UnicodeString;
  140. Function FileIsReadOnly(const FileName : UnicodeString): Boolean;
  141. function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  142. Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
  143. Function FileCreate (Const FileName : RawByteString) : THandle;
  144. Function FileCreate (Const FileName : RawByteString; Rights : Integer) : THandle;
  145. Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights : Integer) : THandle;
  146. Function FileExists (Const FileName : RawByteString) : Boolean;
  147. Function DirectoryExists (Const Directory : RawByteString) : Boolean;
  148. Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
  149. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  150. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  151. Function DeleteFile (Const FileName : RawByteString) : Boolean;
  152. Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
  153. Function FindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TRawByteSearchRec) : Longint;
  154. Function FileSearch (Const Name, DirList : RawByteString; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : RawByteString;
  155. Function FileSearch (Const Name, DirList : RawByteString; ImplicitCurrentDir : Boolean) : RawByteString;
  156. Function ExeSearch (Const Name : RawByteString; Const DirList : RawByteString = '') : RawByteString;
  157. Function FileIsReadOnly(const FileName: RawByteString): Boolean;
  158. function FileAge(const FileName: RawByteString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
  159. {$ifndef FPUNONE}
  160. Function FileAge (Const FileName : RawByteString): Longint;
  161. {$endif}
  162. Function FileRead (Handle : THandle; out Buffer; Count : longint) : Longint;
  163. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  164. Function FileSeek (Handle : THandle; FOffset, Origin: Longint) : Longint;
  165. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  166. Procedure FileClose (Handle : THandle);
  167. Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
  168. Function FindNext (Var Rslt : TRawByteSearchRec) : Longint;
  169. Procedure FindClose (Var F : TRawByteSearchrec);
  170. Function FileGetDate (Handle : THandle) : Longint;
  171. Function FileSetDate (Handle : THandle;Age : Longint) : Longint;
  172. Function GetFileHandle(var f : File):THandle;
  173. Function GetFileHandle(var f : Text):THandle;