diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-06 14:58:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-06 14:58:46 +0000 |
commit | 0c19297362d1a400e4ea536f963ff5e7d3e40112 (patch) | |
tree | ee06759c26852725642b59d5632a2e1307a6c621 /win32 | |
parent | 8eb656fcf59129d7f450de2dbd381095ffb613cd (diff) | |
download | ruby-0c19297362d1a400e4ea536f963ff5e7d3e40112.tar.gz ruby-0c19297362d1a400e4ea536f963ff5e7d3e40112.tar.xz ruby-0c19297362d1a400e4ea536f963ff5e7d3e40112.zip |
* win32/win32.c (init_stdhandle): redirect unopened IOs to NUL.
[ruby-core:09572]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c index a8e755e1f..a50a5f480 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1731,15 +1731,24 @@ 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); } if (fileno(stdout) < 0) { - stdout->_file = 1; + stdout->_file = open_null(1); } if (fileno(stderr) < 0) { - stderr->_file = 2; + stderr->_file = open_null(2); } + if (nullfd >= 0 && !keep) close(nullfd); } #else |