diff options
author | Marc Espie <espie@cvs.openbsd.org> | 1999-09-06 13:20:41 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 1999-09-06 13:20:41 +0000 |
commit | 15ad24c8377afe4177bc2409a503c8251e6b390a (patch) | |
tree | 65df66ab40239d7f5747ac225b49edd82748b8f7 /usr.bin/m4 | |
parent | 8377b604ba1a34886d86ff7a2496219dfc1cc14f (diff) |
Get rid of mktemp in the handling of diversion.
Simply put, mkstemp/unlink/rewind has the proper semantics under Unix,
and so we don't have to keep track about temp file names and remove them.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/eval.c | 16 | ||||
-rw-r--r-- | usr.bin/m4/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/m4/main.c | 14 | ||||
-rw-r--r-- | usr.bin/m4/misc.c | 29 |
4 files changed, 18 insertions, 44 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 470149ad208..c6023b6726a 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.12 1999/09/06 13:10:48 espie Exp $ */ +/* $OpenBSD: eval.c,v 1.13 1999/09/06 13:20:40 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: eval.c,v 1.12 1999/09/06 13:10:48 espie Exp $"; +static char rcsid[] = "$OpenBSD: eval.c,v 1.13 1999/09/06 13:20:40 espie Exp $"; #endif #endif /* not lint */ @@ -56,6 +56,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.12 1999/09/06 13:10:48 espie Exp $"; #include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #include <fcntl.h> #include <err.h> @@ -668,10 +669,13 @@ register int n; if (n < 0 || n >= MAXOUT) n = 0; /* bitbucket */ if (outfile[n] == NULL) { - m4temp[UNIQUE] = n + '0'; - if ((fd = open(m4temp, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0 || - (outfile[n] = fdopen(fd, "w")) == NULL) - err(1, "%s: cannot divert", m4temp); + char fname[] = _PATH_DIVNAME; + + if ((fd = mkstemp(fname)) < 0 || + (outfile[n] = fdopen(fd, "w+")) == NULL) + err(1, "%s: cannot divert", fname); + if (unlink(fname) == -1) + err(1, "%s: cannot unlink", fname); } active = outfile[n]; } diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 51653024523..0ffc9de3339 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.6 1999/09/06 13:15:33 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.7 1999/09/06 13:20:40 espie Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -89,7 +89,6 @@ extern char *endest; /* end of string space */ extern pbent *endpbb; /* end of push-back buffer */ extern char *ep; /* first free char in strspace */ extern char lquote[]; /* left quote character (`) */ -extern char *m4temp; /* filename for diversions */ extern char *m4wraps; /* m4wrap string default. */ extern char *null; /* as it says.. just a null. */ extern char rquote[]; /* right quote character (') */ diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 050d3585701..9b311261e64 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.11 1999/09/06 13:10:48 espie Exp $ */ +/* $OpenBSD: main.c,v 1.12 1999/09/06 13:20:40 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.11 1999/09/06 13:10:48 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.12 1999/09/06 13:20:40 espie Exp $"; #endif #endif /* not lint */ @@ -85,7 +85,6 @@ int fp; /* m4 call frame pointer */ FILE *infile[MAXINP]; /* input file stack (0=stdin) */ FILE *outfile[MAXOUT]; /* diversion array(0=bitbucket)*/ FILE *active; /* active output file pointer */ -char *m4temp; /* filename for diversions */ int ilevel = 0; /* input file stack pointer */ int oindex = 0; /* diversion index.. */ char *null = ""; /* as it says.. just a null.. */ @@ -188,9 +187,6 @@ main(argc,argv) argv += optind; active = stdout; /* default active output */ - /* filename for diversions */ - m4temp = mktemp(xstrdup(_PATH_DIVNAME)); - bbase[0] = bufbase; if (!argc) { sp = -1; /* stack pointer initialized */ @@ -228,12 +224,6 @@ main(argc,argv) /* remove bitbucket if used */ if (outfile[0] != NULL) { (void) fclose(outfile[0]); - m4temp[UNIQUE] = '0'; -#ifdef vms - (void) remove(m4temp); -#else - (void) unlink(m4temp); -#endif } return 0; diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 02d83e6c330..84d923b5d3e 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.7 1999/09/06 13:10:49 espie Exp $ */ +/* $OpenBSD: misc.c,v 1.8 1999/09/06 13:20:40 espie Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: misc.c,v 1.7 1999/09/06 13:10:49 espie Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.8 1999/09/06 13:20:40 espie Exp $"; #endif #endif /* not lint */ @@ -152,26 +152,13 @@ getdiv(n) int n; { register int c; - register FILE *dfil; if (active == outfile[n]) errx(1, "undivert: diversion still active"); + rewind(outfile[n]); + while ((c = getc(outfile[n])) != EOF) + putc(c, active); (void) fclose(outfile[n]); - outfile[n] = NULL; - m4temp[UNIQUE] = n + '0'; - if ((dfil = fopen(m4temp, "r")) == NULL) - err(1, "%s: cannot undivert", m4temp); - else - while ((c = getc(dfil)) != EOF) - putc(c, active); - (void) fclose(dfil); - -#ifdef vms - if (remove(m4temp)) -#else - if (unlink(m4temp) == -1) -#endif - err(1, "%s: cannot unlink", m4temp); } void @@ -192,12 +179,6 @@ killdiv() for (n = 0; n < MAXOUT; n++) if (outfile[n] != NULL) { (void) fclose(outfile[n]); - m4temp[UNIQUE] = n + '0'; -#ifdef vms - (void) remove(m4temp); -#else - (void) unlink(m4temp); -#endif } } |