diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 01:12:11 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 01:12:11 +0000 |
commit | 518a764688815acb1e68e0db31964ebd69651099 (patch) | |
tree | 5bc476823ab18c0a62fb84c40d22f9a325cbfe18 /sbin/restore/dirs.c | |
parent | 2705df45a2067720e7ccabc6d7000f0be227e13c (diff) |
mktemp open & fdopen
Diffstat (limited to 'sbin/restore/dirs.c')
-rw-r--r-- | sbin/restore/dirs.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 9d77b348c00..eb481e7b691 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dirs.c,v 1.4 1996/06/23 14:32:14 deraadt Exp $ */ +/* $OpenBSD: dirs.c,v 1.5 1996/06/25 01:12:10 deraadt Exp $ */ /* $NetBSD: dirs.c,v 1.16 1995/06/19 00:20:11 cgd Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)dirs.c 8.5 (Berkeley) 8/31/94"; #else -static char rcsid[] = "$OpenBSD: dirs.c,v 1.4 1996/06/23 14:32:14 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: dirs.c,v 1.5 1996/06/25 01:12:10 deraadt Exp $"; #endif #endif /* not lint */ @@ -150,6 +150,7 @@ extractdirs(genmode) register struct dinode *ip; struct inotab *itp; struct direct nulldir; + int fd; vprintf(stdout, "Extract directories from tape\n"); (void) sprintf(dirfile, "%s/rstdir%d", _PATH_TMP, dumpdate); @@ -162,8 +163,11 @@ extractdirs(genmode) exit(1); } } - df = fopen(dirfile, "w"); - if (df == NULL) { + fd = -1; + if (fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666) == -1 || + (df = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); fprintf(stderr, "restore: %s - cannot create directory temporary\n", dirfile); @@ -181,8 +185,11 @@ extractdirs(genmode) exit(1); } } - mf = fopen(modefile, "w"); - if (mf == NULL) { + fd = -1; + if (fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, + 0666) == -1 || (mf = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); fprintf(stderr, "restore: %s - cannot create modefile \n", modefile); |