--- libf2c/libI77/open.c.orig	Thu Nov 25 21:07:14 1999
+++ libf2c/libI77/open.c	Thu Nov 25 21:00:03 1999
@@ -136,6 +136,7 @@ integer f_open(olist *a)
 	char buf[256], *s;
 	cllist x;
 	int ufmt;
+	int fd;
 	FILE *tf;
 #ifndef NON_UNIX_STDIO
 	int n;
@@ -209,6 +210,24 @@ integer f_open(olist *a)
 	 case 's':
 	 case 'S':
 		b->uscrtch=1;
+#ifdef HAVE_MKSTEMP
+#define TEMPLATE	"/fort.XXXXXXXXXX"
+#ifdef HAVE_GETENV
+		s = getenv ("TMPDIR");
+		if (s && strlen (s) + sizeof (TEMPLATE) + 2 < sizeof (buf))
+		  strcpy (buf, s);
+	        else
+	   	  strcpy (buf, "/tmp");
+#else
+	        strcpy (buf, "/tmp");
+#endif
+	        strcat (buf, TEMPLATE);
+		fd = mkstemp(buf);
+		if (fd == -1)
+		  err (a->oerr, 132, "open");
+	        close(fd);
+		goto replace2;
+#else
 #ifdef HAVE_TEMPNAM		/* Allow use of TMPDIR preferentially. */
 		s = tempnam (0, buf);
 		if (strlen (s) >= sizeof (buf))
@@ -223,6 +242,7 @@ integer f_open(olist *a)
 		(void) mktemp(buf);
 #endif
 #endif /* ! defined (HAVE_TEMPNAM) */
+#endif /* ! defined (HAVE_MKSTEMP) */
 		goto replace;
 	case 'n':
 	case 'N':
@@ -242,6 +262,7 @@ integer f_open(olist *a)
 		if (tf = fopen(buf,f__w_mode[0]))
 			fclose(tf);
 	}
+ replace2:
 
 	b->ufnm=(char *) malloc((unsigned int)(strlen(buf)+1));
 	if(b->ufnm==NULL) opnerr(a->oerr,113,"no space");
