commit cbf183a973f1e609ac831007271c1986369b5048
Author: Ryan Cahoon <ryan.cahoon@zoox.com>
Date:   Sun Mar 7 11:12:15 2021 -0800

    unique_temp_file_names

diff --git a/Src/main.c b/Src/main.c
index 1f9f152..586cd11 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -38,6 +38,8 @@ static void	add_runtime(char *);
 
 Symbol	*Fname, *oFname;
 
+char	pan_pre_filename[32];
+
 int	Etimeouts;	/* nr timeouts in program */
 int	Ntimeouts;	/* nr timeouts in never claim */
 int	analyze, columns, dumptab, has_remote, has_remvar;
@@ -281,9 +283,6 @@ alldone(int estatus)
 	{	(void) unlink((const char *) out1);
 	}
 
-	(void) unlink(TMP_FILE1);
-	(void) unlink(TMP_FILE2);
-
 	if (!buzzed && seedy && !analyze && !export_ast
 	&& !s_trail && !preprocessonly && depth > 0)
 	{	printf("seed used: %d\n", SeedUsed);
@@ -912,6 +911,8 @@ main(int argc, char *argv[])
 	assert(strlen(CPP) < sizeof(PreProc));
 	strcpy(PreProc, CPP);
 
+	sprintf(pan_pre_filename, "pan%d.pre", getpid());
+
 	/* unused flags: y, z, G, L, Q, R, W */
 	while (argc > 1 && argv[1][0] == '-')
 	{	switch (argv[1][1]) {
@@ -1089,7 +1090,7 @@ samecase:			if (buzzed != 0)
 		char cmd[512], out2[512];
 
 		/* must remain in current dir */
-		strcpy(out1, "pan.pre");
+		strcpy(out1, pan_pre_filename);
 
 		if (add_ltl || nvr_file)
 		{	assert(strlen(argv[1]) < sizeof(out2));
@@ -1282,7 +1283,7 @@ fatal(char *s1, char *s2)
 	(void) unlink("pan.m");
 	(void) unlink("pan.t");
 	(void) unlink("pan.p");
-	(void) unlink("pan.pre");
+	(void) unlink(pan_pre_filename);
 	if (!(verbose&32))
 	{	(void) unlink("_spin_nvr.tmp");
 	}
diff --git a/Src/msc_tcl.c b/Src/msc_tcl.c
index 17004fb..85d676b 100644
--- a/Src/msc_tcl.c
+++ b/Src/msc_tcl.c
@@ -40,6 +40,7 @@ static int	no_box;
 extern int	ntrail, s_trail, prno, depth;
 extern short	Have_claim;
 extern Symbol	*oFname;
+extern char	*pan_pre_filename;
 
 extern void	exit(int);
 extern void	putpostlude(void);
@@ -288,7 +289,7 @@ putpostlude(void)
 	fprintf(stderr, "seed used: -n%d\n", WhatSeed());
 	sprintf(cmd, "wish -f %s.tcl &", oFname?oFname->name:"msc");
 	fprintf(stderr, "%s\n", cmd);
-	(void) unlink("pan.pre");
+	(void) unlink(pan_pre_filename);
 	exit (system(cmd));
 }
 
diff --git a/Src/pangen7.c b/Src/pangen7.c
index b6b492e..279c352 100644
--- a/Src/pangen7.c
+++ b/Src/pangen7.c
@@ -19,6 +19,7 @@ extern ProcList	*ready;
 extern Element *Al_El;
 extern int nclaims, verbose, Strict;
 extern short has_accept;
+extern char *pan_pre_filename;
 
 typedef struct Succ_List Succ_List;
 typedef struct SQueue SQueue;
@@ -586,7 +587,7 @@ sync_product(void)
 
 	if (nclaims <= 1) return;
 
-	(void) unlink("pan.pre");
+	(void) unlink(pan_pre_filename);
 
 	Ist  = (int *) emalloc(sizeof(int) * nclaims);
 	Nacc = (int *) emalloc(sizeof(int) * nclaims);
diff --git a/Src/spin.h b/Src/spin.h
index 5fb4aac..d729239 100644
--- a/Src/spin.h
+++ b/Src/spin.h
@@ -447,7 +447,4 @@ void	yyerror(char *, ...);
 
 extern	int unlink(const char *);
 
-#define TMP_FILE1 "._s_p_i_n_"
-#define TMP_FILE2 "._n_i_p_s_"
-
 #endif
diff --git a/Src/spin.y b/Src/spin.y
index 4e64717..f3a4ca9 100644
--- a/Src/spin.y
+++ b/Src/spin.y
@@ -1074,7 +1074,12 @@ ltl_to_string(Lextok *n)
 {	Lextok *m = nn(ZN, 0, ZN, ZN);
 	ssize_t retval;
 	char *ltl_formula = NULL;
-	FILE *tf = fopen(TMP_FILE1, "w+"); /* tmpfile() fails on Windows 7 */
+	FILE *tf = tmpfile(); /*
+		NOTE_ZOOX(ryan.cahoon, 2021-03-07):
+		Upstream comment: tmpfile() fails on Windows 7
+		Zoox-specific: Use tmpfile() since we don't need Windows support
+			and we don't want multiple concurrent executions to
+			clobber each other. */
 
 	/* convert the parsed ltl to a string
 	   by writing into a file, using existing functions,
@@ -1096,8 +1101,6 @@ ltl_to_string(Lextok *n)
 	retval = getline(&ltl_formula, &linebuffsize, tf);
 	fclose(tf);
 
-	(void) unlink(TMP_FILE1);
-
 	if (!retval)
 	{	printf("%ld\n", (long int) retval);
 		fatal("could not translate ltl ltl_formula", 0);
diff --git a/Src/spinlex.c b/Src/spinlex.c
index a264d8f..cef6b66 100644
--- a/Src/spinlex.c
+++ b/Src/spinlex.c
@@ -1376,13 +1376,8 @@ get_deferred(void)
 	if (!defer_fd)
 	{	return 0;	/* nothing was deferred */
 	}
-	fclose(defer_fd);
+	(void) fseek(defer_fd, 0L, SEEK_SET);
 
-	defer_fd = fopen(TMP_FILE2, "r");
-	if (!defer_fd)
-	{	non_fatal("cannot retrieve deferred ltl formula", (char *) 0);
-		return 0;
-	}
 	fclose(yyin);
 	yyin = defer_fd;
 	return 1;
@@ -1391,14 +1386,13 @@ get_deferred(void)
 void
 zap_deferred(void)
 {
-	(void) unlink(TMP_FILE2);
 }
 
 int
 put_deferred(void)
 {	int c, cnt;
 	if (!defer_fd)
-	{	defer_fd = fopen(TMP_FILE2, "w+");
+	{	defer_fd = tmpfile();
 		if (!defer_fd)
 		{	non_fatal("cannot defer ltl expansion", (char *) 0);
 			return 0;
