aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fileio.c
diff options
context:
space:
mode:
authorPavel Platto <hinidu@gmail.com>2014-06-19 23:46:51 +0300
committerNicolas Hillegeer <nicolas@hillegeer.com>2014-07-14 21:14:40 +0200
commit29e0cd1571b773feb7fd61118930cdac7d83e38c (patch)
tree5190da12cc72647b1573c44b55bcc0e030a6be81 /src/nvim/fileio.c
parentedd7a8c5ddd99bd0c02b4218d43bccb562809d55 (diff)
downloadrneovim-29e0cd1571b773feb7fd61118930cdac7d83e38c.tar.gz
rneovim-29e0cd1571b773feb7fd61118930cdac7d83e38c.tar.bz2
rneovim-29e0cd1571b773feb7fd61118930cdac7d83e38c.zip
Refactor vim_tempname
- temp_count is uint32_t now instead of long because it supposed to be at most 999999999 (comment on line 5227) temporary files. The most probably it was a long for compatibility with systems where int is 16-bit. - Use "nvim" as prefix for temp folder name instead of "v" - Remove unused parameter from vim_tempname
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r--src/nvim/fileio.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 8dcc066258..b8adff3bca 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2146,7 +2146,7 @@ readfile_charconvert (
char_u *tmpname;
char_u *errmsg = NULL;
- tmpname = vim_tempname('r');
+ tmpname = vim_tempname();
if (tmpname == NULL)
errmsg = (char_u *)_("Can't find temp file for conversion");
else {
@@ -3163,7 +3163,7 @@ nobackup:
* overwrite the original file.
*/
if (*p_ccv != NUL) {
- wfname = vim_tempname('w');
+ wfname = vim_tempname();
if (wfname == NULL) { /* Can't write without a tempfile! */
errmsg = (char_u *)_("E214: Can't find temp file for writing");
goto restore_backup;
@@ -5156,7 +5156,7 @@ void write_lnum_adjust(linenr_T offset)
curbuf->b_no_eol_lnum += offset;
}
-static long temp_count = 0; /* Temp filename counter. */
+static uint32_t temp_count = 0; /* Temp filename counter. */
/*
* Delete the temp directory and all files it contains.
@@ -5208,10 +5208,7 @@ static void vim_settempdir(char_u *tempdir)
* The returned pointer is to allocated memory.
* The returned pointer is NULL if no valid name was found.
*/
-char_u *
-vim_tempname (
- int extra_char /* char to use in the name instead of '?' */
-)
+char_u *vim_tempname(void)
{
char_u itmp[TEMP_FILE_PATH_MAXLEN];
@@ -5230,13 +5227,13 @@ vim_tempname (
* Try the entries in `TEMP_DIR_NAMES` to create the temp directory.
*/
for (i = 0; i < (int)(sizeof(temp_dirs) / sizeof(char *)); ++i) {
- /* expand $TMP, leave room for "/v1100000/999999999" */
- expand_env((char_u *)temp_dirs[i], itmp, TEMP_FILE_PATH_MAXLEN - 20);
+ /* expand $TMP, leave room for "/nvimXXXXXX/999999999" */
+ expand_env((char_u *)temp_dirs[i], itmp, TEMP_FILE_PATH_MAXLEN - 22);
if (os_isdir(itmp)) { /* directory exists */
add_pathsep(itmp);
/* Leave room for filename */
- STRCAT(itmp, "vXXXXXX");
+ STRCAT(itmp, "nvimXXXXXX");
if (os_mkdtemp((char *)itmp) != NULL)
vim_settempdir(itmp);
if (vim_tempdir != NULL)
@@ -5248,7 +5245,7 @@ vim_tempname (
if (vim_tempdir != NULL) {
/* There is no need to check if the file exists, because we own the
* directory and nobody else creates a file in it. */
- sprintf((char *)itmp, "%s%" PRId64, vim_tempdir, (int64_t)temp_count++);
+ sprintf((char *)itmp, "%s%" PRIu32, vim_tempdir, temp_count++);
return vim_strsave(itmp);
}