summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-21 07:53:55 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-21 07:53:55 +0000
commitdc2f377889e86a1f11a7a7f68eed47e49d567c3a (patch)
tree074f2d059b0c59240d8d5f063812c94b25026ace /file.c
parent8e30020ca881517ff79ca7cfd1b47940510b0375 (diff)
* file.c (w32_io_info): should return handle because FileIndex is
valid only while file is open. [ruby-dev:28088] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/file.c b/file.c
index dd34478..28b8834 100644
--- a/file.c
+++ b/file.c
@@ -663,39 +663,36 @@ rb_stat(file, st)
}
#ifdef _WIN32
-static BOOL
+static HANDLE
w32_io_info(file, st)
VALUE *file;
BY_HANDLE_FILE_INFORMATION *st;
{
VALUE tmp;
- HANDLE f;
- BOOL ret = FALSE;
+ HANDLE f, ret = 0;
tmp = rb_check_convert_type(*file, T_FILE, "IO", "to_io");
if (!NIL_P(tmp)) {
OpenFile *fptr;
- *file = Qnil;
GetOpenFile(tmp, fptr);
f = (HANDLE)rb_w32_get_osfhandle(fileno(fptr->f));
- if (f == (HANDLE)-1) return FALSE;
+ if (f == (HANDLE)-1) return INVALID_HANDLE_VALUE;
}
else {
SafeStringValue(*file);
f = CreateFile(StringValueCStr(*file), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
rb_w32_iswin95() ? 0 : FILE_FLAG_BACKUP_SEMANTICS, NULL);
- if (f == INVALID_HANDLE_VALUE) return FALSE;
+ if (f == INVALID_HANDLE_VALUE) return f;
+ ret = f;
}
if (GetFileType(f) == FILE_TYPE_DISK) {
ZeroMemory(st, sizeof(*st));
- ret = GetFileInformationByHandle(f, st);
+ if (GetFileInformationByHandle(f, st)) return ret;
}
- if (NIL_P(tmp)) {
- CloseHandle(f);
- }
- return ret;
+ if (ret) CloseHandle(ret);
+ return INVALID_HANDLE_VALUE;
}
#endif
@@ -1417,18 +1414,23 @@ test_identical(obj, fname1, fname2)
#else
#ifdef _WIN32
BY_HANDLE_FILE_INFORMATION st1, st2;
+ HANDLE f1 = 0, f2 = 0;
#endif
rb_secure(2);
#ifdef _WIN32
- if (!w32_io_info(&fname1, &st1)) return Qfalse;
- if (!w32_io_info(&fname2, &st2)) return Qfalse;
+ f1 = w32_io_info(&fname1, &st1);
+ if (f1 == INVALID_HANDLE_VALUE) return Qfalse;
+ f2 = w32_io_info(&fname2, &st2);
+ if (f1) CloseHandle(f1);
+ if (f2 == INVALID_HANDLE_VALUE) return Qfalse;
+ if (f2) CloseHandle(f2);
if (st1.dwVolumeSerialNumber == st2.dwVolumeSerialNumber &&
st1.nFileIndexHigh == st2.nFileIndexHigh &&
st1.nFileIndexLow == st2.nFileIndexLow)
return Qtrue;
- if (NIL_P(fname1) || NIL_P(fname2)) return Qfalse;
+ if (!f1 || !f2) return Qfalse;
if (rb_w32_iswin95()) return Qfalse;
#else
SafeStringValue(fname1);