summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-22 07:22:09 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-22 07:22:09 +0000
commit5ee39c26491e57a97f87896a7e1e76a5472157c1 (patch)
tree649221dc33d99709f1a8d03bafc23ca44b72dea6 /win32
parenta53a144a8c193d5d05bff699c04ede51a0adbdbf (diff)
Fri, 1 Oct 2010 06:13:32 +0000 usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
merge revision(s) 29382: * 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 Signed-off-by: URABE, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@29862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 8497e487b2..1f8a845818 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1883,15 +1883,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