diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2001-03-31 22:58:45 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2001-03-31 22:58:45 +0000 |
commit | d2c0938bde6ad70d66ab54e2057b474798c9e0ff (patch) | |
tree | 31280fd326bffdd47b640ef97b22dc558100aeff /file_io/unix/open.c | |
parent | 0761170e32a3ed10e0b9e8d30df7f5fd662393ad (diff) | |
download | libapr-d2c0938bde6ad70d66ab54e2057b474798c9e0ff.tar.gz |
flush unwritten buffered data in the file cleanup routine, not in
apr_file_close()
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61422 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix/open.c')
-rw-r--r-- | file_io/unix/open.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/file_io/unix/open.c b/file_io/unix/open.c index 4f5237213..254845222 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -59,23 +59,26 @@ apr_status_t apr_unix_file_cleanup(void *thefile) { apr_file_t *file = thefile; - int rv; + apr_status_t flush_rv = APR_SUCCESS, rv = APR_SUCCESS; + int rc; - rv = close(file->filedes); - - if (rv == 0) { + if (file->buffered) { + flush_rv = apr_file_flush(file); + } + rc = close(file->filedes); + if (rc == 0) { file->filedes = -1; #if APR_HAS_THREADS if (file->thlock) { - return apr_lock_destroy(file->thlock); + rv = apr_lock_destroy(file->thlock); } #endif - return APR_SUCCESS; } else { - return errno; /* Are there any error conditions other than EINTR or EBADF? */ + rv = errno; } + return rv != APR_SUCCESS ? rv : flush_rv; } apr_status_t apr_file_open(apr_file_t **new, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *cont) @@ -170,17 +173,13 @@ apr_status_t apr_file_open(apr_file_t **new, const char *fname, apr_int32_t flag apr_status_t apr_file_close(apr_file_t *file) { - apr_status_t flush_rv = APR_SUCCESS, rv; - - if (file->buffered) { - flush_rv = apr_file_flush(file); - } + apr_status_t rv; if ((rv = apr_unix_file_cleanup(file)) == APR_SUCCESS) { apr_pool_cleanup_kill(file->cntxt, file, apr_unix_file_cleanup); return APR_SUCCESS; } - return rv ? rv : flush_rv; + return rv; } apr_status_t apr_file_remove(const char *path, apr_pool_t *cont) |