summaryrefslogtreecommitdiff
path: root/file_io
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-01-08 06:26:09 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-01-08 06:26:09 +0000
commitf7e7a3dd159b48be44b4f6b52b78b7bf8f173728 (patch)
treee783c8b049249af998a4155b13e3b1dfc2925459 /file_io
parent6d270b8236913317f07211bca41d9c53664131d4 (diff)
downloadlibapr-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
Diffstat (limited to 'file_io')
-rw-r--r--file_io/os2/open.c10
-rw-r--r--file_io/unix/mktemp.c17
-rw-r--r--file_io/unix/open.c9
-rw-r--r--file_io/win32/open.c8
4 files changed, 21 insertions, 23 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);