Project

General

Profile

Feature #7067 ยป patch.diff

Glass_saga (Masaki Matsushita), 09/27/2012 11:34 PM

View differences:

io.c
6365 6365
    }
6366 6366

  
6367 6367
    if (!NIL_P(nmode)) {
6368
	int fmode = rb_io_modestr_fmode(StringValueCStr(nmode));
6368
	VALUE intmode;
6369
	int fmode;
6370

  
6371
	if (!NIL_P(intmode = rb_check_to_integer(nmode, "to_int"))) {
6372
	    oflags = NUM2INT(intmode);
6373
	    fmode = rb_io_oflags_fmode(oflags);
6374
	}
6375
	else {
6376
	    fmode = rb_io_modestr_fmode(StringValueCStr(nmode));
6377
	}
6378

  
6369 6379
	if (IS_PREP_STDIO(fptr) &&
6370 6380
            ((fptr->mode & FMODE_READWRITE) & (fmode & FMODE_READWRITE)) !=
6371 6381
            (fptr->mode & FMODE_READWRITE)) {
......
6375 6385
		     rb_io_fmode_modestr(fmode));
6376 6386
	}
6377 6387
	fptr->mode = fmode;
6378
	rb_io_mode_enc(fptr, StringValueCStr(nmode));
6388
	if (NIL_P(intmode)) {
6389
	    rb_io_mode_enc(fptr, StringValueCStr(nmode));
6390
	}
6379 6391
        fptr->encs.ecflags = 0;
6380 6392
        fptr->encs.ecopts = Qnil;
6381 6393
    }
test/ruby/test_io.rb
1713 1713
    }
1714 1714
  end
1715 1715

  
1716
  def test_reopen_mode
1717
    make_tempfile {|t|
1718
      open(__FILE__) do |f|
1719
        assert_nothing_raised {
1720
          f.reopen(t.path, "r")
1721
          assert_equal("foo\n", f.gets)
1722
        }
1723
      end
1724

  
1725
      open(__FILE__) do |f|
1726
        assert_nothing_raised {
1727
          f.reopen(t.path, File::RDONLY)
1728
          assert_equal("foo\n", f.gets)
1729
        }
1730
      end
1731
    }
1732
  end
1733

  
1716 1734
  def test_foreach
1717 1735
    a = []
1718 1736
    IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }