diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 20:50:10 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-25 20:50:10 +0000 |
commit | 76e323a510205a020c0a2732f308a9135ad6f37f (patch) | |
tree | eeb653c2721550bef8b70762e99b3e804d068e7e /usr.bin/m4 | |
parent | 4a43b0634c6e52d6a7b395ba69be4b99fe7b0392 (diff) |
mktemp open + fdopen
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/eval.c | 9 | ||||
-rw-r--r-- | usr.bin/m4/misc.c | 10 | ||||
-rw-r--r-- | usr.bin/m4/serv.c | 8 |
3 files changed, 23 insertions, 4 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index b164f03fd7d..790c995a46c 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -51,6 +51,7 @@ static char rcsid[] = "$NetBSD: eval.c,v 1.5 1996/01/13 23:25:23 pk Exp $"; */ #include <sys/types.h> +#include <sys/file.h> #include <errno.h> #include <unistd.h> #include <stdio.h> @@ -663,12 +664,18 @@ void dodiv(n) register int n; { + int fd; + if (n < 0 || n >= MAXOUT) n = 0; /* bitbucket */ if (outfile[n] == NULL) { m4temp[UNIQUE] = n + '0'; - if ((outfile[n] = fopen(m4temp, "w")) == NULL) + if ((fd = open(m4temp, O_RDWR|O_EXCL|O_CREAT, 0666)) == -1 || + (outfile[n] = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); oops("%s: cannot divert.", m4temp); + } } oindex = n; active = outfile[n]; 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); diff --git a/usr.bin/m4/serv.c b/usr.bin/m4/serv.c index e7c375f4f2d..d7ace57ae27 100644 --- a/usr.bin/m4/serv.c +++ b/usr.bin/m4/serv.c @@ -336,12 +336,18 @@ register int argc; dodiv(n) register int n; { + int fd; + if (n < 0 || n >= MAXOUT) n = 0; /* bitbucket */ if (outfile[n] == NULL) { m4temp[UNIQUE] = n + '0'; - if ((outfile[n] = fopen(m4temp, "w")) == NULL) + if ((fd = open(m4temp, O_RDWR|O_EXECL|O_CREAT, 0666)) == -1 || + (outfile[n] = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); error("m4: cannot divert."); + } } oindex = n; active = outfile[n]; |