diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2007-10-12 01:53:12 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2007-10-12 01:53:12 +0000 |
commit | 748d09f38983d5e69237f38971263c4bf320e6b5 (patch) | |
tree | a7e8cd65e95d46a4b4adca6e0ff8704aecda4448 /file_io/win32/open.c | |
parent | bb2104ff5383f9c0abefe8bead24fc206a98cfe8 (diff) | |
download | libapr-748d09f38983d5e69237f38971263c4bf320e6b5.tar.gz |
Group of two changes; we must keep file->flags in sync when
we are apr_file_dup2()'ing into a standard handle (it has
to remain marked as a standard handle), remove a redundant
CloseFile() (win faux-posix _dup2 does this for us) and also
close the msvcrt faux-posix file when we close std streams.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@584024 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/win32/open.c')
-rw-r--r-- | file_io/win32/open.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/file_io/win32/open.c b/file_io/win32/open.c index 0d8f88d1b..aa3d06e09 100644 --- a/file_io/win32/open.c +++ b/file_io/win32/open.c @@ -31,6 +31,7 @@ #endif #include "apr_arch_misc.h" #include "apr_arch_inherit.h" +#include <io.h> #if APR_HAS_UNICODE_FS apr_status_t utf8_to_unicode_path(apr_wchar_t* retstr, apr_size_t retlen, @@ -227,25 +228,34 @@ apr_status_t file_cleanup(void *thefile) if (file->filehand != INVALID_HANDLE_VALUE) { + if (file->buffered) { + /* XXX: flush here is not mutex protected */ + flush_rv = apr_file_flush((apr_file_t *)thefile); + } + /* In order to avoid later segfaults with handle 'reuse', * we must protect against the case that a dup2'ed handle * is being closed, and invalidate the corresponding StdHandle + * We also tell msvcrt when stdhandles are closed. */ - if (file->filehand == GetStdHandle(STD_ERROR_HANDLE)) { - SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE); - } - if (file->filehand == GetStdHandle(STD_OUTPUT_HANDLE)) { - SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE); - } - if (file->filehand == GetStdHandle(STD_INPUT_HANDLE)) { - SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE); + if (file->flags & APR_STD_FLAGS) + { + if ((file->flags & APR_STD_FLAGS) == APR_STDERR_FLAG) { + _close(2); + SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE); + } + else if ((file->flags & APR_STD_FLAGS) == APR_STDOUT_FLAG) { + _close(1); + SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE); + } + else if ((file->flags & APR_STD_FLAGS) == APR_STDIN_FLAG) { + _close(0); + SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE); + } } + else + CloseHandle(file->filehand); - if (file->buffered) { - /* XXX: flush here is not mutex protected */ - flush_rv = apr_file_flush((apr_file_t *)thefile); - } - CloseHandle(file->filehand); file->filehand = INVALID_HANDLE_VALUE; } if (file->pOverlapped && file->pOverlapped->hEvent) { |