identical?(p1, p2)
public
Show source
static VALUE
rb_file_identical_p(VALUE obj, VALUE fname1, VALUE fname2)
{
struct stat st1, st2;
if (rb_stat(fname1, &st1) < 0) return Qfalse;
if (rb_stat(fname2, &st2) < 0) return Qfalse;
if (st1.st_dev != st2.st_dev) return Qfalse;
if (st1.st_ino != st2.st_ino) return Qfalse;
BY_HANDLE_FILE_INFORMATION st1, st2;
HANDLE f1 = 0, f2 = 0;
rb_secure(2);
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 (!f1 || !f2) return Qfalse;
FilePathValue(fname1);
fname1 = rb_str_new4(fname1);
fname1 = rb_str_encode_ospath(fname1);
FilePathValue(fname2);
fname2 = rb_str_encode_ospath(fname2);
if (access(RSTRING_PTR(fname1), 0)) return Qfalse;
if (access(RSTRING_PTR(fname2), 0)) return Qfalse;
fname1 = rb_file_expand_path(fname1, Qnil);
fname2 = rb_file_expand_path(fname2, Qnil);
if (RSTRING_LEN(fname1) != RSTRING_LEN(fname2)) return Qfalse;
if (rb_memcicmp(RSTRING_PTR(fname1), RSTRING_PTR(fname2), RSTRING_LEN(fname1)))
return Qfalse;
return Qtrue;
}