Main Page | Modules | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

apr_file_io.h

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