1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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/trunk@9730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2005-12-21 07:53:55 +00:00
parent e40aef464a
commit b36585ce42
2 changed files with 21 additions and 14 deletions

View file

@ -1,3 +1,8 @@
Wed Dec 21 16:47:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (w32_io_info): should return handle because FileIndex is
valid only while file is open. [ruby-dev:28088]
Wed Dec 21 12:12:21 2005 Tanaka Akira <akr@m17n.org> Wed Dec 21 12:12:21 2005 Tanaka Akira <akr@m17n.org>
* test/pathname/test_pathname.rb (test_kernel_open): use * test/pathname/test_pathname.rb (test_kernel_open): use

30
file.c
View file

@ -637,37 +637,34 @@ rb_stat(VALUE file, struct stat *st)
} }
#ifdef _WIN32 #ifdef _WIN32
static BOOL static HANDLE
w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st) w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st)
{ {
VALUE tmp; VALUE tmp;
HANDLE f; HANDLE f, ret = 0;
BOOL ret = FALSE;
tmp = rb_check_convert_type(*file, T_FILE, "IO", "to_io"); tmp = rb_check_convert_type(*file, T_FILE, "IO", "to_io");
if (!NIL_P(tmp)) { if (!NIL_P(tmp)) {
OpenFile *fptr; OpenFile *fptr;
*file = Qnil;
GetOpenFile(tmp, fptr); GetOpenFile(tmp, fptr);
f = (HANDLE)rb_w32_get_osfhandle(fptr->fd); f = (HANDLE)rb_w32_get_osfhandle(fptr->fd);
if (f == (HANDLE)-1) return FALSE; if (f == (HANDLE)-1) return INVALID_HANDLE_VALUE;
} }
else { else {
FilePathValue(*file); FilePathValue(*file);
f = CreateFile(StringValueCStr(*file), 0, f = CreateFile(StringValueCStr(*file), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
rb_w32_iswin95() ? 0 : FILE_FLAG_BACKUP_SEMANTICS, NULL); 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) { if (GetFileType(f) == FILE_TYPE_DISK) {
ZeroMemory(st, sizeof(*st)); ZeroMemory(st, sizeof(*st));
ret = GetFileInformationByHandle(f, st); if (GetFileInformationByHandle(f, st)) return ret;
} }
if (NIL_P(tmp)) { if (ret) CloseHandle(ret);
CloseHandle(f); return INVALID_HANDLE_VALUE;
}
return ret;
} }
#endif #endif
@ -1417,18 +1414,23 @@ test_identical(VALUE obj, VALUE fname1, VALUE fname2)
#else #else
#ifdef _WIN32 #ifdef _WIN32
BY_HANDLE_FILE_INFORMATION st1, st2; BY_HANDLE_FILE_INFORMATION st1, st2;
HANDLE f1 = 0, f2 = 0;
#endif #endif
rb_secure(2); rb_secure(2);
#ifdef _WIN32 #ifdef _WIN32
if (!w32_io_info(&fname1, &st1)) return Qfalse; f1 = w32_io_info(&fname1, &st1);
if (!w32_io_info(&fname2, &st2)) return Qfalse; 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 && if (st1.dwVolumeSerialNumber == st2.dwVolumeSerialNumber &&
st1.nFileIndexHigh == st2.nFileIndexHigh && st1.nFileIndexHigh == st2.nFileIndexHigh &&
st1.nFileIndexLow == st2.nFileIndexLow) st1.nFileIndexLow == st2.nFileIndexLow)
return Qtrue; return Qtrue;
if (NIL_P(fname1) || NIL_P(fname2)) return Qfalse; if (!f1 || !f2) return Qfalse;
if (rb_w32_iswin95()) return Qfalse; if (rb_w32_iswin95()) return Qfalse;
#else #else
FilePathValue(fname1); FilePathValue(fname1);