summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 11:07:09 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 11:07:09 +0000
commit6e0ed044b6d7e8247a49e85d622eab9f128dbdba (patch)
treec3c3727d6bb8f95c67a6b3f316edbc4915c5da04 /io.c
parent7c43d8523cadf8cd0483581fb8a50138b7fc4d9f (diff)
* io.c (rb_cloexec_dup): refine control flow.
(rb_cloexec_dup2): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/io.c b/io.c
index 9f696136f2..4dbf337e8c 100644
--- a/io.c
+++ b/io.c
@@ -212,14 +212,13 @@ rb_cloexec_dup(int oldfd)
if (try_fcntl) {
/* don't allocate standard file descriptors: 0, 1, 2 */
ret = fcntl(oldfd, F_DUPFD_CLOEXEC, 3);
+ if (ret != -1)
+ return ret;
/* F_DUPFD_CLOEXEC is available since Linux 2.6.24. Linux 2.6.18 fails with EINVAL */
- if (ret == -1 && errno == EINVAL) {
+ if (errno == EINVAL) {
try_fcntl = 0;
ret = dup(oldfd);
}
- else {
- return ret;
- }
}
else {
ret = dup(oldfd);
@@ -244,14 +243,13 @@ rb_cloexec_dup2(int oldfd, int newfd)
static int try_dup3 = 1;
if (2 < newfd && try_dup3) {
ret = dup3(oldfd, newfd, O_CLOEXEC);
+ if (ret != -1)
+ return ret;
/* dup3 is available since Linux 2.6.27. */
- if (ret == -1 && errno == ENOSYS) {
+ if (errno == ENOSYS) {
try_dup3 = 0;
ret = dup2(oldfd, newfd);
}
- else {
- return ret;
- }
}
else {
ret = dup2(oldfd, newfd);