diff options
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r-- | src/nvim/path.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 57499429ec..a79b7139f1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -18,7 +18,6 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/misc2.h" #include "nvim/option.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" @@ -172,19 +171,23 @@ char_u *path_next_component(char_u *fname) return fname; } -/* - * Get a pointer to one character past the head of a path name. - * Unix: after "/"; DOS: after "c:\"; Mac: no head. - * If there is no head, path is returned. - */ +/// Get a pointer to one character past the head of a path name. +/// Unix: after "/"; Win: after "c:\" +/// If there is no head, path is returned. char_u *get_past_head(char_u *path) { - char_u *retval; + char_u *retval = path; - retval = path; +#ifdef WIN32 + // May skip "c:" + if (isalpha(path[0]) && path[1] == ':') { + retval = path + 2; + } +#endif - while (vim_ispathsep(*retval)) + while (vim_ispathsep(*retval)) { ++retval; + } return retval; } @@ -562,11 +565,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, while (*path_end != NUL) { /* May ignore a wildcard that has a backslash before it; it will * be removed by rem_backslash() or file_pat_to_reg_pat() below. */ - if (path_end >= path + wildoff && rem_backslash(path_end)) + if (path_end >= path + wildoff && rem_backslash(path_end)) { *p++ = *path_end++; - else if (*path_end == '/') { - if (e != NULL) + } else if (vim_ispathsep_nocolon(*path_end)) { + if (e != NULL) { break; + } s = p + 1; } else if (path_end >= path + wildoff && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL @@ -2099,7 +2103,6 @@ int path_full_dir_name(char *directory, char *buffer, size_t len) } // Append to_append to path with a slash in between. -// Append to_append to path with a slash in between. int append_path(char *path, const char *to_append, size_t max_len) { size_t current_length = strlen(path); @@ -2116,7 +2119,7 @@ int append_path(char *path, const char *to_append, size_t max_len) } // Glue both paths with a slash. - if (current_length > 0 && path[current_length-1] != '/') { + if (current_length > 0 && !vim_ispathsep_nocolon(path[current_length-1])) { current_length += 1; // Count the trailing slash. // +1 for the NUL at the end. @@ -2124,7 +2127,7 @@ int append_path(char *path, const char *to_append, size_t max_len) return FAIL; } - STRCAT(path, "/"); + STRCAT(path, PATHSEPSTR); } // +1 for the NUL at the end. @@ -2182,9 +2185,16 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, /// Check if the given file is absolute. /// -/// This just checks if the file name starts with '/' or '~'. /// @return `TRUE` if "fname" is absolute. int path_is_absolute_path(const char_u *fname) { +#ifdef WIN32 + // A name like "d:/foo" and "//server/share" is absolute + return ((isalpha(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 '~'. return *fname == '/' || *fname == '~'; +#endif } |