apr_file_info.inc 16 KB

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