1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251875Speter * contributor license agreements.  See the NOTICE file distributed with
3251875Speter * this work for additional information regarding copyright ownership.
4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251875Speter * (the "License"); you may not use this file except in compliance with
6251875Speter * the License.  You may obtain a copy of the License at
7251875Speter *
8251875Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251875Speter *
10251875Speter * Unless required by applicable law or agreed to in writing, software
11251875Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251875Speter * See the License for the specific language governing permissions and
14251875Speter * limitations under the License.
15251875Speter */
16251875Speter
17251875Speter#ifndef APR_FILE_IO_H
18251875Speter#define APR_FILE_IO_H
19251875Speter
20251875Speter/**
21251875Speter * @file apr_file_io.h
22251875Speter * @brief APR File I/O Handling
23251875Speter */
24251875Speter
25251875Speter#include "apr.h"
26251875Speter#include "apr_pools.h"
27251875Speter#include "apr_time.h"
28251875Speter#include "apr_errno.h"
29251875Speter#include "apr_file_info.h"
30251875Speter#include "apr_inherit.h"
31251875Speter
32251875Speter#define APR_WANT_STDIO          /**< for SEEK_* */
33251875Speter#define APR_WANT_IOVEC          /**< for apr_file_writev */
34251875Speter#include "apr_want.h"
35251875Speter
36251875Speter#ifdef __cplusplus
37251875Speterextern "C" {
38251875Speter#endif /* __cplusplus */
39251875Speter
40251875Speter/**
41251875Speter * @defgroup apr_file_io File I/O Handling Functions
42251875Speter * @ingroup APR
43251875Speter * @{
44251875Speter */
45251875Speter
46251875Speter/**
47251875Speter * @defgroup apr_file_open_flags File Open Flags/Routines
48251875Speter * @{
49251875Speter */
50251875Speter
51251875Speter/* Note to implementors: Values in the range 0x00100000--0x80000000
52251875Speter   are reserved for platform-specific values. */
53251875Speter
54251875Speter#define APR_FOPEN_READ       0x00001  /**< Open the file for reading */
55251875Speter#define APR_FOPEN_WRITE      0x00002  /**< Open the file for writing */
56251875Speter#define APR_FOPEN_CREATE     0x00004  /**< Create the file if not there */
57251875Speter#define APR_FOPEN_APPEND     0x00008  /**< Append to the end of the file */
58251875Speter#define APR_FOPEN_TRUNCATE   0x00010  /**< Open the file and truncate
59251875Speter                                         to 0 length */
60269847Speter#define APR_FOPEN_BINARY     0x00020  /**< Open the file in binary mode
61269847Speter				         (This flag is ignored on UNIX
62269847Speter					 because it has no meaning)*/
63269847Speter#define APR_FOPEN_EXCL       0x00040  /**< Open should fail if #APR_FOPEN_CREATE
64251875Speter                                         and file exists. */
65251875Speter#define APR_FOPEN_BUFFERED   0x00080  /**< Open the file for buffered I/O */
66251875Speter#define APR_FOPEN_DELONCLOSE 0x00100  /**< Delete the file after close */
67251875Speter#define APR_FOPEN_XTHREAD    0x00200  /**< Platform dependent tag to open
68251875Speter                                         the file for use across multiple
69251875Speter                                         threads */
70251875Speter#define APR_FOPEN_SHARELOCK  0x00400  /**< Platform dependent support for
71251875Speter                                         higher level locked read/write
72251875Speter                                         access to support writes across
73251875Speter                                         process/machines */
74251875Speter#define APR_FOPEN_NOCLEANUP  0x00800  /**< Do not register a cleanup
75269847Speter                                         when the file is opened. The
76269847Speter					 apr_os_file_t handle in apr_file_t
77269847Speter					 will not be closed when the pool
78269847Speter					 is destroyed. */
79251875Speter#define APR_FOPEN_SENDFILE_ENABLED 0x01000 /**< Advisory flag that this
80251875Speter                                             file should support
81251875Speter                                             apr_socket_sendfile operation */
82251875Speter#define APR_FOPEN_LARGEFILE   0x04000 /**< Platform dependent flag to enable
83251875Speter                                       * large file support, see WARNING below
84251875Speter                                       */
85251875Speter#define APR_FOPEN_SPARSE      0x08000 /**< Platform dependent flag to enable
86251875Speter                                       * sparse file support, see WARNING below
87251875Speter                                       */
88269847Speter#define APR_FOPEN_NONBLOCK    0x40000 /**< Platform dependent flag to enable
89269847Speter                                       * non blocking file io */
90251875Speter
91269847Speter
92251875Speter/* backcompat */
93251875Speter#define APR_READ             APR_FOPEN_READ       /**< @deprecated @see APR_FOPEN_READ */
94251875Speter#define APR_WRITE            APR_FOPEN_WRITE      /**< @deprecated @see APR_FOPEN_WRITE */
95251875Speter#define APR_CREATE           APR_FOPEN_CREATE     /**< @deprecated @see APR_FOPEN_CREATE */
96251875Speter#define APR_APPEND           APR_FOPEN_APPEND     /**< @deprecated @see APR_FOPEN_APPEND */
97251875Speter#define APR_TRUNCATE         APR_FOPEN_TRUNCATE   /**< @deprecated @see APR_FOPEN_TRUNCATE */
98251875Speter#define APR_BINARY           APR_FOPEN_BINARY     /**< @deprecated @see APR_FOPEN_BINARY */
99251875Speter#define APR_EXCL             APR_FOPEN_EXCL       /**< @deprecated @see APR_FOPEN_EXCL */
100251875Speter#define APR_BUFFERED         APR_FOPEN_BUFFERED   /**< @deprecated @see APR_FOPEN_BUFFERED */
101251875Speter#define APR_DELONCLOSE       APR_FOPEN_DELONCLOSE /**< @deprecated @see APR_FOPEN_DELONCLOSE */
102251875Speter#define APR_XTHREAD          APR_FOPEN_XTHREAD    /**< @deprecated @see APR_FOPEN_XTHREAD */
103251875Speter#define APR_SHARELOCK        APR_FOPEN_SHARELOCK  /**< @deprecated @see APR_FOPEN_SHARELOCK */
104251875Speter#define APR_FILE_NOCLEANUP   APR_FOPEN_NOCLEANUP  /**< @deprecated @see APR_FOPEN_NOCLEANUP */
105251875Speter#define APR_SENDFILE_ENABLED APR_FOPEN_SENDFILE_ENABLED /**< @deprecated @see APR_FOPEN_SENDFILE_ENABLED */
106251875Speter#define APR_LARGEFILE        APR_FOPEN_LARGEFILE  /**< @deprecated @see APR_FOPEN_LARGEFILE */
107251875Speter
108269847Speter/** @def APR_FOPEN_LARGEFILE
109269847Speter * @warning APR_FOPEN_LARGEFILE flag only has effect on some
110251875Speter * platforms where sizeof(apr_off_t) == 4.  Where implemented, it
111251875Speter * allows opening and writing to a file which exceeds the size which
112251875Speter * can be represented by apr_off_t (2 gigabytes).  When a file's size
113251875Speter * does exceed 2Gb, apr_file_info_get() will fail with an error on the
114251875Speter * descriptor, likewise apr_stat()/apr_lstat() will fail on the
115269847Speter * filename.  apr_dir_read() will fail with #APR_INCOMPLETE on a
116251875Speter * directory entry for a large file depending on the particular
117251875Speter * APR_FINFO_* flags.  Generally, it is not recommended to use this
118251875Speter * flag.
119251875Speter *
120269847Speter * @def APR_FOPEN_SPARSE
121251875Speter * @warning APR_FOPEN_SPARSE may, depending on platform, convert a
122251875Speter * normal file to a sparse file.  Some applications may be unable
123251875Speter * to decipher a sparse file, so it's critical that the sparse file
124251875Speter * flag should only be used for files accessed only by APR or other
125251875Speter * applications known to be able to decipher them.  APR does not
126251875Speter * guarantee that it will compress the file into sparse segments
127251875Speter * if it was previously created and written without the sparse flag.
128251875Speter * On platforms which do not understand, or on file systems which
129251875Speter * cannot handle sparse files, the flag is ignored by apr_file_open().
130269847Speter *
131269847Speter * @def APR_FOPEN_NONBLOCK
132269847Speter * @warning APR_FOPEN_NONBLOCK is not implemented on all platforms.
133269847Speter * Callers should be prepared for it to fail with #APR_ENOTIMPL.
134251875Speter */
135251875Speter
136251875Speter/** @} */
137251875Speter
138251875Speter/**
139251875Speter * @defgroup apr_file_seek_flags File Seek Flags
140251875Speter * @{
141251875Speter */
142251875Speter
143251875Speter/* flags for apr_file_seek */
144251875Speter/** Set the file position */
145251875Speter#define APR_SET SEEK_SET
146251875Speter/** Current */
147251875Speter#define APR_CUR SEEK_CUR
148251875Speter/** Go to end of file */
149251875Speter#define APR_END SEEK_END
150251875Speter/** @} */
151251875Speter
152251875Speter/**
153251875Speter * @defgroup apr_file_attrs_set_flags File Attribute Flags
154251875Speter * @{
155251875Speter */
156251875Speter
157251875Speter/* flags for apr_file_attrs_set */
158251875Speter#define APR_FILE_ATTR_READONLY   0x01          /**< File is read-only */
159251875Speter#define APR_FILE_ATTR_EXECUTABLE 0x02          /**< File is executable */
160251875Speter#define APR_FILE_ATTR_HIDDEN     0x04          /**< File is hidden */
161251875Speter/** @} */
162251875Speter
163251875Speter/**
164251875Speter * @defgroup apr_file_writev{_full} max iovec size
165251875Speter * @{
166251875Speter */
167251875Speter#if defined(DOXYGEN)
168251875Speter#define APR_MAX_IOVEC_SIZE 1024                /**< System dependent maximum
169251875Speter                                                    size of an iovec array */
170251875Speter#elif defined(IOV_MAX)
171251875Speter#define APR_MAX_IOVEC_SIZE IOV_MAX
172251875Speter#elif defined(MAX_IOVEC)
173251875Speter#define APR_MAX_IOVEC_SIZE MAX_IOVEC
174251875Speter#else
175251875Speter#define APR_MAX_IOVEC_SIZE 1024
176251875Speter#endif
177251875Speter/** @} */
178251875Speter
179251875Speter/** File attributes */
180251875Spetertypedef apr_uint32_t apr_fileattrs_t;
181251875Speter
182251875Speter/** Type to pass as whence argument to apr_file_seek. */
183251875Spetertypedef int       apr_seek_where_t;
184251875Speter
185251875Speter/**
186251875Speter * Structure for referencing files.
187251875Speter */
188251875Spetertypedef struct apr_file_t         apr_file_t;
189251875Speter
190251875Speter/* File lock types/flags */
191251875Speter/**
192251875Speter * @defgroup apr_file_lock_types File Lock Types
193251875Speter * @{
194251875Speter */
195251875Speter
196251875Speter#define APR_FLOCK_SHARED        1       /**< Shared lock. More than one process
197251875Speter                                           or thread can hold a shared lock
198251875Speter                                           at any given time. Essentially,
199251875Speter                                           this is a "read lock", preventing
200251875Speter                                           writers from establishing an
201251875Speter                                           exclusive lock. */
202251875Speter#define APR_FLOCK_EXCLUSIVE     2       /**< Exclusive lock. Only one process
203251875Speter                                           may hold an exclusive lock at any
204251875Speter                                           given time. This is analogous to
205251875Speter                                           a "write lock". */
206251875Speter
207251875Speter#define APR_FLOCK_TYPEMASK      0x000F  /**< mask to extract lock type */
208251875Speter#define APR_FLOCK_NONBLOCK      0x0010  /**< do not block while acquiring the
209251875Speter                                           file lock */
210251875Speter/** @} */
211251875Speter
212251875Speter/**
213251875Speter * Open the specified file.
214251875Speter * @param newf The opened file descriptor.
215251875Speter * @param fname The full path to the file (using / on all systems)
216251875Speter * @param flag Or'ed value of:
217269847Speter * @li #APR_FOPEN_READ           open for reading
218269847Speter * @li #APR_FOPEN_WRITE          open for writing
219269847Speter * @li #APR_FOPEN_CREATE         create the file if not there
220269847Speter * @li #APR_FOPEN_APPEND         file ptr is set to end prior to all writes
221269847Speter * @li #APR_FOPEN_TRUNCATE       set length to zero if file exists
222269847Speter * @li #APR_FOPEN_BINARY         not a text file
223269847Speter * @li #APR_FOPEN_BUFFERED       buffer the data.  Default is non-buffered
224269847Speter * @li #APR_FOPEN_EXCL           return error if #APR_FOPEN_CREATE and file exists
225269847Speter * @li #APR_FOPEN_DELONCLOSE     delete the file after closing
226269847Speter * @li #APR_FOPEN_XTHREAD        Platform dependent tag to open the file
227251875Speter *                               for use across multiple threads
228269847Speter * @li #APR_FOPEN_SHARELOCK      Platform dependent support for higher
229251875Speter *                               level locked read/write access to support
230251875Speter *                               writes across process/machines
231269847Speter * @li #APR_FOPEN_NOCLEANUP      Do not register a cleanup with the pool
232269847Speter *                               passed in on the @a pool argument (see below)
233269847Speter * @li #APR_FOPEN_SENDFILE_ENABLED  Open with appropriate platform semantics
234251875Speter *                               for sendfile operations.  Advisory only,
235269847Speter *                               apr_socket_sendfile does not check this flag
236269847Speter * @li #APR_FOPEN_LARGEFILE      Platform dependent flag to enable large file
237269847Speter *                               support, see WARNING below
238269847Speter * @li #APR_FOPEN_SPARSE         Platform dependent flag to enable sparse file
239269847Speter *                               support, see WARNING below
240269847Speter * @li #APR_FOPEN_NONBLOCK       Platform dependent flag to enable
241269847Speter *                               non blocking file io
242251875Speter * @param perm Access permissions for file.
243251875Speter * @param pool The pool to use.
244269847Speter * @remark If perm is #APR_FPROT_OS_DEFAULT and the file is being created,
245251875Speter * appropriate default permissions will be used.
246251875Speter * @remark By default, the returned file descriptor will not be
247251875Speter * inherited by child processes created by apr_proc_create().  This
248251875Speter * can be changed using apr_file_inherit_set().
249251875Speter */
250251875SpeterAPR_DECLARE(apr_status_t) apr_file_open(apr_file_t **newf, const char *fname,
251251875Speter                                        apr_int32_t flag, apr_fileperms_t perm,
252251875Speter                                        apr_pool_t *pool);
253251875Speter
254251875Speter/**
255251875Speter * Close the specified file.
256251875Speter * @param file The file descriptor to close.
257251875Speter */
258251875SpeterAPR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file);
259251875Speter
260251875Speter/**
261251875Speter * Delete the specified file.
262251875Speter * @param path The full path to the file (using / on all systems)
263251875Speter * @param pool The pool to use.
264251875Speter * @remark If the file is open, it won't be removed until all
265251875Speter * instances are closed.
266251875Speter */
267251875SpeterAPR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool);
268251875Speter
269251875Speter/**
270251875Speter * Rename the specified file.
271251875Speter * @param from_path The full path to the original file (using / on all systems)
272251875Speter * @param to_path The full path to the new file (using / on all systems)
273251875Speter * @param pool The pool to use.
274251875Speter * @warning If a file exists at the new location, then it will be
275251875Speter * overwritten.  Moving files or directories across devices may not be
276251875Speter * possible.
277251875Speter */
278251875SpeterAPR_DECLARE(apr_status_t) apr_file_rename(const char *from_path,
279251875Speter                                          const char *to_path,
280251875Speter                                          apr_pool_t *pool);
281251875Speter
282251875Speter/**
283251875Speter * Create a hard link to the specified file.
284251875Speter * @param from_path The full path to the original file (using / on all systems)
285251875Speter * @param to_path The full path to the new file (using / on all systems)
286251875Speter * @remark Both files must reside on the same device.
287251875Speter */
288251875SpeterAPR_DECLARE(apr_status_t) apr_file_link(const char *from_path,
289251875Speter                                          const char *to_path);
290251875Speter
291251875Speter/**
292251875Speter * Copy the specified file to another file.
293251875Speter * @param from_path The full path to the original file (using / on all systems)
294251875Speter * @param to_path The full path to the new file (using / on all systems)
295251875Speter * @param perms Access permissions for the new file if it is created.
296251875Speter *     In place of the usual or'd combination of file permissions, the
297269847Speter *     value #APR_FPROT_FILE_SOURCE_PERMS may be given, in which case the source
298251875Speter *     file's permissions are copied.
299251875Speter * @param pool The pool to use.
300251875Speter * @remark The new file does not need to exist, it will be created if required.
301251875Speter * @warning If the new file already exists, its contents will be overwritten.
302251875Speter */
303251875SpeterAPR_DECLARE(apr_status_t) apr_file_copy(const char *from_path,
304251875Speter                                        const char *to_path,
305251875Speter                                        apr_fileperms_t perms,
306251875Speter                                        apr_pool_t *pool);
307251875Speter
308251875Speter/**
309251875Speter * Append the specified file to another file.
310251875Speter * @param from_path The full path to the source file (use / on all systems)
311251875Speter * @param to_path The full path to the destination file (use / on all systems)
312251875Speter * @param perms Access permissions for the destination file if it is created.
313251875Speter *     In place of the usual or'd combination of file permissions, the
314269847Speter *     value #APR_FPROT_FILE_SOURCE_PERMS may be given, in which case the source
315251875Speter *     file's permissions are copied.
316251875Speter * @param pool The pool to use.
317251875Speter * @remark The new file does not need to exist, it will be created if required.
318251875Speter */
319251875SpeterAPR_DECLARE(apr_status_t) apr_file_append(const char *from_path,
320251875Speter                                          const char *to_path,
321251875Speter                                          apr_fileperms_t perms,
322251875Speter                                          apr_pool_t *pool);
323251875Speter
324251875Speter/**
325251875Speter * Are we at the end of the file
326251875Speter * @param fptr The apr file we are testing.
327269847Speter * @remark Returns #APR_EOF if we are at the end of file, #APR_SUCCESS otherwise.
328251875Speter */
329251875SpeterAPR_DECLARE(apr_status_t) apr_file_eof(apr_file_t *fptr);
330251875Speter
331251875Speter/**
332251875Speter * Open standard error as an apr file pointer.
333251875Speter * @param thefile The apr file to use as stderr.
334251875Speter * @param pool The pool to allocate the file out of.
335251875Speter *
336251875Speter * @remark The only reason that the apr_file_open_std* functions exist
337251875Speter * is that you may not always have a stderr/out/in on Windows.  This
338251875Speter * is generally a problem with newer versions of Windows and services.
339251875Speter *
340251875Speter * @remark The other problem is that the C library functions generally work
341251875Speter * differently on Windows and Unix.  So, by using apr_file_open_std*
342251875Speter * functions, you can get a handle to an APR struct that works with
343251875Speter * the APR functions which are supposed to work identically on all
344251875Speter * platforms.
345251875Speter */
346251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile,
347251875Speter                                               apr_pool_t *pool);
348251875Speter
349251875Speter/**
350251875Speter * open standard output as an apr file pointer.
351251875Speter * @param thefile The apr file to use as stdout.
352251875Speter * @param pool The pool to allocate the file out of.
353251875Speter *
354269847Speter * @remark See remarks for apr_file_open_stderr().
355251875Speter */
356251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile,
357251875Speter                                               apr_pool_t *pool);
358251875Speter
359251875Speter/**
360251875Speter * open standard input as an apr file pointer.
361251875Speter * @param thefile The apr file to use as stdin.
362251875Speter * @param pool The pool to allocate the file out of.
363251875Speter *
364269847Speter * @remark See remarks for apr_file_open_stderr().
365251875Speter */
366251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile,
367251875Speter                                              apr_pool_t *pool);
368251875Speter
369251875Speter/**
370251875Speter * open standard error as an apr file pointer, with flags.
371251875Speter * @param thefile The apr file to use as stderr.
372269847Speter * @param flags The flags to open the file with. Only the
373269847Speter *              @li #APR_FOPEN_EXCL
374269847Speter *              @li #APR_FOPEN_BUFFERED
375269847Speter *              @li #APR_FOPEN_XTHREAD
376269847Speter *              @li #APR_FOPEN_SHARELOCK
377269847Speter *              @li #APR_FOPEN_SENDFILE_ENABLED
378269847Speter *              @li #APR_FOPEN_LARGEFILE
379269847Speter *
380269847Speter *              flags should be used. The #APR_FOPEN_WRITE flag will
381269847Speter *              be set unconditionally.
382251875Speter * @param pool The pool to allocate the file out of.
383251875Speter *
384269847Speter * @remark See remarks for apr_file_open_stderr().
385251875Speter */
386251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_flags_stderr(apr_file_t **thefile,
387251875Speter                                                     apr_int32_t flags,
388251875Speter                                                     apr_pool_t *pool);
389251875Speter
390251875Speter/**
391251875Speter * open standard output as an apr file pointer, with flags.
392251875Speter * @param thefile The apr file to use as stdout.
393269847Speter * @param flags The flags to open the file with. Only the
394269847Speter *              @li #APR_FOPEN_EXCL
395269847Speter *              @li #APR_FOPEN_BUFFERED
396269847Speter *              @li #APR_FOPEN_XTHREAD
397269847Speter *              @li #APR_FOPEN_SHARELOCK
398269847Speter *              @li #APR_FOPEN_SENDFILE_ENABLED
399269847Speter *              @li #APR_FOPEN_LARGEFILE
400269847Speter *
401269847Speter *              flags should be used. The #APR_FOPEN_WRITE flag will
402269847Speter *              be set unconditionally.
403251875Speter * @param pool The pool to allocate the file out of.
404251875Speter *
405269847Speter * @remark See remarks for apr_file_open_stderr().
406251875Speter */
407251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile,
408251875Speter                                                     apr_int32_t flags,
409251875Speter                                                     apr_pool_t *pool);
410251875Speter
411251875Speter/**
412251875Speter * open standard input as an apr file pointer, with flags.
413251875Speter * @param thefile The apr file to use as stdin.
414269847Speter * @param flags The flags to open the file with. Only the
415269847Speter *              @li #APR_FOPEN_EXCL
416269847Speter *              @li #APR_FOPEN_BUFFERED
417269847Speter *              @li #APR_FOPEN_XTHREAD
418269847Speter *              @li #APR_FOPEN_SHARELOCK
419269847Speter *              @li #APR_FOPEN_SENDFILE_ENABLED
420269847Speter *              @li #APR_FOPEN_LARGEFILE
421269847Speter *
422269847Speter *              flags should be used. The #APR_FOPEN_WRITE flag will
423269847Speter *              be set unconditionally.
424251875Speter * @param pool The pool to allocate the file out of.
425251875Speter *
426269847Speter * @remark See remarks for apr_file_open_stderr().
427251875Speter */
428251875SpeterAPR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile,
429251875Speter                                                     apr_int32_t flags,
430251875Speter                                                     apr_pool_t *pool);
431251875Speter
432251875Speter/**
433251875Speter * Read data from the specified file.
434251875Speter * @param thefile The file descriptor to read from.
435251875Speter * @param buf The buffer to store the data to.
436251875Speter * @param nbytes On entry, the number of bytes to read; on exit, the number
437251875Speter * of bytes read.
438251875Speter *
439269847Speter * @remark apr_file_read() will read up to the specified number of
440251875Speter * bytes, but never more.  If there isn't enough data to fill that
441251875Speter * number of bytes, all of the available data is read.  The third
442251875Speter * argument is modified to reflect the number of bytes read.  If a
443251875Speter * char was put back into the stream via ungetc, it will be the first
444251875Speter * character returned.
445251875Speter *
446269847Speter * @remark It is not possible for both bytes to be read and an #APR_EOF
447269847Speter * or other error to be returned.  #APR_EINTR is never returned.
448251875Speter */
449251875SpeterAPR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf,
450251875Speter                                        apr_size_t *nbytes);
451251875Speter
452251875Speter/**
453251875Speter * Write data to the specified file.
454251875Speter * @param thefile The file descriptor to write to.
455251875Speter * @param buf The buffer which contains the data.
456251875Speter * @param nbytes On entry, the number of bytes to write; on exit, the number
457251875Speter *               of bytes written.
458251875Speter *
459269847Speter * @remark apr_file_write() will write up to the specified number of
460251875Speter * bytes, but never more.  If the OS cannot write that many bytes, it
461251875Speter * will write as many as it can.  The third argument is modified to
462251875Speter * reflect the * number of bytes written.
463251875Speter *
464251875Speter * @remark It is possible for both bytes to be written and an error to
465269847Speter * be returned.  #APR_EINTR is never returned.
466251875Speter */
467251875SpeterAPR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf,
468251875Speter                                         apr_size_t *nbytes);
469251875Speter
470251875Speter/**
471251875Speter * Write data from iovec array to the specified file.
472251875Speter * @param thefile The file descriptor to write to.
473251875Speter * @param vec The array from which to get the data to write to the file.
474251875Speter * @param nvec The number of elements in the struct iovec array. This must
475269847Speter *             be smaller than #APR_MAX_IOVEC_SIZE.  If it isn't, the function
476269847Speter *             will fail with #APR_EINVAL.
477251875Speter * @param nbytes The number of bytes written.
478251875Speter *
479251875Speter * @remark It is possible for both bytes to be written and an error to
480269847Speter * be returned.  #APR_EINTR is never returned.
481251875Speter *
482269847Speter * @remark apr_file_writev() is available even if the underlying
483251875Speter * operating system doesn't provide writev().
484251875Speter */
485251875SpeterAPR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile,
486251875Speter                                          const struct iovec *vec,
487251875Speter                                          apr_size_t nvec, apr_size_t *nbytes);
488251875Speter
489251875Speter/**
490251875Speter * Read data from the specified file, ensuring that the buffer is filled
491251875Speter * before returning.
492251875Speter * @param thefile The file descriptor to read from.
493251875Speter * @param buf The buffer to store the data to.
494251875Speter * @param nbytes The number of bytes to read.
495251875Speter * @param bytes_read If non-NULL, this will contain the number of bytes read.
496251875Speter *
497269847Speter * @remark apr_file_read_full() will read up to the specified number of
498251875Speter * bytes, but never more.  If there isn't enough data to fill that
499251875Speter * number of bytes, then the process/thread will block until it is
500251875Speter * available or EOF is reached.  If a char was put back into the
501251875Speter * stream via ungetc, it will be the first character returned.
502251875Speter *
503251875Speter * @remark It is possible for both bytes to be read and an error to be
504251875Speter * returned.  And if *bytes_read is less than nbytes, an accompanying
505251875Speter * error is _always_ returned.
506251875Speter *
507269847Speter * @remark #APR_EINTR is never returned.
508251875Speter */
509251875SpeterAPR_DECLARE(apr_status_t) apr_file_read_full(apr_file_t *thefile, void *buf,
510251875Speter                                             apr_size_t nbytes,
511251875Speter                                             apr_size_t *bytes_read);
512251875Speter
513251875Speter/**
514251875Speter * Write data to the specified file, ensuring that all of the data is
515251875Speter * written before returning.
516251875Speter * @param thefile The file descriptor to write to.
517251875Speter * @param buf The buffer which contains the data.
518251875Speter * @param nbytes The number of bytes to write.
519251875Speter * @param bytes_written If non-NULL, set to the number of bytes written.
520251875Speter *
521269847Speter * @remark apr_file_write_full() will write up to the specified number of
522251875Speter * bytes, but never more.  If the OS cannot write that many bytes, the
523251875Speter * process/thread will block until they can be written. Exceptional
524251875Speter * error such as "out of space" or "pipe closed" will terminate with
525251875Speter * an error.
526251875Speter *
527251875Speter * @remark It is possible for both bytes to be written and an error to
528251875Speter * be returned.  And if *bytes_written is less than nbytes, an
529251875Speter * accompanying error is _always_ returned.
530251875Speter *
531269847Speter * @remark #APR_EINTR is never returned.
532251875Speter */
533251875SpeterAPR_DECLARE(apr_status_t) apr_file_write_full(apr_file_t *thefile,
534251875Speter                                              const void *buf,
535251875Speter                                              apr_size_t nbytes,
536251875Speter                                              apr_size_t *bytes_written);
537251875Speter
538251875Speter
539251875Speter/**
540251875Speter * Write data from iovec array to the specified file, ensuring that all of the
541251875Speter * data is written before returning.
542251875Speter * @param thefile The file descriptor to write to.
543251875Speter * @param vec The array from which to get the data to write to the file.
544251875Speter * @param nvec The number of elements in the struct iovec array. This must
545269847Speter *             be smaller than #APR_MAX_IOVEC_SIZE.  If it isn't, the function
546269847Speter *             will fail with #APR_EINVAL.
547251875Speter * @param nbytes The number of bytes written.
548251875Speter *
549269847Speter * @remark apr_file_writev_full() is available even if the underlying
550251875Speter * operating system doesn't provide writev().
551251875Speter */
552251875SpeterAPR_DECLARE(apr_status_t) apr_file_writev_full(apr_file_t *thefile,
553251875Speter                                               const struct iovec *vec,
554251875Speter                                               apr_size_t nvec,
555251875Speter                                               apr_size_t *nbytes);
556251875Speter/**
557251875Speter * Write a character into the specified file.
558251875Speter * @param ch The character to write.
559251875Speter * @param thefile The file descriptor to write to
560251875Speter */
561251875SpeterAPR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile);
562251875Speter
563251875Speter/**
564251875Speter * Read a character from the specified file.
565251875Speter * @param ch The character to read into
566251875Speter * @param thefile The file descriptor to read from
567251875Speter */
568251875SpeterAPR_DECLARE(apr_status_t) apr_file_getc(char *ch, apr_file_t *thefile);
569251875Speter
570251875Speter/**
571251875Speter * Put a character back onto a specified stream.
572251875Speter * @param ch The character to write.
573251875Speter * @param thefile The file descriptor to write to
574251875Speter */
575251875SpeterAPR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile);
576251875Speter
577251875Speter/**
578251875Speter * Read a line from the specified file
579251875Speter * @param str The buffer to store the string in.
580251875Speter * @param len The length of the string
581251875Speter * @param thefile The file descriptor to read from
582251875Speter * @remark The buffer will be NUL-terminated if any characters are stored.
583251875Speter *         The newline at the end of the line will not be stripped.
584251875Speter */
585251875SpeterAPR_DECLARE(apr_status_t) apr_file_gets(char *str, int len,
586251875Speter                                        apr_file_t *thefile);
587251875Speter
588251875Speter/**
589251875Speter * Write the string into the specified file.
590251875Speter * @param str The string to write.
591251875Speter * @param thefile The file descriptor to write to
592251875Speter */
593251875SpeterAPR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile);
594251875Speter
595251875Speter/**
596251875Speter * Flush the file's buffer.
597251875Speter * @param thefile The file descriptor to flush
598251875Speter */
599251875SpeterAPR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile);
600251875Speter
601251875Speter/**
602251875Speter * Transfer all file modified data and metadata to disk.
603251875Speter * @param thefile The file descriptor to sync
604251875Speter */
605251875SpeterAPR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile);
606251875Speter
607251875Speter/**
608251875Speter * Transfer all file modified data to disk.
609251875Speter * @param thefile The file descriptor to sync
610251875Speter */
611251875SpeterAPR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile);
612251875Speter
613251875Speter/**
614251875Speter * Duplicate the specified file descriptor.
615251875Speter * @param new_file The structure to duplicate into.
616251875Speter * @param old_file The file to duplicate.
617251875Speter * @param p The pool to use for the new file.
618251875Speter * @remark *new_file must point to a valid apr_file_t, or point to NULL.
619251875Speter */
620251875SpeterAPR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file,
621251875Speter                                       apr_file_t *old_file,
622251875Speter                                       apr_pool_t *p);
623251875Speter
624251875Speter/**
625251875Speter * Duplicate the specified file descriptor and close the original
626251875Speter * @param new_file The old file that is to be closed and reused
627251875Speter * @param old_file The file to duplicate
628251875Speter * @param p        The pool to use for the new file
629251875Speter *
630251875Speter * @remark new_file MUST point at a valid apr_file_t. It cannot be NULL.
631251875Speter */
632251875SpeterAPR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file,
633251875Speter                                        apr_file_t *old_file,
634251875Speter                                        apr_pool_t *p);
635251875Speter
636251875Speter/**
637251875Speter * Move the specified file descriptor to a new pool
638251875Speter * @param new_file Pointer in which to return the new apr_file_t
639251875Speter * @param old_file The file to move
640251875Speter * @param p        The pool to which the descriptor is to be moved
641251875Speter * @remark Unlike apr_file_dup2(), this function doesn't do an
642251875Speter *         OS dup() operation on the underlying descriptor; it just
643251875Speter *         moves the descriptor's apr_file_t wrapper to a new pool.
644251875Speter * @remark The new pool need not be an ancestor of old_file's pool.
645251875Speter * @remark After calling this function, old_file may not be used
646251875Speter */
647251875SpeterAPR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
648251875Speter                                            apr_file_t *old_file,
649251875Speter                                            apr_pool_t *p);
650251875Speter
651251875Speter/**
652251875Speter * Give the specified apr file handle a new buffer
653251875Speter * @param thefile  The file handle that is to be modified
654251875Speter * @param buffer   The buffer
655251875Speter * @param bufsize  The size of the buffer
656251875Speter * @remark It is possible to add a buffer to previously unbuffered
657269847Speter *         file handles, the #APR_FOPEN_BUFFERED flag will be added to
658251875Speter *         the file handle's flags. Likewise, with buffer=NULL and
659251875Speter *         bufsize=0 arguments it is possible to make a previously
660251875Speter *         buffered file handle unbuffered.
661251875Speter */
662251875SpeterAPR_DECLARE(apr_status_t) apr_file_buffer_set(apr_file_t *thefile,
663251875Speter                                              char * buffer,
664251875Speter                                              apr_size_t bufsize);
665251875Speter
666251875Speter/**
667251875Speter * Get the size of any buffer for the specified apr file handle
668251875Speter * @param thefile  The file handle
669251875Speter */
670251875SpeterAPR_DECLARE(apr_size_t) apr_file_buffer_size_get(apr_file_t *thefile);
671251875Speter
672251875Speter/**
673251875Speter * Move the read/write file offset to a specified byte within a file.
674251875Speter * @param thefile The file descriptor
675251875Speter * @param where How to move the pointer, one of:
676269847Speter *              @li #APR_SET  --  set the offset to offset
677269847Speter *              @li #APR_CUR  --  add the offset to the current position
678269847Speter *              @li #APR_END  --  add the offset to the current file size
679251875Speter * @param offset The offset to move the pointer to.
680251875Speter * @remark The third argument is modified to be the offset the pointer
681251875Speter          was actually moved to.
682251875Speter */
683251875SpeterAPR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile,
684251875Speter                                   apr_seek_where_t where,
685251875Speter                                   apr_off_t *offset);
686251875Speter
687251875Speter/**
688251875Speter * Create an anonymous pipe.
689251875Speter * @param in The newly created pipe's file for reading.
690251875Speter * @param out The newly created pipe's file for writing.
691251875Speter * @param pool The pool to operate on.
692251875Speter * @remark By default, the returned file descriptors will be inherited
693251875Speter * by child processes created using apr_proc_create().  This can be
694251875Speter * changed using apr_file_inherit_unset().
695251875Speter * @bug  Some platforms cannot toggle between blocking and nonblocking,
696251875Speter * and when passing a pipe as a standard handle to an application which
697251875Speter * does not expect it, a non-blocking stream will fluxor the client app.
698269847Speter * @deprecated @see apr_file_pipe_create_ex()
699251875Speter */
700251875SpeterAPR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in,
701251875Speter                                               apr_file_t **out,
702251875Speter                                               apr_pool_t *pool);
703251875Speter
704251875Speter/**
705251875Speter * Create an anonymous pipe which portably supports async timeout options.
706251875Speter * @param in The newly created pipe's file for reading.
707251875Speter * @param out The newly created pipe's file for writing.
708251875Speter * @param blocking one of these values defined in apr_thread_proc.h;
709269847Speter *                 @li #APR_FULL_BLOCK
710269847Speter *                 @li #APR_READ_BLOCK
711269847Speter *                 @li #APR_WRITE_BLOCK
712269847Speter *                 @li #APR_FULL_NONBLOCK
713251875Speter * @param pool The pool to operate on.
714251875Speter * @remark By default, the returned file descriptors will be inherited
715251875Speter * by child processes created using apr_proc_create().  This can be
716251875Speter * changed using apr_file_inherit_unset().
717251875Speter * @remark Some platforms cannot toggle between blocking and nonblocking,
718251875Speter * and when passing a pipe as a standard handle to an application which
719251875Speter * does not expect it, a non-blocking stream will fluxor the client app.
720269847Speter * Use this function rather than apr_file_pipe_create() to create pipes
721251875Speter * where one or both ends require non-blocking semantics.
722251875Speter */
723251875SpeterAPR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in,
724251875Speter                                                  apr_file_t **out,
725251875Speter                                                  apr_int32_t blocking,
726251875Speter                                                  apr_pool_t *pool);
727251875Speter
728251875Speter/**
729251875Speter * Create a named pipe.
730251875Speter * @param filename The filename of the named pipe
731251875Speter * @param perm The permissions for the newly created pipe.
732251875Speter * @param pool The pool to operate on.
733251875Speter */
734251875SpeterAPR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename,
735251875Speter                                                    apr_fileperms_t perm,
736251875Speter                                                    apr_pool_t *pool);
737251875Speter
738251875Speter/**
739251875Speter * Get the timeout value for a pipe or manipulate the blocking state.
740251875Speter * @param thepipe The pipe we are getting a timeout for.
741251875Speter * @param timeout The current timeout value in microseconds.
742251875Speter */
743251875SpeterAPR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe,
744251875Speter                                               apr_interval_time_t *timeout);
745251875Speter
746251875Speter/**
747251875Speter * Set the timeout value for a pipe or manipulate the blocking state.
748251875Speter * @param thepipe The pipe we are setting a timeout on.
749251875Speter * @param timeout The timeout value in microseconds.  Values < 0 mean wait
750251875Speter *        forever, 0 means do not wait at all.
751251875Speter */
752251875SpeterAPR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe,
753251875Speter                                                  apr_interval_time_t timeout);
754251875Speter
755251875Speter/** file (un)locking functions. */
756251875Speter
757251875Speter/**
758251875Speter * Establish a lock on the specified, open file. The lock may be advisory
759251875Speter * or mandatory, at the discretion of the platform. The lock applies to
760251875Speter * the file as a whole, rather than a specific range. Locks are established
761251875Speter * on a per-thread/process basis; a second lock by the same thread will not
762251875Speter * block.
763251875Speter * @param thefile The file to lock.
764251875Speter * @param type The type of lock to establish on the file.
765251875Speter */
766251875SpeterAPR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *thefile, int type);
767251875Speter
768251875Speter/**
769251875Speter * Remove any outstanding locks on the file.
770251875Speter * @param thefile The file to unlock.
771251875Speter */
772251875SpeterAPR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *thefile);
773251875Speter
774251875Speter/**accessor and general file_io functions. */
775251875Speter
776251875Speter/**
777251875Speter * return the file name of the current file.
778251875Speter * @param new_path The path of the file.
779251875Speter * @param thefile The currently open file.
780251875Speter */
781251875SpeterAPR_DECLARE(apr_status_t) apr_file_name_get(const char **new_path,
782251875Speter                                            apr_file_t *thefile);
783251875Speter
784251875Speter/**
785251875Speter * Return the data associated with the current file.
786251875Speter * @param data The user data associated with the file.
787251875Speter * @param key The key to use for retrieving data associated with this file.
788251875Speter * @param file The currently open file.
789251875Speter */
790251875SpeterAPR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key,
791251875Speter                                            apr_file_t *file);
792251875Speter
793251875Speter/**
794251875Speter * Set the data associated with the current file.
795251875Speter * @param file The currently open file.
796251875Speter * @param data The user data to associate with the file.
797251875Speter * @param key The key to use for associating data with the file.
798251875Speter * @param cleanup The cleanup routine to use when the file is destroyed.
799251875Speter */
800251875SpeterAPR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data,
801251875Speter                                            const char *key,
802251875Speter                                            apr_status_t (*cleanup)(void *));
803251875Speter
804251875Speter/**
805251875Speter * Write a string to a file using a printf format.
806251875Speter * @param fptr The file to write to.
807251875Speter * @param format The format string
808251875Speter * @param ... The values to substitute in the format string
809251875Speter * @return The number of bytes written
810251875Speter */
811251875SpeterAPR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr,
812251875Speter                                        const char *format, ...)
813251875Speter        __attribute__((format(printf,2,3)));
814251875Speter
815251875Speter/**
816251875Speter * set the specified file's permission bits.
817251875Speter * @param fname The file (name) to apply the permissions to.
818251875Speter * @param perms The permission bits to apply to the file.
819251875Speter *
820251875Speter * @warning Some platforms may not be able to apply all of the
821269847Speter * available permission bits; #APR_INCOMPLETE will be returned if some
822251875Speter * permissions are specified which could not be set.
823251875Speter *
824251875Speter * @warning Platforms which do not implement this feature will return
825269847Speter * #APR_ENOTIMPL.
826251875Speter */
827251875SpeterAPR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname,
828251875Speter                                             apr_fileperms_t perms);
829251875Speter
830251875Speter/**
831251875Speter * Set attributes of the specified file.
832251875Speter * @param fname The full path to the file (using / on all systems)
833251875Speter * @param attributes Or'd combination of
834269847Speter *            @li #APR_FILE_ATTR_READONLY   - make the file readonly
835269847Speter *            @li #APR_FILE_ATTR_EXECUTABLE - make the file executable
836269847Speter *            @li #APR_FILE_ATTR_HIDDEN     - make the file hidden
837251875Speter * @param attr_mask Mask of valid bits in attributes.
838251875Speter * @param pool the pool to use.
839251875Speter * @remark This function should be used in preference to explicit manipulation
840251875Speter *      of the file permissions, because the operations to provide these
841251875Speter *      attributes are platform specific and may involve more than simply
842251875Speter *      setting permission bits.
843251875Speter * @warning Platforms which do not implement this feature will return
844269847Speter *      #APR_ENOTIMPL.
845251875Speter */
846251875SpeterAPR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname,
847251875Speter                                             apr_fileattrs_t attributes,
848251875Speter                                             apr_fileattrs_t attr_mask,
849251875Speter                                             apr_pool_t *pool);
850251875Speter
851251875Speter/**
852251875Speter * Set the mtime of the specified file.
853251875Speter * @param fname The full path to the file (using / on all systems)
854251875Speter * @param mtime The mtime to apply to the file.
855251875Speter * @param pool The pool to use.
856251875Speter * @warning Platforms which do not implement this feature will return
857269847Speter *      #APR_ENOTIMPL.
858251875Speter */
859251875SpeterAPR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
860251875Speter                                             apr_time_t mtime,
861251875Speter                                             apr_pool_t *pool);
862251875Speter
863251875Speter/**
864251875Speter * Create a new directory on the file system.
865251875Speter * @param path the path for the directory to be created. (use / on all systems)
866251875Speter * @param perm Permissions for the new directory.
867251875Speter * @param pool the pool to use.
868251875Speter */
869251875SpeterAPR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t perm,
870251875Speter                                       apr_pool_t *pool);
871251875Speter
872251875Speter/** Creates a new directory on the file system, but behaves like
873251875Speter * 'mkdir -p'. Creates intermediate directories as required. No error
874251875Speter * will be reported if PATH already exists.
875251875Speter * @param path the path for the directory to be created. (use / on all systems)
876251875Speter * @param perm Permissions for the new directory.
877251875Speter * @param pool the pool to use.
878251875Speter */
879251875SpeterAPR_DECLARE(apr_status_t) apr_dir_make_recursive(const char *path,
880251875Speter                                                 apr_fileperms_t perm,
881251875Speter                                                 apr_pool_t *pool);
882251875Speter
883251875Speter/**
884251875Speter * Remove directory from the file system.
885251875Speter * @param path the path for the directory to be removed. (use / on all systems)
886251875Speter * @param pool the pool to use.
887251875Speter * @remark Removing a directory which is in-use (e.g., the current working
888251875Speter * directory, or during apr_dir_read, or with an open file) is not portable.
889251875Speter */
890251875SpeterAPR_DECLARE(apr_status_t) apr_dir_remove(const char *path, apr_pool_t *pool);
891251875Speter
892251875Speter/**
893251875Speter * get the specified file's stats.
894251875Speter * @param finfo Where to store the information about the file.
895269847Speter * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_* values
896251875Speter * @param thefile The file to get information about.
897251875Speter */
898251875SpeterAPR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo,
899251875Speter                                            apr_int32_t wanted,
900251875Speter                                            apr_file_t *thefile);
901251875Speter
902251875Speter
903251875Speter/**
904251875Speter * Truncate the file's length to the specified offset
905251875Speter * @param fp The file to truncate
906251875Speter * @param offset The offset to truncate to.
907251875Speter * @remark The read/write file offset is repositioned to offset.
908251875Speter */
909251875SpeterAPR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *fp, apr_off_t offset);
910251875Speter
911251875Speter/**
912251875Speter * Retrieve the flags that were passed into apr_file_open()
913251875Speter * when the file was opened.
914251875Speter * @return apr_int32_t the flags
915251875Speter */
916251875SpeterAPR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f);
917251875Speter
918251875Speter/**
919251875Speter * Get the pool used by the file.
920251875Speter */
921251875SpeterAPR_POOL_DECLARE_ACCESSOR(file);
922251875Speter
923251875Speter/**
924251875Speter * Set a file to be inherited by child processes.
925251875Speter *
926251875Speter */
927251875SpeterAPR_DECLARE_INHERIT_SET(file);
928251875Speter
929251875Speter/**
930251875Speter * Unset a file from being inherited by child processes.
931251875Speter */
932251875SpeterAPR_DECLARE_INHERIT_UNSET(file);
933251875Speter
934251875Speter/**
935251875Speter * Open a temporary file
936251875Speter * @param fp The apr file to use as a temporary file.
937251875Speter * @param templ The template to use when creating a temp file.
938251875Speter * @param flags The flags to open the file with. If this is zero,
939251875Speter *              the file is opened with
940269847Speter *              #APR_FOPEN_CREATE | #APR_FOPEN_READ | #APR_FOPEN_WRITE |
941269847Speter *              #APR_FOPEN_EXCL | #APR_FOPEN_DELONCLOSE
942251875Speter * @param p The pool to allocate the file out of.
943251875Speter * @remark
944251875Speter * This function  generates  a unique temporary file name from template.
945251875Speter * The last six characters of template must be XXXXXX and these are replaced
946251875Speter * with a string that makes the filename unique. Since it will  be  modified,
947251875Speter * template must not be a string constant, but should be declared as a character
948251875Speter * array.
949251875Speter *
950251875Speter */
951251875SpeterAPR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *templ,
952251875Speter                                          apr_int32_t flags, apr_pool_t *p);
953251875Speter
954251875Speter
955251875Speter/**
956251875Speter * Find an existing directory suitable as a temporary storage location.
957251875Speter * @param temp_dir The temp directory.
958251875Speter * @param p The pool to use for any necessary allocations.
959251875Speter * @remark
960251875Speter * This function uses an algorithm to search for a directory that an
961251875Speter * an application can use for temporary storage.
962251875Speter *
963251875Speter */
964251875SpeterAPR_DECLARE(apr_status_t) apr_temp_dir_get(const char **temp_dir,
965251875Speter                                           apr_pool_t *p);
966251875Speter
967251875Speter/** @} */
968251875Speter
969251875Speter#ifdef __cplusplus
970251875Speter}
971251875Speter#endif
972251875Speter
973251875Speter#endif  /* ! APR_FILE_IO_H */
974