diff options
author | Pavel Platto <hinidu@gmail.com> | 2014-06-19 23:46:51 +0300 |
---|---|---|
committer | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-07-14 21:14:40 +0200 |
commit | 29e0cd1571b773feb7fd61118930cdac7d83e38c (patch) | |
tree | 5190da12cc72647b1573c44b55bcc0e030a6be81 /src | |
parent | edd7a8c5ddd99bd0c02b4218d43bccb562809d55 (diff) | |
download | rneovim-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')
-rw-r--r-- | src/nvim/diff.c | 10 | ||||
-rw-r--r-- | src/nvim/eval.c | 18 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 6 | ||||
-rw-r--r-- | src/nvim/fileio.c | 19 | ||||
-rw-r--r-- | src/nvim/hardcopy.c | 2 | ||||
-rw-r--r-- | src/nvim/if_cscope.c | 2 | ||||
-rw-r--r-- | src/nvim/memline.c | 2 | ||||
-rw-r--r-- | src/nvim/misc1.c | 2 | ||||
-rw-r--r-- | src/nvim/os/server.c | 2 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 2 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 2 | ||||
-rw-r--r-- | src/nvim/spell.c | 2 |
12 files changed, 26 insertions, 43 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 0ae3d5553e..37210e447c 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -661,9 +661,9 @@ void ex_diffupdate(exarg_T *eap) } // We need three temp file names. - char_u *tmp_orig = vim_tempname('o'); - char_u *tmp_new = vim_tempname('n'); - char_u *tmp_diff = vim_tempname('d'); + char_u *tmp_orig = vim_tempname(); + char_u *tmp_new = vim_tempname(); + char_u *tmp_diff = vim_tempname(); if ((tmp_orig == NULL) || (tmp_new == NULL) || (tmp_diff == NULL)) { goto theend; @@ -852,9 +852,9 @@ void ex_diffpatch(exarg_T *eap) #endif // ifdef UNIX // We need two temp file names. // Name of original temp file. - char_u *tmp_orig = vim_tempname('o'); + char_u *tmp_orig = vim_tempname(); // Name of patched temp file. - char_u *tmp_new = vim_tempname('n'); + char_u *tmp_new = vim_tempname(); if ((tmp_orig == NULL) || (tmp_new == NULL)) { goto theend; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index eafdd2446c..7dc95bcded 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14030,7 +14030,7 @@ static void f_system(typval_T *argvars, typval_T *rettv) * Write the string to a temp file, to be used for input of the shell * command. */ - if ((infile = vim_tempname('i')) == NULL) { + if ((infile = vim_tempname()) == NULL) { EMSG(_(e_notmp)); goto done; } @@ -14231,22 +14231,8 @@ static void f_taglist(typval_T *argvars, typval_T *rettv) */ static void f_tempname(typval_T *argvars, typval_T *rettv) { - static int x = 'A'; - rettv->v_type = VAR_STRING; - rettv->vval.v_string = vim_tempname(x); - - /* Advance 'x' to use A-Z and 0-9, so that there are at least 34 different - * names. Skip 'I' and 'O', they are used for shell redirection. */ - do { - if (x == 'Z') - x = '0'; - else if (x == '9') - x = 'A'; - else { - ++x; - } - } while (x == 'I' || x == 'O'); + rettv->vval.v_string = vim_tempname(); } /* diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 78325fd4a4..05ca5bbb58 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1032,8 +1032,8 @@ do_filter ( curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; curwin->w_cursor.lnum = line2; - } else if ((do_in && (itmp = vim_tempname('i')) == NULL) - || (do_out && (otmp = vim_tempname('o')) == NULL)) { + } else if ((do_in && (itmp = vim_tempname()) == NULL) + || (do_out && (otmp = vim_tempname()) == NULL)) { EMSG(_(e_notmp)); goto filterend; } @@ -1601,7 +1601,7 @@ void write_viminfo(char_u *file, int forceit) */ if (fp_out == NULL) { free(tempname); - if ((tempname = vim_tempname('o')) != NULL) + if ((tempname = vim_tempname()) != NULL) fp_out = mch_fopen((char *)tempname, WRITEBIN); } 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); } diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index e67cb67c69..024564f700 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2346,7 +2346,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) /* If the user didn't specify a file name, use a temp file. */ if (psettings->outfile == NULL) { - prt_ps_file_name = vim_tempname('p'); + prt_ps_file_name = vim_tempname(); if (prt_ps_file_name == NULL) { EMSG(_(e_notmp)); return FAIL; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 9ce0eb7fa0..1b7202dbab 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -1044,7 +1044,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us if (qfpos != NULL && *qfpos != '0' && totmatches > 0) { /* fill error list */ FILE *f; - char_u *tmp = vim_tempname('c'); + char_u *tmp = vim_tempname(); qf_info_T *qi = NULL; win_T *wp = NULL; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f951eb9379..c41942301f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -490,7 +490,7 @@ void ml_open_file(buf_T *buf) /* For a spell buffer use a temp file name. */ if (buf->b_spell) { - fname = vim_tempname('s'); + fname = vim_tempname(); if (fname != NULL) (void)mf_open_file(mfp, fname); /* consumes fname! */ buf->b_may_swap = FALSE; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 3fc078cb8a..4e3879ddef 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -3423,7 +3423,7 @@ get_cmd_output ( return NULL; /* get a name for the temp file */ - if ((tempname = vim_tempname('o')) == NULL) { + if ((tempname = vim_tempname()) == NULL) { EMSG(_(e_notmp)); return NULL; } diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index 23f9393122..2494dfeb9f 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -52,7 +52,7 @@ void server_init(void) servers = pmap_new(cstr_t)(); if (!os_getenv("NEOVIM_LISTEN_ADDRESS")) { - char *listen_address = (char *)vim_tempname('s'); + char *listen_address = (char *)vim_tempname(); os_setenv("NEOVIM_LISTEN_ADDRESS", listen_address, 1); free(listen_address); } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 2c657bebeb..239d7d81db 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -1034,7 +1034,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, /* * get a name for the temp file */ - if ((tempname = vim_tempname('o')) == NULL) { + if ((tempname = vim_tempname()) == NULL) { EMSG(_(e_notmp)); return FAIL; } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ec95c74fef..60bd15701d 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2537,7 +2537,7 @@ static char_u *get_mef_name(void) static int off = 0; if (*p_mef == NUL) { - name = vim_tempname('e'); + name = vim_tempname(); if (name == NULL) EMSG(_(e_notmp)); return name; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c2354bb2c6..4000235304 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -7814,7 +7814,7 @@ spell_add_word ( if (idx == 0) { // use internal wordlist if (int_wordlist == NULL) { - int_wordlist = vim_tempname('s'); + int_wordlist = vim_tempname(); if (int_wordlist == NULL) return; } |