diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-01 06:13:32 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-01 06:13:32 +0000 |
commit | 7b1b979b47409d9bbb16a165e8d3a0d66f10dd92 (patch) | |
tree | ef7d0edb2945e16fc37a3cc43886b1b7461a650b | |
parent | 503c0d1577b45c41f88f3512d15a4973d6224562 (diff) |
* win32/win32.c (init_stdhandle): redirect unopened IOs to NUL.
backport r11362 from trunk. [ruby-core:31445]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@29382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | win32/win32.c | 24 |
2 files changed, 26 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Fri Oct 1 15:12:05 2010 NAKAMURA Usaku <[email protected]> + + * 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 <[email protected]> * ext/-test-/threadswitch/threadswitch_hook.c (event_hook, diff --git a/win32/win32.c b/win32/win32.c index fe7bbc24c9..39b11efef4 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1909,15 +1909,33 @@ rb_w32_open_osfhandle(long osfhandle, int flags) 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 |