[前][次][番号順一覧][スレッド一覧]

ruby-changes:14423

From: nobu <ko1@a...>
Date: Fri, 8 Jan 2010 18:51:36 +0900 (JST)
Subject: [ruby-changes:14423] Ruby:r26253 (ruby_1_8): * io.c (io_fwrite): preserve errno.

nobu	2010-01-08 18:51:23 +0900 (Fri, 08 Jan 2010)

  New Revision: 26253

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26253

  Log:
    * io.c (io_fwrite): preserve errno.  [ruby-core:27425]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/io.c
    branches/ruby_1_8/test/ruby/test_pipe.rb

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 26252)
+++ ruby_1_8/ChangeLog	(revision 26253)
@@ -1,3 +1,7 @@
+Fri Jan  8 18:51:11 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (io_fwrite): preserve errno.  [ruby-core:27425]
+
 Fri Jan  8 17:07:15 2010  NAKAMURA Usaku  <usa@r...>
 
 	* io.c (rb_io_s_read): close the IO if an exception is raised on
Index: ruby_1_8/io.c
===================================================================
--- ruby_1_8/io.c	(revision 26252)
+++ ruby_1_8/io.c	(revision 26253)
@@ -122,6 +122,9 @@
 # endif
 #endif
 
+#define preserving_errno(stmts) \
+	do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
+
 VALUE rb_cIO;
 VALUE rb_eEOFError;
 VALUE rb_eIOError;
@@ -490,7 +493,7 @@
 	r = write(fileno(f), RSTRING(str)->ptr+offset, l);
         TRAP_END;
 #if BSD_STDIO
-	fseeko(f, lseek(fileno(f), (off_t)0, SEEK_CUR), SEEK_SET);
+	preserving_errno(fseeko(f, lseek(fileno(f), (off_t)0, SEEK_CUR), SEEK_SET));
 #endif
         if (r == n) return len;
         if (0 <= r) {
Index: ruby_1_8/test/ruby/test_pipe.rb
===================================================================
--- ruby_1_8/test/ruby/test_pipe.rb	(revision 26252)
+++ ruby_1_8/test/ruby/test_pipe.rb	(revision 26253)
@@ -15,4 +15,18 @@
       r.close
     end
   end
+
+  def test_write
+    bug2559 = '[ruby-core:27425]'
+    a, b = IO.pipe
+    begin
+      a.close
+      assert_raises(Errno::EPIPE, bug2559) do
+        b.write("hi")
+      end
+    ensure
+      a.close if !a.closed?
+      b.close if !b.closed?
+    end
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]