Project

General

Profile

Bug #8676 » win32_file_open_patch.patch

patch file - jiayp@glodon.com (贾 延平), 07/24/2013 11:01 AM

View differences:

include/ruby/intern.h (working copy)
650 650
#define rb_argv rb_get_argv()
651 651
RUBY_EXTERN VALUE rb_argv0;
652 652
VALUE rb_get_argv(void);
653
void *rb_load_file(const char*);
653
void *rb_load_file(VALUE);
654 654
/* signal.c */
655 655
VALUE rb_f_kill(int, VALUE*);
656 656
#ifdef POSIX_SIGNAL
load.c (working copy)
592 592
	VALUE iseq;
593 593

  
594 594
	th->mild_compile_error++;
595
	node = (NODE *)rb_load_file(RSTRING_PTR(fname));
595
	node = (NODE *)rb_load_file(fname);
596 596
	loaded = TRUE;
597 597
	iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
598 598
	th->mild_compile_error--;
ruby.c (working copy)
1748 1748
}
1749 1749

  
1750 1750
void *
1751
rb_load_file(const char *fname)
1751
rb_load_file(VALUE fname)
1752 1752
{
1753 1753
    struct cmdline_options opt;
1754
    VALUE fname_v = rb_str_new_cstr(fname);
1755 1754

  
1756
    return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
1755
    return load_file(rb_parser_new(), fname, 0, cmdline_options_init(&opt));
1757 1756
}
1758 1757

  
1759 1758
static void
win32/file.c (working copy)
686 686
rb_file_load_ok(const char *path)
687 687
{
688 688
    int ret = 1;
689
    DWORD attr = GetFileAttributes(path);
689
    size_t len;
690
    wchar_t* wpath;
691

  
692
    len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0) + 1;
693
    wpath = (wchar_t *)xmalloc(len * sizeof(wchar_t));
694
    MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, len);
695

  
696
    DWORD attr = GetFileAttributesW(wpath);
690 697
    if (attr == INVALID_FILE_ATTRIBUTES ||
691 698
	attr & FILE_ATTRIBUTE_DIRECTORY) {
692 699
	ret = 0;
693 700
    }
694 701
    else {
695
	HANDLE h = CreateFile(path, GENERIC_READ,
702
	HANDLE h = CreateFileW(wpath, GENERIC_READ,
696 703
			      FILE_SHARE_READ | FILE_SHARE_WRITE,
697 704
			      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
698 705
	if (h != INVALID_HANDLE_VALUE) {
......
702 709
	    ret = 0;
703 710
	}
704 711
    }
712
    xfree(wpath);
705 713
    return ret;
706 714
}
707 715