diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2016-07-19 06:43:28 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2016-07-19 06:43:28 +0000 |
commit | 14ee33c883ce8c8d898fa20930100cd54743efed (patch) | |
tree | ab72c96f7e15a2791b55044eb6098e9b11744691 /usr.bin/patch/inp.c | |
parent | 0cdc31e8991e3311a3e7129044451dc4c45b8856 (diff) |
Cleanup close(open idioms.
ok krw
Diffstat (limited to 'usr.bin/patch/inp.c')
-rw-r--r-- | usr.bin/patch/inp.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index 6606ede551f..3f6086108f4 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inp.c,v 1.45 2015/11/11 01:12:10 deraadt Exp $ */ +/* $OpenBSD: inp.c,v 1.46 2016/07/19 06:43:27 deraadt Exp $ */ /* * patch - a program to apply diffs to original files @@ -148,6 +148,8 @@ plan_a(const char *filename) statfailed = stat(filename, &filestat); if (statfailed && ok_to_create_file) { + int fd; + if (verbose) say("(Creating file %s...)\n", filename); @@ -159,7 +161,9 @@ plan_a(const char *filename) if (check_only) return true; makedirs(filename, true); - close(open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666)); + if ((fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666)) != -1) + close(fd); + statfailed = stat(filename, &filestat); } if (statfailed) |