Project

General

Profile

Bug #8676 » win32_file_open_patch.patch

jiayp@glodon.com (贾 延平), 07/26/2013 09:37 AM

View differences:

file.c (working copy)
__attribute__((noinline))
#endif
int
rb_file_load_ok(const char *path)
rb_file_load_ok(VALUE path)
{
char *f = RSTRING_PTR(path)
int ret = 1;
int fd = rb_cloexec_open(path, O_RDONLY, 0);
int fd = rb_cloexec_open(f, O_RDONLY, 0);
if (fd == -1) return 0;
rb_update_max_fd(fd);
#if !defined DOSISH
......
fnlen = RSTRING_LEN(fname);
for (i=0; ext[i]; i++) {
rb_str_cat2(fname, ext[i]);
if (rb_file_load_ok(RSTRING_PTR(fname))) {
if (rb_file_load_ok(fname)) {
*filep = copy_path_class(fname, *filep);
return (int)(i+1);
}
......
RB_GC_GUARD(str) = rb_get_path_check(str, safe_level);
if (RSTRING_LEN(str) == 0) continue;
rb_file_expand_path_internal(fname, str, 0, 0, tmp);
if (rb_file_load_ok(RSTRING_PTR(tmp))) {
if (rb_file_load_ok(tmp)) {
*filep = copy_path_class(tmp, *filep);
return (int)(j+1);
}
......
if (safe_level >= 1 && !fpath_check(path)) {
rb_raise(rb_eSecurityError, "loading from unsafe path %s", f);
}
if (!rb_file_load_ok(f)) return 0;
if (!rb_file_load_ok(path)) return 0;
if (!expanded)
path = copy_path_class(file_expand_path_1(path), path);
return path;
......
RB_GC_GUARD(str) = rb_get_path_check(str, safe_level);
if (RSTRING_LEN(str) > 0) {
rb_file_expand_path_internal(path, str, 0, 0, tmp);
f = RSTRING_PTR(tmp);
if (rb_file_load_ok(f)) goto found;
if (rb_file_load_ok(tmp)) goto found;
}
}
return 0;
include/ruby/intern.h (working copy)
#define rb_argv rb_get_argv()
RUBY_EXTERN VALUE rb_argv0;
VALUE rb_get_argv(void);
void *rb_load_file(const char*);
void *rb_load_file(VALUE);
/* signal.c */
VALUE rb_f_kill(int, VALUE*);
#ifdef POSIX_SIGNAL
internal.h (working copy)
VALUE rb_home_dir(const char *user, VALUE result);
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
void rb_file_const(const char*, VALUE);
int rb_file_load_ok(const char *);
int rb_file_load_ok(VALUE);
VALUE rb_file_expand_path_fast(VALUE, VALUE);
VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
VALUE rb_get_path_check_to_string(VALUE, int);
load.c (working copy)
VALUE iseq;
th->mild_compile_error++;
node = (NODE *)rb_load_file(RSTRING_PTR(fname));
node = (NODE *)rb_load_file(fname);
loaded = TRUE;
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
th->mild_compile_error--;
......
path = rb_find_file(FilePathValue(fname));
if (!path) {
if (!rb_file_load_ok(RSTRING_PTR(fname)))
if (!rb_file_load_ok(fname))
load_failed(fname);
path = fname;
}
ruby.c (working copy)
}
void *
rb_load_file(const char *fname)
rb_load_file(VALUE fname)
{
struct cmdline_options opt;
VALUE fname_v = rb_str_new_cstr(fname);
return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
return load_file(rb_parser_new(), fname, 0, cmdline_options_init(&opt));
}
static void
win32/file.c (working copy)
}
int
rb_file_load_ok(const char *path)
rb_file_load_ok(VALUE path)
{
int ret = 1;
DWORD attr = GetFileAttributes(path);
size_t wpath_len = 0;
wchar_t *wpath = NULL, *wpath_pos = NULL;
rb_encoding *path_encoding = rb_enc_get(path);
UINT path_cp, cp;
cp = path_cp = code_page(path_encoding);
/* workaround invalid codepage */
if (path_cp == INVALID_CODE_PAGE) {
cp = CP_UTF8;
if (!NIL_P(path)) {
path = fix_string_encoding(path, path_encoding);
}
}
/* convert char * to wchar_t */
convert_mb_to_wchar(path, &wpath, &wpath_pos, &wpath_len, cp);
DWORD attr = GetFileAttributesW(wpath);
if (attr == INVALID_FILE_ATTRIBUTES ||
attr & FILE_ATTRIBUTE_DIRECTORY) {
ret = 0;
}
else {
HANDLE h = CreateFile(path, GENERIC_READ,
HANDLE h = CreateFileW(wpath, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE) {
(2-2/2)