--- xc/config/imake/imake.c.orig 2004-11-22 15:45:08 +0300 +++ xc/config/imake/imake.c 2005-02-09 15:27:02 +0300 @@ -278,6 +278,8 @@ #if !(defined(Lynx) || defined(__Lynx__) || (defined(SVR4) && !defined(sun))) && !defined (__CYGWIN__) #define HAS_MKSTEMP +#include +extern const char *__progname; #endif typedef unsigned char boolean; @@ -426,6 +428,17 @@ } else { #ifdef HAS_MKSTEMP int fd; + const char suffix[] = ".XXXXXX"; + const char *tmp_dir = getenv("TMPDIR")?:"/tmp"; + unsigned tmp_len = strlen( tmp_dir ); + unsigned prog_len = strlen( __progname ); + char tmpbuf[ tmp_len + prog_len + sizeof(suffix) + 1 ]; + + memcpy( tmpbuf, tmp_dir, tmp_len ); + tmpbuf[ tmp_len ] = '/'; + memcpy( tmpbuf + tmp_len + 1, __progname, prog_len ); + memcpy( tmpbuf + tmp_len + prog_len + 1, suffix, sizeof(suffix) ); + #endif tmpMakefile = Strdup(tmpMakefile); #ifndef HAS_MKSTEMP @@ -434,7 +447,8 @@ LogFatal("Cannot create temporary file %s.", tmpMakefile); } #else - fd = mkstemp(tmpMakefile); + fd = mkstemp(tmpbuf); + tmpMakefile = strdup(tmpbuf); if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) { if (fd != -1) { unlink(tmpMakefile); close(fd); @@ -1786,6 +1800,17 @@ if (outFile == NULL) { #ifdef HAS_MKSTEMP int fd; + const char suffix[] = ".XXXXXX"; + const char *tmp_dir = getenv("TMPDIR")?:"/tmp"; + unsigned tmp_len = strlen( tmp_dir ); + unsigned prog_len = strlen( __progname ); + char tmpbuf[ tmp_len + prog_len + sizeof(suffix) + 1 ]; + + memcpy( tmpbuf, tmp_dir, tmp_len ); + tmpbuf[ tmp_len ] = '/'; + memcpy( tmpbuf + tmp_len + 1, __progname, prog_len ); + memcpy( tmpbuf + tmp_len + prog_len + 1, suffix, sizeof(suffix) ); + #endif tmpImakefile = Strdup(tmpImakefile); #ifndef HAS_MKSTEMP @@ -1795,7 +1820,8 @@ tmpImakefile); } #else - fd=mkstemp(tmpImakefile); + fd=mkstemp(tmpbuf); + tmpImakefile = strdup(tmpbuf); if (fd != -1) outFile = fdopen(fd, "w"); if (outFile == NULL) {