comparison 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
comparison
equal deleted inserted replaced
6720:1f42458bf2e7 6721:7347229a646a
2870 int *fdp; /* in/out: file descriptor of file */ 2870 int *fdp; /* in/out: file descriptor of file */
2871 { 2871 {
2872 char_u *tmpname; 2872 char_u *tmpname;
2873 char_u *errmsg = NULL; 2873 char_u *errmsg = NULL;
2874 2874
2875 tmpname = vim_tempname('r'); 2875 tmpname = vim_tempname('r', FALSE);
2876 if (tmpname == NULL) 2876 if (tmpname == NULL)
2877 errmsg = (char_u *)_("Can't find temp file for conversion"); 2877 errmsg = (char_u *)_("Can't find temp file for conversion");
2878 else 2878 else
2879 { 2879 {
2880 close(*fdp); /* close the input file, ignore errors */ 2880 close(*fdp); /* close the input file, ignore errors */
4286 * writing, write to a temp file instead and let the conversion 4286 * writing, write to a temp file instead and let the conversion
4287 * overwrite the original file. 4287 * overwrite the original file.
4288 */ 4288 */
4289 if (*p_ccv != NUL) 4289 if (*p_ccv != NUL)
4290 { 4290 {
4291 wfname = vim_tempname('w'); 4291 wfname = vim_tempname('w', FALSE);
4292 if (wfname == NULL) /* Can't write without a tempfile! */ 4292 if (wfname == NULL) /* Can't write without a tempfile! */
4293 { 4293 {
4294 errmsg = (char_u *)_("E214: Can't find temp file for writing"); 4294 errmsg = (char_u *)_("E214: Can't find temp file for writing");
4295 goto restore_backup; 4295 goto restore_backup;
4296 } 4296 }
7342 #endif 7342 #endif
7343 7343
7344 /* 7344 /*
7345 * vim_tempname(): Return a unique name that can be used for a temp file. 7345 * vim_tempname(): Return a unique name that can be used for a temp file.
7346 * 7346 *
7347 * The temp file is NOT created. 7347 * The temp file is NOT garanteed to be created. If "keep" is FALSE it is
7348 * garanteed to NOT be created.
7348 * 7349 *
7349 * The returned pointer is to allocated memory. 7350 * The returned pointer is to allocated memory.
7350 * The returned pointer is NULL if no valid name was found. 7351 * The returned pointer is NULL if no valid name was found.
7351 */ 7352 */
7352 char_u * 7353 char_u *
7353 vim_tempname(extra_char) 7354 vim_tempname(extra_char, keep)
7354 int extra_char UNUSED; /* char to use in the name instead of '?' */ 7355 int extra_char UNUSED; /* char to use in the name instead of '?' */
7356 int keep UNUSED;
7355 { 7357 {
7356 #ifdef USE_TMPNAM 7358 #ifdef USE_TMPNAM
7357 char_u itmp[L_tmpnam]; /* use tmpnam() */ 7359 char_u itmp[L_tmpnam]; /* use tmpnam() */
7358 #else 7360 #else
7359 char_u itmp[TEMPNAMELEN]; 7361 char_u itmp[TEMPNAMELEN];
7485 } 7487 }
7486 strcpy(buf4, "VIM"); 7488 strcpy(buf4, "VIM");
7487 buf4[2] = extra_char; /* make it "VIa", "VIb", etc. */ 7489 buf4[2] = extra_char; /* make it "VIa", "VIb", etc. */
7488 if (GetTempFileName(szTempFile, buf4, 0, itmp) == 0) 7490 if (GetTempFileName(szTempFile, buf4, 0, itmp) == 0)
7489 return NULL; 7491 return NULL;
7490 /* GetTempFileName() will create the file, we don't want that */ 7492 if (!keep)
7491 (void)DeleteFile(itmp); 7493 /* GetTempFileName() will create the file, we don't want that */
7494 (void)DeleteFile(itmp);
7492 7495
7493 /* Backslashes in a temp file name cause problems when filtering with 7496 /* Backslashes in a temp file name cause problems when filtering with
7494 * "sh". NOTE: This also checks 'shellcmdflag' to help those people who 7497 * "sh". NOTE: This also checks 'shellcmdflag' to help those people who
7495 * didn't set 'shellslash'. */ 7498 * didn't set 'shellslash'. */
7496 retval = vim_strsave(itmp); 7499 retval = vim_strsave(itmp);