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)
5257 5257
__attribute__((noinline))
5258 5258
#endif
5259 5259
int
5260
rb_file_load_ok(const char *path)
5260
rb_file_load_ok(VALUE path)
5261 5261
{
5262
    char *f = RSTRING_PTR(path)
5262 5263
    int ret = 1;
5263
    int fd = rb_cloexec_open(path, O_RDONLY, 0);
5264
    int fd = rb_cloexec_open(f, O_RDONLY, 0);
5264 5265
    if (fd == -1) return 0;
5265 5266
    rb_update_max_fd(fd);
5266 5267
#if !defined DOSISH
......
5326 5327
	fnlen = RSTRING_LEN(fname);
5327 5328
	for (i=0; ext[i]; i++) {
5328 5329
	    rb_str_cat2(fname, ext[i]);
5329
	    if (rb_file_load_ok(RSTRING_PTR(fname))) {
5330
	    if (rb_file_load_ok(fname)) {
5330 5331
		*filep = copy_path_class(fname, *filep);
5331 5332
		return (int)(i+1);
5332 5333
	    }
......
5355 5356
	    RB_GC_GUARD(str) = rb_get_path_check(str, safe_level);
5356 5357
	    if (RSTRING_LEN(str) == 0) continue;
5357 5358
	    rb_file_expand_path_internal(fname, str, 0, 0, tmp);
5358
	    if (rb_file_load_ok(RSTRING_PTR(tmp))) {
5359
	    if (rb_file_load_ok(tmp)) {
5359 5360
		*filep = copy_path_class(tmp, *filep);
5360 5361
		return (int)(j+1);
5361 5362
	    }
......
5394 5395
	if (safe_level >= 1 && !fpath_check(path)) {
5395 5396
	    rb_raise(rb_eSecurityError, "loading from unsafe path %s", f);
5396 5397
	}
5397
	if (!rb_file_load_ok(f)) return 0;
5398
	if (!rb_file_load_ok(path)) return 0;
5398 5399
	if (!expanded)
5399 5400
	    path = copy_path_class(file_expand_path_1(path), path);
5400 5401
	return path;
......
5415 5416
	    RB_GC_GUARD(str) = rb_get_path_check(str, safe_level);
5416 5417
	    if (RSTRING_LEN(str) > 0) {
5417 5418
		rb_file_expand_path_internal(path, str, 0, 0, tmp);
5418
		f = RSTRING_PTR(tmp);
5419
		if (rb_file_load_ok(f)) goto found;
5419
		if (rb_file_load_ok(tmp)) goto found;
5420 5420
	    }
5421 5421
	}
5422 5422
	return 0;
include/ruby/intern.h (working copy)
651 651
#define rb_argv rb_get_argv()
652 652
RUBY_EXTERN VALUE rb_argv0;
653 653
VALUE rb_get_argv(void);
654
void *rb_load_file(const char*);
654
void *rb_load_file(VALUE);
655 655
/* signal.c */
656 656
VALUE rb_f_kill(int, VALUE*);
657 657
#ifdef POSIX_SIGNAL
internal.h (working copy)
124 124
VALUE rb_home_dir(const char *user, VALUE result);
125 125
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
126 126
void rb_file_const(const char*, VALUE);
127
int rb_file_load_ok(const char *);
127
int rb_file_load_ok(VALUE);
128 128
VALUE rb_file_expand_path_fast(VALUE, VALUE);
129 129
VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
130 130
VALUE rb_get_path_check_to_string(VALUE, int);
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--;
......
673 673

  
674 674
    path = rb_find_file(FilePathValue(fname));
675 675
    if (!path) {
676
	if (!rb_file_load_ok(RSTRING_PTR(fname)))
676
	if (!rb_file_load_ok(fname))
677 677
	    load_failed(fname);
678 678
	path = fname;
679 679
    }
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)
683 683
}
684 684

  
685 685
int
686
rb_file_load_ok(const char *path)
686
rb_file_load_ok(VALUE path)
687 687
{
688 688
    int ret = 1;
689
    DWORD attr = GetFileAttributes(path);
689
    size_t wpath_len = 0;
690
    wchar_t *wpath = NULL, *wpath_pos = NULL;
691
    rb_encoding *path_encoding = rb_enc_get(path);
692
    UINT path_cp, cp;
693

  
694
    cp = path_cp = code_page(path_encoding);
695

  
696
    /* workaround invalid codepage */
697
    if (path_cp == INVALID_CODE_PAGE) {
698
	cp = CP_UTF8;
699
	if (!NIL_P(path)) {
700
	    path = fix_string_encoding(path, path_encoding);
701
	}
702
    }
703

  
704
    /* convert char * to wchar_t */
705
    convert_mb_to_wchar(path, &wpath, &wpath_pos, &wpath_len, cp);	
706

  
707
    DWORD attr = GetFileAttributesW(wpath);
690 708
    if (attr == INVALID_FILE_ATTRIBUTES ||
691 709
	attr & FILE_ATTRIBUTE_DIRECTORY) {
692 710
	ret = 0;
693 711
    }
694 712
    else {
695
	HANDLE h = CreateFile(path, GENERIC_READ,
713
	HANDLE h = CreateFileW(wpath, GENERIC_READ,
696 714
			      FILE_SHARE_READ | FILE_SHARE_WRITE,
697 715
			      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
698 716
	if (h != INVALID_HANDLE_VALUE) {