summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-02-01 12:57:00 -0500
committerTavian Barnes <tavianator@tavianator.com>2019-02-01 12:57:00 -0500
commit3a52c0e1f55d5dd03a00740c191569b9309c0ad6 (patch)
tree65785e4e2e4ff1a0a5ed4ec2f46895d559333616 /util.c
parent23b55d03ddf69b5ab40dc338c419089e8c64930b (diff)
parent36330d7aab63ef2c202efb0d551f104ed6cefa17 (diff)
downloadbfs-3a52c0e1f55d5dd03a00740c191569b9309c0ad6.tar.xz
Merge branch 'improvements'
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/util.c b/util.c
index b708527..1e5ebdb 100644
--- a/util.c
+++ b/util.c
@@ -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;