ruby-changes:50032
From: nobu <ko1@a...>
Date: Thu, 1 Feb 2018 11:56:32 +0900 (JST)
Subject: [ruby-changes:50032] nobu:r62150 (trunk): win32.c: EPIPE for ERROR_NO_DATA
nobu 2018-02-01 11:56:28 +0900 (Thu, 01 Feb 2018) New Revision: 62150 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62150 Log: win32.c: EPIPE for ERROR_NO_DATA * win32/win32.c (rb_w32_write): writing to closed pipe fails with ERROR_NO_DATA but msvcrt maps it to EINVAL. map it to EPIPE. Modified files: trunk/test/ruby/test_pipe.rb trunk/win32/win32.c Index: win32/win32.c =================================================================== --- win32/win32.c (revision 62149) +++ win32/win32.c (revision 62150) @@ -7119,7 +7119,11 @@ rb_w32_write(int fd, const void *buf, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L7119 if ((_osfile(fd) & FTEXT) && (!(_osfile(fd) & FPIPE) || fd == fileno(stdout) || fd == fileno(stderr))) { - return _write(fd, buf, size); + ssize_t w = _write(fd, buf, size); + if (w == (ssize_t)-1 && errno == EINVAL) { + errno = map_errno(GetLastError()); + } + return w; } rb_acrt_lowio_lock_fh(fd); Index: test/ruby/test_pipe.rb =================================================================== --- test/ruby/test_pipe.rb (revision 62149) +++ test/ruby/test_pipe.rb (revision 62150) @@ -27,4 +27,23 @@ class TestPipe < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pipe.rb#L27 end end end + + def test_stdout_epipe + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + io = STDOUT + begin + save = io.dup + IO.popen("echo", "w", out: IO::NULL) do |f| + io.reopen(f) + Process.wait(f.pid) + assert_raise(Errno::EPIPE) do + io.print "foo\n" + end + end + ensure + io.reopen(save) + end + end; + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/