aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c127
1 files changed, 64 insertions, 63 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 9350335e54..e4c2253357 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -6,6 +6,7 @@
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -154,7 +155,7 @@ char *path_tail_with_sep(char *fname)
/// @post if `len` is not null, stores the length of the executable name.
///
/// @return The position of the last path separator + 1.
-const char_u *invocation_path_tail(const char *invocation, size_t *len)
+const char *invocation_path_tail(const char *invocation, size_t *len)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
{
const char *tail = get_past_head(invocation);
@@ -171,7 +172,7 @@ const char_u *invocation_path_tail(const char *invocation, size_t *len)
*len = (size_t)(p - tail);
}
- return (char_u *)tail;
+ return tail;
}
/// Get the next path component of a path name.
@@ -210,10 +211,10 @@ int path_head_length(void)
/// @return
/// - True if path begins with a path head
/// - False otherwise
-bool is_path_head(const char_u *path)
+bool is_path_head(const char *path)
{
#ifdef MSWIN
- return isalpha(path[0]) && path[1] == ':';
+ return isalpha((uint8_t)path[0]) && path[1] == ':';
#else
return vim_ispathsep(*path);
#endif
@@ -228,7 +229,7 @@ char *get_past_head(const char *path)
#ifdef MSWIN
// May skip "c:"
- if (is_path_head((char_u *)path)) {
+ if (is_path_head(path)) {
retval = path + 2;
}
#endif
@@ -510,7 +511,7 @@ char *FullName_save(const char *fname, bool force)
char *save_abs_path(const char *name)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
- if (!path_is_absolute((char_u *)name)) {
+ if (!path_is_absolute(name)) {
return FullName_save(name, true);
}
return xstrdup(name);
@@ -535,7 +536,7 @@ bool path_has_wildcard(const char *p)
// Windows:
const char *wildcards = "?*$[`";
#endif
- if (vim_strchr(wildcards, *p) != NULL
+ if (vim_strchr(wildcards, (uint8_t)(*p)) != NULL
|| (p[0] == '~' && p[1] != NUL)) {
return true;
}
@@ -648,7 +649,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in
}
s = p + 1;
} else if (path_end >= path + wildoff
- && (vim_strchr("*?[{~$", *path_end) != NULL
+ && (vim_strchr("*?[{~$", (uint8_t)(*path_end)) != NULL
#ifndef MSWIN
|| (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end)))
#endif
@@ -782,8 +783,8 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in
// slow, thus skip it.
size_t matches = (size_t)(gap->ga_len - start_len);
if (matches > 0 && !got_int) {
- qsort(((char_u **)gap->ga_data) + start_len, matches,
- sizeof(char_u *), pstrcmp);
+ qsort(((char **)gap->ga_data) + start_len, matches,
+ sizeof(char *), pstrcmp);
}
return matches;
}
@@ -841,11 +842,11 @@ static bool is_unique(char *maybe_unique, garray_T *gap, int i)
// expanding each into their equivalent path(s).
static void expand_path_option(char *curdir, garray_T *gap)
{
- char_u *path_option = *curbuf->b_p_path == NUL ? p_path : (char_u *)curbuf->b_p_path;
+ char *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path;
char *buf = xmalloc(MAXPATHL);
while (*path_option != NUL) {
- copy_option_part((char **)&path_option, buf, MAXPATHL, " ,");
+ copy_option_part(&path_option, buf, MAXPATHL, " ,");
if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) {
// Relative to current buffer:
@@ -870,7 +871,7 @@ static void expand_path_option(char *curdir, garray_T *gap)
STRCPY(buf, curdir); // relative to current directory
} else if (path_with_url(buf)) {
continue; // URL can't be used here
- } else if (!path_is_absolute((char_u *)buf)) {
+ } else if (!path_is_absolute(buf)) {
// Expand relative path to their full path equivalent
size_t len = strlen(curdir);
if (len + strlen(buf) + 3 > MAXPATHL) {
@@ -894,11 +895,11 @@ static void expand_path_option(char *curdir, garray_T *gap)
// path: /foo/bar/baz
// fname: /foo/bar/baz/quux.txt
// returns: ^this
-static char_u *get_path_cutoff(char_u *fname, garray_T *gap)
+static char *get_path_cutoff(char *fname, garray_T *gap)
{
int maxlen = 0;
- char_u **path_part = (char_u **)gap->ga_data;
- char_u *cutoff = NULL;
+ char **path_part = gap->ga_data;
+ char *cutoff = NULL;
for (int i = 0; i < gap->ga_len; i++) {
int j = 0;
@@ -984,7 +985,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern)
}
// Shorten the filename while maintaining its uniqueness
- path_cutoff = (char *)get_path_cutoff((char_u *)path, &path_ga);
+ path_cutoff = get_path_cutoff(path, &path_ga);
// Don't assume all files can be reached without path when search
// pattern starts with **/, so only remove path_cutoff
@@ -1011,7 +1012,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern)
}
}
- if (path_is_absolute((char_u *)path)) {
+ if (path_is_absolute(path)) {
// Last resort: shorten relative to curdir if possible.
// 'possible' means:
// 1. It is under the current directory.
@@ -1127,7 +1128,7 @@ static int expand_in_path(garray_T *const gap, char *const pattern, const int fl
return 0;
}
- char *const paths = (char *)ga_concat_strings(&path_ga);
+ char *const paths = ga_concat_strings(&path_ga);
ga_clear_strings(&path_ga);
int glob_flags = 0;
@@ -1137,7 +1138,7 @@ static int expand_in_path(garray_T *const gap, char *const pattern, const int fl
if (flags & EW_ADDSLASH) {
glob_flags |= WILD_ADD_SLASH;
}
- globpath(paths, pattern, gap, glob_flags);
+ globpath(paths, pattern, gap, glob_flags, false);
xfree(paths);
return gap->ga_len;
@@ -1145,12 +1146,12 @@ static int expand_in_path(garray_T *const gap, char *const pattern, const int fl
/// Return true if "p" contains what looks like an environment variable.
/// Allowing for escaping.
-static bool has_env_var(char_u *p)
+static bool has_env_var(char *p)
{
for (; *p; MB_PTR_ADV(p)) {
if (*p == '\\' && p[1] != NUL) {
p++;
- } else if (vim_strchr("$", *p) != NULL) {
+ } else if (vim_strchr("$", (uint8_t)(*p)) != NULL) {
return true;
}
}
@@ -1161,7 +1162,7 @@ static bool has_env_var(char_u *p)
// Return true if "p" contains a special wildcard character, one that Vim
// cannot expand, requires using a shell.
-static bool has_special_wildchar(char_u *p)
+static bool has_special_wildchar(char *p)
{
for (; *p; MB_PTR_ADV(p)) {
// Disallow line break characters.
@@ -1171,13 +1172,13 @@ static bool has_special_wildchar(char_u *p)
// Allow for escaping.
if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n') {
p++;
- } else if (vim_strchr(SPECIAL_WILDCHAR, *p) != NULL) {
+ } else if (vim_strchr(SPECIAL_WILDCHAR, (uint8_t)(*p)) != NULL) {
// A { must be followed by a matching }.
- if (*p == '{' && vim_strchr((char *)p, '}') == NULL) {
+ if (*p == '{' && vim_strchr(p, '}') == NULL) {
continue;
}
// A quote and backtick must be followed by another one.
- if ((*p == '`' || *p == '\'') && vim_strchr((char *)p, *p) == NULL) {
+ if ((*p == '`' || *p == '\'') && vim_strchr(p, (uint8_t)(*p)) == NULL) {
continue;
}
return true;
@@ -1231,7 +1232,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i
// avoids starting the shell for each argument separately.
// For `=expr` do use the internal function.
for (int i = 0; i < num_pat; i++) {
- if (has_special_wildchar((char_u *)pat[i])
+ if (has_special_wildchar(pat[i])
&& !(vim_backtick(pat[i]) && pat[i][1] == '=')) {
return os_expand_wildcards(num_pat, pat, num_file, file, flags);
}
@@ -1258,8 +1259,8 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i
}
} else {
// First expand environment variables, "~/" and "~user/".
- if ((has_env_var((char_u *)p) && !(flags & EW_NOTENV)) || *p == '~') {
- p = (char *)expand_env_save_opt(p, true);
+ if ((has_env_var(p) && !(flags & EW_NOTENV)) || *p == '~') {
+ p = expand_env_save_opt(p, true);
if (p == NULL) {
p = pat[i];
} else {
@@ -1267,7 +1268,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i
// On Unix, if expand_env() can't expand an environment
// variable, use the shell to do that. Discard previously
// found file names and start all over again.
- if (has_env_var((char_u *)p) || *p == '~') {
+ if (has_env_var(p) || *p == '~') {
xfree(p);
ga_clear_strings(&ga);
i = os_expand_wildcards(num_pat, pat, num_file, file,
@@ -1286,7 +1287,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i
// given.
if (path_has_exp_wildcard(p) || (flags & EW_ICASE)) {
if ((flags & EW_PATH)
- && !path_is_absolute((char_u *)p)
+ && !path_is_absolute(p)
&& !(p[0] == '.'
&& (vim_ispathsep(p[1])
|| (p[1] == '.'
@@ -1413,9 +1414,9 @@ static int expand_backtick(garray_T *gap, char *pat, int flags)
/// backslash twice.
/// When 'shellslash' set do it the other way around.
/// When the path looks like a URL leave it unmodified.
-void slash_adjust(char_u *p)
+void slash_adjust(char *p)
{
- if (path_with_url((const char *)p)) {
+ if (path_with_url(p)) {
return;
}
@@ -1428,8 +1429,8 @@ void slash_adjust(char_u *p)
}
while (*p) {
- if (*p == (char_u)psepcN) {
- *p = (char_u)psepc;
+ if (*p == psepcN) {
+ *p = psepc;
}
MB_PTR_ADV(p);
}
@@ -1460,7 +1461,7 @@ void addfile(garray_T *gap, char *f, int flags)
#ifdef FNAME_ILLEGAL
// if the file/dir contains illegal characters, don't add it
- if (strpbrk((char *)f, FNAME_ILLEGAL) != NULL) {
+ if (strpbrk(f, FNAME_ILLEGAL) != NULL) {
return;
}
#endif
@@ -1477,7 +1478,7 @@ void addfile(garray_T *gap, char *f, int flags)
return;
}
- char_u *p = xmalloc(strlen(f) + 1 + isdir);
+ char *p = xmalloc(strlen(f) + 1 + isdir);
STRCPY(p, f);
#ifdef BACKSLASH_IN_FILENAME
@@ -1485,9 +1486,9 @@ void addfile(garray_T *gap, char *f, int flags)
#endif
// Append a slash or backslash after directory names if none is present.
if (isdir && (flags & EW_ADDSLASH)) {
- add_pathsep((char *)p);
+ add_pathsep(p);
}
- GA_APPEND(char_u *, gap, p);
+ GA_APPEND(char *, gap, p);
}
// Converts a file name into a canonical form. It simplifies a file name into
@@ -1689,8 +1690,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha
}
if (options & FNAME_EXP) {
- file_name = (char *)find_file_in_path(ptr, len, options & ~FNAME_MESS, true,
- rel_fname);
+ file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true,
+ rel_fname);
// If the file could not be found in a normal way, try applying
// 'includeexpr' (unless done already).
@@ -1700,8 +1701,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha
if (tofree != NULL) {
ptr = tofree;
len = strlen(ptr);
- file_name = (char *)find_file_in_path(ptr, len, options & ~FNAME_MESS,
- true, rel_fname);
+ file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
+ true, rel_fname);
}
}
if (file_name == NULL && (options & FNAME_MESS)) {
@@ -1716,7 +1717,7 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha
while (file_name != NULL && --count > 0) {
xfree(file_name);
file_name =
- (char *)find_file_in_path(ptr, len, options, false, rel_fname);
+ find_file_in_path(ptr, len, options, false, rel_fname);
}
} else {
file_name = xstrnsave(ptr, len);
@@ -1767,7 +1768,7 @@ int path_with_url(const char *fname)
// non-URL text.
// first character must be alpha
- if (!isalpha(*fname)) {
+ if (!ASCII_ISALPHA(*fname)) {
return 0;
}
@@ -1776,7 +1777,7 @@ int path_with_url(const char *fname)
}
// check body: alpha or dash
- for (p = fname + 1; (isalpha(*p) || (*p == '-')); p++) {}
+ for (p = fname + 1; (ASCII_ISALPHA(*p) || (*p == '-')); p++) {}
// check last char is not a dash
if (p[-1] == '-') {
@@ -1799,7 +1800,7 @@ bool path_with_extension(const char *path, const char *extension)
/// Return true if "name" is a full (absolute) path name or URL.
bool vim_isAbsName(char *name)
{
- return path_with_url(name) != 0 || path_is_absolute((char_u *)name);
+ return path_with_url(name) != 0 || path_is_absolute(name);
}
/// Save absolute file name to "buf[len]".
@@ -1823,7 +1824,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force)
if (strlen(fname) > (len - 1)) {
xstrlcpy(buf, fname, len); // truncate
#ifdef MSWIN
- slash_adjust((char_u *)buf);
+ slash_adjust(buf);
#endif
return FAIL;
}
@@ -1838,7 +1839,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force)
xstrlcpy(buf, fname, len); // something failed; use the filename
}
#ifdef MSWIN
- slash_adjust((char_u *)buf);
+ slash_adjust(buf);
#endif
return rv;
}
@@ -1858,7 +1859,7 @@ char *fix_fname(const char *fname)
#ifdef UNIX
return FullName_save(fname, true);
#else
- if (!vim_isAbsName((char_u *)fname)
+ if (!vim_isAbsName((char *)fname)
|| strstr(fname, "..") != NULL
|| strstr(fname, "//") != NULL
# ifdef BACKSLASH_IN_FILENAME
@@ -2075,7 +2076,7 @@ char *path_shorten_fname(char *full_path, char *dir_name)
size_t len = strlen(dir_name);
// If dir_name is a path head, full_path can always be made relative.
- if (len == (size_t)path_head_length() && is_path_head((char_u *)dir_name)) {
+ if (len == (size_t)path_head_length() && is_path_head(dir_name)) {
return full_path + len;
}
@@ -2123,9 +2124,9 @@ int expand_wildcards_eval(char **pat, int *num_file, char ***file, int flags)
if (is_cur_alt_file || *exp_pat == '<') {
emsg_off++;
- eval_pat = (char *)eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg,
- NULL,
- true);
+ eval_pat = eval_vars(exp_pat, exp_pat, &usedlen, NULL, &ignored_msg,
+ NULL,
+ true);
emsg_off--;
if (eval_pat != NULL) {
star_follows = strcmp(exp_pat + usedlen, "*") == 0;
@@ -2185,15 +2186,15 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int
// Remove names that match 'wildignore'.
if (*p_wig) {
- char_u *ffname;
+ char *ffname;
// check all files in (*files)[]
assert(*num_files == 0 || *files != NULL);
for (i = 0; i < *num_files; i++) {
- ffname = (char_u *)FullName_save((*files)[i], false);
+ ffname = FullName_save((*files)[i], false);
assert((*files)[i] != NULL);
assert(ffname != NULL);
- if (match_file_list((char_u *)p_wig, (char_u *)(*files)[i], ffname)) {
+ if (match_file_list(p_wig, (*files)[i], ffname)) {
// remove this matching file from the list
xfree((*files)[i]);
for (j = i; j + 1 < *num_files; j++) {
@@ -2240,7 +2241,7 @@ int match_suffix(char *fname)
size_t fnamelen = strlen(fname);
size_t setsuflen = 0;
- for (char *setsuf = (char *)p_su; *setsuf;) {
+ for (char *setsuf = p_su; *setsuf;) {
setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
if (setsuflen == 0) {
char *tail = path_tail(fname);
@@ -2290,7 +2291,7 @@ int path_full_dir_name(char *directory, char *buffer, size_t len)
// Path does not exist (yet). For a full path fail,
// will use the path as-is. For a relative path use
// the current directory and append the file name.
- if (path_is_absolute((const char_u *)directory)) {
+ if (path_is_absolute(directory)) {
// Do not return immediately since we may be in the wrong directory.
retval = FAIL;
} else {
@@ -2360,7 +2361,7 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force)
char *end_of_path = (char *)fname;
// expand it if forced or not an absolute path
- if (force || !path_is_absolute((char_u *)fname)) {
+ if (force || !path_is_absolute(fname)) {
p = strrchr(fname, '/');
#ifdef MSWIN
if (p == NULL) {
@@ -2389,14 +2390,14 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force)
/// Check if file `fname` is a full (absolute) path.
///
/// @return `true` if "fname" is absolute.
-int path_is_absolute(const char_u *fname)
+int path_is_absolute(const char *fname)
{
#ifdef MSWIN
if (*fname == NUL) {
return false;
}
// A name like "d:/foo" and "//server/share" is absolute
- return ((isalpha(fname[0]) && fname[1] == ':' && vim_ispathsep_nocolon(fname[2]))
+ return ((isalpha((uint8_t)fname[0]) && fname[1] == ':' && vim_ispathsep_nocolon(fname[2]))
|| (vim_ispathsep_nocolon(fname[0]) && fname[0] == fname[1]));
#else
// UNIX: This just checks if the file name starts with '/' or '~'.
@@ -2416,7 +2417,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize)
{
const char *path = os_getenv("PATH");
- if (path == NULL || path_is_absolute((char_u *)argv0)) {
+ if (path == NULL || path_is_absolute(argv0)) {
xstrlcpy(buf, argv0, bufsize);
} else if (argv0[0] == '.' || strchr(argv0, PATHSEP)) {
// Relative to CWD.