apr_file_info.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_file_info.h
  18. * @brief APR File Information
  19. }
  20. {#include "apr.h"
  21. #include "apr_user.h"
  22. #include "apr_pools.h"
  23. #include "apr_tables.h"
  24. #include "apr_time.h"
  25. #include "apr_errno.h"
  26. #if APR_HAVE_SYS_UIO_H
  27. #include <sys/uio.h>
  28. #endif}
  29. {
  30. * @defgroup apr_file_info File Information
  31. * @ingroup APR
  32. }
  33. { Many applications use the type member to determine the
  34. * existance of a file or initialization of the file info,
  35. * so the APR_NOFILE value must be distinct from APR_UNKFILE.
  36. }
  37. { apr_filetype_e values for the filetype member of the
  38. * apr_file_info_t structure
  39. * @warning: Not all of the filetypes below can be determined.
  40. * For example, a given platform might not correctly report
  41. * a socket descriptor as APR_SOCK if that type isn't
  42. * well-identified on that platform. In such cases where
  43. * a filetype exists but cannot be described by the recognized
  44. * flags below, the filetype will be APR_UNKFILE. If the
  45. * filetype member is not determined, the type will be APR_NOFILE.
  46. }
  47. type
  48. apr_filetype_e = (
  49. APR_NOFILE = 0, {< no file type determined }
  50. APR_REG, {< a regular file }
  51. APR_DIR, {< a directory }
  52. APR_CHR, {< a character device }
  53. APR_BLK, {< a block device }
  54. APR_PIPE, {< a FIFO / pipe }
  55. APR_LNK, {< a symbolic link }
  56. APR_SOCK, {< a [unix domain] socket }
  57. APR_UNKFILE = 127 {< a file of some other unknown type }
  58. );
  59. {
  60. * @defgroup apr_file_permissions File Permissions flags
  61. * @
  62. }
  63. const
  64. APR_FPROT_USETID = $8000; {< Set user id }
  65. APR_FPROT_UREAD = $0400; {< Read by user }
  66. APR_FPROT_UWRITE = $0200; {< Write by user }
  67. APR_FPROT_UEXECUTE = $0100; {< Execute by user }
  68. APR_FPROT_GSETID = $4000; {< Set group id }
  69. APR_FPROT_GREAD = $0040; {< Read by group }
  70. APR_FPROT_GWRITE = $0020; {< Write by group }
  71. APR_FPROT_GEXECUTE = $0010; {< Execute by group }
  72. APR_FPROT_WSTICKY = $2000; {< Sticky bit }
  73. APR_FPROT_WREAD = $0004; {< Read by others }
  74. APR_FPROT_WWRITE = $0002; {< Write by others }
  75. APR_FPROT_WEXECUTE = $0001; {< Execute by others }
  76. APR_FPROT_OS_DEFAULT = $0FFF; {< use OS's default permissions }
  77. { additional permission flags for apr_file_copy and apr_file_append }
  78. APR_FPROT_FILE_SOURCE_PERMS = $1000; {< Copy source file's permissions }
  79. { backcompat }
  80. APR_USETID = APR_FPROT_USETID; {< @deprecated @see APR_FPROT_USETID }
  81. APR_UREAD = APR_FPROT_UREAD; {< @deprecated @see APR_FPROT_UREAD }
  82. APR_UWRITE = APR_FPROT_UWRITE; {< @deprecated @see APR_FPROT_UWRITE }
  83. APR_UEXECUTE = APR_FPROT_UEXECUTE; {< @deprecated @see APR_FPROT_UEXECUTE }
  84. APR_GSETID = APR_FPROT_GSETID; {< @deprecated @see APR_FPROT_GSETID }
  85. APR_GREAD = APR_FPROT_GREAD; {< @deprecated @see APR_FPROT_GREAD }
  86. APR_GWRITE = APR_FPROT_GWRITE; {< @deprecated @see APR_FPROT_GWRITE }
  87. APR_GEXECUTE = APR_FPROT_GEXECUTE; {< @deprecated @see APR_FPROT_GEXECUTE }
  88. APR_WSTICKY = APR_FPROT_WSTICKY; {< @deprecated @see APR_FPROT_WSTICKY }
  89. APR_WREAD = APR_FPROT_WREAD; {< @deprecated @see APR_FPROT_WREAD }
  90. APR_WWRITE = APR_FPROT_WWRITE; {< @deprecated @see APR_FPROT_WWRITE }
  91. APR_WEXECUTE = APR_FPROT_WEXECUTE; {< @deprecated @see APR_FPROT_WEXECUTE }
  92. APR_OS_DEFAULT= APR_FPROT_OS_DEFAULT; {< @deprecated @see APR_FPROT_OS_DEFAULT }
  93. APR_FILE_SOURCE_PERMS = APR_FPROT_FILE_SOURCE_PERMS; {< @deprecated @see APR_FPROT_FILE_SOURCE_PERMS }
  94. {
  95. * Structure for referencing directories.
  96. }
  97. type
  98. apr_dir_t = record end;
  99. Papr_dir_t = ^apr_dir_t;
  100. PPapr_dir_t = ^Papr_dir_t;
  101. {
  102. * Structure for determining file permissions.
  103. }
  104. apr_fileperms_t = apr_int32_t;
  105. {$if defined(WINDOWS) or defined(NETWARE)}
  106. {
  107. * Structure for determining the inode of the file.
  108. }
  109. apr_ino_t = apr_uint64_t;
  110. {
  111. * Structure for determining the device the file is on.
  112. }
  113. apr_dev_t = apr_uint32_t;
  114. {$else}
  115. { The inode of the file. }
  116. apr_ino_t = ino_t;
  117. {
  118. * Structure for determining the device the file is on.
  119. }
  120. apr_dev_t = dev_t;
  121. {$endif}
  122. {
  123. * @defgroup apr_file_stat Stat Functions
  124. * @
  125. }
  126. const
  127. APR_FINFO_LINK = $00000001; {< Stat the link not the file itself if it is a link }
  128. APR_FINFO_MTIME = $00000010; {< Modification Time }
  129. APR_FINFO_CTIME = $00000020; {< Creation Time }
  130. APR_FINFO_ATIME = $00000040; {< Access Time }
  131. APR_FINFO_SIZE = $00000100; {< Size of the file }
  132. APR_FINFO_CSIZE = $00000200; {< Storage size consumed by the file }
  133. APR_FINFO_DEV = $00001000; {< Device }
  134. APR_FINFO_INODE = $00002000; {< Inode }
  135. APR_FINFO_NLINK = $00004000; {< Number of links }
  136. APR_FINFO_TYPE = $00008000; {< Type }
  137. APR_FINFO_USER = $00010000; {< User }
  138. APR_FINFO_GROUP = $00020000; {< Group }
  139. APR_FINFO_UPROT = $00100000; {< User protection bits }
  140. APR_FINFO_GPROT = $00200000; {< Group protection bits }
  141. APR_FINFO_WPROT = $00400000; {< World protection bits }
  142. APR_FINFO_ICASE = $01000000; {< if dev is case insensitive }
  143. APR_FINFO_NAME = $02000000; {< ->name in proper case }
  144. APR_FINFO_MIN = $00008170; {< type, mtime, ctime, atime, size }
  145. APR_FINFO_IDENT = $00003000; {< dev and inode }
  146. APR_FINFO_OWNER = $00030000; {< user and group }
  147. APR_FINFO_PROT = $00700000; {< all protections }
  148. APR_FINFO_NORM = $0073b170; {< an atomic unix apr_stat() }
  149. APR_FINFO_DIRENT = $02000000; {< an atomic unix apr_dir_read() }
  150. {
  151. * The file information structure. This is analogous to the POSIX
  152. * stat structure.
  153. }
  154. type
  155. apr_finfo_t = record
  156. { Allocates memory and closes lingering handles in the specified pool }
  157. pool: Papr_pool_t;
  158. { The bitmask describing valid fields of this apr_finfo_t structure
  159. * including all available 'wanted' fields and potentially more }
  160. valid: apr_int32_t;
  161. { The access permissions of the file. Mimics Unix access rights. }
  162. protection: apr_fileperms_t;
  163. { The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE,
  164. * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE.
  165. * If the type cannot be determined, the value is APR_UNKFILE.
  166. }
  167. filetype: apr_filetype_e;
  168. { The user id that owns the file }
  169. user: apr_uid_t;
  170. { The group id that owns the file }
  171. group: apr_gid_t;
  172. { The inode of the file. }
  173. inode: apr_ino_t;
  174. { The id of the device the file is on. }
  175. device: apr_dev_t;
  176. { The number of hard links to the file. }
  177. nlink: apr_int32_t;
  178. { The size of the file }
  179. size: apr_off_t;
  180. { The storage size consumed by the file }
  181. csize: apr_off_t;
  182. { The time the file was last accessed }
  183. atime: apr_time_t;
  184. { The time the file was last modified }
  185. mtime: apr_time_t;
  186. { The time the file was last changed }
  187. ctime: apr_time_t;
  188. { The pathname of the file (possibly unrooted) }
  189. fname: PChar;
  190. { The file's name (no path) in filesystem case }
  191. name: PChar;
  192. { The file's handle, if accessed (can be submitted to apr_duphandle) }
  193. filehand: Papr_file_t;
  194. end;
  195. Papr_finfo_t = ^apr_finfo_t;
  196. {
  197. * get the specified file's stats. The file is specified by filename,
  198. * instead of using a pre-opened file.
  199. * @param finfo Where to store the information about the file, which is
  200. * never touched if the call fails.
  201. * @param fname The name of the file to stat.
  202. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
  203. values
  204. * @param pool the pool to use to allocate the new file.
  205. *
  206. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  207. * not be filled in, and you need to check the @c finfo->valid bitmask
  208. * to verify that what you're looking for is there.
  209. }
  210. function apr_stat(finfo: Papr_finfo_t; const fname: PChar;
  211. wanted: apr_int32_t; pool: Papr_pool_t): apr_status_t;
  212. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  213. external LibAPR name LibNamePrefix + 'apr_stat' + LibSuff16;
  214. {
  215. * @defgroup apr_dir Directory Manipulation Functions
  216. }
  217. {
  218. * Open the specified directory.
  219. * @param new_dir The opened directory descriptor.
  220. * @param dirname The full path to the directory (use / on all systems)
  221. * @param pool The pool to use.
  222. }
  223. function apr_dir_open(new_dir: PPapr_dir_t; const dirname: PChar;
  224. pool: Papr_pool_t): apr_status_t;
  225. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  226. external LibAPR name LibNamePrefix + 'apr_dir_open' + LibSuff12;
  227. {
  228. * close the specified directory.
  229. * @param thedir the directory descriptor to close.
  230. }
  231. function apr_dir_close(thedir: Papr_dir_t): apr_status_t;
  232. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  233. external LibAPR name LibNamePrefix + 'apr_dir_close' + LibSuff4;
  234. {
  235. * Read the next entry from the specified directory.
  236. * @param finfo the file info structure and filled in by apr_dir_read
  237. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
  238. values
  239. * @param thedir the directory descriptor returned from apr_dir_open
  240. * @remark No ordering is guaranteed for the entries read.
  241. *
  242. * @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
  243. * not be filled in, and you need to check the @c finfo->valid bitmask
  244. * to verify that what you're looking for is there.
  245. }
  246. function apr_dir_read(finfo: Papr_finfo_t; wanted: apr_int32_t;
  247. thedir: Papr_dir_t): apr_status_t;
  248. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  249. external LibAPR name LibNamePrefix + 'apr_dir_read' + LibSuff12;
  250. {
  251. * Rewind the directory to the first entry.
  252. * @param thedir the directory descriptor to rewind.
  253. }
  254. function apr_dir_rewind(thedir: Papr_dir_t): apr_status_t;
  255. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  256. external LibAPR name LibNamePrefix + 'apr_dir_rewind' + LibSuff4;
  257. {
  258. * @defgroup apr_filepath Filepath Manipulation Functions
  259. }
  260. const
  261. { Cause apr_filepath_merge to fail if addpath is above rootpath }
  262. APR_FILEPATH_NOTABOVEROOT = $01;
  263. { internal: Only meaningful with APR_FILEPATH_NOTABOVEROOT }
  264. APR_FILEPATH_SECUREROOTTEST =$02;
  265. { Cause apr_filepath_merge to fail if addpath is above rootpath,
  266. * even given a rootpath /foo/bar and an addpath ../bar/bash
  267. }
  268. APR_FILEPATH_SECUREROOT = $03;
  269. { Fail apr_filepath_merge if the merged path is relative }
  270. APR_FILEPATH_NOTRELATIVE = $04;
  271. { Fail apr_filepath_merge if the merged path is absolute }
  272. APR_FILEPATH_NOTABSOLUTE = $08;
  273. { Return the file system's native path format (e.g. path delimiters
  274. * of ':' on MacOS9, '\' on Win32, etc.) }
  275. APR_FILEPATH_NATIVE = $10;
  276. { Resolve the true case of existing directories and file elements
  277. * of addpath, (resolving any aliases on Win32) and append a proper
  278. * trailing slash if a directory
  279. }
  280. APR_FILEPATH_TRUENAME = $20;
  281. {
  282. * Extract the rootpath from the given filepath
  283. * @param rootpath the root file path returned with APR_SUCCESS or APR_EINCOMPLETE
  284. * @param filepath the pathname to parse for its root component
  285. * @param flags the desired rules to apply, from
  286. * <PRE>
  287. * APR_FILEPATH_NATIVE Use native path seperators (e.g. '\' on Win32)
  288. * APR_FILEPATH_TRUENAME Tests that the root exists, and makes it proper
  289. * </PRE>
  290. * @param p the pool to allocate the new path string from
  291. * @remark on return, filepath points to the first non-root character in the
  292. * given filepath. In the simplest example, given a filepath of "/foo",
  293. * returns the rootpath of "/" and filepath points at "foo". This is far
  294. * more complex on other platforms, which will canonicalize the root form
  295. * to a consistant format, given the APR_FILEPATH_TRUENAME flag, and also
  296. * test for the validity of that root (e.g., that a drive d:/ or network
  297. * share //machine/foovol/).
  298. * The function returns APR_ERELATIVE if filepath isn't rooted (an
  299. * error), APR_EINCOMPLETE if the root path is ambigious (but potentially
  300. * legitimate, e.g. "/" on Windows is incomplete because it doesn't specify
  301. * the drive letter), or APR_EBADPATH if the root is simply invalid.
  302. * APR_SUCCESS is returned if filepath is an absolute path.
  303. }
  304. function apr_filepath_root(const rootpath, filepath: PPChar;
  305. flags: apr_int32_t; p: Papr_pool_t): apr_status_t;
  306. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  307. external LibAPR name LibNamePrefix + 'apr_filepath_root' + LibSuff16;
  308. {
  309. * Merge additional file path onto the previously processed rootpath
  310. * @param newpath the merged paths returned
  311. * @param rootpath the root file path (NULL uses the current working path)
  312. * @param addpath the path to add to the root path
  313. * @param flags the desired APR_FILEPATH_ rules to apply when merging
  314. * @param p the pool to allocate the new path string from
  315. * @remark if the flag APR_FILEPATH_TRUENAME is given, and the addpath
  316. * contains wildcard characters ('*', '?') on platforms that don't support
  317. * such characters within filenames, the paths will be merged, but the
  318. * result code will be APR_EPATHWILD, and all further segments will not
  319. * reflect the true filenames including the wildcard and following segments.
  320. }
  321. function apr_filepath_merge(newpath: PPChar; const rootpath, addpath: PPChar;
  322. flags: apr_int32_t; p: Papr_pool_t): apr_status_t;
  323. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  324. external LibAPR name LibNamePrefix + 'apr_filepath_merge' + LibSuff20;
  325. {
  326. * Split a search path into separate components
  327. * @param pathelts the returned components of the search path
  328. * @param liststr the search path (e.g., <tt>getenv("PATH")</tt>)
  329. * @param p the pool to allocate the array and path components from
  330. * @remark empty path componenta do not become part of @a pathelts.
  331. * @remark the path separator in @a liststr is system specific;
  332. * e.g., ':' on Unix, ';' on Windows, etc.
  333. }
  334. function apr_filepath_list_split(pathelts: PPapr_array_header_t;
  335. const liststr: PChar; p: Papr_pool_t): apr_status_t;
  336. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  337. external LibAPR name LibNamePrefix + 'apr_filepath_list_split' + LibSuff12;
  338. {
  339. * Merge a list of search path components into a single search path
  340. * @param liststr the returned search path; may be NULL if @a pathelts is empty
  341. * @param pathelts the components of the search path
  342. * @param p the pool to allocate the search path from
  343. * @remark emtpy strings in the source array are ignored.
  344. * @remark the path separator in @a liststr is system specific;
  345. * e.g., ':' on Unix, ';' on Windows, etc.
  346. }
  347. function apr_filepath_list_merge(liststr: PPChar;
  348. pathelts: Papr_array_header_t; p: Papr_pool_t): apr_status_t;
  349. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  350. external LibAPR name LibNamePrefix + 'apr_filepath_list_merge' + LibSuff12;
  351. {
  352. * Return the default file path (for relative file names)
  353. * @param path the default path string returned
  354. * @param flags optional flag APR_FILEPATH_NATIVE to retrieve the
  355. * default file path in os-native format.
  356. * @param p the pool to allocate the default path string from
  357. }
  358. function apr_filepath_get(path: PPChar; flags: apr_int32_t;
  359. p: Papr_pool_t): apr_status_t;
  360. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  361. external LibAPR name LibNamePrefix + 'apr_filepath_get' + LibSuff12;
  362. {
  363. * Set the default file path (for relative file names)
  364. * @param path the default path returned
  365. * @param p the pool to allocate any working storage
  366. }
  367. function apr_filepath_set(const path: PChar; p: Papr_pool_t): apr_status_t;
  368. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  369. external LibAPR name LibNamePrefix + 'apr_filepath_set' + LibSuff8;
  370. const
  371. { The FilePath character encoding is unknown }
  372. APR_FILEPATH_ENCODING_UNKNOWN = 0;
  373. { The FilePath character encoding is locale-dependent }
  374. APR_FILEPATH_ENCODING_LOCALE = 1;
  375. { The FilePath character encoding is UTF-8 }
  376. APR_FILEPATH_ENCODING_UTF8 = 2;
  377. {
  378. * Determine the encoding used internally by the FilePath functions
  379. * @param style points to a variable which receives the encoding style flag
  380. * @param p the pool to allocate any working storage
  381. * @remark Use @c apr_os_locale_encoding and/or @c apr_os_default_encoding
  382. * to get the name of the path encoding if it's not UTF-8.
  383. }
  384. function apr_filepath_encoding(style: PInteger; p: Papr_pool_t): apr_status_t;
  385. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  386. external LibAPR name LibNamePrefix + 'apr_filepath_encoding' + LibSuff8;