Optimise 'path_is_absolute()'

This commit is contained in:
jdgleaver 2020-05-21 13:28:42 +01:00
parent e1e6f2db51
commit f522cfcce8

View File

@ -621,19 +621,29 @@ const char *path_basename(const char *path)
**/
bool path_is_absolute(const char *path)
{
#if defined(__wiiu__) || defined(VITA)
const char *seperator = NULL;
#endif
if (string_is_empty(path))
return false;
if (path[0] == '/')
return true;
#ifdef _WIN32
/* Many roads lead to Rome ... */
if (( strstr(path, "\\\\") == path)
|| strstr(path, ":/")
|| strstr(path, ":\\")
|| strstr(path, ":\\\\"))
#if defined(_WIN32)
/* Many roads lead to Rome...
* Note: Drive letter can only be 1 character long */
if (string_starts_with(path, "\\\\") ||
string_starts_with(path + 1, ":/") ||
string_starts_with(path + 1, ":\\"))
return true;
#elif defined(__wiiu__) || defined(VITA)
if (strstr(path, ":/"))
seperator = strchr(path, ':');
if (seperator && (seperator[1] == '/'))
return true;
#endif
return false;
}