diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2019-02-01 12:57:00 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2019-02-01 12:57:00 -0500 |
commit | 3a52c0e1f55d5dd03a00740c191569b9309c0ad6 (patch) | |
tree | 65785e4e2e4ff1a0a5ed4ec2f46895d559333616 /util.c | |
parent | 23b55d03ddf69b5ab40dc338c419089e8c64930b (diff) | |
parent | 36330d7aab63ef2c202efb0d551f104ed6cefa17 (diff) | |
download | bfs-3a52c0e1f55d5dd03a00740c191569b9309c0ad6.tar.xz |
Merge branch 'improvements'
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 10 |
1 files changed, 3 insertions, 7 deletions
@@ -85,8 +85,6 @@ bool isopen(int fd) { } int redirect(int fd, const char *path, int flags, ...) { - close(fd); - mode_t mode = 0; if (flags & O_CREAT) { va_list args; @@ -102,11 +100,9 @@ int redirect(int fd, const char *path, int flags, ...) { int ret = open(path, flags, mode); if (ret >= 0 && ret != fd) { - int other = ret; - ret = dup2(other, fd); - if (close(other) != 0) { - ret = -1; - } + int orig = ret; + ret = dup2(orig, fd); + close(orig); } return ret; |