From 22e9c51b0f24bd8717d9793a35d741adb9ade797 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Mon, 13 Apr 2015 12:48:35 +0100 Subject: Add Windows support to path_is_absolute() vim-patch:0 --- src/nvim/path.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index c20dffa9b1..4a47a70799 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2186,9 +2186,15 @@ 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 ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) + || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))); +#else + // UNIX: This just checks if the file name starts with '/' or '~'. return *fname == '/' || *fname == '~'; +#endif } -- cgit From 6b94d4d14f701b76b61a2c45862dff98d011f447 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Sun, 14 Aug 2016 11:20:40 +0100 Subject: Windows: Check drive letter in absolute paths Check if drive letter is alphabetic character in path_is_absolute_path(). --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index 4a47a70799..80eeac9e74 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2191,7 +2191,7 @@ int path_is_absolute_path(const char_u *fname) { #ifdef WIN32 // A name like "d:/foo" and "//server/share" is absolute - return ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) + return ((isalpha(fname[0]) && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))); #else // UNIX: This just checks if the file name starts with '/' or '~'. -- cgit From ccb6af064fe879dc8e213a582f7f938ad1972ae3 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Sun, 14 Aug 2016 15:18:09 +0100 Subject: path.c: Avoid code duplication for path separator checks --- src/nvim/path.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index 80eeac9e74..a2617973b1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2191,8 +2191,9 @@ 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] == ':' && (fname[2] == '/' || fname[2] == '\\')) - || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))); + 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 == '~'; -- cgit