Check for mkstemp, added a port implementation if it is not
present. Use mkstemp() in various places needing tmp files.
diff --git a/configure b/configure
index b96b12e..eb19ffc 100755
--- a/configure
+++ b/configure
@@ -11199,6 +11199,7 @@
+
for ac_func in \
__libc_fork \
_lwp_create \
@@ -11226,6 +11227,7 @@
lseek64 \
lstat \
memmove \
+ mkstemp \
mmap \
pclose \
popen \
diff --git a/configure.ac b/configure.ac
index 8c2a857..f0617d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -879,6 +879,7 @@
lseek64 \
lstat \
memmove \
+ mkstemp \
mmap \
pclose \
popen \
diff --git a/debugger/gdbproxy.c b/debugger/gdbproxy.c
index 860d4ef..a78702f 100644
--- a/debugger/gdbproxy.c
+++ b/debugger/gdbproxy.c
@@ -1812,11 +1812,15 @@
case 0: /* in child... and alive */
{
char buf[MAX_PATH];
+ int fd;
char* gdb_path;
FILE* f;
if (!(gdb_path = getenv("WINE_GDB"))) gdb_path = "gdb";
- if (!tmpnam(buf) || (f = fopen(buf, "w+")) == NULL) return FALSE;
+ strcpy(buf,"/tmp/winegdb.XXXXXX");
+ fd = mkstemp(buf);
+ if (fd == -1) return FALSE;
+ if ((f = fdopen(fd, "w+")) == NULL) return FALSE;
fprintf(f, "file %s\n", wine_path);
fprintf(f, "target remote localhost:%d\n", ntohs(s_addr.sin_port));
fprintf(f, "monitor trace=0\n");
diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c
index 32a40e6..0321093 100644
--- a/dlls/shell32/shelllink.c
+++ b/dlls/shell32/shelllink.c
@@ -28,6 +28,7 @@
# include <sys/wait.h>
#endif
#include "wine/debug.h"
+#include "wine/port.h"
#include "winerror.h"
#include "winbase.h"
#include "winnls.h"
@@ -551,8 +552,15 @@
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
static char *extract_icon( const char *path, int index)
{
- int nodefault = 1;
- char *filename = heap_strdup( tmpnam(NULL) );
+ int fd, nodefault = 1;
+ char *filename, tmpfn[25];
+
+ strcpy(tmpfn,"/tmp/icon.XXXXXX");
+ fd = mkstemp( tmpfn );
+ if (fd == -1)
+ return NULL;
+ filename = heap_strdup( tmpfn );
+ close(fd); /* not needed */
/* If icon path begins with a '*' then this is a deferred call */
if (path[0] == '*')
diff --git a/include/config.h.in b/include/config.h.in
index 38b78c5..1a3e26b 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -290,6 +290,9 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
+/* Define to 1 if you have the `mkstemp' function. */
+#undef HAVE_MKSTEMP
+
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
diff --git a/include/wine/port.h b/include/wine/port.h
index 3d95259..ca4728b 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -222,6 +222,10 @@
int lstat(const char *file_name, struct stat *buf);
#endif /* HAVE_LSTAT */
+#ifndef HAVE_MKSTEMP
+int mkstemp(char *tmpfn);
+#endif /* HAVE_MKSTEMP */
+
#ifndef HAVE_MEMMOVE
void *memmove(void *dest, const void *src, unsigned int len);
#endif /* !defined(HAVE_MEMMOVE) */
diff --git a/library/port.c b/library/port.c
index def9469..eb93423 100644
--- a/library/port.c
+++ b/library/port.c
@@ -340,6 +340,35 @@
}
#endif /* HAVE_LSTAT */
+/***********************************************************************
+ * mkstemp
+ */
+#ifndef HAVE_MKSTEMP
+int mkstemp(char *tmpfn)
+{
+ int tries;
+ char *xstart;
+
+ xstart = tmpfn+strlen(tmpfn)-1;
+ while ((xstart > tmpfn) && (*xstart == 'X'))
+ xstart--;
+ tries = 10;
+ while (tries--) {
+ char *newfn = mktemp(tmpfn);
+ int fd;
+ if (!newfn) /* something else broke horribly */
+ return -1;
+ fd = open(newfn,O_CREAT|O_RDWR|O_EXCL,0600);
+ if (fd!=-1)
+ return fd;
+ newfn = xstart;
+ /* fill up with X and try again ... */
+ while (*newfn) *newfn++ = 'X';
+ }
+ return -1;
+}
+#endif /* HAVE_MKSTEMP */
+
/***********************************************************************
* pread
diff --git a/server/file.c b/server/file.c
index d8da517..b302fe6 100644
--- a/server/file.c
+++ b/server/file.c
@@ -230,24 +230,17 @@
/* Create an anonymous Unix file */
int create_anonymous_file(void)
{
- char *name;
+ char tmpfn[21];
int fd;
- do
- {
- if (!(name = tmpnam(NULL)))
- {
- set_error( STATUS_TOO_MANY_OPENED_FILES );
- return -1;
- }
- fd = open( name, O_CREAT | O_EXCL | O_RDWR, 0600 );
- } while ((fd == -1) && (errno == EEXIST));
+ sprintf(tmpfn,"/tmp/anonmap.XXXXXX");
+ fd = mkstemp(tmpfn);
if (fd == -1)
{
file_set_error();
return -1;
}
- unlink( name );
+ unlink( tmpfn );
return fd;
}
diff --git a/tools/wpp/wpp.c b/tools/wpp/wpp.c
index 7ceee3f..6d9ef5a 100644
--- a/tools/wpp/wpp.c
+++ b/tools/wpp/wpp.c
@@ -19,6 +19,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "config.h"
+#include "wine/port.h"
+
#include <time.h>
#include <stdlib.h>
@@ -109,20 +112,22 @@
/* parse into a temporary file */
int wpp_parse_temp( const char *input, char **output_name )
{
- char *temp_name;
FILE *output;
- int ret;
+ int ret, fd;
+ char tmpfn[20], *temp_name;
- if(!(temp_name = tmpnam(NULL)))
+ strcpy(tmpfn,"/tmp/wpp.XXXXXX");
+
+ if((fd = mkstemp(tmpfn)) == -1)
{
fprintf(stderr, "Could not generate a temp-name\n");
exit(2);
}
- temp_name = pp_xstrdup(temp_name);
+ temp_name = pp_xstrdup(tmpfn);
- if (!(output = fopen(temp_name, "wt")))
+ if (!(output = fdopen(fd, "wt")))
{
- fprintf(stderr,"Could not open %s for writing\n", temp_name);
+ fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
exit(2);
}