Alexandre Julliard : winebuild: Fix the creation of temp files in /tmp.

Alexandre Julliard julliard at winehq.org
Thu May 26 10:56:25 CDT 2011


Module: wine
Branch: master
Commit: 2f4f9ee1cbf61e4540abbfe56e7d765fad6c8d08
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2f4f9ee1cbf61e4540abbfe56e7d765fad6c8d08

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu May 26 12:20:37 2011 +0200

winebuild: Fix the creation of temp files in /tmp.

---

 tools/winebuild/utils.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index acd6915..2edb9e3 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -410,25 +410,30 @@ const char *get_nm_command(void)
 char *get_temp_file_name( const char *prefix, const char *suffix )
 {
     char *name;
-    const char *ext;
+    const char *ext, *basename;
     int fd;
 
     if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
 
     if (!prefix || !prefix[0]) prefix = "winebuild";
     if (!suffix) suffix = "";
-    if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix);
+    if ((basename = strrchr( prefix, '/' ))) basename++;
+    else basename = prefix;
+    if (!(ext = strchr( basename, '.' ))) ext = prefix + strlen(prefix);
     name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
-    strcpy( name, "/tmp/" );
-    memcpy( name + 5, prefix, ext - prefix );
-    strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
+    memcpy( name, prefix, ext - prefix );
+    strcpy( name + (ext - prefix), ".XXXXXX" );
     strcat( name, suffix );
 
-    /* first try without the /tmp/ prefix */
-    if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1)
-        name += 5;
-    else if ((fd = mkstemps( name, strlen(suffix) )) == -1)
-        fatal_error( "could not generate a temp file\n" );
+    if ((fd = mkstemps( name, strlen(suffix) )) == -1)
+    {
+        strcpy( name, "/tmp/" );
+        memcpy( name + 5, basename, ext - basename );
+        strcpy( name + 5 + (ext - basename), ".XXXXXX" );
+        strcat( name, suffix );
+        if ((fd = mkstemps( name, strlen(suffix) )) == -1)
+            fatal_error( "could not generate a temp file\n" );
+    }
 
     close( fd );
     if (nb_tmp_files >= max_tmp_files)




More information about the wine-cvs mailing list