mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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
This commit is contained in:
parent
edd7a8c5dd
commit
29e0cd1571
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user