00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_FILE_IO_H 00018 #define APR_FILE_IO_H 00019 00020 /** 00021 * @file apr_file_io.h 00022 * @brief APR File I/O Handling 00023 */ 00024 00025 #include "apr.h" 00026 #include "apr_pools.h" 00027 #include "apr_time.h" 00028 #include "apr_errno.h" 00029 #include "apr_file_info.h" 00030 #include "apr_inherit.h" 00031 00032 #define APR_WANT_STDIO /**< for SEEK_* */ 00033 #define APR_WANT_IOVEC /**< for apr_file_writev */ 00034 #include "apr_want.h" 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif /* __cplusplus */ 00039 00040 /** 00041 * @defgroup apr_file_io File I/O Handling Functions 00042 * @ingroup APR 00043 * @{ 00044 */ 00045 00046 /** 00047 * @defgroup apr_file_open_flags File Open Flags/Routines 00048 * @{ 00049 */ 00050 00051 /* Note to implementors: Values in the range 0x00100000--0x80000000 00052 are reserved for platform-specific values. */ 00053 00054 #define APR_FOPEN_READ 0x00001 /**< Open the file for reading */ 00055 #define APR_FOPEN_WRITE 0x00002 /**< Open the file for writing */ 00056 #define APR_FOPEN_CREATE 0x00004 /**< Create the file if not there */ 00057 #define APR_FOPEN_APPEND 0x00008 /**< Append to the end of the file */ 00058 #define APR_FOPEN_TRUNCATE 0x00010 /**< Open the file and truncate 00059 to 0 length */ 00060 #define APR_FOPEN_BINARY 0x00020 /**< Open the file in binary mode */ 00061 #define APR_FOPEN_EXCL 0x00040 /**< Open should fail if APR_CREATE 00062 and file exists. */ 00063 #define APR_FOPEN_BUFFERED 0x00080 /**< Open the file for buffered I/O */ 00064 #define APR_FOPEN_DELONCLOSE 0x00100 /**< Delete the file after close */ 00065 #define APR_FOPEN_XTHREAD 0x00200 /**< Platform dependent tag to open 00066 the file for use across multiple 00067 threads */ 00068 #define APR_FOPEN_SHARELOCK 0x00400 /**< Platform dependent support for 00069 higher level locked read/write 00070 access to support writes across 00071 process/machines */ 00072 #define APR_FOPEN_NOCLEANUP 0x00800 /**< Do not register a cleanup 00073 when the file is opened */ 00074 #define APR_FOPEN_SENDFILE_ENABLED 0x01000 /**< Advisory flag that this 00075 file should support 00076 apr_socket_sendfile operation */ 00077 #define APR_FOPEN_LARGEFILE 0x04000 /**< Platform dependent flag to enable 00078 large file support; WARNING see 00079 below. */ 00080 /* backcompat */ 00081 #define APR_READ APR_FOPEN_READ /**< @deprecated @see APR_FOPEN_READ */ 00082 #define APR_WRITE APR_FOPEN_WRITE /**< @deprecated @see APR_FOPEN_WRITE */ 00083 #define APR_CREATE APR_FOPEN_CREATE /**< @deprecated @see APR_FOPEN_CREATE */ 00084 #define APR_APPEND APR_FOPEN_APPEND /**< @deprecated @see APR_FOPEN_APPEND */ 00085 #define APR_TRUNCATE APR_FOPEN_TRUNCATE /**< @deprecated @see APR_FOPEN_TRUNCATE */ 00086 #define APR_BINARY APR_FOPEN_BINARY /**< @deprecated @see APR_FOPEN_BINARY */ 00087 #define APR_EXCL APR_FOPEN_EXCL /**< @deprecated @see APR_FOPEN_EXCL */ 00088 #define APR_BUFFERED APR_FOPEN_BUFFERED /**< @deprecated @see APR_FOPEN_BUFFERED */ 00089 #define APR_DELONCLOSE APR_FOPEN_DELONCLOSE /**< @deprecated @see APR_FOPEN_DELONCLOSE */ 00090 #define APR_XTHREAD APR_FOPEN_XTHREAD /**< @deprecated @see APR_FOPEN_XTHREAD */ 00091 #define APR_SHARELOCK APR_FOPEN_SHARELOCK /**< @deprecated @see APR_FOPEN_SHARELOCK */ 00092 #define APR_FILE_NOCLEANUP APR_FOPEN_NOCLEANUP /**< @deprecated @see APR_FOPEN_NOCLEANUP */ 00093 #define APR_SENDFILE_ENABLED APR_FOPEN_SENDFILE_ENABLED /**< @deprecated @see APR_FOPEN_SENDFILE_ENABLED */ 00094 #define APR_LARGEFILE APR_FOPEN_LARGEFILE /**< @deprecated @see APR_FOPEN_LARGEFILE */ 00095 00096 /** @warning The APR_LARGEFILE flag only has effect on some platforms 00097 * where sizeof(apr_off_t) == 4. Where implemented, it allows opening 00098 * and writing to a file which exceeds the size which can be 00099 * represented by apr_off_t (2 gigabytes). When a file's size does 00100 * exceed 2Gb, apr_file_info_get() will fail with an error on the 00101 * descriptor, likewise apr_stat()/apr_lstat() will fail on the 00102 * filename. apr_dir_read() will fail with APR_INCOMPLETE on a 00103 * directory entry for a large file depending on the particular 00104 * APR_FINFO_* flags. Generally, it is not recommended to use this 00105 * flag. */ 00106 00107 /** @} */ 00108 00109 /** 00110 * @defgroup apr_file_seek_flags File Seek Flags 00111 * @{ 00112 */ 00113 00114 /* flags for apr_file_seek */ 00115 /** Set the file position */ 00116 #define APR_SET SEEK_SET 00117 /** Current */ 00118 #define APR_CUR SEEK_CUR 00119 /** Go to end of file */ 00120 #define APR_END SEEK_END 00121 /** @} */ 00122 00123 /** 00124 * @defgroup apr_file_attrs_set_flags File Attribute Flags 00125 * @{ 00126 */ 00127 00128 /* flags for apr_file_attrs_set */ 00129 #define APR_FILE_ATTR_READONLY 0x01 /**< File is read-only */ 00130 #define APR_FILE_ATTR_EXECUTABLE 0x02 /**< File is executable */ 00131 #define APR_FILE_ATTR_HIDDEN 0x04 /**< File is hidden */ 00132 /** @} */ 00133 00134 /** 00135 * @defgroup apr_file_writev{_full} max iovec size 00136 * @{ 00137 */ 00138 #if defined(DOXYGEN) 00139 #define APR_MAX_IOVEC_SIZE 1024 /**< System dependent maximum 00140 size of an iovec array */ 00141 #elif defined(IOV_MAX) 00142 #define APR_MAX_IOVEC_SIZE IOV_MAX 00143 #elif defined(MAX_IOVEC) 00144 #define APR_MAX_IOVEC_SIZE MAX_IOVEC 00145 #else 00146 #define APR_MAX_IOVEC_SIZE 1024 00147 #endif 00148 /** @} */ 00149 00150 /** File attributes */ 00151 typedef apr_uint32_t apr_fileattrs_t; 00152 00153 /** Type to pass as whence argument to apr_file_seek. */ 00154 typedef int apr_seek_where_t; 00155 00156 /** 00157 * Structure for referencing files. 00158 */ 00159 typedef struct apr_file_t apr_file_t; 00160 00161 /* File lock types/flags */ 00162 /** 00163 * @defgroup apr_file_lock_types File Lock Types 00164 * @{ 00165 */ 00166 00167 #define APR_FLOCK_SHARED 1 /**< Shared lock. More than one process 00168 or thread can hold a shared lock 00169 at any given time. Essentially, 00170 this is a "read lock", preventing 00171 writers from establishing an 00172 exclusive lock. */ 00173 #define APR_FLOCK_EXCLUSIVE 2 /**< Exclusive lock. Only one process 00174 may hold an exclusive lock at any 00175 given time. This is analogous to 00176 a "write lock". */ 00177 00178 #define APR_FLOCK_TYPEMASK 0x000F /**< mask to extract lock type */ 00179 #define APR_FLOCK_NONBLOCK 0x0010 /**< do not block while acquiring the 00180 file lock */ 00181 /** @} */ 00182 00183 /** 00184 * Open the specified file. 00185 * @param newf The opened file descriptor. 00186 * @param fname The full path to the file (using / on all systems) 00187 * @param flag Or'ed value of: 00188 * <PRE> 00189 * APR_READ open for reading 00190 * APR_WRITE open for writing 00191 * APR_CREATE create the file if not there 00192 * APR_APPEND file ptr is set to end prior to all writes 00193 * APR_TRUNCATE set length to zero if file exists 00194 * APR_BINARY not a text file (This flag is ignored on 00195 * UNIX because it has no meaning) 00196 * APR_BUFFERED buffer the data. Default is non-buffered 00197 * APR_EXCL return error if APR_CREATE and file exists 00198 * APR_DELONCLOSE delete the file after closing. 00199 * APR_XTHREAD Platform dependent tag to open the file 00200 * for use across multiple threads 00201 * APR_SHARELOCK Platform dependent support for higher 00202 * level locked read/write access to support 00203 * writes across process/machines 00204 * APR_FILE_NOCLEANUP Do not register a cleanup with the pool 00205 * passed in on the <EM>pool</EM> argument (see below). 00206 * The apr_os_file_t handle in apr_file_t will not 00207 * be closed when the pool is destroyed. 00208 * APR_SENDFILE_ENABLED Open with appropriate platform semantics 00209 * for sendfile operations. Advisory only, 00210 * apr_socket_sendfile does not check this flag. 00211 * </PRE> 00212 * @param perm Access permissions for file. 00213 * @param pool The pool to use. 00214 * @remark If perm is APR_OS_DEFAULT and the file is being created, 00215 * appropriate default permissions will be used. 00216 * @remark By default, the returned file descriptor will not be 00217 * inherited by child processes created by apr_proc_create(). This 00218 * can be changed using apr_file_inherit_set(). 00219 */ 00220 APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **newf, const char *fname, 00221 apr_int32_t flag, apr_fileperms_t perm, 00222 apr_pool_t *pool); 00223 00224 /** 00225 * Close the specified file. 00226 * @param file The file descriptor to close. 00227 */ 00228 APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file); 00229 00230 /** 00231 * Delete the specified file. 00232 * @param path The full path to the file (using / on all systems) 00233 * @param pool The pool to use. 00234 * @remark If the file is open, it won't be removed until all 00235 * instances are closed. 00236 */ 00237 APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool); 00238 00239 /** 00240 * Rename the specified file. 00241 * @param from_path The full path to the original file (using / on all systems) 00242 * @param to_path The full path to the new file (using / on all systems) 00243 * @param pool The pool to use. 00244 * @warning If a file exists at the new location, then it will be 00245 * overwritten. Moving files or directories across devices may not be 00246 * possible. 00247 */ 00248 APR_DECLARE(apr_status_t) apr_file_rename(const char *from_path, 00249 const char *to_path, 00250 apr_pool_t *pool); 00251 00252 /** 00253 * Copy the specified file to another file. 00254 * @param from_path The full path to the original file (using / on all systems) 00255 * @param to_path The full path to the new file (using / on all systems) 00256 * @param perms Access permissions for the new file if it is created. 00257 * In place of the usual or'd combination of file permissions, the 00258 * value APR_FILE_SOURCE_PERMS may be given, in which case the source 00259 * file's permissions are copied. 00260 * @param pool The pool to use. 00261 * @remark The new file does not need to exist, it will be created if required. 00262 * @warning If the new file already exists, its contents will be overwritten. 00263 */ 00264 APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path, 00265 const char *to_path, 00266 apr_fileperms_t perms, 00267 apr_pool_t *pool); 00268 00269 /** 00270 * Append the specified file to another file. 00271 * @param from_path The full path to the source file (use / on all systems) 00272 * @param to_path The full path to the destination file (use / on all systems) 00273 * @param perms Access permissions for the destination file if it is created. 00274 * In place of the usual or'd combination of file permissions, the 00275 * value APR_FILE_SOURCE_PERMS may be given, in which case the source 00276 * file's permissions are copied. 00277 * @param pool The pool to use. 00278 * @remark The new file does not need to exist, it will be created if required. 00279 */ 00280 APR_DECLARE(apr_status_t) apr_file_append(const char *from_path, 00281 const char *to_path, 00282 apr_fileperms_t perms, 00283 apr_pool_t *pool); 00284 00285 /** 00286 * Are we at the end of the file 00287 * @param fptr The apr file we are testing. 00288 * @remark Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise. 00289 */ 00290 APR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr); 00291 00292 /** 00293 * Open standard error as an apr file pointer. 00294 * @param thefile The apr file to use as stderr. 00295 * @param pool The pool to allocate the file out of. 00296 * 00297 * @remark The only reason that the apr_file_open_std* functions exist 00298 * is that you may not always have a stderr/out/in on Windows. This 00299 * is generally a problem with newer versions of Windows and services. 00300 * 00301 * @remark The other problem is that the C library functions generally work 00302 * differently on Windows and Unix. So, by using apr_file_open_std* 00303 * functions, you can get a handle to an APR struct that works with 00304 * the APR functions which are supposed to work identically on all 00305 * platforms. 00306 */ 00307 APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, 00308 apr_pool_t *pool); 00309 00310 /** 00311 * open standard output as an apr file pointer. 00312 * @param thefile The apr file to use as stdout. 00313 * @param pool The pool to allocate the file out of. 00314 * 00315 * @remark See remarks for apr_file_open_stdout. 00316 */ 00317 APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, 00318 apr_pool_t *pool); 00319 00320 /** 00321 * open standard input as an apr file pointer. 00322 * @param thefile The apr file to use as stdin. 00323 * @param pool The pool to allocate the file out of. 00324 * 00325 * @remark See remarks for apr_file_open_stdout. 00326 */ 00327 APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, 00328 apr_pool_t *pool); 00329 00330 /** 00331 * Read data from the specified file. 00332 * @param thefile The file descriptor to read from. 00333 * @param buf The buffer to store the data to. 00334 * @param nbytes On entry, the number of bytes to read; on exit, the number 00335 * of bytes read. 00336 * 00337 * @remark apr_file_read will read up to the specified number of 00338 * bytes, but never more. If there isn't enough data to fill that 00339 * number of bytes, all of the available data is read. The third 00340 * argument is modified to reflect the number of bytes read. If a 00341 * char was put back into the stream via ungetc, it will be the first 00342 * character returned. 00343 * 00344 * @remark It is not possible for both bytes to be read and an APR_EOF 00345 * or other error to be returned. APR_EINTR is never returned. 00346 */ 00347 APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, 00348 apr_size_t *nbytes); 00349 00350 /** 00351 * Write data to the specified file. 00352 * @param thefile The file descriptor to write to. 00353 * @param buf The buffer which contains the data. 00354 * @param nbytes On entry, the number of bytes to write; on exit, the number 00355 * of bytes written. 00356 * 00357 * @remark apr_file_write will write up to the specified number of 00358 * bytes, but never more. If the OS cannot write that many bytes, it 00359 * will write as many as it can. The third argument is modified to 00360 * reflect the * number of bytes written. 00361 * 00362 * @remark It is possible for both bytes to be written and an error to 00363 * be returned. APR_EINTR is never returned. 00364 */ 00365 APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, 00366 apr_size_t *nbytes); 00367 00368 /** 00369 * Write data from iovec array to the specified file. 00370 * @param thefile The file descriptor to write to. 00371 * @param vec The array from which to get the data to write to the file. 00372 * @param nvec The number of elements in the struct iovec array. This must 00373 * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function 00374 * will fail with APR_EINVAL. 00375 * @param nbytes The number of bytes written. 00376 * 00377 * @remark It is possible for both bytes to be written and an error to 00378 * be returned. APR_EINTR is never returned. 00379 * 00380 * @remark apr_file_writev is available even if the underlying 00381 * operating system doesn't provide writev(). 00382 */ 00383 APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, 00384 const struct iovec *vec, 00385 apr_size_t nvec, apr_size_t *nbytes); 00386 00387 /** 00388 * Read data from the specified file, ensuring that the buffer is filled 00389 * before returning. 00390 * @param thefile The file descriptor to read from. 00391 * @param buf The buffer to store the data to. 00392 * @param nbytes The number of bytes to read. 00393 * @param bytes_read If non-NULL, this will contain the number of bytes read. 00394 * 00395 * @remark apr_file_read will read up to the specified number of 00396 * bytes, but never more. If there isn't enough data to fill that 00397 * number of bytes, then the process/thread will block until it is 00398 * available or EOF is reached. If a char was put back into the 00399 * stream via ungetc, it will be the first character returned. 00400 * 00401 * @remark It is possible for both bytes to be read and an error to be 00402 * returned. And if *bytes_read is less than nbytes, an accompanying 00403 * error is _always_ returned. 00404 * 00405 * @remark APR_EINTR is never returned. 00406 */ 00407 APR_DECLARE(apr_status_t) apr_file_read_full(apr_file_t *thefile, void *buf, 00408 apr_size_t nbytes, 00409 apr_size_t *bytes_read); 00410 00411 /** 00412 * Write data to the specified file, ensuring that all of the data is 00413 * written before returning. 00414 * @param thefile The file descriptor to write to. 00415 * @param buf The buffer which contains the data. 00416 * @param nbytes The number of bytes to write. 00417 * @param bytes_written If non-NULL, set to the number of bytes written. 00418 * 00419 * @remark apr_file_write will write up to the specified number of 00420 * bytes, but never more. If the OS cannot write that many bytes, the 00421 * process/thread will block until they can be written. Exceptional 00422 * error such as "out of space" or "pipe closed" will terminate with 00423 * an error. 00424 * 00425 * @remark It is possible for both bytes to be written and an error to 00426 * be returned. And if *bytes_written is less than nbytes, an 00427 * accompanying error is _always_ returned. 00428 * 00429 * @remark APR_EINTR is never returned. 00430 */ 00431 APR_DECLARE(apr_status_t) apr_file_write_full(apr_file_t *thefile, 00432 const void *buf, 00433 apr_size_t nbytes, 00434 apr_size_t *bytes_written); 00435 00436 00437 /** 00438 * Write data from iovec array to the specified file, ensuring that all of the 00439 * data is written before returning. 00440 * @param thefile The file descriptor to write to. 00441 * @param vec The array from which to get the data to write to the file. 00442 * @param nvec The number of elements in the struct iovec array. This must 00443 * be smaller than APR_MAX_IOVEC_SIZE. If it isn't, the function 00444 * will fail with APR_EINVAL. 00445 * @param nbytes The number of bytes written. 00446 * 00447 * @remark apr_file_writev_full is available even if the underlying 00448 * operating system doesn't provide writev(). 00449 */ 00450 APR_DECLARE(apr_status_t) apr_file_writev_full(apr_file_t *thefile, 00451 const struct iovec *vec, 00452 apr_size_t nvec, 00453 apr_size_t *nbytes); 00454 /** 00455 * Write a character into the specified file. 00456 * @param ch The character to write. 00457 * @param thefile The file descriptor to write to 00458 */ 00459 APR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile); 00460 00461 /** 00462 * Read a character from the specified file. 00463 * @param ch The character to read into 00464 * @param thefile The file descriptor to read from 00465 */ 00466 APR_DECLARE(apr_status_t) apr_file_getc(char *ch, apr_file_t *thefile); 00467 00468 /** 00469 * Put a character back onto a specified stream. 00470 * @param ch The character to write. 00471 * @param thefile The file descriptor to write to 00472 */ 00473 APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile); 00474 00475 /** 00476 * Read a string from the specified file. 00477 * @param str The buffer to store the string in. 00478 * @param len The length of the string 00479 * @param thefile The file descriptor to read from 00480 * @remark The buffer will be NUL-terminated if any characters are stored. 00481 */ 00482 APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, 00483 apr_file_t *thefile); 00484 00485 /** 00486 * Write the string into the specified file. 00487 * @param str The string to write. 00488 * @param thefile The file descriptor to write to 00489 */ 00490 APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile); 00491 00492 /** 00493 * Flush the file's buffer. 00494 * @param thefile The file descriptor to flush 00495 */ 00496 APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile); 00497 00498 /** 00499 * Duplicate the specified file descriptor. 00500 * @param new_file The structure to duplicate into. 00501 * @param old_file The file to duplicate. 00502 * @param p The pool to use for the new file. 00503 * @remark *new_file must point to a valid apr_file_t, or point to NULL. 00504 */ 00505 APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file, 00506 apr_file_t *old_file, 00507 apr_pool_t *p); 00508 00509 /** 00510 * Duplicate the specified file descriptor and close the original 00511 * @param new_file The old file that is to be closed and reused 00512 * @param old_file The file to duplicate 00513 * @param p The pool to use for the new file 00514 * 00515 * @remark new_file MUST point at a valid apr_file_t. It cannot be NULL. 00516 */ 00517 APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file, 00518 apr_file_t *old_file, 00519 apr_pool_t *p); 00520 00521 /** 00522 * Move the specified file descriptor to a new pool 00523 * @param new_file Pointer in which to return the new apr_file_t 00524 * @param old_file The file to move 00525 * @param p The pool to which the descriptor is to be moved 00526 * @remark Unlike apr_file_dup2(), this function doesn't do an 00527 * OS dup() operation on the underlying descriptor; it just 00528 * moves the descriptor's apr_file_t wrapper to a new pool. 00529 * @remark The new pool need not be an ancestor of old_file's pool. 00530 * @remark After calling this function, old_file may not be used 00531 */ 00532 APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, 00533 apr_file_t *old_file, 00534 apr_pool_t *p); 00535 00536 /** 00537 * Move the read/write file offset to a specified byte within a file. 00538 * @param thefile The file descriptor 00539 * @param where How to move the pointer, one of: 00540 * <PRE> 00541 * APR_SET -- set the offset to offset 00542 * APR_CUR -- add the offset to the current position 00543 * APR_END -- add the offset to the current file size 00544 * </PRE> 00545 * @param offset The offset to move the pointer to. 00546 * @remark The third argument is modified to be the offset the pointer 00547 was actually moved to. 00548 */ 00549 APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, 00550 apr_seek_where_t where, 00551 apr_off_t *offset); 00552 00553 /** 00554 * Create an anonymous pipe. 00555 * @param in The file descriptor to use as input to the pipe. 00556 * @param out The file descriptor to use as output from the pipe. 00557 * @param pool The pool to operate on. 00558 * @remark By default, the returned file descriptors will be inherited 00559 * by child processes created using apr_proc_create(). This can be 00560 * changed using apr_file_inherit_unset(). 00561 */ 00562 APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, 00563 apr_file_t **out, 00564 apr_pool_t *pool); 00565 00566 /** 00567 * Create a named pipe. 00568 * @param filename The filename of the named pipe 00569 * @param perm The permissions for the newly created pipe. 00570 * @param pool The pool to operate on. 00571 */ 00572 APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, 00573 apr_fileperms_t perm, 00574 apr_pool_t *pool); 00575 00576 /** 00577 * Get the timeout value for a pipe or manipulate the blocking state. 00578 * @param thepipe The pipe we are getting a timeout for. 00579 * @param timeout The current timeout value in microseconds. 00580 */ 00581 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe, 00582 apr_interval_time_t *timeout); 00583 00584 /** 00585 * Set the timeout value for a pipe or manipulate the blocking state. 00586 * @param thepipe The pipe we are setting a timeout on. 00587 * @param timeout The timeout value in microseconds. Values < 0 mean wait 00588 * forever, 0 means do not wait at all. 00589 */ 00590 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, 00591 apr_interval_time_t timeout); 00592 00593 /** file (un)locking functions. */ 00594 00595 /** 00596 * Establish a lock on the specified, open file. The lock may be advisory 00597 * or mandatory, at the discretion of the platform. The lock applies to 00598 * the file as a whole, rather than a specific range. Locks are established 00599 * on a per-thread/process basis; a second lock by the same thread will not 00600 * block. 00601 * @param thefile The file to lock. 00602 * @param type The type of lock to establish on the file. 00603 */ 00604 APR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *thefile, int type); 00605 00606 /** 00607 * Remove any outstanding locks on the file. 00608 * @param thefile The file to unlock. 00609 */ 00610 APR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *thefile); 00611 00612 /**accessor and general file_io functions. */ 00613 00614 /** 00615 * return the file name of the current file. 00616 * @param new_path The path of the file. 00617 * @param thefile The currently open file. 00618 */ 00619 APR_DECLARE(apr_status_t) apr_file_name_get(const char **new_path, 00620 apr_file_t *thefile); 00621 00622 /** 00623 * Return the data associated with the current file. 00624 * @param data The user data associated with the file. 00625 * @param key The key to use for retreiving data associated with this file. 00626 * @param file The currently open file. 00627 */ 00628 APR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key, 00629 apr_file_t *file); 00630 00631 /** 00632 * Set the data associated with the current file. 00633 * @param file The currently open file. 00634 * @param data The user data to associate with the file. 00635 * @param key The key to use for assocaiteing data with the file. 00636 * @param cleanup The cleanup routine to use when the file is destroyed. 00637 */ 00638 APR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data, 00639 const char *key, 00640 apr_status_t (*cleanup)(void *)); 00641 00642 /** 00643 * Write a string to a file using a printf format. 00644 * @param fptr The file to write to. 00645 * @param format The format string 00646 * @param ... The values to substitute in the format string 00647 * @return The number of bytes written 00648 */ 00649 APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr, 00650 const char *format, ...) 00651 __attribute__((format(printf,2,3))); 00652 00653 /** 00654 * set the specified file's permission bits. 00655 * @param fname The file (name) to apply the permissions to. 00656 * @param perms The permission bits to apply to the file. 00657 * 00658 * @warning Some platforms may not be able to apply all of the 00659 * available permission bits; APR_INCOMPLETE will be returned if some 00660 * permissions are specified which could not be set. 00661 * 00662 * @warning Platforms which do not implement this feature will return 00663 * APR_ENOTIMPL. 00664 */ 00665 APR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname, 00666 apr_fileperms_t perms); 00667 00668 /** 00669 * Set attributes of the specified file. 00670 * @param fname The full path to the file (using / on all systems) 00671 * @param attributes Or'd combination of 00672 * <PRE> 00673 * APR_FILE_ATTR_READONLY - make the file readonly 00674 * APR_FILE_ATTR_EXECUTABLE - make the file executable 00675 * APR_FILE_ATTR_HIDDEN - make the file hidden 00676 * </PRE> 00677 * @param attr_mask Mask of valid bits in attributes. 00678 * @param pool the pool to use. 00679 * @remark This function should be used in preference to explict manipulation 00680 * of the file permissions, because the operations to provide these 00681 * attributes are platform specific and may involve more than simply 00682 * setting permission bits. 00683 * @warning Platforms which do not implement this feature will return 00684 * APR_ENOTIMPL. 00685 */ 00686 APR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname, 00687 apr_fileattrs_t attributes, 00688 apr_fileattrs_t attr_mask, 00689 apr_pool_t *pool); 00690 00691 /** 00692 * Set the mtime of the specified file. 00693 * @param fname The full path to the file (using / on all systems) 00694 * @param mtime The mtime to apply to the file. 00695 * @param pool The pool to use. 00696 * @warning Platforms which do not implement this feature will return 00697 * APR_ENOTIMPL. 00698 */ 00699 APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname, 00700 apr_time_t mtime, 00701 apr_pool_t *pool); 00702 00703 /** 00704 * Create a new directory on the file system. 00705 * @param path the path for the directory to be created. (use / on all systems) 00706 * @param perm Permissions for the new direcoty. 00707 * @param pool the pool to use. 00708 */ 00709 APR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t perm, 00710 apr_pool_t *pool); 00711 00712 /** Creates a new directory on the file system, but behaves like 00713 * 'mkdir -p'. Creates intermediate directories as required. No error 00714 * will be reported if PATH already exists. 00715 * @param path the path for the directory to be created. (use / on all systems) 00716 * @param perm Permissions for the new direcoty. 00717 * @param pool the pool to use. 00718 */ 00719 APR_DECLARE(apr_status_t) apr_dir_make_recursive(const char *path, 00720 apr_fileperms_t perm, 00721 apr_pool_t *pool); 00722 00723 /** 00724 * Remove directory from the file system. 00725 * @param path the path for the directory to be removed. (use / on all systems) 00726 * @param pool the pool to use. 00727 * @remark Removing a directory which is in-use (e.g., the current working 00728 * directory, or during apr_dir_read, or with an open file) is not portable. 00729 */ 00730 APR_DECLARE(apr_status_t) apr_dir_remove(const char *path, apr_pool_t *pool); 00731 00732 /** 00733 * get the specified file's stats. 00734 * @param finfo Where to store the information about the file. 00735 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values 00736 * @param thefile The file to get information about. 00737 */ 00738 APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, 00739 apr_int32_t wanted, 00740 apr_file_t *thefile); 00741 00742 00743 /** 00744 * Truncate the file's length to the specified offset 00745 * @param fp The file to truncate 00746 * @param offset The offset to truncate to. 00747 * @remark The read/write file offset is repositioned to offset. 00748 */ 00749 APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *fp, apr_off_t offset); 00750 00751 /** 00752 * Retrieve the flags that were passed into apr_file_open() 00753 * when the file was opened. 00754 * @return apr_int32_t the flags 00755 */ 00756 APR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f); 00757 00758 /** 00759 * Get the pool used by the file. 00760 */ 00761 APR_POOL_DECLARE_ACCESSOR(file); 00762 00763 /** 00764 * Set a file to be inherited by child processes. 00765 * 00766 */ 00767 APR_DECLARE_INHERIT_SET(file); 00768 00769 /** 00770 * Unset a file from being inherited by child processes. 00771 */ 00772 APR_DECLARE_INHERIT_UNSET(file); 00773 00774 /** 00775 * Open a temporary file 00776 * @param fp The apr file to use as a temporary file. 00777 * @param templ The template to use when creating a temp file. 00778 * @param flags The flags to open the file with. If this is zero, 00779 * the file is opened with 00780 * APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE 00781 * @param p The pool to allocate the file out of. 00782 * @remark 00783 * This function generates a unique temporary file name from template. 00784 * The last six characters of template must be XXXXXX and these are replaced 00785 * with a string that makes the filename unique. Since it will be modified, 00786 * template must not be a string constant, but should be declared as a character 00787 * array. 00788 * 00789 */ 00790 APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *templ, 00791 apr_int32_t flags, apr_pool_t *p); 00792 00793 00794 /** 00795 * Find an existing directory suitable as a temporary storage location. 00796 * @param temp_dir The temp directory. 00797 * @param p The pool to use for any necessary allocations. 00798 * @remark 00799 * This function uses an algorithm to search for a directory that an 00800 * an application can use for temporary storage. Once such a 00801 * directory is found, that location is cached by the library. Thus, 00802 * callers only pay the cost of this algorithm once if that one time 00803 * is successful. 00804 * 00805 */ 00806 APR_DECLARE(apr_status_t) apr_temp_dir_get(const char **temp_dir, 00807 apr_pool_t *p); 00808 00809 /** @} */ 00810 00811 #ifdef __cplusplus 00812 } 00813 #endif 00814 00815 #endif /* ! APR_FILE_IO_H */