PATCH: temp fixes, again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Well spotted problem, a parser was 1 off.

Ciao, Marcus

License: LGPL
Changelog:
	Check for mkstemp, added a port implementation if it is
	not present. Use mkstemp() in various places needing tmp files.

Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.63
diff -u -r1.63 configure.ac
--- configure.ac	23 Jul 2002 02:02:02 -0000	1.63
+++ configure.ac	26 Jul 2002 13:18:26 -0000
@@ -879,6 +879,7 @@
 	lseek64 \
 	lstat \
 	memmove \
+	mkstemp \
 	mmap \
 	pclose \
 	popen \
Index: debugger/gdbproxy.c
===================================================================
RCS file: /home/wine/wine/debugger/gdbproxy.c,v
retrieving revision 1.1
diff -u -r1.1 gdbproxy.c
--- debugger/gdbproxy.c	20 Jul 2002 20:29:09 -0000	1.1
+++ debugger/gdbproxy.c	26 Jul 2002 13:18:36 -0000
@@ -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");
Index: dlls/shell32/shelllink.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shelllink.c,v
retrieving revision 1.42
diff -u -r1.42 shelllink.c
--- dlls/shell32/shelllink.c	24 Jul 2002 01:56:03 -0000	1.42
+++ dlls/shell32/shelllink.c	26 Jul 2002 13:18:55 -0000
@@ -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] == '*')
Index: include/wine/port.h
===================================================================
RCS file: /home/wine/wine/include/wine/port.h,v
retrieving revision 1.27
diff -u -r1.27 port.h
--- include/wine/port.h	22 Jul 2002 20:51:03 -0000	1.27
+++ include/wine/port.h	26 Jul 2002 13:18:56 -0000
@@ -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) */
Index: library/port.c
===================================================================
RCS file: /home/wine/wine/library/port.c,v
retrieving revision 1.31
diff -u -r1.31 port.c
--- library/port.c	31 May 2002 23:06:51 -0000	1.31
+++ library/port.c	26 Jul 2002 13:18:57 -0000
@@ -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
Index: server/file.c
===================================================================
RCS file: /home/wine/wine/server/file.c,v
retrieving revision 1.58
diff -u -r1.58 file.c
--- server/file.c	30 May 2002 20:12:58 -0000	1.58
+++ server/file.c	26 Jul 2002 13:19:01 -0000
@@ -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;
 }
 
Index: tools/wpp/wpp.c
===================================================================
RCS file: /home/wine/wine/tools/wpp/wpp.c,v
retrieving revision 1.2
diff -u -r1.2 wpp.c
--- tools/wpp/wpp.c	16 Jul 2002 03:21:35 -0000	1.2
+++ tools/wpp/wpp.c	26 Jul 2002 13:19:01 -0000
@@ -21,8 +21,10 @@
 
 #include <time.h>
 
+#include "config.h"
 #include "wpp_private.h"
 #include "wpp.h"
+#include "wine/port.h"
 
 static void add_special_defines(void)
 {
@@ -108,20 +110,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;
+
+    strcpy(tmpfn,"/tmp/wpp.XXXXXX");
 
-    if(!(temp_name = tmpnam(NULL)))
+    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);
     }
 


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux