ruby-changes:17377
From: usa <ko1@a...>
Date: Fri, 1 Oct 2010 15:14:50 +0900 (JST)
Subject: [ruby-changes:17377] Ruby:r29382 (ruby_1_8): * win32/win32.c (init_stdhandle): redirect unopened IOs to NUL.
usa 2010-10-01 15:13:32 +0900 (Fri, 01 Oct 2010) New Revision: 29382 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29382 Log: * win32/win32.c (init_stdhandle): redirect unopened IOs to NUL. backport r11362 from trunk. [ruby-core:31445] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/win32/win32.c Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 29381) +++ ruby_1_8/ChangeLog (revision 29382) @@ -1,3 +1,8 @@ +Fri Oct 1 15:12:05 2010 NAKAMURA Usaku <usa@r...> + + * win32/win32.c (init_stdhandle): redirect unopened IOs to NUL. + backport r11362 from trunk. [ruby-core:31445] + Fri Oct 1 15:07:30 2010 NAKAMURA Usaku <usa@r...> * ext/-test-/threadswitch/threadswitch_hook.c (event_hook, Index: ruby_1_8/win32/win32.c =================================================================== --- ruby_1_8/win32/win32.c (revision 29381) +++ ruby_1_8/win32/win32.c (revision 29382) @@ -1909,15 +1909,33 @@ static void init_stdhandle(void) { + int nullfd = -1; + int keep = 0; +#define open_null(fd) \ + (((nullfd < 0) ? \ + (nullfd = open("NUL", O_RDWR|O_BINARY)) : 0), \ + ((nullfd == (fd)) ? (keep = 1) : dup2(nullfd, fd)), \ + (fd)) + if (fileno(stdin) < 0) { - stdin->_file = 0; + stdin->_file = open_null(0); } + else { + setmode(fileno(stdin), O_BINARY); + } if (fileno(stdout) < 0) { - stdout->_file = 1; + stdout->_file = open_null(1); } + else { + setmode(fileno(stdout), O_BINARY); + } if (fileno(stderr) < 0) { - stderr->_file = 2; + stderr->_file = open_null(2); } + else { + setmode(fileno(stderr), O_BINARY); + } + if (nullfd >= 0 && !keep) close(nullfd); setvbuf(stderr, NULL, _IONBF, 0); } #else -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/