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/misc.c | |
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/misc.c')
-rw-r--r-- | usr.bin/m4/misc.c | 29 |
1 files changed, 5 insertions, 24 deletions
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 } } |