aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/tempfile.c
diff options
context:
space:
mode:
authorPavel Platto <hinidu@gmail.com>2014-08-05 16:54:32 +0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-08-09 11:28:43 -0300
commit5e42b406a57fd6f4f6dc982745f854eb8e0cd92f (patch)
tree90036928a4094cb1b3b06051348a2375b51b795f /src/nvim/tempfile.c
parent19f44fda8bc74abdcd13deca47be99b151f69239 (diff)
downloadrneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.tar.gz
rneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.tar.bz2
rneovim-5e42b406a57fd6f4f6dc982745f854eb8e0cd92f.zip
Implement `os_mkdtemp` on top of `uv_fs_mkdtemp`
Diffstat (limited to 'src/nvim/tempfile.c')
-rw-r--r--src/nvim/tempfile.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c
index c25da77717..33d6f0f37d 100644
--- a/src/nvim/tempfile.c
+++ b/src/nvim/tempfile.c
@@ -28,26 +28,29 @@ static void vim_maketempdir(void)
{
static const char *temp_dirs[] = TEMP_DIR_NAMES;
// Try the entries in `TEMP_DIR_NAMES` to create the temp directory.
- char_u itmp[TEMP_FILE_PATH_MAXLEN];
+ char_u template[TEMP_FILE_PATH_MAXLEN];
+ char_u path[TEMP_FILE_PATH_MAXLEN];
for (size_t i = 0; i < sizeof(temp_dirs) / sizeof(char *); ++i) {
// Expand environment variables, leave room for "/nvimXXXXXX/999999999"
- expand_env((char_u *)temp_dirs[i], itmp, TEMP_FILE_PATH_MAXLEN - 22);
- if (!os_isdir(itmp)) { // directory doesn't exist
+ expand_env((char_u *)temp_dirs[i], template, TEMP_FILE_PATH_MAXLEN - 22);
+ if (!os_isdir(template)) { // directory doesn't exist
continue;
}
- add_pathsep(itmp);
+ add_pathsep(template);
// Concatenate with temporary directory name pattern
- STRCAT(itmp, "nvimXXXXXX");
- if (!os_mkdtemp((char *)itmp)) {
+ STRCAT(template, "nvimXXXXXX");
+
+ if (os_mkdtemp((const char *)template, (char *)path) != 0) {
continue;
}
- if (vim_settempdir(itmp)) {
+
+ if (vim_settempdir(path)) {
// Successfully created and set temporary directory so stop trying.
break;
} else {
- // Couldn't set `vim_tempdir` to itmp so remove created directory.
- os_rmdir((char *)itmp);
+ // Couldn't set `vim_tempdir` to `path` so remove created directory.
+ os_rmdir((char *)path);
}
}
}
@@ -128,8 +131,8 @@ char_u *vim_tempname(void)
// There is no need to check if the file exists, because we own the directory
// and nobody else creates a file in it.
- char_u itmp[TEMP_FILE_PATH_MAXLEN];
- snprintf((char *)itmp, TEMP_FILE_PATH_MAXLEN,
+ char_u template[TEMP_FILE_PATH_MAXLEN];
+ snprintf((char *)template, TEMP_FILE_PATH_MAXLEN,
"%s%" PRIu32, tempdir, temp_count++);
- return vim_strsave(itmp);
+ return vim_strsave(template);
}