apr_file_io.inc 33 KB

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