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:
parent
e40aef464a
commit
b36585ce42
2 changed files with 21 additions and 14 deletions
|
@ -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>
|
||||
|
||||
* test/pathname/test_pathname.rb (test_kernel_open): use
|
||||
|
|
30
file.c
30
file.c
|
@ -637,37 +637,34 @@ rb_stat(VALUE file, struct stat *st)
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static BOOL
|
||||
static HANDLE
|
||||
w32_io_info(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(fptr->fd);
|
||||
if (f == (HANDLE)-1) return FALSE;
|
||||
if (f == (HANDLE)-1) return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
else {
|
||||
FilePathValue(*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(VALUE obj, VALUE fname1, VALUE 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
|
||||
FilePathValue(fname1);
|
||||
|
|
Loading…
Reference in a new issue