aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorGregory Neil Shapiro <gshapiro@FreeBSD.org>2001-04-21 05:24:08 +0000
committerGregory Neil Shapiro <gshapiro@FreeBSD.org>2001-04-21 05:24:08 +0000
commitd6d9b7925e3f36e5b322463f6b997f5cfb2924de (patch)
tree8b719fc1804e7b7db17be2441d6a9044cb316a91 /usr.bin/m4
parent6d0c3515d83ee329c12421b74683f7be15c70ce1 (diff)
Notes
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/extern.h3
-rw-r--r--usr.bin/m4/main.c9
-rw-r--r--usr.bin/m4/misc.c13
3 files changed, 18 insertions, 7 deletions
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index 25fc74128023..e791ee2a2341 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -34,6 +34,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.1 (Berkeley) 6/6/93
+ * $FreeBSD$
*/
char *basename __P((char *));
@@ -41,6 +42,7 @@ char *xalloc __P((unsigned long));
int expr __P((char *));
ndptr addent __P((char *));
void chrsave __P((int));
+void cleanup __P((int));
void dochc __P((char *[], int));
void dochq __P((char *[], int));
void dodefine __P((char *, char *));
@@ -87,6 +89,7 @@ extern char *endest; /* end of string space */
extern unsigned char *endpbb; /* end of push-back buffer */
extern char *ep; /* first free char in strspace */
extern char lquote; /* left quote character (`) */
+extern char *m4dir; /* directory for temporary files */
extern char *m4temp; /* filename for diversions */
extern char *m4wraps; /* m4wrap string default. */
extern char *null; /* as it says.. just a null. */
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index 6b77df8afeec..86253eb1256d 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -183,6 +183,7 @@ main(argc,argv)
active = stdout; /* default active output */
/* filename for diversions */
m4dir = mkdtemp(xstrdup(_PATH_DIVDIRNAME));
+ err_set_exit(cleanup);
(void) asprintf(&m4temp, "%s/%s", m4dir, _PATH_DIVNAME);
bbase[0] = bufbase;
@@ -220,13 +221,7 @@ main(argc,argv)
if (outfile[n] != NULL)
getdiv(n);
/* remove bitbucket if used */
- if (outfile[0] != NULL) {
- (void) fclose(outfile[0]);
- m4temp[UNIQUE] = '0';
- (void) remove(m4temp);
- }
- (void) remove(m4dir);
-
+ cleanup(0);
return 0;
}
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index f1c5101033d3..3c64eb19df5a 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -237,6 +237,19 @@ register char *s;
}
void
+cleanup(n)
+int n;
+{
+ if (outfile[0] != NULL) {
+ (void) fclose(outfile[0]);
+ outfile[0] = NULL;
+ m4temp[UNIQUE] = '0';
+ (void) remove(m4temp);
+ }
+ (void) remove(m4dir);
+}
+
+void
usage()
{
fprintf(stderr, "usage: m4 [-Dname[=val]] [-Uname]\n");