--- gp_unifs.c.orig	Wed Jul 15 23:54:13 1998
+++ gp_unifs.c	Sun Feb  6 16:41:52 2000
@@ -27,6 +27,7 @@
 #include "stat_.h"
 #include "dirent_.h"
 #include <sys/param.h>		/* for MAXPATHLEN */
+#include <unistd.h>
 
 /* Some systems (Interactive for example) don't define MAXPATHLEN,
  * so we define it here.  (This probably should be done via a Config-Script.)
@@ -57,6 +58,8 @@ gp_open_scratch_file(const char *prefix,
 		     const char *mode)
 {				/* The -8 is for XXXXXX plus a possible final / and -. */
     int len = gp_file_name_sizeof - strlen(prefix) - 8;
+    int fd;
+    FILE *f;
 
     if (gp_getenv("TEMP", fname, &len) != 0)
 	strcpy(fname, "/tmp/");
@@ -69,8 +72,12 @@ gp_open_scratch_file(const char *prefix,
     if (*fname != 0 && fname[strlen(fname) - 1] == 'X')
 	strcat(fname, "-");
     strcat(fname, "XXXXXX");
-    mktemp(fname);
-    return fopen(fname, mode);
+    fd = mkstemp(fname);
+    if (fd == -1)
+    	return NULL;
+    if ((f = fdopen(fd, mode)) == NULL)
+    	close(fd);
+    return f;
 }
 
 /* Open a file with the given name, as a stream of uninterpreted bytes. */
