aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/fs.c
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-17 00:58:30 -0400
committerScott Prager <splinterofchaos@gmail.com>2014-09-17 01:00:24 -0400
commit9445eaa297a7e01c20cb5e5141be54cc7d8d5cce (patch)
treecb44a949bab57286b4cda4aee8843b39bdef5b12 /src/nvim/os/fs.c
parent899878d347b4a85e3a19e5bb86f7519cc9255992 (diff)
downloadrneovim-9445eaa297a7e01c20cb5e5141be54cc7d8d5cce.tar.gz
rneovim-9445eaa297a7e01c20cb5e5141be54cc7d8d5cce.tar.bz2
rneovim-9445eaa297a7e01c20cb5e5141be54cc7d8d5cce.zip
vim-patch:7.4.235
Problem: It is not easy to get the full path of a command. Solution: Add the exepath() function. https://code.google.com/p/vim/source/detail?r=5ab2946f7ce560985830fbc3c453bb0f7a01f385
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r--src/nvim/os/fs.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index bb4e897887..07accb339a 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -66,7 +66,10 @@ bool os_isdir(const char_u *name)
return true;
}
-/// Check if the given path represents an executable file.
+/// Checks if the given path represents an executable file.
+///
+/// @param[in] name The name of the executable.
+/// @param[out] abspath Path of the executable, if found and not `NULL`.
///
/// @return `true` if `name` is executable and
/// - can be found in $PATH,
@@ -74,16 +77,24 @@ bool os_isdir(const char_u *name)
/// - is absolute.
///
/// @return `false` otherwise.
-bool os_can_exe(const char_u *name)
+bool os_can_exe(const char_u *name, char_u **abspath)
{
// If it's an absolute or relative path don't need to use $PATH.
if (path_is_absolute_path(name) ||
(name[0] == '.' && (name[1] == '/' ||
(name[1] == '.' && name[2] == '/')))) {
- return is_executable(name);
+ if (is_executable(name)) {
+ if (abspath != NULL) {
+ *abspath = save_absolute_path(name);
+ }
+
+ return true;
+ }
+
+ return false;
}
- return is_executable_in_path(name);
+ return is_executable_in_path(name, abspath);
}
// Return true if "name" is an executable file, false if not or it doesn't
@@ -103,10 +114,13 @@ static bool is_executable(const char_u *name)
return false;
}
-/// Check if a file is inside the $PATH and is executable.
+/// Checks if a file is inside the `$PATH` and is executable.
+///
+/// @param[in] name The name of the executable.
+/// @param[out] abspath Path of the executable, if found and not `NULL`.
///
-/// @return `true` if `name` is an executable inside $PATH.
-static bool is_executable_in_path(const char_u *name)
+/// @return `true` if `name` is an executable inside `$PATH`.
+static bool is_executable_in_path(const char_u *name, char_u **abspath)
{
const char *path = getenv("PATH");
// PATH environment variable does not exist or is empty.
@@ -131,8 +145,13 @@ static bool is_executable_in_path(const char_u *name)
append_path((char *) buf, (const char *) name, (int)buf_len);
if (is_executable(buf)) {
- // Found our executable. Free buf and return.
+ // Check if the caller asked for a copy of the path.
+ if (abspath != NULL) {
+ *abspath = save_absolute_path(buf);
+ }
+
free(buf);
+
return true;
}