summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-04-09 19:06:34 +0000
committerchristos <christos@NetBSD.org>2006-04-09 19:06:34 +0000
commitf5a5211062510468df030f29cc0c6e8e4b6230f5 (patch)
tree98103a35b3cd87138283db11e15aa90cf635384e /usr.bin/patch
parent5800a5519e1fe99bc031e58334a0a84476246168 (diff)
It is silly to creat() and close a file just to stat it. open/fstat/close
instead checking for errors. From Coverity CID 1276.
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/inp.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 1ddbb579ff7..46c98405c68 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: inp.c,v 1.17 2003/07/30 08:51:04 itojun Exp $ */
+/* $NetBSD: inp.c,v 1.18 2006/04/09 19:06:34 christos Exp $ */
/*
* Copyright (c) 1988, Larry Wall
@@ -24,7 +24,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: inp.c,v 1.17 2003/07/30 08:51:04 itojun Exp $");
+__RCSID("$NetBSD: inp.c,v 1.18 2006/04/09 19:06:34 christos Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -88,11 +88,14 @@ plan_a(char *filename)
statfailed = stat(filename, &filestat);
if (statfailed && ok_to_create_file) {
+ int fd;
if (verbose)
say("(Creating file %s...)\n",filename);
makedirs(filename, TRUE);
- close(creat(filename, 0666));
- statfailed = stat(filename, &filestat);
+ if ((fd = open(filename, O_CREAT|O_TRUNC, 0666)) == -1)
+ pfatal("can't open file %s", filename);
+ statfailed = fstat(fd, &filestat);
+ (void)close(fd);
}
/*
* For nonexistent or read-only files, look for RCS or SCCS