summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-26 19:47:28 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-26 19:47:28 +0100
commit2472a74be4dedfeaff22314f31cf9787618163d1 (patch)
treef4bae9fddfe574e6049939d6ae53c391eda67ef2 /src/fileio.c
parentd49a35a1c3b736637733b36011fccbee7ef43fcf (diff)
downloadvim-git-2472a74be4dedfeaff22314f31cf9787618163d1.tar.gz
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp filev8.2.2055
Problem: MS-Windows: two Vim instances may use the same temp file. Solution: Use the process ID for the temp name. (Ken Takata, closes #7378)
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 27e9aaecf..66061680b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5167,17 +5167,24 @@ vim_tempname(
# ifdef MSWIN
WCHAR wszTempFile[_MAX_PATH + 1];
WCHAR buf4[4];
+ WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char_u *retval;
char_u *p;
+ long i;
wcscpy(itmp, L"");
if (GetTempPathW(_MAX_PATH, wszTempFile) == 0)
{
wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir
- wszTempFile[1] = NUL;
+ wszTempFile[1] = L'\\';
+ wszTempFile[2] = NUL;
}
wcscpy(buf4, L"VIM");
- buf4[2] = extra_char; // make it "VIa", "VIb", etc.
+
+ // randomize the name to avoid collisions
+ i = mch_get_pid() + extra_char;
+ buf4[1] = chartab[i % 36];
+ buf4[2] = chartab[101 * i % 36];
if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0)
return NULL;
if (!keep)