Index: file.c =================================================================== --- file.c (revision 42158) +++ file.c (working copy) @@ -5257,10 +5257,11 @@ __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 @@ -5326,7 +5327,7 @@ 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); } @@ -5355,7 +5356,7 @@ 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); } @@ -5394,7 +5395,7 @@ 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; @@ -5415,8 +5416,7 @@ 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; Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 42158) +++ include/ruby/intern.h (working copy) @@ -651,7 +651,7 @@ #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 Index: internal.h =================================================================== --- internal.h (revision 42158) +++ internal.h (working copy) @@ -124,7 +124,7 @@ 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); Index: load.c =================================================================== --- load.c (revision 42158) +++ load.c (working copy) @@ -592,7 +592,7 @@ 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(""), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse); th->mild_compile_error--; @@ -673,7 +673,7 @@ 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; } Index: ruby.c =================================================================== --- ruby.c (revision 42158) +++ ruby.c (working copy) @@ -1748,12 +1748,11 @@ } 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 Index: win32/file.c =================================================================== --- win32/file.c (revision 42158) +++ win32/file.c (working copy) @@ -683,16 +683,34 @@ } 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) {