Merge #2470: Remove char_u (5)

Reviewed-by: Scott Prager <splinterofchaos@gmail.com>
Reviewed-by: Michael Reed <m.reed@mykolab.com>
Reviewed-by: Eliseo Martínez <eliseomarmol@gmail.com>
This commit is contained in:
Eliseo Martínez 2015-05-07 08:08:31 +02:00
commit f88cec8021
24 changed files with 263 additions and 266 deletions

View File

@ -1661,7 +1661,7 @@ buf_T *buflist_findname_exp(char_u *fname)
buf_T *buf = NULL; buf_T *buf = NULL;
/* First make the name into a full path name */ /* First make the name into a full path name */
ffname = FullName_save(fname, ffname = (char_u *)FullName_save((char *)fname,
#ifdef UNIX #ifdef UNIX
TRUE /* force expansion, get rid of symbolic links */ TRUE /* force expansion, get rid of symbolic links */
#else #else
@ -3569,7 +3569,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
return; return;
if (*sfname == NULL) /* if no short file name given, use ffname */ if (*sfname == NULL) /* if no short file name given, use ffname */
*sfname = *ffname; *sfname = *ffname;
*ffname = fix_fname(*ffname); /* expand to full path */ *ffname = (char_u *)fix_fname((char *)*ffname); /* expand to full path */
#ifdef FEAT_SHORTCUT #ifdef FEAT_SHORTCUT
if (!buf->b_p_bin) { if (!buf->b_p_bin) {

View File

@ -867,7 +867,7 @@ void ex_diffpatch(exarg_T *eap)
#ifdef UNIX #ifdef UNIX
// Get the absolute path of the patchfile, changing directory below. // Get the absolute path of the patchfile, changing directory below.
fullname = FullName_save(eap->arg, FALSE); fullname = (char_u *)FullName_save((char *)eap->arg, FALSE);
#endif // ifdef UNIX #endif // ifdef UNIX
#ifdef UNIX #ifdef UNIX

View File

@ -7347,7 +7347,7 @@ static buf_T *find_buffer(typval_T *avar)
* buffer, these don't use the full path. */ * buffer, these don't use the full path. */
FOR_ALL_BUFFERS(bp) { FOR_ALL_BUFFERS(bp) {
if (bp->b_fname != NULL if (bp->b_fname != NULL
&& (path_with_url(bp->b_fname) && (path_with_url((char *)bp->b_fname)
|| bt_nofile(bp) || bt_nofile(bp)
) )
&& STRCMP(bp->b_fname, avar->vval.v_string) == 0) { && STRCMP(bp->b_fname, avar->vval.v_string) == 0) {
@ -12484,7 +12484,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
/* Ensure that the result will have a trailing path separator /* Ensure that the result will have a trailing path separator
* if the argument has one. */ * if the argument has one. */
if (remain == NULL && has_trailing_pathsep) if (remain == NULL && has_trailing_pathsep)
add_pathsep(buf); add_pathsep((char *)buf);
/* Separate the first path component in the link value and /* Separate the first path component in the link value and
* concatenate the remainders. */ * concatenate the remainders. */
@ -15490,7 +15490,7 @@ static void f_undofile(typval_T *argvars, typval_T *rettv)
/* If there is no file name there will be no undo file. */ /* If there is no file name there will be no undo file. */
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
} else { } else {
char_u *ffname = FullName_save(fname, FALSE); char_u *ffname = (char_u *)FullName_save((char *)fname, FALSE);
if (ffname != NULL) if (ffname != NULL)
rettv->vval.v_string = u_get_undo_file_name(ffname, FALSE); rettv->vval.v_string = u_get_undo_file_name(ffname, FALSE);
@ -19912,7 +19912,7 @@ repeat:
/* FullName_save() is slow, don't use it when not needed. */ /* FullName_save() is slow, don't use it when not needed. */
if (*p != NUL || !vim_isAbsName(*fnamep)) { if (*p != NUL || !vim_isAbsName(*fnamep)) {
*fnamep = FullName_save(*fnamep, *p != NUL); *fnamep = (char_u *)FullName_save((char *)*fnamep, *p != NUL);
xfree(*bufp); /* free any allocated file name */ xfree(*bufp); /* free any allocated file name */
*bufp = *fnamep; *bufp = *fnamep;
if (*fnamep == NULL) if (*fnamep == NULL)
@ -19927,7 +19927,7 @@ repeat:
*bufp = *fnamep; *bufp = *fnamep;
if (*fnamep == NULL) if (*fnamep == NULL)
return -1; return -1;
add_pathsep(*fnamep); add_pathsep((char *)*fnamep);
} }
} }
@ -19946,7 +19946,7 @@ repeat:
if (c == '.' && **fnamep == '~') if (c == '.' && **fnamep == '~')
p = pbuf = expand_env_save(*fnamep); p = pbuf = expand_env_save(*fnamep);
else else
p = pbuf = FullName_save(*fnamep, FALSE); p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);
} else } else
p = *fnamep; p = *fnamep;

View File

@ -1530,7 +1530,7 @@ void write_viminfo(char_u *file, int forceit)
#endif #endif
// Make tempname // Make tempname
tempname = modname(fname, (char_u *)".tmp", FALSE); tempname = (char_u *)modname((char *)fname, ".tmp", FALSE);
if (tempname != NULL) { if (tempname != NULL) {
/* /*
* Check if tempfile already exists. Never overwrite an * Check if tempfile already exists. Never overwrite an
@ -2080,7 +2080,7 @@ int do_write(exarg_T *eap)
other = FALSE; other = FALSE;
} else { } else {
fname = ffname; fname = ffname;
free_fname = fix_fname(ffname); free_fname = (char_u *)fix_fname((char *)ffname);
/* /*
* When out-of-memory, keep unexpanded file name, because we MUST be * When out-of-memory, keep unexpanded file name, because we MUST be
* able to write the file in this situation. * able to write the file in this situation.
@ -2579,7 +2579,7 @@ do_ecmd (
ffname = curbuf->b_ffname; ffname = curbuf->b_ffname;
sfname = curbuf->b_fname; sfname = curbuf->b_fname;
} }
free_fname = fix_fname(ffname); /* may expand to full path name */ free_fname = (char_u *)fix_fname((char *)ffname); /* may expand to full path name */
if (free_fname != NULL) if (free_fname != NULL)
ffname = free_fname; ffname = free_fname;
other_file = otherfile(ffname); other_file = otherfile(ffname);
@ -5126,7 +5126,7 @@ void fix_help_buffer(void)
char_u *cp; char_u *cp;
/* Find all "doc/ *.txt" files in this directory. */ /* Find all "doc/ *.txt" files in this directory. */
add_pathsep(NameBuff); add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "doc/*.??[tx]"); STRCAT(NameBuff, "doc/*.??[tx]");
// Note: We cannot just do `&NameBuff` because it is a statically sized array // Note: We cannot just do `&NameBuff` because it is a statically sized array
@ -5297,7 +5297,7 @@ void ex_helptags(exarg_T *eap)
/* Get a list of all files in the help directory and in subdirectories. */ /* Get a list of all files in the help directory and in subdirectories. */
STRCPY(NameBuff, dirname); STRCPY(NameBuff, dirname);
add_pathsep(NameBuff); add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "**"); STRCAT(NameBuff, "**");
// Note: We cannot just do `&NameBuff` because it is a statically sized array // Note: We cannot just do `&NameBuff` because it is a statically sized array
@ -5419,7 +5419,7 @@ helptags_one (
* Do this before scanning through all the files. * Do this before scanning through all the files.
*/ */
STRCPY(NameBuff, dir); STRCPY(NameBuff, dir);
add_pathsep(NameBuff); add_pathsep((char *)NameBuff);
STRCAT(NameBuff, tagfname); STRCAT(NameBuff, tagfname);
fd_tags = mch_fopen((char *)NameBuff, "w"); fd_tags = mch_fopen((char *)NameBuff, "w");
if (fd_tags == NULL) { if (fd_tags == NULL) {

View File

@ -495,7 +495,7 @@ dbg_parsearg (
if (p == NULL) if (p == NULL)
return FAIL; return FAIL;
if (*p != '*') { if (*p != '*') {
bp->dbg_name = fix_fname(p); bp->dbg_name = (char_u *)fix_fname((char *)p);
xfree(p); xfree(p);
} else } else
bp->dbg_name = p; bp->dbg_name = p;
@ -1692,7 +1692,7 @@ void do_argfile(exarg_T *eap, int argn)
*/ */
other = TRUE; other = TRUE;
if (P_HID(curbuf)) { if (P_HID(curbuf)) {
p = fix_fname(alist_name(&ARGLIST[argn])); p = (char_u *)fix_fname((char *)alist_name(&ARGLIST[argn]));
other = otherfile(p); other = otherfile(p);
xfree(p); xfree(p);
} }
@ -2144,7 +2144,7 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
if (!did_one) if (!did_one)
did_one = (cookie == NULL); did_one = (cookie == NULL);
} else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) { } else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) {
add_pathsep(buf); add_pathsep((char *)buf);
tail = buf + STRLEN(buf); tail = buf + STRLEN(buf);
/* Loop over all patterns in "name" */ /* Loop over all patterns in "name" */
@ -2313,7 +2313,7 @@ do_source (
p = expand_env_save(fname); p = expand_env_save(fname);
if (p == NULL) if (p == NULL)
return retval; return retval;
fname_exp = fix_fname(p); fname_exp = (char_u *)fix_fname((char *)p);
xfree(p); xfree(p);
if (fname_exp == NULL) if (fname_exp == NULL)
return retval; return retval;
@ -3305,7 +3305,7 @@ static void script_host_execute(char *name, exarg_T *eap)
static void script_host_execute_file(char *name, exarg_T *eap) static void script_host_execute_file(char *name, exarg_T *eap)
{ {
uint8_t buffer[MAXPATHL]; uint8_t buffer[MAXPATHL];
vim_FullName(eap->arg, buffer, sizeof(buffer), false); vim_FullName((char *)eap->arg, (char *)buffer, sizeof(buffer), false);
list_T *args = list_alloc(); list_T *args = list_alloc();
// filename // filename

View File

@ -7544,7 +7544,7 @@ static void ex_mkrc(exarg_T *eap)
char_u *tbuf; char_u *tbuf;
tbuf = xmalloc(MAXPATHL); tbuf = xmalloc(MAXPATHL);
if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) if (vim_FullName((char *)fname, (char *)tbuf, MAXPATHL, FALSE) == OK)
set_vim_var_string(VV_THIS_SESSION, tbuf, -1); set_vim_var_string(VV_THIS_SESSION, tbuf, -1);
xfree(tbuf); xfree(tbuf);
} }
@ -8155,7 +8155,7 @@ eval_vars (
/* Still need to turn the fname into a full path. It is /* Still need to turn the fname into a full path. It is
* postponed to avoid a delay when <afile> is not used. */ * postponed to avoid a delay when <afile> is not used. */
autocmd_fname_full = TRUE; autocmd_fname_full = TRUE;
result = FullName_save(autocmd_fname, FALSE); result = (char_u *)FullName_save((char *)autocmd_fname, FALSE);
xfree(autocmd_fname); xfree(autocmd_fname);
autocmd_fname = result; autocmd_fname = result;
} }
@ -8975,7 +8975,7 @@ ses_arglist (
if (s != NULL) { if (s != NULL) {
if (fullname) { if (fullname) {
buf = xmalloc(MAXPATHL); buf = xmalloc(MAXPATHL);
(void)vim_FullName(s, buf, MAXPATHL, FALSE); (void)vim_FullName((char *)s, (char *)buf, MAXPATHL, FALSE);
s = buf; s = buf;
} }
if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL
@ -9089,7 +9089,7 @@ static char_u *get_view_file(int c)
++len; ++len;
retval = xmalloc(STRLEN(sname) + len + STRLEN(p_vdir) + 9); retval = xmalloc(STRLEN(sname) + len + STRLEN(p_vdir) + 9);
STRCPY(retval, p_vdir); STRCPY(retval, p_vdir);
add_pathsep(retval); add_pathsep((char *)retval);
s = retval + STRLEN(retval); s = retval + STRLEN(retval);
for (p = sname; *p; ++p) { for (p = sname; *p; ++p) {
if (*p == '=') { if (*p == '=') {

View File

@ -3890,7 +3890,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
if (l > MAXPATHL - 5) if (l > MAXPATHL - 5)
break; break;
STRLCPY(buf, s, l + 1); STRLCPY(buf, s, l + 1);
add_pathsep(buf); add_pathsep((char *)buf);
l = STRLEN(buf); l = STRLEN(buf);
STRLCPY(buf + l, pat, MAXPATHL - l); STRLCPY(buf + l, pat, MAXPATHL - l);
@ -4107,7 +4107,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
// Copy one item of the path to buf[] and concatenate the file name. // Copy one item of the path to buf[] and concatenate the file name.
copy_option_part(&path, buf, MAXPATHL, ","); copy_option_part(&path, buf, MAXPATHL, ",");
if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) { if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) {
add_pathsep(buf); add_pathsep((char *)buf);
STRCAT(buf, file); // NOLINT STRCAT(buf, file); // NOLINT
char_u **p; char_u **p;

View File

@ -313,7 +313,7 @@ vim_findfile_init (
if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) { if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) {
/* Make the start dir an absolute path name. */ /* Make the start dir an absolute path name. */
STRLCPY(ff_expand_buffer, rel_fname, len + 1); STRLCPY(ff_expand_buffer, rel_fname, len + 1);
search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); search_ctx->ffsc_start_dir = (char_u *)FullName_save((char *)ff_expand_buffer, FALSE);
} else } else
search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
if (*++path != NUL) if (*++path != NUL)
@ -465,7 +465,7 @@ vim_findfile_init (
goto error_return; goto error_return;
} }
STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
add_pathsep(ff_expand_buffer); add_pathsep((char *)ff_expand_buffer);
{ {
size_t eb_len = STRLEN(ff_expand_buffer); size_t eb_len = STRLEN(ff_expand_buffer);
char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1); char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1);
@ -474,7 +474,7 @@ vim_findfile_init (
STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); STRCPY(buf + eb_len, search_ctx->ffsc_fix_path);
if (os_isdir(buf)) { if (os_isdir(buf)) {
STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
add_pathsep(ff_expand_buffer); add_pathsep((char *)ff_expand_buffer);
} else { } else {
char_u *p = path_tail(search_ctx->ffsc_fix_path); char_u *p = path_tail(search_ctx->ffsc_fix_path);
char_u *wc_path = NULL; char_u *wc_path = NULL;
@ -484,7 +484,7 @@ vim_findfile_init (
if (p > search_ctx->ffsc_fix_path) { if (p > search_ctx->ffsc_fix_path) {
len = (int)(p - search_ctx->ffsc_fix_path) - 1; len = (int)(p - search_ctx->ffsc_fix_path) - 1;
STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len); STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len);
add_pathsep(ff_expand_buffer); add_pathsep((char *)ff_expand_buffer);
} else } else
len = (int)STRLEN(search_ctx->ffsc_fix_path); len = (int)STRLEN(search_ctx->ffsc_fix_path);
@ -695,12 +695,12 @@ char_u *vim_findfile(void *search_ctx_arg)
if (!vim_isAbsName(stackp->ffs_fix_path) if (!vim_isAbsName(stackp->ffs_fix_path)
&& search_ctx->ffsc_start_dir) { && search_ctx->ffsc_start_dir) {
STRCPY(file_path, search_ctx->ffsc_start_dir); STRCPY(file_path, search_ctx->ffsc_start_dir);
add_pathsep(file_path); add_pathsep((char *)file_path);
} }
/* append the fix part of the search path */ /* append the fix part of the search path */
STRCAT(file_path, stackp->ffs_fix_path); STRCAT(file_path, stackp->ffs_fix_path);
add_pathsep(file_path); add_pathsep((char *)file_path);
rest_of_wildcards = stackp->ffs_wc_path; rest_of_wildcards = stackp->ffs_wc_path;
if (*rest_of_wildcards != NUL) { if (*rest_of_wildcards != NUL) {
@ -749,7 +749,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* Expand wildcards like "*" and "$VAR". * Expand wildcards like "*" and "$VAR".
* If the path is a URL don't try this. * If the path is a URL don't try this.
*/ */
if (path_with_url(dirptrs[0])) { if (path_with_url((char *)dirptrs[0])) {
stackp->ffs_filearray = (char_u **)xmalloc(sizeof(char *)); stackp->ffs_filearray = (char_u **)xmalloc(sizeof(char *));
stackp->ffs_filearray[0] = vim_strsave(dirptrs[0]); stackp->ffs_filearray[0] = vim_strsave(dirptrs[0]);
stackp->ffs_filearray_size = 1; stackp->ffs_filearray_size = 1;
@ -777,14 +777,14 @@ char_u *vim_findfile(void *search_ctx_arg)
*/ */
for (int i = stackp->ffs_filearray_cur; for (int i = stackp->ffs_filearray_cur;
i < stackp->ffs_filearray_size; ++i) { i < stackp->ffs_filearray_size; ++i) {
if (!path_with_url(stackp->ffs_filearray[i]) if (!path_with_url((char *)stackp->ffs_filearray[i])
&& !os_isdir(stackp->ffs_filearray[i])) && !os_isdir(stackp->ffs_filearray[i]))
continue; /* not a directory */ continue; /* not a directory */
/* prepare the filename to be checked for existence /* prepare the filename to be checked for existence
* below */ * below */
STRCPY(file_path, stackp->ffs_filearray[i]); STRCPY(file_path, stackp->ffs_filearray[i]);
add_pathsep(file_path); add_pathsep((char *)file_path);
STRCAT(file_path, search_ctx->ffsc_file_to_search); STRCAT(file_path, search_ctx->ffsc_file_to_search);
/* /*
@ -798,7 +798,7 @@ char_u *vim_findfile(void *search_ctx_arg)
suf = curbuf->b_p_sua; suf = curbuf->b_p_sua;
for (;; ) { for (;; ) {
/* if file exists and we didn't already find it */ /* if file exists and we didn't already find it */
if ((path_with_url(file_path) if ((path_with_url((char *)file_path)
|| (os_file_exists(file_path) || (os_file_exists(file_path)
&& (search_ctx->ffsc_find_what && (search_ctx->ffsc_find_what
== FINDFILE_BOTH == FINDFILE_BOTH
@ -836,7 +836,7 @@ char_u *vim_findfile(void *search_ctx_arg)
stackp->ffs_filearray_cur = (char_u)(i + 1); stackp->ffs_filearray_cur = (char_u)(i + 1);
ff_push(search_ctx, stackp); ff_push(search_ctx, stackp);
if (!path_with_url(file_path)) if (!path_with_url((char *)file_path))
simplify_filename(file_path); simplify_filename(file_path);
if (os_dirname(ff_expand_buffer, MAXPATHL) if (os_dirname(ff_expand_buffer, MAXPATHL)
== OK) { == OK) {
@ -936,7 +936,7 @@ char_u *vim_findfile(void *search_ctx_arg)
break; break;
STRCPY(file_path, search_ctx->ffsc_start_dir); STRCPY(file_path, search_ctx->ffsc_start_dir);
add_pathsep(file_path); add_pathsep((char *)file_path);
STRCAT(file_path, search_ctx->ffsc_fix_path); STRCAT(file_path, search_ctx->ffsc_fix_path);
/* create a new stack entry */ /* create a new stack entry */
@ -1097,7 +1097,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
FileID file_id; FileID file_id;
// For an URL we only compare the name, otherwise we compare the // For an URL we only compare the name, otherwise we compare the
// device/inode. // device/inode.
if (path_with_url(fname)) { if (path_with_url((char *)fname)) {
STRLCPY(ff_expand_buffer, fname, MAXPATHL); STRLCPY(ff_expand_buffer, fname, MAXPATHL);
url = true; url = true;
} else { } else {
@ -1404,7 +1404,7 @@ find_file_in_path_option (
* filename on the first call. * filename on the first call.
*/ */
if (first == TRUE) { if (first == TRUE) {
if (path_with_url(ff_file_to_find)) { if (path_with_url((char *)ff_file_to_find)) {
file_name = vim_strsave(ff_file_to_find); file_name = vim_strsave(ff_file_to_find);
goto theend; goto theend;
} }

View File

@ -2814,7 +2814,7 @@ buf_write (
/* /*
* Make backup file name. * Make backup file name.
*/ */
backup = modname(rootname, backup_ext, FALSE); backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
if (backup == NULL) { if (backup == NULL) {
xfree(rootname); xfree(rootname);
some_error = TRUE; /* out of memory */ some_error = TRUE; /* out of memory */
@ -2985,7 +2985,7 @@ nobackup:
if (rootname == NULL) if (rootname == NULL)
backup = NULL; backup = NULL;
else { else {
backup = modname(rootname, backup_ext, FALSE); backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
xfree(rootname); xfree(rootname);
} }
@ -3595,7 +3595,7 @@ restore_backup:
* the backup file our 'original' file. * the backup file our 'original' file.
*/ */
if (*p_pm && dobackup) { if (*p_pm && dobackup) {
char *org = (char *)modname(fname, p_pm, FALSE); char *org = modname((char *)fname, (char *)p_pm, FALSE);
if (backup != NULL) { if (backup != NULL) {
/* /*
@ -4310,7 +4310,7 @@ void shorten_fnames(int force)
FOR_ALL_BUFFERS(buf) { FOR_ALL_BUFFERS(buf) {
if (buf->b_fname != NULL if (buf->b_fname != NULL
&& !bt_nofile(buf) && !bt_nofile(buf)
&& !path_with_url(buf->b_fname) && !path_with_url((char *)buf->b_fname)
&& (force && (force
|| buf->b_sfname == NULL || buf->b_sfname == NULL
|| path_is_absolute_path(buf->b_sfname))) { || path_is_absolute_path(buf->b_sfname))) {
@ -4333,108 +4333,108 @@ void shorten_fnames(int force)
redraw_tabline = TRUE; redraw_tabline = TRUE;
} }
/* /// Get new filename ended by given extension.
* add extension to file name - change path/fo.o.h to path/fo.o.h.ext ///
* /// @param fname The original filename.
* Assumed that fname is a valid name found in the filesystem we assure that /// If NULL, use current directory name and ext to
* the return value is a different name and ends in 'ext'. /// compute new filename.
* "ext" MUST be at most 4 characters long if it starts with a dot, 3 /// @param ext The extension to add to the filename.
* characters otherwise. /// 4 chars max if prefixed with a dot, 3 otherwise.
* Space for the returned name is allocated, must be freed later. /// @param prepend_dot If true, prefix ext with a dot.
* Returns NULL when out of memory. /// Does nothing if ext already starts with a dot, or
*/ /// if fname is NULL.
char_u * ///
modname ( /// @return [allocated] - A new filename, made up from:
char_u *fname, /// * fname + ext, if fname not NULL.
char_u *ext, /// * current dir + ext, if fname is NULL.
int prepend_dot /* may prepend a '.' to file name */ /// On Windows, and if ext starts with ".", a "_" is
) /// preprended to ext (for filename to be valid).
/// Result is guaranteed to:
/// * be ended by <ext>.
/// * have a basename with at most BASENAMELEN chars:
/// original basename is truncated if necessary.
/// * be different than original: basename chars are
/// replaced by "_" if necessary. If that can't be done
/// because truncated value of original filename was
/// made of all underscores, replace first "_" by "v".
/// - NULL, if fname is NULL and there was a problem trying
/// to get current directory.
char *modname(const char *fname, const char *ext, bool prepend_dot)
FUNC_ATTR_NONNULL_ARG(2)
{ {
char_u *retval; char *retval;
char_u *s; size_t fnamelen;
char_u *e; size_t extlen = strlen(ext);
char_u *ptr;
int fnamelen, extlen;
extlen = (int)STRLEN(ext); // If there is no file name we must get the name of the current directory
// (we need the full path in case :cd is used).
/*
* If there is no file name we must get the name of the current directory
* (we need the full path in case :cd is used).
*/
if (fname == NULL || *fname == NUL) { if (fname == NULL || *fname == NUL) {
retval = xmalloc(MAXPATHL + extlen + 3); retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL
if (os_dirname(retval, MAXPATHL) == FAIL || if (os_dirname((char_u *)retval, MAXPATHL) == FAIL ||
(fnamelen = (int)STRLEN(retval)) == 0) { (fnamelen = strlen(retval)) == 0) {
xfree(retval); xfree(retval);
return NULL; return NULL;
} }
if (!after_pathsep((char *)retval, (char *)retval + fnamelen)) { add_pathsep(retval);
retval[fnamelen++] = PATHSEP; fnamelen = strlen(retval);
retval[fnamelen] = NUL; prepend_dot = FALSE; // nothing to prepend a dot to
}
prepend_dot = FALSE; /* nothing to prepend a dot to */
} else { } else {
fnamelen = (int)STRLEN(fname); fnamelen = strlen(fname);
retval = xmalloc(fnamelen + extlen + 3); retval = xmalloc(fnamelen + extlen + 3);
STRCPY(retval, fname); strcpy(retval, fname);
} }
/* // Search backwards until we hit a '/', '\' or ':'.
* search backwards until we hit a '/', '\' or ':'. // Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters.
* Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters. char *ptr = NULL;
*/
for (ptr = retval + fnamelen; ptr > retval; mb_ptr_back(retval, ptr)) { for (ptr = retval + fnamelen; ptr > retval; mb_ptr_back(retval, ptr)) {
if (vim_ispathsep(*ptr)) { if (vim_ispathsep(*ptr)) {
++ptr; ptr++;
break; break;
} }
} }
/* the file name has at most BASENAMELEN characters. */ // the file name has at most BASENAMELEN characters.
if (STRLEN(ptr) > BASENAMELEN) if (strlen(ptr) > BASENAMELEN) {
ptr[BASENAMELEN] = '\0'; ptr[BASENAMELEN] = '\0';
}
s = ptr + STRLEN(ptr); char *s;
s = ptr + strlen(ptr);
#if defined(WIN3264) #if defined(WIN3264)
/* // If there is no file name, and the extension starts with '.', put a
* If there is no file name, and the extension starts with '.', put a // '_' before the dot, because just ".ext" may be invalid if it's on a
* '_' before the dot, because just ".ext" may be invalid if it's on a // FAT partition, and on HPFS it doesn't matter.
* FAT partition, and on HPFS it doesn't matter. else if ((fname == NULL || *fname == NUL) && *ext == '.') {
*/
else if ((fname == NULL || *fname == NUL) && *ext == '.')
*s++ = '_'; *s++ = '_';
}
#endif #endif
/* // Append the extension.
* Append the extension. // ext can start with '.' and cannot exceed 3 more characters.
* ext can start with '.' and cannot exceed 3 more characters. strcpy(s, ext);
*/
STRCPY(s, ext);
/* char *e;
* Prepend the dot. // Prepend the dot if needed.
*/ if (prepend_dot && *(e = (char *)path_tail((char_u *)retval)) != '.') {
if (prepend_dot && *(e = path_tail(retval)) != '.') {
STRMOVE(e + 1, e); STRMOVE(e + 1, e);
*e = '.'; *e = '.';
} }
/* // Check that, after appending the extension, the file name is really
* Check that, after appending the extension, the file name is really // different.
* different. if (fname != NULL && strcmp(fname, retval) == 0) {
*/ // we search for a character that can be replaced by '_'
if (fname != NULL && STRCMP(fname, retval) == 0) {
/* we search for a character that can be replaced by '_' */
while (--s >= ptr) { while (--s >= ptr) {
if (*s != '_') { if (*s != '_') {
*s = '_'; *s = '_';
break; break;
} }
} }
if (s < ptr) /* fname was "________.<ext>", how tricky! */ if (s < ptr) { // fname was "________.<ext>", how tricky!
*ptr = 'v'; *ptr = 'v';
}
} }
return retval; return retval;
} }
@ -6597,7 +6597,7 @@ apply_autocmds_group (
|| event == EVENT_TABCLOSED) || event == EVENT_TABCLOSED)
fname = vim_strsave(fname); fname = vim_strsave(fname);
else else
fname = FullName_save(fname, FALSE); fname = (char_u *)FullName_save((char *)fname, FALSE);
} }
if (fname == NULL) { /* out of memory */ if (fname == NULL) { /* out of memory */
xfree(sfname); xfree(sfname);
@ -6923,7 +6923,7 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
char_u *tail = path_tail(sfname); char_u *tail = path_tail(sfname);
int retval = FALSE; int retval = FALSE;
fname = FullName_save(sfname, FALSE); fname = (char_u *)FullName_save((char *)sfname, FALSE);
if (fname == NULL) if (fname == NULL)
return FALSE; return FALSE;

View File

@ -1532,7 +1532,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
STRLCPY(resource->name, name, 64); STRLCPY(resource->name, name, 64);
/* Look for named resource file in runtimepath */ /* Look for named resource file in runtimepath */
STRCPY(buffer, "print"); STRCPY(buffer, "print");
add_pathsep(buffer); add_pathsep((char *)buffer);
vim_strcat(buffer, (char_u *)name, MAXPATHL); vim_strcat(buffer, (char_u *)name, MAXPATHL);
vim_strcat(buffer, (char_u *)".ps", MAXPATHL); vim_strcat(buffer, (char_u *)".ps", MAXPATHL);
resource->filename[0] = NUL; resource->filename[0] = NUL;

View File

@ -2054,7 +2054,7 @@ static char *cs_resolve_file(int i, char *name)
} else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) { } else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) {
/* Check for csdir to be non empty to avoid empty path concatenated to /* Check for csdir to be non empty to avoid empty path concatenated to
* cscope output. */ * cscope output. */
fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); fullname = concat_fnames((char *)csdir, name, TRUE);
} else { } else {
fullname = xstrdup(name); fullname = xstrdup(name);
} }

View File

@ -128,12 +128,12 @@
/* Get the length of the character p points to */ /* Get the length of the character p points to */
# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1) # define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
/* Advance multi-byte pointer, skip over composing chars. */ /* Advance multi-byte pointer, skip over composing chars. */
# define mb_ptr_adv(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1 # define mb_ptr_adv(p) (p += has_mbyte ? (*mb_ptr2len)((char_u *)p) : 1)
/* Advance multi-byte pointer, do not skip over composing chars. */ /* Advance multi-byte pointer, do not skip over composing chars. */
# define mb_cptr_adv(p) p += \ # define mb_cptr_adv(p) (p += \
enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1 enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1)
/* Backup multi-byte pointer. Only use with "p" > "s" ! */ /* Backup multi-byte pointer. Only use with "p" > "s" ! */
# define mb_ptr_back(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1 # define mb_ptr_back(s, p) (p -= has_mbyte ? ((*mb_head_off)((char_u *)s, (char_u *)p - 1) + 1) : 1)
/* get length of multi-byte char, not including composing chars */ /* get length of multi-byte char, not including composing chars */
# define mb_cptr2len(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p)) # define mb_cptr2len(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))

View File

@ -1282,7 +1282,7 @@ scripterror:
&& !os_isdir(alist_name(&GARGLIST[0]))) { && !os_isdir(alist_name(&GARGLIST[0]))) {
char_u *r; char_u *r;
r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), TRUE); r = (char_u *)concat_fnames((char *)p, (char *)path_tail(alist_name(&GARGLIST[0])), TRUE);
xfree(p); xfree(p);
p = r; p = r;
} }

View File

@ -893,7 +893,7 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
/// name so we must work out the full path name. /// name so we must work out the full path name.
void mf_set_ffname(memfile_T *mfp) void mf_set_ffname(memfile_T *mfp)
{ {
mfp->mf_ffname = FullName_save(mfp->mf_fname, false); mfp->mf_ffname = (char_u *)FullName_save((char *)mfp->mf_fname, false);
} }
/// Make name of memfile's swapfile a full path. /// Make name of memfile's swapfile a full path.

View File

@ -1332,20 +1332,20 @@ recover_names (
num_names = recov_file_names(names, fname_res, TRUE); num_names = recov_file_names(names, fname_res, TRUE);
} else { /* check directory dir_name */ } else { /* check directory dir_name */
if (fname == NULL) { if (fname == NULL) {
names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); names[0] = (char_u *)concat_fnames((char *)dir_name, "*.sw?", TRUE);
/* For Unix names starting with a dot are special. MS-Windows /* For Unix names starting with a dot are special. MS-Windows
* supports this too, on some file systems. */ * supports this too, on some file systems. */
names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[1] = (char_u *)concat_fnames((char *)dir_name, ".*.sw?", TRUE);
names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); names[2] = (char_u *)concat_fnames((char *)dir_name, ".sw?", TRUE);
num_names = 3; num_names = 3;
} else { } else {
p = dir_name + STRLEN(dir_name); p = dir_name + STRLEN(dir_name);
if (after_pathsep((char *)dir_name, (char *)p) && p[-1] == p[-2]) { if (after_pathsep((char *)dir_name, (char *)p) && p[-1] == p[-2]) {
/* Ends with '//', Use Full path for swap name */ /* Ends with '//', Use Full path for swap name */
tail = make_percent_swname(dir_name, fname_res); tail = (char_u *)make_percent_swname((char *)dir_name, (char *)fname_res);
} else { } else {
tail = path_tail(fname_res); tail = path_tail(fname_res);
tail = concat_fnames(dir_name, tail, TRUE); tail = (char_u *)concat_fnames((char *)dir_name, (char *)tail, TRUE);
} }
num_names = recov_file_names(names, tail, FALSE); num_names = recov_file_names(names, tail, FALSE);
xfree(tail); xfree(tail);
@ -1364,7 +1364,7 @@ recover_names (
* Try finding a swap file by simply adding ".swp" to the file name. * Try finding a swap file by simply adding ".swp" to the file name.
*/ */
if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) {
char_u *swapname = modname(fname_res, (char_u *)".swp", TRUE); char_u *swapname = (char_u *)modname((char *)fname_res, ".swp", TRUE);
if (swapname != NULL) { if (swapname != NULL) {
if (os_file_exists(swapname)) { if (os_file_exists(swapname)) {
files = (char_u **)xmalloc(sizeof(char_u *)); files = (char_u **)xmalloc(sizeof(char_u *));
@ -1441,17 +1441,18 @@ recover_names (
* Append the full path to name with path separators made into percent * Append the full path to name with path separators made into percent
* signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"") * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
*/ */
static char_u *make_percent_swname(char_u *dir, char_u *name) static char *make_percent_swname(const char *dir, char *name)
FUNC_ATTR_NONNULL_ARG(1)
{ {
char_u *d, *s, *f; char *d = NULL;
char *f = fix_fname(name != NULL ? name : "");
f = fix_fname(name != NULL ? name : (char_u *) "");
d = NULL;
if (f != NULL) { if (f != NULL) {
s = (char_u *)xstrdup((char *)f); char *s = xstrdup(f);
for (d = s; *d != NUL; mb_ptr_adv(d)) for (d = s; *d != NUL; mb_ptr_adv(d)) {
if (vim_ispathsep(*d)) if (vim_ispathsep(*d)) {
*d = '%'; *d = '%';
}
}
d = concat_fnames(dir, s, TRUE); d = concat_fnames(dir, s, TRUE);
xfree(s); xfree(s);
xfree(f); xfree(f);
@ -1565,14 +1566,14 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
// May also add the file name with a dot prepended, for swap file in same // May also add the file name with a dot prepended, for swap file in same
// dir as original file. // dir as original file.
if (prepend_dot) { if (prepend_dot) {
names[num_names] = modname(path, (char_u *)".sw?", TRUE); names[num_names] = (char_u *)modname((char *)path, ".sw?", TRUE);
if (names[num_names] == NULL) if (names[num_names] == NULL)
return num_names; return num_names;
++num_names; ++num_names;
} }
// Form the normal swap file name pattern by appending ".sw?". // Form the normal swap file name pattern by appending ".sw?".
names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE); names[num_names] = (char_u *)concat_fnames((char *)path, ".sw?", FALSE);
if (num_names >= 1) { /* check if we have the same name twice */ if (num_names >= 1) { /* check if we have the same name twice */
char_u *p = names[num_names - 1]; char_u *p = names[num_names - 1];
int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]);
@ -3049,7 +3050,7 @@ int resolve_symlink(char_u *fname, char_u *buf)
* be consistent even when opening a relative symlink from different * be consistent even when opening a relative symlink from different
* working directories. * working directories.
*/ */
return vim_FullName(tmp, buf, MAXPATHL, TRUE); return vim_FullName((char *)tmp, (char *)buf, MAXPATHL, TRUE);
} }
#endif #endif
@ -3068,8 +3069,8 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
s = dir_name + STRLEN(dir_name); s = dir_name + STRLEN(dir_name);
if (after_pathsep((char *)dir_name, (char *)s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */ if (after_pathsep((char *)dir_name, (char *)s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */
r = NULL; r = NULL;
if ((s = make_percent_swname(dir_name, fname)) != NULL) { if ((s = (char_u *)make_percent_swname((char *)dir_name, (char *)fname)) != NULL) {
r = modname(s, (char_u *)".swp", FALSE); r = (char_u *)modname((char *)s, ".swp", FALSE);
xfree(s); xfree(s);
} }
return r; return r;
@ -3083,7 +3084,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
#endif #endif
// Prepend a '.' to the swap file name for the current directory. // Prepend a '.' to the swap file name for the current directory.
r = modname(fname_res, (char_u *)".swp", r = (char_u *)modname((char *)fname_res, ".swp",
dir_name[0] == '.' && dir_name[1] == NUL); dir_name[0] == '.' && dir_name[1] == NUL);
if (r == NULL) /* out of memory */ if (r == NULL) /* out of memory */
return NULL; return NULL;
@ -3122,17 +3123,17 @@ get_file_in_dir (
retval = vim_strsave(fname); retval = vim_strsave(fname);
else if (dname[0] == '.' && vim_ispathsep(dname[1])) { else if (dname[0] == '.' && vim_ispathsep(dname[1])) {
if (tail == fname) /* no path before file name */ if (tail == fname) /* no path before file name */
retval = concat_fnames(dname + 2, tail, TRUE); retval = (char_u *)concat_fnames((char *)dname + 2, (char *)tail, TRUE);
else { else {
save_char = *tail; save_char = *tail;
*tail = NUL; *tail = NUL;
t = concat_fnames(fname, dname + 2, TRUE); t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, TRUE);
*tail = save_char; *tail = save_char;
retval = concat_fnames(t, tail, TRUE); retval = (char_u *)concat_fnames((char *)t, (char *)tail, TRUE);
xfree(t); xfree(t);
} }
} else { } else {
retval = concat_fnames(dname, tail, TRUE); retval = (char_u *)concat_fnames((char *)dname, (char *)tail, TRUE);
} }
return retval; return retval;
@ -3554,8 +3555,8 @@ fnamecmp_ino (
* One of the inode numbers is unknown, try a forced vim_FullName() and * One of the inode numbers is unknown, try a forced vim_FullName() and
* compare the file names. * compare the file names.
*/ */
retval_c = vim_FullName(fname_c, buf_c, MAXPATHL, TRUE); retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, TRUE);
retval_s = vim_FullName(fname_s, buf_s, MAXPATHL, TRUE); retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, TRUE);
if (retval_c == OK && retval_s == OK) if (retval_c == OK && retval_s == OK)
return STRCMP(buf_c, buf_s) != 0; return STRCMP(buf_c, buf_s) != 0;

View File

@ -7390,7 +7390,7 @@ void vimrc_found(char_u *fname, char_u *envname)
p = (char_u *)vim_getenv((char *)envname); p = (char_u *)vim_getenv((char *)envname);
if (p == NULL) { if (p == NULL) {
/* Set $MYVIMRC to the first vimrc file found. */ /* Set $MYVIMRC to the first vimrc file found. */
p = FullName_save(fname, FALSE); p = (char_u *)FullName_save((char *)fname, FALSE);
if (p != NULL) { if (p != NULL) {
vim_setenv((char *)envname, (char *)p); vim_setenv((char *)envname, (char *)p);
xfree(p); xfree(p);

View File

@ -379,17 +379,18 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one,
/// @param vimdir directory to test /// @param vimdir directory to test
static char *vim_version_dir(const char *vimdir) static char *vim_version_dir(const char *vimdir)
{ {
char_u *p; if (vimdir == NULL || *vimdir == NUL) {
if (vimdir == NULL || *vimdir == NUL)
return NULL; return NULL;
p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true); }
if (os_isdir(p)) char *p = concat_fnames(vimdir, VIM_VERSION_NODOT, true);
return (char *)p; if (os_isdir((char_u *)p)) {
return p;
}
xfree(p); xfree(p);
p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true); p = concat_fnames(vimdir, RUNTIME_DIRNAME, true);
if (os_isdir(p)) if (os_isdir((char_u *)p)) {
return (char *)p; return p;
}
xfree(p); xfree(p);
return NULL; return NULL;
} }

View File

@ -625,7 +625,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
p = xmalloc(STRLEN((*file)[i]) + 1 + dir); p = xmalloc(STRLEN((*file)[i]) + 1 + dir);
STRCPY(p, (*file)[i]); STRCPY(p, (*file)[i]);
if (dir) if (dir)
add_pathsep(p); /* add '/' to a directory name */ add_pathsep((char *)p); /* add '/' to a directory name */
(*file)[j++] = p; (*file)[j++] = p;
} }
xfree(buffer); xfree(buffer);

View File

@ -66,8 +66,8 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
if (!id_ok_1 && !id_ok_2) { if (!id_ok_1 && !id_ok_2) {
// If os_fileid() doesn't work, may compare the names. // If os_fileid() doesn't work, may compare the names.
if (checkname) { if (checkname) {
vim_FullName(exp1, full1, MAXPATHL, FALSE); vim_FullName((char *)exp1, (char *)full1, MAXPATHL, FALSE);
vim_FullName(s2, full2, MAXPATHL, FALSE); vim_FullName((char *)s2, (char *)full2, MAXPATHL, FALSE);
if (fnamecmp(full1, full2) == 0) { if (fnamecmp(full1, full2) == 0) {
return kEqualFileNames; return kEqualFileNames;
} }
@ -329,20 +329,25 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len)
#endif #endif
} }
/* /// Concatenate file names fname1 and fname2 into allocated memory.
* Concatenate file names fname1 and fname2 into allocated memory. ///
* Only add a '/' or '\\' when 'sep' is TRUE and it is necessary. /// Only add a '/' or '\\' when 'sep' is true and it is necessary.
*/ ///
char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep) /// @param fname1 is the first part of the path or filename
FUNC_ATTR_NONNULL_RET /// @param fname2 is the second half of the path or filename
/// @param sep is a flag to indicate a path separator should be added
/// if necessary
/// @return [allocated] Concatenation of fname1 and fname2.
char *concat_fnames(const char *fname1, const char *fname2, bool sep)
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_NONNULL_RET
{ {
char_u *dest = xmalloc(STRLEN(fname1) + STRLEN(fname2) + 3); char *dest = xmalloc(strlen(fname1) + strlen(fname2) + 3);
STRCPY(dest, fname1); strcpy(dest, fname1);
if (sep) { if (sep) {
add_pathsep(dest); add_pathsep(dest);
} }
STRCAT(dest, fname2); strcat(dest, fname2);
return dest; return dest;
} }
@ -351,34 +356,33 @@ char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep)
* Add a path separator to a file name, unless it already ends in a path * Add a path separator to a file name, unless it already ends in a path
* separator. * separator.
*/ */
void add_pathsep(char_u *p) void add_pathsep(char *p)
FUNC_ATTR_NONNULL_ALL
{ {
if (*p != NUL && !after_pathsep((char *)p, (char *)p + STRLEN(p))) if (*p != NUL && !after_pathsep(p, p + strlen(p)))
STRCAT(p, PATHSEPSTR); strcat(p, PATHSEPSTR);
} }
/* /// Get an allocated copy of the full path to a file.
* FullName_save - Make an allocated copy of a full file name. ///
* Returns NULL when fname is NULL. /// @param fname is the filename to save
*/ /// @param force is a flag to expand `fname` even if it looks absolute
char_u * ///
FullName_save ( /// @return [allocated] Copy of absolute path to `fname` or NULL when
char_u *fname, /// `fname` is NULL.
int force /* force expansion, even when it already looks char *FullName_save(char *fname, bool force)
* like a full path name */ FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
)
{ {
char_u *new_fname = NULL; if (fname == NULL) {
if (fname == NULL)
return NULL; return NULL;
}
char_u *buf = xmalloc(MAXPATHL); char *buf = xmalloc(MAXPATHL);
char *new_fname = NULL;
if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) { if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) {
new_fname = vim_strsave(buf); new_fname = xstrdup(buf);
} else { } else {
new_fname = vim_strsave(fname); new_fname = xstrdup(fname);
} }
xfree(buf); xfree(buf);
@ -392,7 +396,7 @@ char_u *save_absolute_path(const char_u *name)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL
{ {
if (!path_is_absolute_path(name)) { if (!path_is_absolute_path(name)) {
return FullName_save((char_u *) name, true); return (char_u *)FullName_save((char *)name, true);
} }
return vim_strsave((char_u *) name); return vim_strsave((char_u *) name);
} }
@ -733,7 +737,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
} else if (buf[0] == NUL) } else if (buf[0] == NUL)
/* relative to current directory */ /* relative to current directory */
STRCPY(buf, curdir); STRCPY(buf, curdir);
else if (path_with_url(buf)) else if (path_with_url((char *)buf))
/* URL can't be used here */ /* URL can't be used here */
continue; continue;
else if (!path_is_absolute_path(buf)) { else if (!path_is_absolute_path(buf)) {
@ -880,7 +884,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
if (short_name != NULL && short_name > path + 1 if (short_name != NULL && short_name > path + 1
) { ) {
STRCPY(path, "."); STRCPY(path, ".");
add_pathsep(path); add_pathsep((char *)path);
STRMOVE(path + STRLEN(path), short_name); STRMOVE(path + STRLEN(path), short_name);
} }
} }
@ -907,7 +911,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
rel_path = xmalloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2); rel_path = xmalloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2);
STRCPY(rel_path, "."); STRCPY(rel_path, ".");
add_pathsep(rel_path); add_pathsep((char *)rel_path);
STRCAT(rel_path, short_name); STRCAT(rel_path, short_name);
xfree(fnames[i]); xfree(fnames[i]);
@ -1278,7 +1282,7 @@ addfile (
* Append a slash or backslash after directory names if none is present. * Append a slash or backslash after directory names if none is present.
*/ */
if (isdir && (flags & EW_ADDSLASH)) if (isdir && (flags & EW_ADDSLASH))
add_pathsep(p); add_pathsep((char *)p);
GA_APPEND(char_u *, gap, p); GA_APPEND(char_u *, gap, p);
} }
@ -1520,31 +1524,26 @@ find_file_name_in_path (
return file_name; return file_name;
} }
/* // Check if the "://" of a URL is at the pointer, return URL_SLASH.
* Check if the "://" of a URL is at the pointer, return URL_SLASH. // Also check for ":\\", which MS Internet Explorer accepts, return
* Also check for ":\\", which MS Internet Explorer accepts, return // URL_BACKSLASH.
* URL_BACKSLASH. int path_is_url(const char *p)
*/
int path_is_url(char_u *p)
{ {
if (STRNCMP(p, "://", (size_t)3) == 0) if (strncmp(p, "://", 3) == 0)
return URL_SLASH; return URL_SLASH;
else if (STRNCMP(p, ":\\\\", (size_t)3) == 0) else if (strncmp(p, ":\\\\", 3) == 0)
return URL_BACKSLASH; return URL_BACKSLASH;
return 0; return 0;
} }
/* /// Check if "fname" starts with "name://". Return URL_SLASH if it does.
* Check if "fname" starts with "name://". Return URL_SLASH if it does. ///
* Return URL_BACKSLASH for "name:\\". /// @param fname is the filename to test
* Return zero otherwise. /// @return URL_BACKSLASH for "name:\\", zero otherwise.
*/ int path_with_url(const char *fname)
int path_with_url(char_u *fname)
{ {
char_u *p; const char *p;
for (p = fname; isalpha(*p); p++) {}
for (p = fname; isalpha(*p); ++p)
;
return path_is_url(p); return path_is_url(p);
} }
@ -1553,21 +1552,19 @@ int path_with_url(char_u *fname)
*/ */
int vim_isAbsName(char_u *name) int vim_isAbsName(char_u *name)
{ {
return path_with_url(name) != 0 || path_is_absolute_path(name); return path_with_url((char *)name) != 0 || path_is_absolute_path(name);
} }
/* /// Save absolute file name to "buf[len]".
* Get absolute file name into buffer "buf[len]". ///
* /// @param fname is the filename to evaluate
* return FAIL for failure, OK otherwise /// @param[out] buf is the buffer for returning the absolute path for `fname`
*/ /// @param len is the length of `buf`
int /// @param force is a flag to force expanding even if the path is absolute
vim_FullName ( ///
char_u *fname, /// @return FAIL for failure, OK otherwise
char_u *buf, int vim_FullName(const char *fname, char *buf, int len, bool force)
int len, FUNC_ATTR_NONNULL_ARG(1)
int force /* force expansion even when already absolute */
)
{ {
int retval = OK; int retval = OK;
int url; int url;
@ -1578,44 +1575,42 @@ vim_FullName (
url = path_with_url(fname); url = path_with_url(fname);
if (!url) if (!url)
retval = path_get_absolute_path(fname, buf, len, force); retval = path_get_absolute_path((char_u *)fname, (char_u *)buf, len, force);
if (url || retval == FAIL) { if (url || retval == FAIL) {
/* something failed; use the file name (truncate when too long) */ /* something failed; use the file name (truncate when too long) */
STRLCPY(buf, fname, len); xstrlcpy(buf, fname, len);
} }
return retval; return retval;
} }
/* /// Get the full resolved path for `fname`
* If fname is not a full path, make it a full path. ///
* Returns pointer to allocated memory (NULL for failure). /// Even filenames that appear to be absolute based on starting from
*/ /// the root may have relative paths (like dir/../subdir) or symlinks
char_u *fix_fname(char_u *fname) /// embedded, or even extra separators (//). This function addresses
/// those possibilities, returning a resolved absolute path.
/// For MS-Windows, this also expands names like "longna~1".
///
/// @param fname is the filename to expand
/// @return [allocated] Full path (NULL for failure).
char *fix_fname(char *fname)
{ {
/*
* Force expanding the path always for Unix, because symbolic links may
* mess up the full path name, even though it starts with a '/'.
* Also expand when there is ".." in the file name, try to remove it,
* because "c:/src/../README" is equal to "c:/README".
* Similarly "c:/src//file" is equal to "c:/src/file".
* For MS-Windows also expand names like "longna~1" to "longname".
*/
#ifdef UNIX #ifdef UNIX
return FullName_save(fname, TRUE); return FullName_save(fname, TRUE);
#else #else
if (!vim_isAbsName(fname) if (!vim_isAbsName((char_u *)fname)
|| strstr((char *)fname, "..") != NULL || strstr(fname, "..") != NULL
|| strstr((char *)fname, "//") != NULL || strstr(fname, "//") != NULL
# ifdef BACKSLASH_IN_FILENAME # ifdef BACKSLASH_IN_FILENAME
|| strstr((char *)fname, "\\\\") != NULL || strstr(fname, "\\\\") != NULL
# endif # endif
) )
return FullName_save(fname, FALSE); return FullName_save(fname, FALSE);
fname = vim_strsave(fname); fname = xstrdup(fname);
# ifdef USE_FNAME_CASE # ifdef USE_FNAME_CASE
path_fix_case(fname); // set correct case for file name path_fix_case((char_u *)fname); // set correct case for file name
# endif # endif
return fname; return fname;
@ -1702,7 +1697,7 @@ int same_directory(char_u *f1, char_u *f2)
if (f1 == NULL || f2 == NULL) if (f1 == NULL || f2 == NULL)
return FALSE; return FALSE;
(void)vim_FullName(f1, ffname, MAXPATHL, FALSE); (void)vim_FullName((char *)f1, (char *)ffname, MAXPATHL, FALSE);
t1 = path_tail_with_sep(ffname); t1 = path_tail_with_sep(ffname);
t2 = path_tail_with_sep(f2); t2 = path_tail_with_sep(f2);
return t1 - ffname == t2 - f2 return t1 - ffname == t2 - f2
@ -1761,7 +1756,7 @@ int pathcmp(const char *p, const char *q, int maxlen)
/* ignore a trailing slash, but not "//" or ":/" */ /* ignore a trailing slash, but not "//" or ":/" */
if (c2 == NUL if (c2 == NUL
&& i > 0 && i > 0
&& !after_pathsep(s, s + i) && !after_pathsep((char *)s, (char *)s + i)
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
&& (c1 == '/' || c1 == '\\') && (c1 == '/' || c1 == '\\')
#else #else
@ -1898,7 +1893,7 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file,
/* check all files in (*file)[] */ /* check all files in (*file)[] */
for (i = 0; i < *num_file; ++i) { for (i = 0; i < *num_file; ++i) {
ffname = FullName_save((*file)[i], FALSE); ffname = (char_u *)FullName_save((char *)(*file)[i], FALSE);
if (ffname == NULL) /* out of memory */ if (ffname == NULL) /* out of memory */
break; break;
if (match_file_list(p_wig, (*file)[i], ffname)) { if (match_file_list(p_wig, (*file)[i], ffname)) {
@ -2057,7 +2052,7 @@ int append_path(char *path, const char *to_append, int max_len)
/// @param len Length of `buf`. /// @param len Length of `buf`.
/// @param force Also expand when `fname` is already absolute. /// @param force Also expand when `fname` is already absolute.
/// @return `FAIL` for failure, `OK` for success. /// @return `FAIL` for failure, `OK` for success.
static int path_get_absolute_path(char_u *fname, char_u *buf, int len, int force) static int path_get_absolute_path(const char_u *fname, char_u *buf, int len, int force)
{ {
char_u *p; char_u *p;
*buf = NUL; *buf = NUL;
@ -2080,7 +2075,7 @@ static int path_get_absolute_path(char_u *fname, char_u *buf, int len, int force
return FAIL; return FAIL;
} }
} }
return append_path((char *) buf, (char *) end_of_path, len); return append_path((char *)buf, end_of_path, len);
} }
/// Check if the given file is absolute. /// Check if the given file is absolute.

View File

@ -1085,7 +1085,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
slash_adjust(fname); slash_adjust(fname);
#endif #endif
if (directory != NULL && !vim_isAbsName(fname)) { if (directory != NULL && !vim_isAbsName(fname)) {
ptr = concat_fnames(directory, fname, TRUE); ptr = (char_u *)concat_fnames((char *)directory, (char *)fname, TRUE);
/* /*
* Here we check if the file really exists. * Here we check if the file really exists.
* This should normally be true, but if make works without * This should normally be true, but if make works without
@ -1096,7 +1096,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
xfree(ptr); xfree(ptr);
directory = qf_guess_filepath(fname); directory = qf_guess_filepath(fname);
if (directory) if (directory)
ptr = concat_fnames(directory, fname, TRUE); ptr = (char_u *)concat_fnames((char *)directory, (char *)fname, TRUE);
else else
ptr = vim_strsave(fname); ptr = vim_strsave(fname);
} }
@ -1137,8 +1137,8 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr)
(*stackptr)->dirname = NULL; (*stackptr)->dirname = NULL;
while (ds_new) { while (ds_new) {
xfree((*stackptr)->dirname); xfree((*stackptr)->dirname);
(*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, (*stackptr)->dirname = (char_u *)concat_fnames((char *)ds_new->dirname,
TRUE); (char *)dirbuf, TRUE);
if (os_isdir((*stackptr)->dirname)) if (os_isdir((*stackptr)->dirname))
break; break;
@ -1242,7 +1242,7 @@ static char_u *qf_guess_filepath(char_u *filename)
fullname = NULL; fullname = NULL;
while (ds_ptr) { while (ds_ptr) {
xfree(fullname); xfree(fullname);
fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); fullname = (char_u *)concat_fnames((char *)ds_ptr->dirname, (char *)filename, TRUE);
if (os_file_exists(fullname)) if (os_file_exists(fullname))
break; break;
@ -3546,7 +3546,7 @@ void ex_helpgrep(exarg_T *eap)
copy_option_part(&p, NameBuff, MAXPATHL, ","); copy_option_part(&p, NameBuff, MAXPATHL, ",");
/* Find all "*.txt" and "*.??x" files in the "doc" directory. */ /* Find all "*.txt" and "*.??x" files in the "doc" directory. */
add_pathsep(NameBuff); add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)");
// Note: We cannot just do `&NameBuff` because it is a statically sized array // Note: We cannot just do `&NameBuff` because it is a statically sized array

View File

@ -2380,7 +2380,7 @@ jumpto_tag (
* into a fullpath * into a fullpath
*/ */
if (!curwin->w_p_pvw) { if (!curwin->w_p_pvw) {
full_fname = FullName_save(fname, FALSE); full_fname = (char_u *)FullName_save((char *)fname, FALSE);
fname = full_fname; fname = full_fname;
/* /*

View File

@ -37,7 +37,7 @@ static void vim_maketempdir(void)
continue; continue;
} }
add_pathsep(template); add_pathsep((char *)template);
// Concatenate with temporary directory name pattern // Concatenate with temporary directory name pattern
STRCAT(template, "nvimXXXXXX"); STRCAT(template, "nvimXXXXXX");
@ -45,7 +45,7 @@ static void vim_maketempdir(void)
continue; continue;
} }
if (vim_settempdir(path)) { if (vim_settempdir((char *)path)) {
// Successfully created and set temporary directory so stop trying. // Successfully created and set temporary directory so stop trying.
break; break;
} else { } else {
@ -100,15 +100,15 @@ char_u *vim_gettempdir(void)
/// @param tempdir must be no longer than MAXPATHL. /// @param tempdir must be no longer than MAXPATHL.
/// ///
/// @return false if we run out of memory. /// @return false if we run out of memory.
static bool vim_settempdir(char_u *tempdir) static bool vim_settempdir(char *tempdir)
{ {
char_u *buf = verbose_try_malloc((size_t)MAXPATHL + 2); char *buf = verbose_try_malloc(MAXPATHL + 2);
if (!buf) { if (!buf) {
return false; return false;
} }
vim_FullName(tempdir, buf, MAXPATHL, false); vim_FullName(tempdir, buf, MAXPATHL, false);
add_pathsep(buf); add_pathsep(buf);
vim_tempdir = vim_strsave(buf); vim_tempdir = (char_u *)xstrdup(buf);
xfree(buf); xfree(buf);
return true; return true;
} }

View File

@ -677,7 +677,7 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
if (vim_ispathsep(*p)) if (vim_ispathsep(*p))
*p = '%'; *p = '%';
} }
undo_file_name = concat_fnames(dir_name, munged_name, TRUE); undo_file_name = (char_u *)concat_fnames((char *)dir_name, (char *)munged_name, TRUE);
} }
} }

View File

@ -4916,7 +4916,7 @@ file_name_in_line (
if (has_mbyte && (len = (size_t)((*mb_head_off)(line, ptr - 1))) > 0) if (has_mbyte && (len = (size_t)((*mb_head_off)(line, ptr - 1))) > 0)
ptr -= len + 1; ptr -= len + 1;
else if (vim_isfilec(ptr[-1]) else if (vim_isfilec(ptr[-1])
|| ((options & FNAME_HYP) && path_is_url(ptr - 1))) || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1)))
--ptr; --ptr;
else else
break; break;
@ -4928,7 +4928,7 @@ file_name_in_line (
*/ */
len = 0; len = 0;
while (vim_isfilec(ptr[len]) while (vim_isfilec(ptr[len])
|| ((options & FNAME_HYP) && path_is_url(ptr + len))) || ((options & FNAME_HYP) && path_is_url((char *)ptr + len)))
if (has_mbyte) if (has_mbyte)
len += (size_t)(*mb_ptr2len)(ptr + len); len += (size_t)(*mb_ptr2len)(ptr + len);
else else