diff src/fileio.c @ 6721:7347229a646a v7.4.684

updated for version 7.4.684 Problem: When starting several Vim instances in diff mode, the temp files used may not be unique. (Issue 353) Solution: Add an argument to vim_tempname() to keep the file.
author Bram Moolenaar <bram@vim.org>
date Tue, 31 Mar 2015 13:33:08 +0200
parents 050e6df85f99
children 62ba356c2d4e
line wrap: on
line diff
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2872,7 +2872,7 @@ readfile_charconvert(fname, fenc, fdp)
     char_u	*tmpname;
     char_u	*errmsg = NULL;
 
-    tmpname = vim_tempname('r');
+    tmpname = vim_tempname('r', FALSE);
     if (tmpname == NULL)
 	errmsg = (char_u *)_("Can't find temp file for conversion");
     else
@@ -4288,7 +4288,7 @@ buf_write(buf, fname, sfname, start, end
 	     */
 	    if (*p_ccv != NUL)
 	    {
-		wfname = vim_tempname('w');
+		wfname = vim_tempname('w', FALSE);
 		if (wfname == NULL)	/* Can't write without a tempfile! */
 		{
 		    errmsg = (char_u *)_("E214: Can't find temp file for writing");
@@ -7344,14 +7344,16 @@ vim_settempdir(tempdir)
 /*
  * vim_tempname(): Return a unique name that can be used for a temp file.
  *
- * The temp file is NOT created.
+ * The temp file is NOT garanteed to be created.  If "keep" is FALSE it is
+ * garanteed to NOT be created.
  *
  * The returned pointer is to allocated memory.
  * The returned pointer is NULL if no valid name was found.
  */
     char_u  *
-vim_tempname(extra_char)
+vim_tempname(extra_char, keep)
     int	    extra_char UNUSED;  /* char to use in the name instead of '?' */
+    int	    keep UNUSED;
 {
 #ifdef USE_TMPNAM
     char_u	itmp[L_tmpnam];	/* use tmpnam() */
@@ -7487,8 +7489,9 @@ vim_tempname(extra_char)
     buf4[2] = extra_char;   /* make it "VIa", "VIb", etc. */
     if (GetTempFileName(szTempFile, buf4, 0, itmp) == 0)
 	return NULL;
-    /* GetTempFileName() will create the file, we don't want that */
-    (void)DeleteFile(itmp);
+    if (!keep)
+	/* GetTempFileName() will create the file, we don't want that */
+	(void)DeleteFile(itmp);
 
     /* Backslashes in a temp file name cause problems when filtering with
      * "sh".  NOTE: This also checks 'shellcmdflag' to help those people who