apr_file_io.inc 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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_io.h
  18. * @brief APR File I/O Handling
  19. }
  20. {#include "apr.h"
  21. #include "apr_pools.h"
  22. #include "apr_time.h"
  23. #include "apr_errno.h"}
  24. {.$include apr_file_info.inc}
  25. {#include "apr_inherit.h"}
  26. //#define APR_WANT_STDIO {< for SEEK_* }
  27. //#define APR_WANT_IOVEC {< for apr_file_writev }
  28. //#include "apr_want.h"
  29. {
  30. * @defgroup apr_file_io File I/O Handling Functions
  31. * @ingroup APR
  32. }
  33. {
  34. * @defgroup apr_file_open_flags File Open Flags/Routines
  35. }
  36. { Note to implementors: Values in the range 0x00100000--0x80000000
  37. are reserved for platform-specific values. }
  38. const
  39. APR_FOPEN_READ = $00001; {< Open the file for reading }
  40. APR_FOPEN_WRITE = $00002; {< Open the file for writing }
  41. APR_FOPEN_CREATE = $00004; {< Create the file if not there }
  42. APR_FOPEN_APPEND = $00008; {< Append to the end of the file }
  43. APR_FOPEN_TRUNCATE = $00010; {< Open the file and truncate
  44. to 0 length }
  45. APR_FOPEN_BINARY = $00020; {< Open the file in binary mode }
  46. APR_FOPEN_EXCL = $00040; {< Open should fail if APR_CREATE
  47. and file exists. }
  48. APR_FOPEN_BUFFERED = $00080; {< Open the file for buffered I/O }
  49. APR_FOPEN_DELONCLOSE= $00100; {< Delete the file after close }
  50. APR_FOPEN_XTHREAD = $00200; {< Platform dependent tag to open
  51. the file for use across multiple
  52. threads }
  53. APR_FOPEN_SHARELOCK = $00400; {< Platform dependent support for
  54. higher level locked read/write
  55. access to support writes across
  56. process/machines }
  57. APR_FOPEN_NOCLEANUP = $00800; {< Do not register a cleanup
  58. when the file is opened }
  59. APR_FOPEN_SENDFILE_ENABLED = $01000; {< Advisory flag that this
  60. file should support
  61. apr_socket_sendfile operation }
  62. APR_FOPEN_LARGEFILE = $04000; {< Platform dependent flag to enable
  63. large file support; WARNING see
  64. below. }
  65. { backcompat }
  66. APR_READ = APR_FOPEN_READ; {< @deprecated @see APR_FOPEN_READ }
  67. APR_WRITE = APR_FOPEN_WRITE; {< @deprecated @see APR_FOPEN_WRITE }
  68. APR_CREATE = APR_FOPEN_CREATE; {< @deprecated @see APR_FOPEN_CREATE }
  69. APR_APPEND = APR_FOPEN_APPEND; {< @deprecated @see APR_FOPEN_APPEND }
  70. APR_TRUNCATE = APR_FOPEN_TRUNCATE; {< @deprecated @see APR_FOPEN_TRUNCATE }
  71. APR_BINARY = APR_FOPEN_BINARY; {< @deprecated @see APR_FOPEN_BINARY }
  72. APR_EXCL = APR_FOPEN_EXCL; {< @deprecated @see APR_FOPEN_EXCL }
  73. APR_BUFFERED = APR_FOPEN_BUFFERED; {< @deprecated @see APR_FOPEN_BUFFERED }
  74. APR_DELONCLOSE = APR_FOPEN_DELONCLOSE; {< @deprecated @see APR_FOPEN_DELONCLOSE }
  75. APR_XTHREAD = APR_FOPEN_XTHREAD; {< @deprecated @see APR_FOPEN_XTHREAD }
  76. APR_SHARELOCK = APR_FOPEN_SHARELOCK; {< @deprecated @see APR_FOPEN_SHARELOCK }
  77. APR_FILE_NOCLEANUP = APR_FOPEN_NOCLEANUP; {< @deprecated @see APR_FOPEN_NOCLEANUP }
  78. APR_SENDFILE_ENABLED= APR_FOPEN_SENDFILE_ENABLED; {< @deprecated @see APR_FOPEN_SENDFILE_ENABLED }
  79. APR_LARGEFILE = APR_FOPEN_LARGEFILE; {< @deprecated @see APR_FOPEN_LARGEFILE }
  80. { @warning The APR_LARGEFILE flag only has effect on some platforms
  81. * where sizeof(apr_off_t) == 4. Where implemented, it allows opening
  82. * and writing to a file which exceeds the size which can be
  83. * represented by apr_off_t (2 gigabytes). When a file's size does
  84. * exceed 2Gb, apr_file_info_get() will fail with an error on the
  85. * descriptor, likewise apr_stat()/apr_lstat() will fail on the
  86. * filename. apr_dir_read() will fail with APR_INCOMPLETE on a
  87. * directory entry for a large file depending on the particular
  88. * APR_FINFO_* flags. Generally, it is not recommended to use this
  89. * flag. }
  90. {
  91. * @defgroup apr_file_seek_flags File Seek Flags
  92. }
  93. {
  94. * @defgroup apr_file_attrs_set_flags File Attribute Flags
  95. }
  96. { flags for apr_file_attrs_set }
  97. APR_FILE_ATTR_READONLY = $01; {< File is read-only }
  98. APR_FILE_ATTR_EXECUTABLE =$02; {< File is executable }
  99. APR_FILE_ATTR_HIDDEN = $04; {< File is hidden }
  100. {
  101. * @defgroup apr_file_writev(_full) max iovec size
  102. }
  103. {$ifdef DOXYGEN}
  104. APR_MAX_IOVEC_SIZE = 1024; {< System dependent maximum
  105. size of an iovec array }
  106. {#elif defined(IOV_MAX)
  107. #define APR_MAX_IOVEC_SIZE IOV_MAX
  108. #elif defined(MAX_IOVEC)
  109. #define APR_MAX_IOVEC_SIZE MAX_IOVEC}
  110. {$else}
  111. APR_MAX_IOVEC_SIZE = 1024;
  112. {$endif}
  113. { File attributes }
  114. type
  115. apr_fileattrs_t = apr_uint32_t;
  116. { Type to pass as whence argument to apr_file_seek. }
  117. apr_seek_where_t = Integer;
  118. {
  119. * Structure for referencing files.
  120. }
  121. apr_file_t = record end;
  122. // Papr_file_t = ^apr_file_t;
  123. PPapr_file_t = ^Papr_file_t;
  124. { File lock types/flags }
  125. {
  126. * @defgroup apr_file_lock_types File Lock Types
  127. }
  128. const
  129. APR_FLOCK_SHARED = 1; {< Shared lock. More than one process
  130. or thread can hold a shared lock
  131. at any given time. Essentially,
  132. this is a "read lock", preventing
  133. writers from establishing an
  134. exclusive lock. }
  135. APR_FLOCK_EXCLUSIVE = 2; {< Exclusive lock. Only one process
  136. may hold an exclusive lock at any
  137. given time. This is analogous to
  138. a "write lock". }
  139. APR_FLOCK_TYPEMASK = $000F; {< mask to extract lock type }
  140. APR_FLOCK_NONBLOCK = $0010; {< do not block while acquiring the
  141. file lock }
  142. {
  143. * Open the specified file.
  144. * @param newf The opened file descriptor.
  145. * @param fname The full path to the file (using / on all systems)
  146. * @param flag Or'ed value of:
  147. * <PRE>
  148. * APR_READ open for reading
  149. * APR_WRITE open for writing
  150. * APR_CREATE create the file if not there
  151. * APR_APPEND file ptr is set to end prior to all writes
  152. * APR_TRUNCATE set length to zero if file exists
  153. * APR_BINARY not a text file (This flag is ignored on
  154. * UNIX because it has no meaning)
  155. * APR_BUFFERED buffer the data. Default is non-buffered
  156. * APR_EXCL return error if APR_CREATE and file exists
  157. * APR_DELONCLOSE delete the file after closing.
  158. * APR_XTHREAD Platform dependent tag to open the file
  159. * for use across multiple threads
  160. * APR_SHARELOCK Platform dependent support for higher
  161. * level locked read/write access to support
  162. * writes across process/machines
  163. * APR_FILE_NOCLEANUP Do not register a cleanup with the pool
  164. * passed in on the <EM>pool</EM> argument (see below).
  165. * The apr_os_file_t handle in apr_file_t will not
  166. * be closed when the pool is destroyed.
  167. * APR_SENDFILE_ENABLED Open with appropriate platform semantics
  168. * for sendfile operations. Advisory only,
  169. * apr_socket_sendfile does not check this flag.
  170. * </PRE>
  171. * @param perm Access permissions for file.
  172. * @param pool The pool to use.
  173. * @remark If perm is APR_OS_DEFAULT and the file is being created, appropriate
  174. * default permissions will be used. *arg1 must point to a valid file_t,
  175. * or NULL (in which case it will be allocated)
  176. }
  177. function apr_file_open(newf: PPapr_file_t; const fname: PChar;
  178. flag: apr_int32_t; perm: apr_fileperms_t;
  179. pool: Papr_pool_t): apr_status_t;
  180. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  181. external LibAPR name LibNamePrefix + 'apr_file_open' + LibSuff20;
  182. {
  183. * Close the specified file.
  184. * @param file The file descriptor to close.
  185. }
  186. function apr_file_close(file_: Papr_file_t): apr_status_t;
  187. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  188. external LibAPR name LibNamePrefix + 'apr_file_close' + LibSuff4;
  189. {
  190. * delete the specified file.
  191. * @param path The full path to the file (using / on all systems)
  192. * @param pool The pool to use.
  193. * @remark If the file is open, it won't be removed until all instances are closed.
  194. }
  195. function apr_file_remove(const path: PChar; pool: Papr_pool_t): apr_status_t;
  196. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  197. external LibAPR name LibNamePrefix + 'apr_file_remove' + LibSuff8;
  198. {
  199. * rename the specified file.
  200. * @param from_path The full path to the original file (using / on all systems)
  201. * @param to_path The full path to the new file (using / on all systems)
  202. * @param pool The pool to use.
  203. * @warning If a file exists at the new location, then it will be overwritten.
  204. * Moving files or directories across devices may not be possible.
  205. }
  206. function apr_file_rename(const from_path, to_path: PChar; pool: Papr_pool_t): apr_status_t;
  207. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  208. external LibAPR name LibNamePrefix + 'apr_file_rename' + LibSuff12;
  209. {
  210. * copy the specified file to another file.
  211. * @param from_path The full path to the original file (using / on all systems)
  212. * @param to_path The full path to the new file (using / on all systems)
  213. * @param perms Access permissions for the new file if it is created.
  214. * In place of the usual or'd combination of file permissions, the
  215. * value APR_FILE_SOURCE_PERMS may be given, in which case the source
  216. * file's permissions are copied.
  217. * @param pool The pool to use.
  218. * @remark The new file does not need to exist, it will be created if required.
  219. * @warning If the new file already exists, its contents will be overwritten.
  220. }
  221. function apr_file_copy(const from_path, to_path: PChar;
  222. perms: apr_fileperms_t; pool: Papr_pool_t): apr_status_t;
  223. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  224. external LibAPR name LibNamePrefix + 'apr_file_copy' + LibSuff16;
  225. {
  226. * append the specified file to another file.
  227. * @param from_path The full path to the source file (using / on all systems)
  228. * @param to_path The full path to the destination file (using / on all systems)
  229. * @param perms Access permissions for the destination file if it is created.
  230. * In place of the usual or'd combination of file permissions, the
  231. * value APR_FILE_SOURCE_PERMS may be given, in which case the source
  232. * file's permissions are copied.
  233. * @param pool The pool to use.
  234. * @remark The new file does not need to exist, it will be created if required.
  235. }
  236. function apr_file_append(const from_path, to_path: PChar;
  237. perms: apr_fileperms_t; pool: Papr_pool_t): apr_status_t;
  238. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  239. external LibAPR name LibNamePrefix + 'apr_file_append' + LibSuff16;
  240. {
  241. * Are we at the end of the file
  242. * @param fptr The apr file we are testing.
  243. * @remark Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise.
  244. }
  245. function apr_file_eof(fptr: Papr_file_t): apr_status_t;
  246. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  247. external LibAPR name LibNamePrefix + 'apr_file_eof' + LibSuff4;
  248. {
  249. * open standard error as an apr file pointer.
  250. * @param thefile The apr file to use as stderr.
  251. * @param pool The pool to allocate the file out of.
  252. *
  253. * @remark The only reason that the apr_file_open_std* functions exist
  254. * is that you may not always have a stderr/out/in on Windows. This
  255. * is generally a problem with newer versions of Windows and services.
  256. *
  257. * The other problem is that the C library functions generally work
  258. * differently on Windows and Unix. So, by using apr_file_open_std*
  259. * functions, you can get a handle to an APR struct that works with
  260. * the APR functions which are supposed to work identically on all
  261. * platforms.
  262. }
  263. function apr_file_open_stderr(thefile: PPapr_file_t;
  264. pool: Papr_pool_t): apr_status_t;
  265. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  266. external LibAPR name LibNamePrefix + 'apr_file_open_stderr' + LibSuff8;
  267. {
  268. * open standard output as an apr file pointer.
  269. * @param thefile The apr file to use as stdout.
  270. * @param pool The pool to allocate the file out of.
  271. *
  272. * @remark See remarks for apr_file_open_stdout.
  273. }
  274. function apr_file_open_stdout(thefile: PPapr_file_t;
  275. pool: Papr_pool_t): apr_status_t;
  276. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  277. external LibAPR name LibNamePrefix + 'apr_file_open_stdout' + LibSuff8;
  278. {
  279. * open standard input as an apr file pointer.
  280. * @param thefile The apr file to use as stdin.
  281. * @param pool The pool to allocate the file out of.
  282. *
  283. * @remark See remarks for apr_file_open_stdout.
  284. }
  285. function apr_file_open_stdin(thefile: PPapr_file_t;
  286. pool: Papr_pool_t): apr_status_t;
  287. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  288. external LibAPR name LibNamePrefix + 'apr_file_open_stdin' + LibSuff8;
  289. {
  290. * Read data from the specified file.
  291. * @param thefile The file descriptor to read from.
  292. * @param buf The buffer to store the data to.
  293. * @param nbytes On entry, the number of bytes to read; on exit, the number
  294. * of bytes read.
  295. *
  296. * @remark apr_file_read will read up to the specified number of
  297. * bytes, but never more. If there isn't enough data to fill that
  298. * number of bytes, all of the available data is read. The third
  299. * argument is modified to reflect the number of bytes read. If a
  300. * char was put back into the stream via ungetc, it will be the first
  301. * character returned.
  302. *
  303. * @remark It is not possible for both bytes to be read and an APR_EOF
  304. * or other error to be returned. APR_EINTR is never returned.
  305. }
  306. function apr_file_read(thefile: Papr_file_t; buf: Pointer;
  307. nbytes: Papr_size_t): apr_status_t;
  308. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  309. external LibAPR name LibNamePrefix + 'apr_file_read' + LibSuff12;
  310. {
  311. * Write data to the specified file.
  312. * @param thefile The file descriptor to write to.
  313. * @param buf The buffer which contains the data.
  314. * @param nbytes On entry, the number of bytes to write; on exit, the number
  315. * of bytes written.
  316. *
  317. * @remark apr_file_write will write up to the specified number of
  318. * bytes, but never more. If the OS cannot write that many bytes, it
  319. * will write as many as it can. The third argument is modified to
  320. * reflect the * number of bytes written.
  321. *
  322. * @remark It is possible for both bytes to be written and an error to
  323. * be returned. APR_EINTR is never returned.
  324. }
  325. function apr_file_write(thefile: Papr_file_t; buf: Pointer;
  326. nbytes: Papr_size_t): apr_status_t;
  327. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  328. external LibAPR name LibNamePrefix + 'apr_file_write' + LibSuff12;
  329. {
  330. * Write data from iovec array to the specified file.
  331. * @param thefile The file descriptor to write to.
  332. * @param vec The array from which to get the data to write to the file.
  333. * @param nvec The number of elements in the struct iovec array. This must
  334. * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function
  335. * will fail with APR_EINVAL.
  336. * @param nbytes The number of bytes written.
  337. *
  338. * @remark It is possible for both bytes to be written and an error to
  339. * be returned. APR_EINTR is never returned.
  340. *
  341. * @remark apr_file_writev is available even if the underlying
  342. * operating system doesn't provide writev().
  343. }
  344. function apr_file_writev(thefile: Papr_file_t; const vec: Piovec;
  345. nvec: apr_size_t; nbytes: Papr_size_t): apr_status_t;
  346. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  347. external LibAPR name LibNamePrefix + 'apr_file_writev' + LibSuff16;
  348. {
  349. * Read data from the specified file, ensuring that the buffer is filled
  350. * before returning.
  351. * @param thefile The file descriptor to read from.
  352. * @param buf The buffer to store the data to.
  353. * @param nbytes The number of bytes to read.
  354. * @param bytes_read If non-NULL, this will contain the number of bytes read.
  355. *
  356. * @remark apr_file_read will read up to the specified number of
  357. * bytes, but never more. If there isn't enough data to fill that
  358. * number of bytes, then the process/thread will block until it is
  359. * available or EOF is reached. If a char was put back into the
  360. * stream via ungetc, it will be the first character returned.
  361. *
  362. * @remark It is possible for both bytes to be read and an error to be
  363. * returned. And if *bytes_read is less than nbytes, an accompanying
  364. * error is _always_ returned.
  365. *
  366. * @remark APR_EINTR is never returned.
  367. }
  368. function apr_file_read_full(thefile: Papr_file_t; buf: Pointer;
  369. nbytes: apr_size_t; bytes_read: Papr_size_t): apr_status_t;
  370. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  371. external LibAPR name LibNamePrefix + 'apr_file_read_full' + LibSuff16;
  372. {
  373. * Write data to the specified file, ensuring that all of the data is
  374. * written before returning.
  375. * @param thefile The file descriptor to write to.
  376. * @param buf The buffer which contains the data.
  377. * @param nbytes The number of bytes to write.
  378. * @param bytes_written If non-NULL, set to the number of bytes written.
  379. *
  380. * @remark apr_file_write will write up to the specified number of
  381. * bytes, but never more. If the OS cannot write that many bytes, the
  382. * process/thread will block until they can be written. Exceptional
  383. * error such as "out of space" or "pipe closed" will terminate with
  384. * an error.
  385. *
  386. * @remark It is possible for both bytes to be written and an error to
  387. * be returned. And if *bytes_written is less than nbytes, an
  388. * accompanying error is _always_ returned.
  389. *
  390. * @remark APR_EINTR is never returned.
  391. }
  392. function apr_file_write_full(thefile: Papr_file_t; buf: Pointer;
  393. nbytes: apr_size_t; bytes_written: Papr_size_t): apr_status_t;
  394. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  395. external LibAPR name LibNamePrefix + 'apr_file_write_full' + LibSuff16;
  396. {
  397. * Write data from iovec array to the specified file, ensuring that all of the
  398. * data is written before returning.
  399. * @param thefile The file descriptor to write to.
  400. * @param vec The array from which to get the data to write to the file.
  401. * @param nvec The number of elements in the struct iovec array. This must
  402. * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function
  403. * will fail with APR_EINVAL.
  404. * @param nbytes The number of bytes written.
  405. *
  406. * @remark apr_file_writev_full is available even if the underlying
  407. * operating system doesn't provide writev().
  408. }
  409. function apr_file_writev_full(thefile: Papr_file_t; const vec: Piovec;
  410. nvec: apr_size_t; nbytes: Papr_size_t): apr_status_t;
  411. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  412. external LibAPR name LibNamePrefix + 'apr_file_writev_full' + LibSuff16;
  413. {
  414. * Write a character into the specified file.
  415. * @param ch The character to write.
  416. * @param thefile The file descriptor to write to
  417. }
  418. function apr_file_putc(ch: Char; thefile: Papr_file_t): apr_status_t;
  419. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  420. external LibAPR name LibNamePrefix + 'apr_file_putc' + LibSuff8;
  421. {
  422. * get a character from the specified file.
  423. * @param ch The character to read into
  424. * @param thefile The file descriptor to read from
  425. }
  426. function apr_file_getc(ch: PChar; thefile: Papr_file_t): apr_status_t;
  427. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  428. external LibAPR name LibNamePrefix + 'apr_file_getc' + LibSuff8;
  429. {
  430. * put a character back onto a specified stream.
  431. * @param ch The character to write.
  432. * @param thefile The file descriptor to write to
  433. }
  434. function apr_file_ungetc(ch: Char; thefile: PPapr_file_t): apr_status_t;
  435. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  436. external LibAPR name LibNamePrefix + 'apr_file_ungetc' + LibSuff8;
  437. {
  438. * Get a string from a specified file.
  439. * @param str The buffer to store the string in.
  440. * @param len The length of the string
  441. * @param thefile The file descriptor to read from
  442. * @remark The buffer will be '\0'-terminated if any characters are stored.
  443. }
  444. function apr_file_gets(str: PChar; len: Integer;
  445. thefile: Papr_file_t): apr_status_t;
  446. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  447. external LibAPR name LibNamePrefix + 'apr_file_gets' + LibSuff12;
  448. {
  449. * Put the string into a specified file.
  450. * @param str The string to write.
  451. * @param thefile The file descriptor to write to
  452. }
  453. function apr_file_puts(const str: PChar; thefile: Papr_file_t): apr_status_t;
  454. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  455. external LibAPR name LibNamePrefix + 'apr_file_puts' + LibSuff8;
  456. {
  457. * Flush the file's buffer.
  458. * @param thefile The file descriptor to flush
  459. }
  460. function apr_file_flush(thefile: PPapr_file_t): apr_status_t;
  461. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  462. external LibAPR name LibNamePrefix + 'apr_file_flush' + LibSuff4;
  463. {
  464. * duplicate the specified file descriptor.
  465. * @param new_file The structure to duplicate into.
  466. * @param old_file The file to duplicate.
  467. * @param p The pool to use for the new file.
  468. * @remark *new_file must point to a valid apr_file_t, or point to NULL
  469. }
  470. function apr_file_dup(new_file: PPapr_file_t; old_file: PPapr_file_t;
  471. p: Papr_pool_t): apr_status_t;
  472. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  473. external LibAPR name LibNamePrefix + 'apr_file_dup' + LibSuff12;
  474. {
  475. * duplicate the specified file descriptor and close the original
  476. * @param new_file The old file that is to be closed and reused
  477. * @param old_file The file to duplicate
  478. * @param p The pool to use for the new file
  479. *
  480. * @remark new_file MUST point at a valid apr_file_t. It cannot be NULL
  481. }
  482. function apr_file_dup2(new_file: PPapr_file_t; old_file: PPapr_file_t;
  483. p: Papr_pool_t): apr_status_t;
  484. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  485. external LibAPR name LibNamePrefix + 'apr_file_dup2' + LibSuff12;
  486. {
  487. * move the specified file descriptor to a new pool
  488. * @param new_file Pointer in which to return the new apr_file_t
  489. * @param old_file The file to move
  490. * @param p The pool to which the descriptor is to be moved
  491. * @remark Unlike apr_file_dup2(), this function doesn't do an
  492. * OS dup() operation on the underlying descriptor; it just
  493. * moves the descriptor's apr_file_t wrapper to a new pool.
  494. * @remark The new pool need not be an ancestor of old_file's pool.
  495. * @remark After calling this function, old_file may not be used
  496. }
  497. function apr_file_setaside(new_file: PPapr_file_t; old_file: PPapr_file_t;
  498. p: Papr_pool_t): apr_status_t;
  499. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  500. external LibAPR name LibNamePrefix + 'apr_file_setaside' + LibSuff12;
  501. {
  502. * Move the read/write file offset to a specified byte within a file.
  503. * @param thefile The file descriptor
  504. * @param where How to move the pointer, one of:
  505. * <PRE>
  506. * APR_SET -- set the offset to offset
  507. * APR_CUR -- add the offset to the current position
  508. * APR_END -- add the offset to the current file size
  509. * </PRE>
  510. * @param offset The offset to move the pointer to.
  511. * @remark The third argument is modified to be the offset the pointer
  512. was actually moved to.
  513. }
  514. function apr_file_seek(thefile: Papr_file_t;
  515. where: apr_seek_where_t; offset: Papr_off_t): apr_status_t;
  516. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  517. external LibAPR name LibNamePrefix + 'apr_file_seek' + LibSuff12;
  518. {
  519. * Create an anonymous pipe.
  520. * @param in The file descriptor to use as input to the pipe.
  521. * @param out The file descriptor to use as output from the pipe.
  522. * @param pool The pool to operate on.
  523. }
  524. function apr_file_pipe_create(in_: PPapr_file_t; out_: PPapr_file_t;
  525. pool: Papr_pool_t): apr_status_t;
  526. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  527. external LibAPR name LibNamePrefix + 'apr_file_pipe_create' + LibSuff12;
  528. {
  529. * Create a named pipe.
  530. * @param filename The filename of the named pipe
  531. * @param perm The permissions for the newly created pipe.
  532. * @param pool The pool to operate on.
  533. }
  534. function apr_file_namedpipe_create(const filename: PChar;
  535. perm: apr_fileperms_t; pool: Papr_pool_t): apr_status_t;
  536. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  537. external LibAPR name LibNamePrefix + 'apr_file_namedpipe_create' + LibSuff12;
  538. {
  539. * Get the timeout value for a pipe or manipulate the blocking state.
  540. * @param thepipe The pipe we are getting a timeout for.
  541. * @param timeout The current timeout value in microseconds.
  542. }
  543. function apr_file_pipe_timeout_get(thepipe: Papr_file_t;
  544. timeout: Papr_interval_time_t): apr_status_t;
  545. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  546. external LibAPR name LibNamePrefix + 'apr_file_pipe_timeout_get' + LibSuff8;
  547. {
  548. * Set the timeout value for a pipe or manipulate the blocking state.
  549. * @param thepipe The pipe we are setting a timeout on.
  550. * @param timeout The timeout value in microseconds. Values < 0 mean wait
  551. * forever, 0 means do not wait at all.
  552. }
  553. function apr_file_pipe_timeout_set(thepipe: Papr_file_t;
  554. timeout: apr_interval_time_t): apr_status_t;
  555. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  556. external LibAPR name LibNamePrefix + 'apr_file_pipe_timeout_set' + LibSuff12;
  557. { file (un)locking functions. }
  558. {
  559. * Establish a lock on the specified, open file. The lock may be advisory
  560. * or mandatory, at the discretion of the platform. The lock applies to
  561. * the file as a whole, rather than a specific range. Locks are established
  562. * on a per-thread/process basis; a second lock by the same thread will not
  563. * block.
  564. * @param thefile The file to lock.
  565. * @param type The type of lock to establish on the file.
  566. }
  567. function apr_file_lock(thefile: Papr_file_t; type_: Integer): apr_status_t;
  568. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  569. external LibAPR name LibNamePrefix + 'apr_file_lock' + LibSuff8;
  570. {
  571. * Remove any outstanding locks on the file.
  572. * @param thefile The file to unlock.
  573. }
  574. function apr_file_unlock(thefile: Papr_file_t): apr_status_t;
  575. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  576. external LibAPR name LibNamePrefix + 'apr_file_unlock' + LibSuff4;
  577. {accessor and general file_io functions. }
  578. {
  579. * return the file name of the current file.
  580. * @param new_path The path of the file.
  581. * @param thefile The currently open file.
  582. }
  583. function apr_file_name_get(const newpath: PPChar; thefile: Papr_file_t): apr_status_t;
  584. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  585. external LibAPR name LibNamePrefix + 'apr_file_name_get' + LibSuff8;
  586. {
  587. * Return the data associated with the current file.
  588. * @param data The user data associated with the file.
  589. * @param key The key to use for retreiving data associated with this file.
  590. * @param file The currently open file.
  591. }
  592. function apr_file_data_get(data: PPointer; const key: PChar;
  593. file_: Papr_file_t): apr_status_t;
  594. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  595. external LibAPR name LibNamePrefix + 'apr_file_data_get' + LibSuff12;
  596. {
  597. * Set the data associated with the current file.
  598. * @param file The currently open file.
  599. * @param data The user data to associate with the file.
  600. * @param key The key to use for assocaiteing data with the file.
  601. * @param cleanup The cleanup routine to use when the file is destroyed.
  602. }
  603. //function apr_file_data_set(ch: Char; thefile: PPapr_file_t): apr_status_t;
  604. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  605. // external LibAPR name LibNamePrefix + 'apr_file_data_set' + LibSuff4;
  606. //APR_DECLARE(apr_status_t) (apr_file_t *file, void *data,
  607. // const char *key,
  608. // apr_status_t (*cleanup)(void *));
  609. {
  610. * Write a string to a file using a printf format.
  611. * @param fptr The file to write to.
  612. * @param format The format string
  613. * @param ... The values to substitute in the format string
  614. * @return The number of bytes written
  615. }
  616. function apr_file_printf(fptr: Papr_file_t; const format: PChar;
  617. othres: array of const): Integer;
  618. cdecl; external LibAPR name 'apr_file_printf';
  619. {
  620. * set the specified file's permission bits.
  621. * @param fname The file (name) to apply the permissions to.
  622. * @param perms The permission bits to apply to the file.
  623. * @warning Some platforms may not be able to apply all of the available
  624. * permission bits; APR_INCOMPLETE will be returned if some permissions
  625. * are specified which could not be set.
  626. *
  627. * Platforms which do not implement this feature will return APR_ENOTIMPL.
  628. }
  629. function apr_file_perms_set(const fname: PChar;
  630. perms: apr_fileperms_t): apr_status_t;
  631. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  632. external LibAPR name LibNamePrefix + 'apr_file_perms_set' + LibSuff8;
  633. {
  634. * Set attributes of the specified file.
  635. * @param fname The full path to the file (using / on all systems)
  636. * @param attributes Or'd combination of
  637. * <PRE>
  638. * APR_FILE_ATTR_READONLY - make the file readonly
  639. * APR_FILE_ATTR_EXECUTABLE - make the file executable
  640. * APR_FILE_ATTR_HIDDEN - make the file hidden
  641. * </PRE>
  642. * @param attr_mask Mask of valid bits in attributes.
  643. * @param pool the pool to use.
  644. * @remark This function should be used in preference to explict manipulation
  645. * of the file permissions, because the operations to provide these
  646. * attributes are platform specific and may involve more than simply
  647. * setting permission bits.
  648. * @warning Platforms which do not implement this feature will return
  649. * APR_ENOTIMPL.
  650. }
  651. function apr_file_attrs_set(const fname: PChar;
  652. attributes, attr_mask: apr_fileattrs_t;
  653. pool: Papr_pool_t): apr_status_t;
  654. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  655. external LibAPR name LibNamePrefix + 'apr_file_attrs_set' + LibSuff16;
  656. {
  657. * Set the mtime of the specified file.
  658. * @param fname The full path to the file (using / on all systems)
  659. * @param mtime The mtime to apply to the file.
  660. * @param pool The pool to use.
  661. * @warning Platforms which do not implement this feature will return
  662. * APR_ENOTIMPL.
  663. }
  664. function apr_file_mtime_set(const fname: PChar;
  665. mtime: apr_time_t; pool: Papr_pool_t): apr_status_t;
  666. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  667. external LibAPR name LibNamePrefix + 'apr_file_mtime_set' + LibSuff16;
  668. {
  669. * Create a new directory on the file system.
  670. * @param path the path for the directory to be created. (use / on all systems)
  671. * @param perm Permissions for the new direcoty.
  672. * @param pool the pool to use.
  673. }
  674. function apr_dir_make(const path: PChar; perm: apr_fileperms_t;
  675. pool: Papr_pool_t): apr_status_t;
  676. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  677. external LibAPR name LibNamePrefix + 'apr_dir_make' + LibSuff12;
  678. { Creates a new directory on the file system, but behaves like
  679. * 'mkdir -p'. Creates intermediate directories as required. No error
  680. * will be reported if PATH already exists.
  681. * @param path the path for the directory to be created. (use / on all systems)
  682. * @param perm Permissions for the new direcoty.
  683. * @param pool the pool to use.
  684. }
  685. function apr_dir_make_recursive(const path: PChar;
  686. perm: apr_fileperms_t; pool: Papr_pool_t): apr_status_t;
  687. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  688. external LibAPR name LibNamePrefix + 'apr_dir_make_recursive' + LibSuff12;
  689. {
  690. * Remove directory from the file system.
  691. * @param path the path for the directory to be removed. (use / on all systems)
  692. * @param pool the pool to use.
  693. }
  694. function apr_dir_remove(const path: PChar; pool: Papr_pool_t): apr_status_t;
  695. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  696. external LibAPR name LibNamePrefix + 'apr_dir_remove' + LibSuff8;
  697. {
  698. * get the specified file's stats.
  699. * @param finfo Where to store the information about the file.
  700. * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
  701. * @param thefile The file to get information about.
  702. }
  703. function apr_file_info_get(finfo: Papr_finfo_t;
  704. wanted: apr_int32_t; thefile: Papr_file_t): apr_status_t;
  705. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  706. external LibAPR name LibNamePrefix + 'apr_file_info_get' + LibSuff12;
  707. {
  708. * Truncate the file's length to the specified offset
  709. * @param fp The file to truncate
  710. * @param offset The offset to truncate to.
  711. }
  712. function apr_file_trunc(fp: Papr_file_t; offset: apr_off_t): apr_status_t;
  713. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  714. external LibAPR name LibNamePrefix + 'apr_file_trunc' + LibSuff12;
  715. {
  716. * Retrieve the flags that were passed into apr_file_open()
  717. * when the file was opened.
  718. * @return apr_int32_t the flags
  719. }
  720. function apr_file_flags_get(f: Papr_file_t): apr_int32_t;
  721. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  722. external LibAPR name LibNamePrefix + 'apr_file_flags_get' + LibSuff4;
  723. {
  724. * Get the pool used by the file.
  725. }
  726. {APR_POOL_DECLARE_ACCESSOR(file);
  727. }
  728. {
  729. * Set a file to be inherited by child processes.
  730. *
  731. }
  732. {APR_DECLARE_INHERIT_SET(file);
  733. }
  734. {
  735. * Unset a file from being inherited by child processes.
  736. }
  737. {APR_DECLARE_INHERIT_UNSET(file);
  738. }
  739. {
  740. * Open a temporary file
  741. * @param fp The apr file to use as a temporary file.
  742. * @param templ The template to use when creating a temp file.
  743. * @param flags The flags to open the file with. If this is zero,
  744. * the file is opened with
  745. * APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE
  746. * @param p The pool to allocate the file out of.
  747. * @remark
  748. * This function generates a unique temporary file name from template.
  749. * The last six characters of template must be XXXXXX and these are replaced
  750. * with a string that makes the filename unique. Since it will be modified,
  751. * template must not be a string constant, but should be declared as a character
  752. * array.
  753. *
  754. }
  755. function apr_file_mktemp(fp: PPapr_file_t; templ: PChar;
  756. flags: apr_int32_t; p: Papr_pool_t): apr_status_t;
  757. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  758. external LibAPR name LibNamePrefix + 'apr_file_mktemp' + LibSuff16;
  759. {
  760. * Find an existing directory suitable as a temporary storage location.
  761. * @param temp_dir The temp directory.
  762. * @param p The pool to use for any necessary allocations.
  763. * @remark
  764. * This function uses an algorithm to search for a directory that an
  765. * an application can use for temporary storage. Once such a
  766. * directory is found, that location is cached by the library. Thus,
  767. * callers only pay the cost of this algorithm once if that one time
  768. * is successful.
  769. *
  770. }
  771. function apr_temp_dir_get(const temp_dir: PPChar; p: Papr_pool_t): apr_status_t;
  772. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  773. external LibAPR name LibNamePrefix + 'apr_temp_dir_get' + LibSuff8;