diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-01-08 06:26:09 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-01-08 06:26:09 +0000 |
commit | f7e7a3dd159b48be44b4f6b52b78b7bf8f173728 (patch) | |
tree | e783c8b049249af998a4155b13e3b1dfc2925459 | |
parent | 6d270b8236913317f07211bca41d9c53664131d4 (diff) | |
download | libapr-f7e7a3dd159b48be44b4f6b52b78b7bf8f173728.tar.gz |
Add the ability to pass flags to both apr_file_open and apr_mktemp.
The reason for this, is that it is very possible to want a temp
file that isn't deleted when the file is closed. It also makes sense
to have the flags in the apr_file_t if possible.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62716 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | file_io/os2/open.c | 10 | ||||
-rw-r--r-- | file_io/unix/mktemp.c | 17 | ||||
-rw-r--r-- | file_io/unix/open.c | 9 | ||||
-rw-r--r-- | file_io/win32/open.c | 8 | ||||
-rw-r--r-- | include/apr_file_io.h | 5 | ||||
-rw-r--r-- | include/apr_portable.h | 3 | ||||
-rw-r--r-- | locks/unix/locks.c | 2 | ||||
-rw-r--r-- | locks/unix/proc_mutex.c | 2 | ||||
-rw-r--r-- | shmem/unix/shmem.c | 2 |
9 files changed, 30 insertions, 28 deletions
diff --git a/file_io/os2/open.c b/file_io/os2/open.c index 6664da334..8c569098e 100644 --- a/file_io/os2/open.c +++ b/file_io/os2/open.c @@ -213,7 +213,7 @@ APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile, apr_file_t *fi -APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, apr_pool_t *cont) +APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, apr_int32_t flags, apr_pool_t *cont) { apr_os_file_t *dafile = thefile; @@ -223,7 +223,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef (*file)->isopen = TRUE; (*file)->buffered = FALSE; (*file)->eof_hit = FALSE; - (*file)->flags = 0; + (*file)->flags = flags; (*file)->pipe = FALSE; return APR_SUCCESS; } @@ -242,7 +242,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, apr_pool_t { apr_os_file_t fd = 2; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } @@ -251,7 +251,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, apr_pool_t { apr_os_file_t fd = 1; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } @@ -259,7 +259,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, apr_pool_t * { apr_os_file_t fd = 0; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt); diff --git a/file_io/unix/mktemp.c b/file_io/unix/mktemp.c index c5cb10117..aa87c3293 100644 --- a/file_io/unix/mktemp.c +++ b/file_io/unix/mktemp.c @@ -120,7 +120,7 @@ static const unsigned char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static apr_uint32_t randseed=0; -static int gettemp(char *path, apr_file_t **doopen, apr_pool_t *p) +static int gettemp(char *path, apr_file_t **doopen, apr_int32_t flags, apr_pool_t *p) { register char *start, *trv, *suffp; char *pad; @@ -168,8 +168,7 @@ static int gettemp(char *path, apr_file_t **doopen, apr_pool_t *p) } for (;;) { - if ((rv = apr_file_open(doopen, path, APR_CREATE|APR_EXCL|APR_READ| - APR_WRITE|APR_DELONCLOSE, + if ((rv = apr_file_open(doopen, path, flags, APR_UREAD | APR_UWRITE, p)) == APR_SUCCESS) return APR_SUCCESS; if (rv != APR_EEXIST) @@ -202,24 +201,20 @@ static int gettemp(char *path, apr_file_t **doopen, apr_pool_t *p) #endif #endif /* !defined(HAVE_MKSTEMP) */ -APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_pool_t *p) +APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_int32_t flags, apr_pool_t *p) { + flags = (!flags) ? APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE : flags; #ifndef HAVE_MKSTEMP - return gettemp(template, fp, p); + return gettemp(template, fp, flags, p); #else int fd; - (*fp) = apr_pcalloc(p, sizeof(**fp)); - (*fp)->cntxt = p; - (*fp)->timeout = -1; - (*fp)->blocking = BLK_ON; - (*fp)->flags = APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE; fd = mkstemp(template); if (fd == -1) { return errno; } + apr_os_file_put(fp, &fd, flags, p); (*fp)->fname = apr_pstrdup(p, template); - (*fp)->filedes = fd; apr_pool_cleanup_register((*fp)->cntxt, (void *)(*fp), apr_unix_file_cleanup, apr_unix_file_cleanup); diff --git a/file_io/unix/open.c b/file_io/unix/open.c index 97a15073e..0ba47f482 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -211,7 +211,7 @@ APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile, APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, - apr_pool_t *cont) + apr_int32_t flags, apr_pool_t *cont) { int *dafile = thefile; @@ -223,6 +223,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, (*file)->timeout = -1; (*file)->ungetchar = -1; /* no char avail */ (*file)->filedes = *dafile; + (*file)->flags = flags; /* buffer already NULL; * don't get a lock (only for buffered files) */ @@ -242,7 +243,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, { int fd = STDERR_FILENO; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, @@ -250,7 +251,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, { int fd = STDOUT_FILENO; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, @@ -258,7 +259,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, { int fd = STDIN_FILENO; - return apr_os_file_put(thefile, &fd, cont); + return apr_os_file_put(thefile, &fd, 0, cont); } APR_IMPLEMENT_SET_INHERIT(file, flags, cntxt, apr_unix_file_cleanup) diff --git a/file_io/win32/open.c b/file_io/win32/open.c index aad54853e..2cf6fb0bd 100644 --- a/file_io/win32/open.c +++ b/file_io/win32/open.c @@ -415,12 +415,14 @@ APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile, APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, + apr_int32_t flags, apr_pool_t *cont) { (*file) = apr_pcalloc(cont, sizeof(apr_file_t)); (*file)->cntxt = cont; (*file)->filehand = *thefile; (*file)->ungetchar = -1; /* no char avail */ + (*file)->flags; return APR_SUCCESS; } @@ -440,7 +442,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, apr_pool_t if (file_handle == INVALID_HANDLE_VALUE) return apr_get_os_error(); - return apr_os_file_put(thefile, &file_handle, cont); + return apr_os_file_put(thefile, &file_handle, 0, cont); } APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, apr_pool_t *cont) @@ -451,7 +453,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdout(apr_file_t **thefile, apr_pool_t if (file_handle == INVALID_HANDLE_VALUE) return apr_get_os_error(); - return apr_os_file_put(thefile, &file_handle, cont); + return apr_os_file_put(thefile, &file_handle, 0, cont); } APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, apr_pool_t *cont) @@ -462,7 +464,7 @@ APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, apr_pool_t * if (file_handle == INVALID_HANDLE_VALUE) return apr_get_os_error(); - return apr_os_file_put(thefile, &file_handle, cont); + return apr_os_file_put(thefile, &file_handle, 0, cont); } APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt); diff --git a/include/apr_file_io.h b/include/apr_file_io.h index ae2dcfb3f..19e481ecf 100644 --- a/include/apr_file_io.h +++ b/include/apr_file_io.h @@ -579,6 +579,9 @@ APR_DECLARE(void) apr_file_unset_inherit(apr_file_t *file); * Open a temporary file * @param fp The apr file to use as a temporary file. * @param template The template to use when creating a temp file. + * @param flags The flags to open the file with. If this is zero, + * the file is opened with + * APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE * @param p The pool to allocate the file out of. * @ingroup apr_file_open * @remark @@ -590,7 +593,7 @@ APR_DECLARE(void) apr_file_unset_inherit(apr_file_t *file); * */ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *tmplt, - apr_pool_t *p); + apr_int32_t flags, apr_pool_t *p); #ifdef __cplusplus } diff --git a/include/apr_portable.h b/include/apr_portable.h index e9dec3967..11ef5d91d 100644 --- a/include/apr_portable.h +++ b/include/apr_portable.h @@ -340,13 +340,14 @@ APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1, * convert the file from os specific type to apr type. * @param file The apr file we are converting to. * @param thefile The os specific file to convert + * @param flags The flags that were used to open this file. * @param cont The pool to use if it is needed. * @remark On Unix, it is only possible to put a file descriptor into * an apr file type. */ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, - apr_pool_t *cont); + apr_int32_t flags, apr_pool_t *cont); /** * convert the dir from os specific type to apr type. diff --git a/locks/unix/locks.c b/locks/unix/locks.c index ac2bc0d73..5f876bef5 100644 --- a/locks/unix/locks.c +++ b/locks/unix/locks.c @@ -388,7 +388,7 @@ APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thel (*lock)->pool = pool; } #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE - apr_os_file_put(&(*lock)->interproc, &thelock->crossproc, pool); + apr_os_file_put(&(*lock)->interproc, &thelock->crossproc, 0, pool); #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE (*lock)->pthread_interproc = thelock->pthread_interproc; diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index a9513506f..08be4ad1c 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -827,7 +827,7 @@ APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex, (*pmutex)->pool = pool; } #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE - apr_os_file_put(&(*pmutex)->interproc, &ospmutex->crossproc, pool); + apr_os_file_put(&(*pmutex)->interproc, &ospmutex->crossproc, 0, pool); #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE (*pmutex)->pthread_interproc = ospmutex->pthread_interproc; diff --git a/shmem/unix/shmem.c b/shmem/unix/shmem.c index c30595d3c..a4b09c82f 100644 --- a/shmem/unix/shmem.c +++ b/shmem/unix/shmem.c @@ -153,7 +153,7 @@ APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, if (tmpfd == -1) return errno; - apr_os_file_put(&new_m->file, &tmpfd, pool); + apr_os_file_put(&new_m->file, &tmpfd, O_READ | O_WRITE | O_CREATE, pool); status = apr_file_trunc(new_m->file, reqsize); if (status != APR_SUCCESS) { |