Merge #5198 from equalsraf/windows-path-is-absolute

Windows: path_is_absolute()
This commit is contained in:
Justin M. Keyes
2016-08-18 18:53:03 -04:00
committed by GitHub

View File

@@ -2186,9 +2186,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
}