- {
- FILE *muscles_m4 = xfopen ("/tmp/muscles.m4", "w");
- /* There are no comments, especially not `#': we do want M4 expansion
- after `#': think of CPP macros! */
- fprintf (muscles_m4, "m4_changecom()\n");
- fprintf (muscles_m4, "m4_init()\n");
-
- fprintf (muscles_m4, "m4_define([b4_actions], \n[[");
- actions_output (muscles_m4);
- fprintf (muscles_m4, "]])\n\n");
-
- fprintf (muscles_m4, "m4_define([b4_guards], \n[[");
- guards_output (muscles_m4);
- fprintf (muscles_m4, "]])\n\n");
-
- fprintf (muscles_m4, "m4_define([b4_tokendef], \n[[");
- token_definitions_output (muscles_m4);
- fprintf (muscles_m4, "]])\n\n");
+ const char *tempdir = getenv ("TMPDIR");
+ char *tempfile = NULL;
+ FILE *out = NULL;
+ int fd;
+
+ if (tempdir == NULL)
+ tempdir = DEFAULT_TMPDIR;
+ tempfile = xmalloc (strlen (tempdir) + 11);
+ sprintf (tempfile, "%s/bsnXXXXXX", tempdir);
+ fd = mkstemp (tempfile);
+ if (fd == -1)
+ error (EXIT_FAILURE, errno, "%s", tempfile);
+
+ out = fdopen (fd, "w");
+ if (out == NULL)
+ error (EXIT_FAILURE, errno, "%s", tempfile);
+
+ /* There are no comments, especially not `#': we do want M4 expansion
+ after `#': think of CPP macros! */
+ fputs ("m4_changecom()\n", out);
+ fputs ("m4_init()\n", out);
+
+ fputs ("m4_define([b4_actions], \n[[", out);
+ actions_output (out);
+ fputs ("]])\n\n", out);
+
+ fputs ("m4_define([b4_guards], \n[[", out);
+ guards_output (out);
+ fputs ("]])\n\n", out);
+
+ fputs ("m4_define([b4_tokens], \n[", out);
+ token_definitions_output (out);
+ fputs ("])\n\n", out);