summaryrefslogtreecommitdiff
path: root/usr.bin/m4/misc.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-25 20:50:10 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-25 20:50:10 +0000
commit76e323a510205a020c0a2732f308a9135ad6f37f (patch)
treeeeb653c2721550bef8b70762e99b3e804d068e7e /usr.bin/m4/misc.c
parent4a43b0634c6e52d6a7b395ba69be4b99fe7b0392 (diff)
mktemp open + fdopen
Diffstat (limited to 'usr.bin/m4/misc.c')
-rw-r--r--usr.bin/m4/misc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index 7be00f42d66..702e6980bfa 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -45,6 +45,7 @@ static char rcsid[] = "$NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $";
#endif /* not lint */
#include <sys/types.h>
+#include <sys/file.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
@@ -153,15 +154,20 @@ int n;
{
register int c;
register FILE *dfil;
+ int fd;
if (active == outfile[n])
oops("%s: diversion still active.", "undivert");
(void) fclose(outfile[n]);
outfile[n] = NULL;
m4temp[UNIQUE] = n + '0';
- if ((dfil = fopen(m4temp, "r")) == NULL)
+
+ if ((fd = open(m4temp, O_RDWR|O_EXCL|O_CREAT, 0666)) == -1 ||
+ (dfil = fdopen(fd, "r")) == NULL) {
+ if (fd != -1)
+ close(fd);
oops("%s: cannot undivert.", m4temp);
- else
+ } else
while ((c = getc(dfil)) != EOF)
putc(c, active);
(void) fclose(dfil);