summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-25 09:57:40 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-25 09:57:40 +0000
commit5b7d89de755390ae1a03f79b602c4fcc37f6559e (patch)
treeb480be64d0dcdbe950661ca46fbe9443e081d8f8 /io.c
parent8474bf6b7c0222580000f717c3059e56bdbf9539 (diff)
merges r20987 from trunk into ruby_1_9_1.
* io.c (fptr_finalize): close the IO object even if close(2) is failed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/io.c b/io.c
index 3331d442f4..6ae5ea9d8d 100644
--- a/io.c
+++ b/io.c
@@ -3090,7 +3090,7 @@ finish_writeconv_sync(VALUE arg)
static void
fptr_finalize(rb_io_t *fptr, int noraise)
{
- int ebadf = 0;
+ int close_failure = 0;
if (fptr->writeconv) {
if (fptr->write_lock) {
struct finish_writeconv_arg arg;
@@ -3110,29 +3110,22 @@ fptr_finalize(rb_io_t *fptr, int noraise)
return;
}
if (fptr->stdio_file) {
- if (fclose(fptr->stdio_file) < 0 && !noraise) {
- /* fptr->stdio_file is deallocated anyway */
- fptr->stdio_file = 0;
- fptr->fd = -1;
- rb_sys_fail_path(fptr->pathv);
- }
+ /* fptr->stdio_file is deallocated anyway
+ * even if fclose failed. */
+ if (fclose(fptr->stdio_file) < 0)
+ close_failure = 1;
}
else if (0 <= fptr->fd) {
- if (close(fptr->fd) < 0 && !noraise) {
- if (errno != EBADF) {
- /* fptr->fd is still not closed */
- rb_sys_fail_path(fptr->pathv);
- }
- else {
- /* fptr->fd is already closed. */
- ebadf = 1;
- }
- }
+ /* fptr->fd may be closed even if close fails.
+ * POSIX doesn't specify it.
+ * We assumes it is closed. */
+ if (close(fptr->fd) < 0)
+ close_failure = 1;
}
fptr->fd = -1;
fptr->stdio_file = 0;
fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
- if (ebadf) {
+ if (close_failure && !noraise) {
rb_sys_fail_path(fptr->pathv);
}
}