diff options
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r-- | src/nvim/os/fs.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4a10b5199c..57a864b7ec 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -230,7 +230,7 @@ int os_exepath(char *buffer, size_t *size) /// Checks if the file `name` is executable. /// /// @param[in] name Filename to check. -/// @param[out] abspath Returns resolved executable path, if not NULL. +/// @param[out,allocated] abspath Returns resolved exe path, if not NULL. /// @param[in] use_path Also search $PATH. /// /// @return true if `name` is executable and @@ -239,10 +239,10 @@ int os_exepath(char *buffer, size_t *size) /// - is absolute. /// /// @return `false` otherwise. -bool os_can_exe(const char_u *name, char_u **abspath, bool use_path) +bool os_can_exe(const char *name, char **abspath, bool use_path) FUNC_ATTR_NONNULL_ARG(1) { - bool no_path = !use_path || path_is_absolute(name); + bool no_path = !use_path || path_is_absolute((char_u *)name); // If the filename is "qualified" (relative or absolute) do not check $PATH. #ifdef WIN32 no_path |= (name[0] == '.' @@ -255,11 +255,11 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path) if (no_path) { #ifdef WIN32 - if (is_executable_ext((char *)name, abspath)) { + if (is_executable_ext(name, abspath)) { #else // Must have path separator, cannot execute files in the current directory. - if ((const char_u *)gettail_dir((const char *)name) != name - && is_executable((char *)name, abspath)) { + if (gettail_dir(name) != name + && is_executable(name, abspath)) { #endif return true; } else { @@ -271,10 +271,13 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path) } /// Returns true if `name` is an executable file. -static bool is_executable(const char *name, char_u **abspath) +/// +/// @param[in] name Filename to check. +/// @param[out,allocated] abspath Returns full exe path, if not NULL. +static bool is_executable(const char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { - int32_t mode = os_getperm((const char *)name); + int32_t mode = os_getperm(name); if (mode < 0) { return false; @@ -292,7 +295,7 @@ static bool is_executable(const char *name, char_u **abspath) const bool ok = (r == 0); #endif if (ok && abspath != NULL) { - *abspath = save_abs_path((char_u *)name); + *abspath = save_abs_path(name); } return ok; } @@ -301,7 +304,7 @@ static bool is_executable(const char *name, char_u **abspath) /// Checks if file `name` is executable under any of these conditions: /// - extension is in $PATHEXT and `name` is executable /// - result of any $PATHEXT extension appended to `name` is executable -static bool is_executable_ext(char *name, char_u **abspath) +static bool is_executable_ext(char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { const bool is_unix_shell = strstr((char *)path_tail(p_sh), "sh") != NULL; @@ -353,7 +356,7 @@ static bool is_executable_ext(char *name, char_u **abspath) /// @param[out] abspath Returns resolved executable path, if not NULL. /// /// @return `true` if `name` is an executable inside `$PATH`. -static bool is_executable_in_path(const char_u *name, char_u **abspath) +static bool is_executable_in_path(const char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { const char *path_env = os_getenv("PATH"); @@ -370,7 +373,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) char *path = xstrdup(path_env); #endif - size_t buf_len = STRLEN(name) + strlen(path) + 2; + size_t buf_len = strlen(name) + strlen(path) + 2; char *buf = xmalloc(buf_len); // Walk through all entries in $PATH to check if "name" exists there and @@ -382,7 +385,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) // Combine the $PATH segment with `name`. STRLCPY(buf, p, e - p + 1); - append_path(buf, (char *)name, buf_len); + append_path(buf, name, buf_len); #ifdef WIN32 if (is_executable_ext(buf, abspath)) { |