summaryrefslogtreecommitdiff
path: root/file_io
diff options
context:
space:
mode:
authorgstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2001-01-26 09:05:55 +0000
committergstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2001-01-26 09:05:55 +0000
commitc9e6bb83dadab222f782fb4e9e11a5e78c414e07 (patch)
treef621d7446b34b4f1e40911e0ad17a8fe31133ddc /file_io
parent0b7e804a9fd34bd85422ddba122440887900b842 (diff)
downloadlibapr-c9e6bb83dadab222f782fb4e9e11a5e78c414e07.tar.gz
apr_put_os_file() expected the caller to have an existing file or init to
NULL. using an existing file doesn't normally work: where would you get a blank file to shove an FD into? expecting the user to assign to NULL is error-prone (mod_isapi didn't). *) always create and return a new file from apr_put_os_file() *) reimplement apr_open_stderr() in terms of apr_put_os_file() [ except for win32... some issues there ] *) remove some (obsolete) inits to NULL git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61131 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io')
-rw-r--r--file_io/os2/open.c22
-rw-r--r--file_io/unix/open.c22
-rw-r--r--file_io/win32/open.c14
3 files changed, 16 insertions, 42 deletions
diff --git a/file_io/os2/open.c b/file_io/os2/open.c
index 8e07c6cd6..e2cfeba1d 100644
--- a/file_io/os2/open.c
+++ b/file_io/os2/open.c
@@ -220,10 +220,9 @@ apr_status_t apr_get_os_file(apr_os_file_t *thefile, apr_file_t *file)
apr_status_t apr_put_os_file(apr_file_t **file, apr_os_file_t *thefile, apr_pool_t *cont)
{
apr_os_file_t *dafile = thefile;
- if ((*file) == NULL) {
- (*file) = (apr_file_t *)apr_palloc(cont, sizeof(apr_file_t));
- (*file)->cntxt = cont;
- }
+
+ (*file) = apr_palloc(cont, sizeof(apr_file_t));
+ (*file)->cntxt = cont;
(*file)->filedes = *dafile;
(*file)->isopen = TRUE;
(*file)->buffered = FALSE;
@@ -247,20 +246,9 @@ apr_status_t apr_eof(apr_file_t *fptr)
apr_status_t apr_open_stderr(apr_file_t **thefile, apr_pool_t *cont)
{
- (*thefile) = apr_palloc(cont, sizeof(apr_file_t));
- if ((*thefile) == NULL) {
- return APR_ENOMEM;
- }
- (*thefile)->cntxt = cont;
- (*thefile)->filedes = 2;
- (*thefile)->fname = NULL;
- (*thefile)->isopen = TRUE;
- (*thefile)->buffered = FALSE;
- (*thefile)->eof_hit = FALSE;
- (*thefile)->flags = 0;
- (*thefile)->pipe = FALSE;
+ int fd = 2;
- return APR_SUCCESS;
+ return apr_put_os_file(thefile, &fd, cont);
}
APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
diff --git a/file_io/unix/open.c b/file_io/unix/open.c
index 187a64bda..f766b9b97 100644
--- a/file_io/unix/open.c
+++ b/file_io/unix/open.c
@@ -217,10 +217,8 @@ apr_status_t apr_put_os_file(apr_file_t **file, apr_os_file_t *thefile,
{
int *dafile = thefile;
- if ((*file) == NULL) {
- (*file) = apr_pcalloc(cont, sizeof(apr_file_t));
- (*file)->cntxt = cont;
- }
+ (*file) = apr_pcalloc(cont, sizeof(apr_file_t));
+ (*file)->cntxt = cont;
(*file)->eof_hit = 0;
(*file)->buffered = 0;
(*file)->blocking = BLK_UNKNOWN; /* in case it is a pipe */
@@ -249,23 +247,11 @@ apr_status_t apr_ferror(apr_file_t *fptr)
return APR_SUCCESS;
}
-/* apr_open_stderr() could just call apr_put_os_file() with
- * STDERR_FILENO for the descriptor...
- */
apr_status_t apr_open_stderr(apr_file_t **thefile, apr_pool_t *cont)
{
- (*thefile) = apr_pcalloc(cont, sizeof(apr_file_t));
- if ((*thefile) == NULL) {
- return APR_ENOMEM;
- }
- (*thefile)->filedes = STDERR_FILENO;
- (*thefile)->cntxt = cont;
- (*thefile)->buffered = 0;
- (*thefile)->blocking = BLK_UNKNOWN;
- (*thefile)->fname = NULL;
- (*thefile)->eof_hit = 0;
+ int fd = STDERR_FILENO;
- return APR_SUCCESS;
+ return apr_put_os_file(thefile, &fd, cont);
}
APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
diff --git a/file_io/win32/open.c b/file_io/win32/open.c
index 83b0e4c8a..98bf71a7f 100644
--- a/file_io/win32/open.c
+++ b/file_io/win32/open.c
@@ -400,13 +400,8 @@ APR_DECLARE(apr_status_t) apr_put_os_file(apr_file_t **file,
apr_os_file_t *thefile,
apr_pool_t *cont)
{
- if ((*file) == NULL) {
- if (cont == NULL) {
- return APR_ENOPOOL;
- }
- (*file) = (apr_file_t *)apr_pcalloc(cont, sizeof(apr_file_t));
- (*file)->cntxt = cont;
- }
+ (*file) = apr_pcalloc(cont, sizeof(apr_file_t));
+ (*file)->cntxt = cont;
(*file)->filehand = *thefile;
(*file)->ungetchar = -1; /* no char avail */
return APR_SUCCESS;
@@ -422,6 +417,11 @@ APR_DECLARE(apr_status_t) apr_eof(apr_file_t *fptr)
APR_DECLARE(apr_status_t) apr_open_stderr(apr_file_t **thefile, apr_pool_t *cont)
{
+ /* ### should this be rebuilt in terms of apr_put_os_file()?? their
+ ### initializations are slightly different (maybe one or both are
+ ### not init'ing properly?)
+ */
+
(*thefile) = apr_pcalloc(cont, sizeof(apr_file_t));
if ((*thefile) == NULL) {
return APR_ENOMEM;