summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 07:15:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 07:15:56 +0000
commit21f81885ab310f564fb60bfe7dcde816eeb11994 (patch)
treed5b3f4dc354405854a354ba1c80a0f333dc906cb /win32/win32.c
parentb3ffb68b5bacd05af67c3b8b51c9209d184e3a60 (diff)
win32.c: rb_w32_dup2
* win32/win32.c (rb_w32_dup2): extract from rb_cloexec_dup2() and redirect_dup2(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index e1ac405..9cbd07f 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -79,6 +79,7 @@ static char *w32_getenv(const char *name, UINT cp);
#undef fclose
#undef close
#undef setsockopt
+#undef dup2
#if defined __BORLANDC__
# define _filbuf _fgetc
@@ -5465,6 +5466,28 @@ rb_w32_getppid(void)
return ppid;
}
+STATIC_ASSERT(std_handle, (STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)==(STD_ERROR_HANDLE-STD_OUTPUT_HANDLE));
+
+/* License: Ruby's */
+#define set_new_std_handle(newfd, handle) do { \
+ if ((unsigned)(newfd) > 2) break; \
+ SetStdHandle(STD_INPUT_HANDLE+(STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)*(newfd), \
+ (handle)); \
+ } while (0)
+#define set_new_std_fd(newfd) set_new_std_handle(newfd, (HANDLE)rb_w32_get_osfhandle(newfd))
+
+/* License: Ruby's */
+int
+rb_w32_dup2(int oldfd, int newfd)
+{
+ int ret;
+
+ if (oldfd == newfd) return newfd;
+ ret = dup2(oldfd, newfd);
+ set_new_std_fd(newfd);
+ return ret;
+}
+
/* License: Ruby's */
int
rb_w32_uopen(const char *file, int oflag, ...)