summaryrefslogtreecommitdiff
path: root/usr.bin/error
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-25 01:04:00 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-25 01:04:00 +0000
commit2705df45a2067720e7ccabc6d7000f0be227e13c (patch)
treed8bb0eca7f3ca5592c79fa158b1c234d24e29192 /usr.bin/error
parent4ba67c724eb49e1ef2b6b8af6d6bcda67035bb3c (diff)
mkstemp + fdopen
Diffstat (limited to 'usr.bin/error')
-rw-r--r--usr.bin/error/touch.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/error/touch.c b/usr.bin/error/touch.c
index 03809f7752b..661a808f439 100644
--- a/usr.bin/error/touch.c
+++ b/usr.bin/error/touch.c
@@ -531,6 +531,8 @@ boolean tempfileopen = FALSE;
boolean edit(name)
char *name;
{
+ int fd;
+
o_name = name;
if ( (o_touchedfile = fopen(name, "r")) == NULL){
fprintf(stderr, "%s: Can't open file \"%s\" to touch (read).\n",
@@ -538,8 +540,10 @@ boolean edit(name)
return(TRUE);
}
(void)strcpy(n_name, canon_name);
- (void)mktemp(n_name);
- if ( (n_touchedfile = fopen(n_name, "w")) == NULL){
+ if ((fd = mkstemp(n_name)) == -1 ||
+ (n_touchedfile = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
fprintf(stderr,"%s: Can't open file \"%s\" to touch (write).\n",
processname, name);
return(TRUE);