From 65370097cda754090f57da3d9df85f98c7725e50 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 20 Aug 2008 11:33:36 +0000 Subject: * io.c (rb_io_open_with_args): use rb_open_file instead of rb_io_open. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ io.c | 16 ++++------------ test/ruby/test_io.rb | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4db67c0025..a38dd8c920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Aug 20 20:32:49 2008 Tanaka Akira + + * io.c (rb_io_open_with_args): use rb_open_file instead of rb_io_open. + Wed Aug 20 20:16:17 2008 Tanaka Akira * io.c (rb_scan_open_args): extracted from rb_open_file. diff --git a/io.c b/io.c index a0b877e3ff..60f9241720 100644 --- a/io.c +++ b/io.c @@ -4807,19 +4807,11 @@ rb_io_open(const char *fname, const char *mode) static VALUE rb_io_open_with_args(int argc, VALUE *argv) { - const char *mode; - VALUE pname, pmode; + VALUE io; - if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) { - mode = "r"; - } - else if (FIXNUM_P(pmode)) { - mode = rb_io_modenum_mode(FIX2INT(pmode)); - } - else { - mode = StringValueCStr(pmode); - } - return rb_io_open(StringValueCStr(pname), mode); + io = io_alloc(rb_cFile); + rb_open_file(argc, argv, io); + return io; } static VALUE diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 3d1dada06c..a181b41023 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1225,4 +1225,22 @@ class TestIO < Test::Unit::TestCase def test_uninitialized assert_raise(IOError) { IO.allocate.print "" } end + + def test_nofollow + return unless defined? File::NOFOLLOW + mkcdtmpdir { + open("file", "w") {|f| f << "content" } + begin + File.symlink("file", "slnk") + rescue NotImplementedError + return + end + assert_raise(Errno::ELOOP) { + open("slnk", File::RDONLY|File::NOFOLLOW) {} + } + assert_raise(Errno::ELOOP) { + File.foreach("slnk", :open_args=>[File::RDONLY|File::NOFOLLOW]) {} + } + } + end end -- cgit v1.2.3