mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
b3ffb68b5b
commit
21f81885ab
5 changed files with 34 additions and 16 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Nov 28 16:15:47 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_dup2): extract from rb_cloexec_dup2() and
|
||||||
|
redirect_dup2().
|
||||||
|
|
||||||
Tue Nov 28 14:40:00 2013 Akira Matsuda <ronnie@dio.jp>
|
Tue Nov 28 14:40:00 2013 Akira Matsuda <ronnie@dio.jp>
|
||||||
|
|
||||||
* lib/drb/ssl.rb: [Doc] Fix typo
|
* lib/drb/ssl.rb: [Doc] Fix typo
|
||||||
|
|
|
@ -346,6 +346,7 @@ extern int rb_w32_access(const char *, int);
|
||||||
extern int rb_w32_uaccess(const char *, int);
|
extern int rb_w32_uaccess(const char *, int);
|
||||||
extern char rb_w32_fd_is_text(int);
|
extern char rb_w32_fd_is_text(int);
|
||||||
extern int rb_w32_fstati64(int, struct stati64 *);
|
extern int rb_w32_fstati64(int, struct stati64 *);
|
||||||
|
extern int rb_w32_dup2(int, int);
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
extern off_t _lseeki64(int, off_t, int);
|
extern off_t _lseeki64(int, off_t, int);
|
||||||
|
@ -734,6 +735,9 @@ extern char *rb_w32_strerror(int);
|
||||||
|
|
||||||
#undef times
|
#undef times
|
||||||
#define times(t) rb_w32_times(t)
|
#define times(t) rb_w32_times(t)
|
||||||
|
|
||||||
|
#undef dup2
|
||||||
|
#define dup2(o, n) rb_w32_dup2(o, n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct tms {
|
struct tms {
|
||||||
|
|
4
io.c
4
io.c
|
@ -275,10 +275,6 @@ rb_cloexec_dup2(int oldfd, int newfd)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ret = dup2(oldfd, newfd);
|
ret = dup2(oldfd, newfd);
|
||||||
# ifdef _WIN32
|
|
||||||
if (newfd >= 0 && newfd <= 2)
|
|
||||||
SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)rb_w32_get_osfhandle(newfd));
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
if (ret == -1) return -1;
|
if (ret == -1) return -1;
|
||||||
}
|
}
|
||||||
|
|
14
process.c
14
process.c
|
@ -2500,28 +2500,16 @@ redirect_dup(int oldfd)
|
||||||
ttyprintf("dup(%d) => %d\n", oldfd, ret);
|
ttyprintf("dup(%d) => %d\n", oldfd, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#define redirect_dup(oldfd) dup(oldfd)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(DEBUG_REDIRECT) || defined(_WIN32)
|
|
||||||
static int
|
static int
|
||||||
redirect_dup2(int oldfd, int newfd)
|
redirect_dup2(int oldfd, int newfd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = dup2(oldfd, newfd);
|
ret = dup2(oldfd, newfd);
|
||||||
if (newfd >= 0 && newfd <= 2)
|
|
||||||
SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)rb_w32_get_osfhandle(newfd));
|
|
||||||
#if defined(DEBUG_REDIRECT)
|
|
||||||
ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
|
ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
|
||||||
#endif
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(DEBUG_REDIRECT)
|
|
||||||
static int
|
static int
|
||||||
redirect_close(int fd)
|
redirect_close(int fd)
|
||||||
{
|
{
|
||||||
|
@ -2541,6 +2529,8 @@ redirect_open(const char *pathname, int flags, mode_t perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#define redirect_dup(oldfd) dup(oldfd)
|
||||||
|
#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
|
||||||
#define redirect_close(fd) close(fd)
|
#define redirect_close(fd) close(fd)
|
||||||
#define redirect_open(pathname, flags, perm) open((pathname), (flags), (perm))
|
#define redirect_open(pathname, flags, perm) open((pathname), (flags), (perm))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -79,6 +79,7 @@ static char *w32_getenv(const char *name, UINT cp);
|
||||||
#undef fclose
|
#undef fclose
|
||||||
#undef close
|
#undef close
|
||||||
#undef setsockopt
|
#undef setsockopt
|
||||||
|
#undef dup2
|
||||||
|
|
||||||
#if defined __BORLANDC__
|
#if defined __BORLANDC__
|
||||||
# define _filbuf _fgetc
|
# define _filbuf _fgetc
|
||||||
|
@ -5465,6 +5466,28 @@ rb_w32_getppid(void)
|
||||||
return ppid;
|
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 */
|
/* License: Ruby's */
|
||||||
int
|
int
|
||||||
rb_w32_uopen(const char *file, int oflag, ...)
|
rb_w32_uopen(const char *file, int oflag, ...)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue