diff mbox

[Ada] Use current process id to create temp filenames (windows)

Message ID 20110804082706.GA15586@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 4, 2011, 8:27 a.m. UTC
This ensures unicity of temp filenames across processes under Windows.

Tested on i686-pc-mingw32, committed on trunk

2011-08-04  Pascal Obry  <obry@adacore.com>

	* adaint.c (__gnat_tmp_name): Use current process id to create temp
	filenames, this ensures unicity of filenames across processes.
diff mbox

Patch

Index: adaint.c
===================================================================
--- adaint.c	(revision 177328)
+++ adaint.c	(working copy)
@@ -1177,13 +1177,15 @@ 
 #elif defined (__MINGW32__)
   {
     char *pname;
+    char prefix[25];
 
     /* tempnam tries to create a temporary file in directory pointed to by
        TMP environment variable, in c:\temp if TMP is not set, and in
        directory specified by P_tmpdir in stdio.h if c:\temp does not
        exist. The filename will be created with the prefix "gnat-".  */
 
-    pname = (char *) _tempnam ("c:\\temp", "gnat-");
+    sprintf (prefix, "gnat-%d-", (int)getpid());
+    pname = (char *) _tempnam ("c:\\temp", prefix);
 
     /* if pname is NULL, the file was not created properly, the disk is full
        or there is no more free temporary files */