Merge pull request #10678 from jdgleaver/path-is-absolute

Optimise 'path_is_absolute()'
This commit is contained in:
Autechre 2020-05-21 15:37:29 +02:00 committed by GitHub
commit 29e9a54000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;
}