diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-06 09:48:00 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-06 09:48:00 +0000 |
commit | c9f5a8f3f2a18b1a2e283d29e906471dade5f3be (patch) | |
tree | 8db79e72a6f0a9450ff08b2d23d49964df3c8727 /io.c | |
parent | 015997ecde57588a5ae850b0c27751162cbc0cf4 (diff) | |
download | ruby-c9f5a8f3f2a18b1a2e283d29e906471dade5f3be.tar.gz |
* bootstraptest/test_io.c: add a test for [ruby-dev:46834].
* io.c (rb_cloexec_fcntl_dupfd) Use an emulation with dup(2) when
fcntl(2) and/or F_DUPFD is unavailable.
Suggested by akr.
* configure.in (HAVE_FCNTL): NativeClient does not provide fcntl(2).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -168,7 +168,7 @@ void rb_maygvl_fd_fix_cloexec(int fd) { /* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */ -#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) && !defined(__native_client__) +#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) int flags, flags2, ret; flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */ if (flags == -1) { @@ -298,7 +298,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd) { int ret; -#if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD) && !defined(__native_client__) +#if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD) static int try_dupfd_cloexec = 1; if (try_dupfd_cloexec) { ret = fcntl(fd, F_DUPFD_CLOEXEC, minfd); @@ -318,10 +318,18 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd) else { ret = fcntl(fd, F_DUPFD, minfd); } -#elif defined(HAVE_FCNTL) && defined(F_DUPFD) && !defined(__native_client__) +#elif defined(HAVE_FCNTL) && defined(F_DUPFD) ret = fcntl(fd, F_DUPFD, minfd); +#elif defined(HAVE_DUP) + ret = dup(fd); + if (ret != -1 && ret < minfd) { + const int prev_fd = ret; + ret = rb_cloexec_fcntl_dupfd(fd, minfd); + close(prev_fd); + } + return ret; #else - ret = dup2(fd, minfd); +# error "dup() or fcntl(F_DUPFD) must be supported." #endif if (ret == -1) return -1; rb_maygvl_fd_fix_cloexec(ret); |