diff options
author | 1996-06-26 03:42:13 +0000 | |
---|---|---|
committer | 1996-06-26 03:42:13 +0000 | |
commit | f19977349d5758ab662faf5449d853ded91de50e (patch) | |
tree | 33a1d6f09d4ee9948a024a7c70e211cd6847ba0a | |
parent | mktemp w/ open & fdopen (diff) | |
download | wireguard-openbsd-f19977349d5758ab662faf5449d853ded91de50e.tar.xz wireguard-openbsd-f19977349d5758ab662faf5449d853ded91de50e.zip |
open + fdopen
-rw-r--r-- | usr.bin/oldrdist/docmd.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/oldrdist/docmd.c b/usr.bin/oldrdist/docmd.c index 5fc534421d7..bc05fcac0c8 100644 --- a/usr.bin/oldrdist/docmd.c +++ b/usr.bin/oldrdist/docmd.c @@ -33,7 +33,7 @@ #ifndef lint /* from: static char sccsid[] = "@(#)docmd.c 8.1 (Berkeley) 6/9/93"; */ -static char *rcsid = "$Id: docmd.c,v 1.1 1996/02/03 12:11:55 dm Exp $"; +static char *rcsid = "$Id: docmd.c,v 1.2 1996/06/26 03:42:13 deraadt Exp $"; #endif /* not lint */ #include "defs.h" @@ -139,12 +139,17 @@ doarrow(filev, files, rhost, cmds) if (nflag) printf("updating host %s\n", rhost); else { + int fd; + if (setjmp(env)) goto done; signal(SIGPIPE, lostconn); if (!makeconn(rhost)) return; - if ((lfp = fopen(tempfile, "w")) == NULL) { + if ((fd = open(tempfile, O_RDWR|O_EXCL|O_CREAT, 0666)) == -1 || + (lfp = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); fatal("cannot open %s\n", tempfile); exit(1); } @@ -367,7 +372,12 @@ dodcolon(filev, files, stamp, cmds) if (nflag || (options & VERIFY)) tfp = NULL; else { - if ((tfp = fopen(tempfile, "w")) == NULL) { + int fd; + + if ((fd = open(tempfile, O_RDWR|O_EXCL|O_CREAT, 0666)) == -1 || + (tfp = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); error("%s: %s\n", stamp, strerror(errno)); return; } |