aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2015-05-07 08:08:31 +0200
committerEliseo Martínez <eliseomarmol@gmail.com>2015-05-07 08:08:31 +0200
commitf88cec802169d94ad0a19d45746feac5fe2ea0fa (patch)
treec87107941de9eab120e21df65e46432921c7aebe
parenta2cf628603bf5948f96ceb90b653d2879a9d2f9e (diff)
parent2f60a69bafc4b5130fb213df206179701ec0d74a (diff)
downloadrneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.tar.gz
rneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.tar.bz2
rneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.zip
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>
-rw-r--r--src/nvim/buffer.c4
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/eval.c12
-rw-r--r--src/nvim/ex_cmds.c12
-rw-r--r--src/nvim/ex_cmds2.c10
-rw-r--r--src/nvim/ex_docmd.c8
-rw-r--r--src/nvim/ex_getln.c4
-rw-r--r--src/nvim/file_search.c28
-rw-r--r--src/nvim/fileio.c146
-rw-r--r--src/nvim/hardcopy.c2
-rw-r--r--src/nvim/if_cscope.c2
-rw-r--r--src/nvim/macros.h8
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/memfile.c2
-rw-r--r--src/nvim/memline.c53
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/os/env.c19
-rw-r--r--src/nvim/os_unix.c2
-rw-r--r--src/nvim/path.c181
-rw-r--r--src/nvim/quickfix.c12
-rw-r--r--src/nvim/tag.c2
-rw-r--r--src/nvim/tempfile.c10
-rw-r--r--src/nvim/undo.c2
-rw-r--r--src/nvim/window.c4
24 files changed, 263 insertions, 266 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 395b20b219..094e80086c 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1661,7 +1661,7 @@ buf_T *buflist_findname_exp(char_u *fname)
buf_T *buf = NULL;
/* First make the name into a full path name */
- ffname = FullName_save(fname,
+ ffname = (char_u *)FullName_save((char *)fname,
#ifdef UNIX
TRUE /* force expansion, get rid of symbolic links */
#else
@@ -3569,7 +3569,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
return;
if (*sfname == NULL) /* if no short file name given, use 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
if (!buf->b_p_bin) {
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index d4fbb290c1..b21bc1f2f4 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -867,7 +867,7 @@ void ex_diffpatch(exarg_T *eap)
#ifdef UNIX
// 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
#ifdef UNIX
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index c4c2821b80..8a98eae21f 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7347,7 +7347,7 @@ static buf_T *find_buffer(typval_T *avar)
* buffer, these don't use the full path. */
FOR_ALL_BUFFERS(bp) {
if (bp->b_fname != NULL
- && (path_with_url(bp->b_fname)
+ && (path_with_url((char *)bp->b_fname)
|| bt_nofile(bp)
)
&& 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
* if the argument has one. */
if (remain == NULL && has_trailing_pathsep)
- add_pathsep(buf);
+ add_pathsep((char *)buf);
/* Separate the first path component in the link value and
* 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. */
rettv->vval.v_string = NULL;
} else {
- char_u *ffname = FullName_save(fname, FALSE);
+ char_u *ffname = (char_u *)FullName_save((char *)fname, FALSE);
if (ffname != NULL)
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. */
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 */
*bufp = *fnamep;
if (*fnamep == NULL)
@@ -19927,7 +19927,7 @@ repeat:
*bufp = *fnamep;
if (*fnamep == NULL)
return -1;
- add_pathsep(*fnamep);
+ add_pathsep((char *)*fnamep);
}
}
@@ -19946,7 +19946,7 @@ repeat:
if (c == '.' && **fnamep == '~')
p = pbuf = expand_env_save(*fnamep);
else
- p = pbuf = FullName_save(*fnamep, FALSE);
+ p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);
} else
p = *fnamep;
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 78200e4689..62c2d4ac98 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1530,7 +1530,7 @@ void write_viminfo(char_u *file, int forceit)
#endif
// Make tempname
- tempname = modname(fname, (char_u *)".tmp", FALSE);
+ tempname = (char_u *)modname((char *)fname, ".tmp", FALSE);
if (tempname != NULL) {
/*
* Check if tempfile already exists. Never overwrite an
@@ -2080,7 +2080,7 @@ int do_write(exarg_T *eap)
other = FALSE;
} else {
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
* able to write the file in this situation.
@@ -2579,7 +2579,7 @@ do_ecmd (
ffname = curbuf->b_ffname;
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)
ffname = free_fname;
other_file = otherfile(ffname);
@@ -5126,7 +5126,7 @@ void fix_help_buffer(void)
char_u *cp;
/* Find all "doc/ *.txt" files in this directory. */
- add_pathsep(NameBuff);
+ add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "doc/*.??[tx]");
// 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. */
STRCPY(NameBuff, dirname);
- add_pathsep(NameBuff);
+ add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "**");
// 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.
*/
STRCPY(NameBuff, dir);
- add_pathsep(NameBuff);
+ add_pathsep((char *)NameBuff);
STRCAT(NameBuff, tagfname);
fd_tags = mch_fopen((char *)NameBuff, "w");
if (fd_tags == NULL) {
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index b79d09885c..08d84c2440 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -495,7 +495,7 @@ dbg_parsearg (
if (p == NULL)
return FAIL;
if (*p != '*') {
- bp->dbg_name = fix_fname(p);
+ bp->dbg_name = (char_u *)fix_fname((char *)p);
xfree(p);
} else
bp->dbg_name = p;
@@ -1692,7 +1692,7 @@ void do_argfile(exarg_T *eap, int argn)
*/
other = TRUE;
if (P_HID(curbuf)) {
- p = fix_fname(alist_name(&ARGLIST[argn]));
+ p = (char_u *)fix_fname((char *)alist_name(&ARGLIST[argn]));
other = otherfile(p);
xfree(p);
}
@@ -2144,7 +2144,7 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
if (!did_one)
did_one = (cookie == NULL);
} else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) {
- add_pathsep(buf);
+ add_pathsep((char *)buf);
tail = buf + STRLEN(buf);
/* Loop over all patterns in "name" */
@@ -2313,7 +2313,7 @@ do_source (
p = expand_env_save(fname);
if (p == NULL)
return retval;
- fname_exp = fix_fname(p);
+ fname_exp = (char_u *)fix_fname((char *)p);
xfree(p);
if (fname_exp == NULL)
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)
{
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();
// filename
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 9ff19521b6..289bb85f4d 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -7544,7 +7544,7 @@ static void ex_mkrc(exarg_T *eap)
char_u *tbuf;
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);
xfree(tbuf);
}
@@ -8155,7 +8155,7 @@ eval_vars (
/* Still need to turn the fname into a full path. It is
* postponed to avoid a delay when <afile> is not used. */
autocmd_fname_full = TRUE;
- result = FullName_save(autocmd_fname, FALSE);
+ result = (char_u *)FullName_save((char *)autocmd_fname, FALSE);
xfree(autocmd_fname);
autocmd_fname = result;
}
@@ -8975,7 +8975,7 @@ ses_arglist (
if (s != NULL) {
if (fullname) {
buf = xmalloc(MAXPATHL);
- (void)vim_FullName(s, buf, MAXPATHL, FALSE);
+ (void)vim_FullName((char *)s, (char *)buf, MAXPATHL, FALSE);
s = buf;
}
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;
retval = xmalloc(STRLEN(sname) + len + STRLEN(p_vdir) + 9);
STRCPY(retval, p_vdir);
- add_pathsep(retval);
+ add_pathsep((char *)retval);
s = retval + STRLEN(retval);
for (p = sname; *p; ++p) {
if (*p == '=') {
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 1a04f1bd91..3af035a6e3 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3890,7 +3890,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
if (l > MAXPATHL - 5)
break;
STRLCPY(buf, s, l + 1);
- add_pathsep(buf);
+ add_pathsep((char *)buf);
l = STRLEN(buf);
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_option_part(&path, buf, MAXPATHL, ",");
if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) {
- add_pathsep(buf);
+ add_pathsep((char *)buf);
STRCAT(buf, file); // NOLINT
char_u **p;
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 2777271377..855de6595f 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -313,7 +313,7 @@ vim_findfile_init (
if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) {
/* Make the start dir an absolute path name. */
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
search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
if (*++path != NUL)
@@ -465,7 +465,7 @@ vim_findfile_init (
goto error_return;
}
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);
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);
if (os_isdir(buf)) {
STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
- add_pathsep(ff_expand_buffer);
+ add_pathsep((char *)ff_expand_buffer);
} else {
char_u *p = path_tail(search_ctx->ffsc_fix_path);
char_u *wc_path = NULL;
@@ -484,7 +484,7 @@ vim_findfile_init (
if (p > search_ctx->ffsc_fix_path) {
len = (int)(p - search_ctx->ffsc_fix_path) - 1;
STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len);
- add_pathsep(ff_expand_buffer);
+ add_pathsep((char *)ff_expand_buffer);
} else
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)
&& 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 */
STRCAT(file_path, stackp->ffs_fix_path);
- add_pathsep(file_path);
+ add_pathsep((char *)file_path);
rest_of_wildcards = stackp->ffs_wc_path;
if (*rest_of_wildcards != NUL) {
@@ -749,7 +749,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* Expand wildcards like "*" and "$VAR".
* 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[0] = vim_strsave(dirptrs[0]);
stackp->ffs_filearray_size = 1;
@@ -777,14 +777,14 @@ char_u *vim_findfile(void *search_ctx_arg)
*/
for (int i = stackp->ffs_filearray_cur;
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]))
continue; /* not a directory */
/* prepare the filename to be checked for existence
* below */
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);
/*
@@ -798,7 +798,7 @@ char_u *vim_findfile(void *search_ctx_arg)
suf = curbuf->b_p_sua;
for (;; ) {
/* 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)
&& (search_ctx->ffsc_find_what
== FINDFILE_BOTH
@@ -836,7 +836,7 @@ char_u *vim_findfile(void *search_ctx_arg)
stackp->ffs_filearray_cur = (char_u)(i + 1);
ff_push(search_ctx, stackp);
- if (!path_with_url(file_path))
+ if (!path_with_url((char *)file_path))
simplify_filename(file_path);
if (os_dirname(ff_expand_buffer, MAXPATHL)
== OK) {
@@ -936,7 +936,7 @@ char_u *vim_findfile(void *search_ctx_arg)
break;
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);
/* 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;
// For an URL we only compare the name, otherwise we compare the
// device/inode.
- if (path_with_url(fname)) {
+ if (path_with_url((char *)fname)) {
STRLCPY(ff_expand_buffer, fname, MAXPATHL);
url = true;
} else {
@@ -1404,7 +1404,7 @@ find_file_in_path_option (
* filename on the first call.
*/
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);
goto theend;
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 98a2cb4076..f5cf226da4 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2814,7 +2814,7 @@ buf_write (
/*
* Make backup file name.
*/
- backup = modname(rootname, backup_ext, FALSE);
+ backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
if (backup == NULL) {
xfree(rootname);
some_error = TRUE; /* out of memory */
@@ -2985,7 +2985,7 @@ nobackup:
if (rootname == NULL)
backup = NULL;
else {
- backup = modname(rootname, backup_ext, FALSE);
+ backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE);
xfree(rootname);
}
@@ -3595,7 +3595,7 @@ restore_backup:
* the backup file our 'original' file.
*/
if (*p_pm && dobackup) {
- char *org = (char *)modname(fname, p_pm, FALSE);
+ char *org = modname((char *)fname, (char *)p_pm, FALSE);
if (backup != NULL) {
/*
@@ -4310,7 +4310,7 @@ void shorten_fnames(int force)
FOR_ALL_BUFFERS(buf) {
if (buf->b_fname != NULL
&& !bt_nofile(buf)
- && !path_with_url(buf->b_fname)
+ && !path_with_url((char *)buf->b_fname)
&& (force
|| buf->b_sfname == NULL
|| path_is_absolute_path(buf->b_sfname))) {
@@ -4333,108 +4333,108 @@ void shorten_fnames(int force)
redraw_tabline = TRUE;
}
-/*
- * add extension to file name - change path/fo.o.h to path/fo.o.h.ext
- *
- * Assumed that fname is a valid name found in the filesystem we assure that
- * the return value is a different name and ends in 'ext'.
- * "ext" MUST be at most 4 characters long if it starts with a dot, 3
- * characters otherwise.
- * Space for the returned name is allocated, must be freed later.
- * Returns NULL when out of memory.
- */
-char_u *
-modname (
- char_u *fname,
- char_u *ext,
- int prepend_dot /* may prepend a '.' to file name */
-)
+/// Get new filename ended by given extension.
+///
+/// @param fname The original filename.
+/// If NULL, use current directory name and ext to
+/// compute new filename.
+/// @param ext The extension to add to the filename.
+/// 4 chars max if prefixed with a dot, 3 otherwise.
+/// @param prepend_dot If true, prefix ext with a dot.
+/// Does nothing if ext already starts with a dot, or
+/// if fname is NULL.
+///
+/// @return [allocated] - A new filename, made up from:
+/// * fname + ext, if fname not NULL.
+/// * current dir + ext, if fname is NULL.
+/// 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_u *s;
- char_u *e;
- char_u *ptr;
- int fnamelen, extlen;
-
- extlen = (int)STRLEN(ext);
+ char *retval;
+ size_t fnamelen;
+ size_t extlen = 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) {
- retval = xmalloc(MAXPATHL + extlen + 3);
- if (os_dirname(retval, MAXPATHL) == FAIL ||
- (fnamelen = (int)STRLEN(retval)) == 0) {
+ retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL
+ if (os_dirname((char_u *)retval, MAXPATHL) == FAIL ||
+ (fnamelen = strlen(retval)) == 0) {
xfree(retval);
return NULL;
}
- if (!after_pathsep((char *)retval, (char *)retval + fnamelen)) {
- retval[fnamelen++] = PATHSEP;
- retval[fnamelen] = NUL;
- }
- prepend_dot = FALSE; /* nothing to prepend a dot to */
+ add_pathsep(retval);
+ fnamelen = strlen(retval);
+ prepend_dot = FALSE; // nothing to prepend a dot to
} else {
- fnamelen = (int)STRLEN(fname);
+ fnamelen = strlen(fname);
retval = xmalloc(fnamelen + extlen + 3);
- STRCPY(retval, fname);
+ strcpy(retval, fname);
}
- /*
- * search backwards until we hit a '/', '\' or ':'.
- * Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters.
- */
+ // Search backwards until we hit a '/', '\' or ':'.
+ // Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters.
+ char *ptr = NULL;
for (ptr = retval + fnamelen; ptr > retval; mb_ptr_back(retval, ptr)) {
if (vim_ispathsep(*ptr)) {
- ++ptr;
+ ptr++;
break;
}
}
- /* the file name has at most BASENAMELEN characters. */
- if (STRLEN(ptr) > BASENAMELEN)
+ // the file name has at most BASENAMELEN characters.
+ if (strlen(ptr) > BASENAMELEN) {
ptr[BASENAMELEN] = '\0';
+ }
- s = ptr + STRLEN(ptr);
+ char *s;
+ s = ptr + strlen(ptr);
#if defined(WIN3264)
- /*
- * 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
- * FAT partition, and on HPFS it doesn't matter.
- */
- else if ((fname == NULL || *fname == NUL) && *ext == '.')
+ // 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
+ // FAT partition, and on HPFS it doesn't matter.
+ else if ((fname == NULL || *fname == NUL) && *ext == '.') {
*s++ = '_';
+ }
#endif
- /*
- * Append the extension.
- * ext can start with '.' and cannot exceed 3 more characters.
- */
- STRCPY(s, ext);
+ // Append the extension.
+ // ext can start with '.' and cannot exceed 3 more characters.
+ strcpy(s, ext);
- /*
- * Prepend the dot.
- */
- if (prepend_dot && *(e = path_tail(retval)) != '.') {
+ char *e;
+ // Prepend the dot if needed.
+ if (prepend_dot && *(e = (char *)path_tail((char_u *)retval)) != '.') {
STRMOVE(e + 1, e);
*e = '.';
}
- /*
- * Check that, after appending the extension, the file name is really
- * different.
- */
- if (fname != NULL && STRCMP(fname, retval) == 0) {
- /* we search for a character that can be replaced by '_' */
+ // Check that, after appending the extension, the file name is really
+ // different.
+ if (fname != NULL && strcmp(fname, retval) == 0) {
+ // we search for a character that can be replaced by '_'
while (--s >= ptr) {
if (*s != '_') {
*s = '_';
break;
}
}
- if (s < ptr) /* fname was "________.<ext>", how tricky! */
+ if (s < ptr) { // fname was "________.<ext>", how tricky!
*ptr = 'v';
+ }
}
return retval;
}
@@ -6597,7 +6597,7 @@ apply_autocmds_group (
|| event == EVENT_TABCLOSED)
fname = vim_strsave(fname);
else
- fname = FullName_save(fname, FALSE);
+ fname = (char_u *)FullName_save((char *)fname, FALSE);
}
if (fname == NULL) { /* out of memory */
xfree(sfname);
@@ -6923,7 +6923,7 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
char_u *tail = path_tail(sfname);
int retval = FALSE;
- fname = FullName_save(sfname, FALSE);
+ fname = (char_u *)FullName_save((char *)sfname, FALSE);
if (fname == NULL)
return FALSE;
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index cf33703fdb..819015a85d 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -1532,7 +1532,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
STRLCPY(resource->name, name, 64);
/* Look for named resource file in runtimepath */
STRCPY(buffer, "print");
- add_pathsep(buffer);
+ add_pathsep((char *)buffer);
vim_strcat(buffer, (char_u *)name, MAXPATHL);
vim_strcat(buffer, (char_u *)".ps", MAXPATHL);
resource->filename[0] = NUL;
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index a7052149e0..b5751f0a6e 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -2054,7 +2054,7 @@ static char *cs_resolve_file(int i, char *name)
} else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) {
/* Check for csdir to be non empty to avoid empty path concatenated to
* cscope output. */
- fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE);
+ fullname = concat_fnames((char *)csdir, name, TRUE);
} else {
fullname = xstrdup(name);
}
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index 46f591eb33..51542bd3a7 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -128,12 +128,12 @@
/* Get the length of the character p points to */
# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
/* 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. */
-# define mb_cptr_adv(p) p += \
- enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
+# define mb_cptr_adv(p) (p += \
+ enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1)
/* 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 */
# define mb_cptr2len(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))
diff --git a/src/nvim/main.c b/src/nvim/main.c
index e1d53183aa..c1270c6181 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1282,7 +1282,7 @@ scripterror:
&& !os_isdir(alist_name(&GARGLIST[0]))) {
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);
p = r;
}
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index bbe2e62021..b6a341d5e8 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -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.
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.
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 8e87bef244..29263144a4 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1332,20 +1332,20 @@ recover_names (
num_names = recov_file_names(names, fname_res, TRUE);
} else { /* check directory dir_name */
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
* supports this too, on some file systems. */
- names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE);
- names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE);
+ names[1] = (char_u *)concat_fnames((char *)dir_name, ".*.sw?", TRUE);
+ names[2] = (char_u *)concat_fnames((char *)dir_name, ".sw?", TRUE);
num_names = 3;
} else {
p = dir_name + STRLEN(dir_name);
if (after_pathsep((char *)dir_name, (char *)p) && p[-1] == p[-2]) {
/* 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 {
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);
xfree(tail);
@@ -1364,7 +1364,7 @@ recover_names (
* Try finding a swap file by simply adding ".swp" to the file name.
*/
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 (os_file_exists(swapname)) {
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
* 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;
-
- f = fix_fname(name != NULL ? name : (char_u *) "");
- d = NULL;
+ char *d = NULL;
+ char *f = fix_fname(name != NULL ? name : "");
if (f != NULL) {
- s = (char_u *)xstrdup((char *)f);
- for (d = s; *d != NUL; mb_ptr_adv(d))
- if (vim_ispathsep(*d))
+ char *s = xstrdup(f);
+ for (d = s; *d != NUL; mb_ptr_adv(d)) {
+ if (vim_ispathsep(*d)) {
*d = '%';
+ }
+ }
d = concat_fnames(dir, s, TRUE);
xfree(s);
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
// dir as original file.
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)
return num_names;
++num_names;
}
// 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 */
char_u *p = names[num_names - 1];
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
* working directories.
*/
- return vim_FullName(tmp, buf, MAXPATHL, TRUE);
+ return vim_FullName((char *)tmp, (char *)buf, MAXPATHL, TRUE);
}
#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);
if (after_pathsep((char *)dir_name, (char *)s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */
r = NULL;
- if ((s = make_percent_swname(dir_name, fname)) != NULL) {
- r = modname(s, (char_u *)".swp", FALSE);
+ if ((s = (char_u *)make_percent_swname((char *)dir_name, (char *)fname)) != NULL) {
+ r = (char_u *)modname((char *)s, ".swp", FALSE);
xfree(s);
}
return r;
@@ -3083,7 +3084,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
#endif
// 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);
if (r == NULL) /* out of memory */
return NULL;
@@ -3122,17 +3123,17 @@ get_file_in_dir (
retval = vim_strsave(fname);
else if (dname[0] == '.' && vim_ispathsep(dname[1])) {
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 {
save_char = *tail;
*tail = NUL;
- t = concat_fnames(fname, dname + 2, TRUE);
+ t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, TRUE);
*tail = save_char;
- retval = concat_fnames(t, tail, TRUE);
+ retval = (char_u *)concat_fnames((char *)t, (char *)tail, TRUE);
xfree(t);
}
} else {
- retval = concat_fnames(dname, tail, TRUE);
+ retval = (char_u *)concat_fnames((char *)dname, (char *)tail, TRUE);
}
return retval;
@@ -3554,8 +3555,8 @@ fnamecmp_ino (
* One of the inode numbers is unknown, try a forced vim_FullName() and
* compare the file names.
*/
- retval_c = vim_FullName(fname_c, buf_c, MAXPATHL, TRUE);
- retval_s = vim_FullName(fname_s, buf_s, MAXPATHL, TRUE);
+ retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, TRUE);
+ retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, TRUE);
if (retval_c == OK && retval_s == OK)
return STRCMP(buf_c, buf_s) != 0;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 33e3f5b459..dcf02513dd 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -7390,7 +7390,7 @@ void vimrc_found(char_u *fname, char_u *envname)
p = (char_u *)vim_getenv((char *)envname);
if (p == NULL) {
/* Set $MYVIMRC to the first vimrc file found. */
- p = FullName_save(fname, FALSE);
+ p = (char_u *)FullName_save((char *)fname, FALSE);
if (p != NULL) {
vim_setenv((char *)envname, (char *)p);
xfree(p);
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 2cf56f0201..fd115ab2b3 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -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
static char *vim_version_dir(const char *vimdir)
{
- char_u *p;
-
- if (vimdir == NULL || *vimdir == NUL)
+ if (vimdir == NULL || *vimdir == NUL) {
return NULL;
- p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true);
- if (os_isdir(p))
- return (char *)p;
+ }
+ char *p = concat_fnames(vimdir, VIM_VERSION_NODOT, true);
+ if (os_isdir((char_u *)p)) {
+ return p;
+ }
xfree(p);
- p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true);
- if (os_isdir(p))
- return (char *)p;
+ p = concat_fnames(vimdir, RUNTIME_DIRNAME, true);
+ if (os_isdir((char_u *)p)) {
+ return p;
+ }
xfree(p);
return NULL;
}
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index 7f2efd8d68..b2d5bae477 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -625,7 +625,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
p = xmalloc(STRLEN((*file)[i]) + 1 + dir);
STRCPY(p, (*file)[i]);
if (dir)
- add_pathsep(p); /* add '/' to a directory name */
+ add_pathsep((char *)p); /* add '/' to a directory name */
(*file)[j++] = p;
}
xfree(buffer);
diff --git a/src/nvim/path.c b/src/nvim/path.c
index d1dd94c190..9bdf03dacf 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -66,8 +66,8 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
if (!id_ok_1 && !id_ok_2) {
// If os_fileid() doesn't work, may compare the names.
if (checkname) {
- vim_FullName(exp1, full1, MAXPATHL, FALSE);
- vim_FullName(s2, full2, MAXPATHL, FALSE);
+ vim_FullName((char *)exp1, (char *)full1, MAXPATHL, FALSE);
+ vim_FullName((char *)s2, (char *)full2, MAXPATHL, FALSE);
if (fnamecmp(full1, full2) == 0) {
return kEqualFileNames;
}
@@ -329,20 +329,25 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len)
#endif
}
-/*
- * Concatenate file names fname1 and fname2 into allocated memory.
- * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary.
- */
-char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep)
- FUNC_ATTR_NONNULL_RET
+/// Concatenate file names fname1 and fname2 into allocated memory.
+///
+/// Only add a '/' or '\\' when 'sep' is true and it is necessary.
+///
+/// @param fname1 is the first part of the path or filename
+/// @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) {
add_pathsep(dest);
}
- STRCAT(dest, fname2);
+ strcat(dest, fname2);
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
* 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)))
- STRCAT(p, PATHSEPSTR);
+ if (*p != NUL && !after_pathsep(p, p + strlen(p)))
+ strcat(p, PATHSEPSTR);
}
-/*
- * FullName_save - Make an allocated copy of a full file name.
- * Returns NULL when fname is NULL.
- */
-char_u *
-FullName_save (
- char_u *fname,
- int force /* force expansion, even when it already looks
- * like a full path name */
-)
+/// Get an allocated copy of the full path to a file.
+///
+/// @param fname is the filename to save
+/// @param force is a flag to expand `fname` even if it looks absolute
+///
+/// @return [allocated] Copy of absolute path to `fname` or NULL when
+/// `fname` is NULL.
+char *FullName_save(char *fname, bool force)
+ FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
- char_u *new_fname = NULL;
-
- if (fname == NULL)
+ if (fname == NULL) {
return NULL;
+ }
- char_u *buf = xmalloc(MAXPATHL);
-
+ char *buf = xmalloc(MAXPATHL);
+ char *new_fname = NULL;
if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) {
- new_fname = vim_strsave(buf);
+ new_fname = xstrdup(buf);
} else {
- new_fname = vim_strsave(fname);
+ new_fname = xstrdup(fname);
}
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
{
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);
}
@@ -733,7 +737,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
} else if (buf[0] == NUL)
/* relative to current directory */
STRCPY(buf, curdir);
- else if (path_with_url(buf))
+ else if (path_with_url((char *)buf))
/* URL can't be used here */
continue;
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
) {
STRCPY(path, ".");
- add_pathsep(path);
+ add_pathsep((char *)path);
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);
STRCPY(rel_path, ".");
- add_pathsep(rel_path);
+ add_pathsep((char *)rel_path);
STRCAT(rel_path, short_name);
xfree(fnames[i]);
@@ -1278,7 +1282,7 @@ addfile (
* Append a slash or backslash after directory names if none is present.
*/
if (isdir && (flags & EW_ADDSLASH))
- add_pathsep(p);
+ add_pathsep((char *)p);
GA_APPEND(char_u *, gap, p);
}
@@ -1520,31 +1524,26 @@ find_file_name_in_path (
return file_name;
}
-/*
- * Check if the "://" of a URL is at the pointer, return URL_SLASH.
- * Also check for ":\\", which MS Internet Explorer accepts, return
- * URL_BACKSLASH.
- */
-int path_is_url(char_u *p)
+// Check if the "://" of a URL is at the pointer, return URL_SLASH.
+// Also check for ":\\", which MS Internet Explorer accepts, return
+// URL_BACKSLASH.
+int path_is_url(const char *p)
{
- if (STRNCMP(p, "://", (size_t)3) == 0)
+ if (strncmp(p, "://", 3) == 0)
return URL_SLASH;
- else if (STRNCMP(p, ":\\\\", (size_t)3) == 0)
+ else if (strncmp(p, ":\\\\", 3) == 0)
return URL_BACKSLASH;
return 0;
}
-/*
- * Check if "fname" starts with "name://". Return URL_SLASH if it does.
- * Return URL_BACKSLASH for "name:\\".
- * Return zero otherwise.
- */
-int path_with_url(char_u *fname)
+/// Check if "fname" starts with "name://". Return URL_SLASH if it does.
+///
+/// @param fname is the filename to test
+/// @return URL_BACKSLASH for "name:\\", zero otherwise.
+int path_with_url(const char *fname)
{
- char_u *p;
-
- for (p = fname; isalpha(*p); ++p)
- ;
+ const char *p;
+ for (p = fname; isalpha(*p); p++) {}
return path_is_url(p);
}
@@ -1553,21 +1552,19 @@ int path_with_url(char_u *fname)
*/
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);
}
-/*
- * Get absolute file name into buffer "buf[len]".
- *
- * return FAIL for failure, OK otherwise
- */
-int
-vim_FullName (
- char_u *fname,
- char_u *buf,
- int len,
- int force /* force expansion even when already absolute */
-)
+/// Save absolute file name to "buf[len]".
+///
+/// @param fname is the filename to evaluate
+/// @param[out] buf is the buffer for returning the absolute path for `fname`
+/// @param len is the length of `buf`
+/// @param force is a flag to force expanding even if the path is absolute
+///
+/// @return FAIL for failure, OK otherwise
+int vim_FullName(const char *fname, char *buf, int len, bool force)
+ FUNC_ATTR_NONNULL_ARG(1)
{
int retval = OK;
int url;
@@ -1578,44 +1575,42 @@ vim_FullName (
url = path_with_url(fname);
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) {
/* something failed; use the file name (truncate when too long) */
- STRLCPY(buf, fname, len);
+ xstrlcpy(buf, fname, len);
}
return retval;
}
-/*
- * If fname is not a full path, make it a full path.
- * Returns pointer to allocated memory (NULL for failure).
- */
-char_u *fix_fname(char_u *fname)
+/// Get the full resolved path for `fname`
+///
+/// Even filenames that appear to be absolute based on starting from
+/// the root may have relative paths (like dir/../subdir) or symlinks
+/// 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
return FullName_save(fname, TRUE);
#else
- if (!vim_isAbsName(fname)
- || strstr((char *)fname, "..") != NULL
- || strstr((char *)fname, "//") != NULL
+ if (!vim_isAbsName((char_u *)fname)
+ || strstr(fname, "..") != NULL
+ || strstr(fname, "//") != NULL
# ifdef BACKSLASH_IN_FILENAME
- || strstr((char *)fname, "\\\\") != NULL
+ || strstr(fname, "\\\\") != NULL
# endif
)
return FullName_save(fname, FALSE);
- fname = vim_strsave(fname);
+ fname = xstrdup(fname);
# 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
return fname;
@@ -1702,7 +1697,7 @@ int same_directory(char_u *f1, char_u *f2)
if (f1 == NULL || f2 == NULL)
return FALSE;
- (void)vim_FullName(f1, ffname, MAXPATHL, FALSE);
+ (void)vim_FullName((char *)f1, (char *)ffname, MAXPATHL, FALSE);
t1 = path_tail_with_sep(ffname);
t2 = path_tail_with_sep(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 ":/" */
if (c2 == NUL
&& i > 0
- && !after_pathsep(s, s + i)
+ && !after_pathsep((char *)s, (char *)s + i)
#ifdef BACKSLASH_IN_FILENAME
&& (c1 == '/' || c1 == '\\')
#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)[] */
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 */
break;
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 force Also expand when `fname` is already absolute.
/// @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;
*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 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.
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index a37a41caeb..7e22da6e7a 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1085,7 +1085,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
slash_adjust(fname);
#endif
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.
* 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);
directory = qf_guess_filepath(fname);
if (directory)
- ptr = concat_fnames(directory, fname, TRUE);
+ ptr = (char_u *)concat_fnames((char *)directory, (char *)fname, TRUE);
else
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;
while (ds_new) {
xfree((*stackptr)->dirname);
- (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf,
- TRUE);
+ (*stackptr)->dirname = (char_u *)concat_fnames((char *)ds_new->dirname,
+ (char *)dirbuf, TRUE);
if (os_isdir((*stackptr)->dirname))
break;
@@ -1242,7 +1242,7 @@ static char_u *qf_guess_filepath(char_u *filename)
fullname = NULL;
while (ds_ptr) {
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))
break;
@@ -3546,7 +3546,7 @@ void ex_helpgrep(exarg_T *eap)
copy_option_part(&p, NameBuff, MAXPATHL, ",");
/* Find all "*.txt" and "*.??x" files in the "doc" directory. */
- add_pathsep(NameBuff);
+ add_pathsep((char *)NameBuff);
STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)");
// Note: We cannot just do `&NameBuff` because it is a statically sized array
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index df583c66ef..a087986685 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -2380,7 +2380,7 @@ jumpto_tag (
* into a fullpath
*/
if (!curwin->w_p_pvw) {
- full_fname = FullName_save(fname, FALSE);
+ full_fname = (char_u *)FullName_save((char *)fname, FALSE);
fname = full_fname;
/*
diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c
index 1b51b226db..a218c03fdb 100644
--- a/src/nvim/tempfile.c
+++ b/src/nvim/tempfile.c
@@ -37,7 +37,7 @@ static void vim_maketempdir(void)
continue;
}
- add_pathsep(template);
+ add_pathsep((char *)template);
// Concatenate with temporary directory name pattern
STRCAT(template, "nvimXXXXXX");
@@ -45,7 +45,7 @@ static void vim_maketempdir(void)
continue;
}
- if (vim_settempdir(path)) {
+ if (vim_settempdir((char *)path)) {
// Successfully created and set temporary directory so stop trying.
break;
} else {
@@ -100,15 +100,15 @@ char_u *vim_gettempdir(void)
/// @param tempdir must be no longer than MAXPATHL.
///
/// @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) {
return false;
}
vim_FullName(tempdir, buf, MAXPATHL, false);
add_pathsep(buf);
- vim_tempdir = vim_strsave(buf);
+ vim_tempdir = (char_u *)xstrdup(buf);
xfree(buf);
return true;
}
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 3999f475c6..ef1ac60599 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -677,7 +677,7 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
if (vim_ispathsep(*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);
}
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index f69d3aa78c..c97dc22741 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -4916,7 +4916,7 @@ file_name_in_line (
if (has_mbyte && (len = (size_t)((*mb_head_off)(line, ptr - 1))) > 0)
ptr -= len + 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;
else
break;
@@ -4928,7 +4928,7 @@ file_name_in_line (
*/
len = 0;
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)
len += (size_t)(*mb_ptr2len)(ptr + len);
else