aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-07-23 12:04:10 -0400
committerScott Prager <splinterofchaos@gmail.com>2014-08-17 22:16:00 -0400
commitb9553bd0384d80418d129c0d4a714363800c14dc (patch)
treef8f19d49242e528d5af76af42c929d455a8f20e8 /src
parent53a3c5c21ceb0d2f5c242ae3f4ad6e2634852497 (diff)
downloadrneovim-b9553bd0384d80418d129c0d4a714363800c14dc.tar.gz
rneovim-b9553bd0384d80418d129c0d4a714363800c14dc.tar.bz2
rneovim-b9553bd0384d80418d129c0d4a714363800c14dc.zip
path.c: Learn invocation_path_tail().
Required for vim patch 276 as an alternative to `get_isolated_shell_name()`.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/path.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index dbbb77a8e9..2d819b39a4 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -131,6 +131,35 @@ char_u *path_tail_with_sep(char_u *fname)
return tail;
}
+/// Finds the path tail (or executable) in an invocation.
+///
+/// @param[in] invocation A program invocation in the form:
+/// "path/to/exe [args]".
+/// @param[out] len Stores the length of the executable name.
+///
+/// @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_u *invocation, size_t *len)
+ FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
+{
+ const char_u *tail = get_past_head((char_u *) invocation);
+ const char_u *p = tail;
+ while (*p != NUL && *p != ' ') {
+ bool was_sep = vim_ispathsep_nocolon(*p);
+ mb_ptr_adv(p);
+ if (was_sep) {
+ tail = p; // Now tail points one past the separator.
+ }
+ }
+
+ if (len != NULL) {
+ *len = (size_t)(p - tail);
+ }
+
+ return tail;
+}
+
/// Get the next path component of a path name.
///
/// @param fname A file path. (Must be != NULL.)