diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 23:06:42 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 23:06:42 +0000 |
commit | 3ed880dac0ac490038c5e826e7faabd621b3d3a0 (patch) | |
tree | a8130d48e91a6082ad7bad3800222b2215aea4e3 /usr.bin/patch/pch.c | |
parent | 0e1dfa183145680a78c7ce01bfae7c09df055209 (diff) |
mktemp w/ open & fdopen
Diffstat (limited to 'usr.bin/patch/pch.c')
-rw-r--r-- | usr.bin/patch/pch.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 3d6caf2ef30..4d2200dc61a 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pch.c,v 1.2 1996/06/10 11:21:33 niklas Exp $ */ +/* $OpenBSD: pch.c,v 1.3 1996/06/25 23:06:41 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pch.c,v 1.2 1996/06/10 11:21:33 niklas Exp $"; +static char rcsid[] = "$OpenBSD: pch.c,v 1.3 1996/06/25 23:06:41 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -54,10 +54,15 @@ void open_patch_file(filename) char *filename; { + int fd; + if (filename == Nullch || !*filename || strEQ(filename, "-")) { - pfp = fopen(TMPPATNAME, "w"); - if (pfp == Nullfp) + if ((fd = open(TMPPATNAME, O_EXCL|O_CREAT|O_RDWR, 0666)) == -1 || + (pfp = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); pfatal2("can't create %s", TMPPATNAME); + } while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); Fclose(pfp); |