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) 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] == '/') if (path[0] == '/')
return true; return true;
#ifdef _WIN32
/* Many roads lead to Rome ... */ #if defined(_WIN32)
if (( strstr(path, "\\\\") == path) /* Many roads lead to Rome...
|| strstr(path, ":/") * Note: Drive letter can only be 1 character long */
|| strstr(path, ":\\") if (string_starts_with(path, "\\\\") ||
|| strstr(path, ":\\\\")) string_starts_with(path + 1, ":/") ||
string_starts_with(path + 1, ":\\"))
return true; return true;
#elif defined(__wiiu__) || defined(VITA) #elif defined(__wiiu__) || defined(VITA)
if (strstr(path, ":/")) seperator = strchr(path, ':');
if (seperator && (seperator[1] == '/'))
return true; return true;
#endif #endif
return false; return false;
} }