utils: Provide a path_absolute() function to check path for non-relativeness
The usually used trivial '/' check won't work on Windows platforms.
This commit is contained in:
@@ -288,6 +288,33 @@ char* path_basename(const char *path)
|
||||
return trail ? strndup(pos, trail - pos) : strdup(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
bool path_absolute(const char *path)
|
||||
{
|
||||
if (!path)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef WIN32
|
||||
if (strpfx(path, "\\\\"))
|
||||
{ /* UNC */
|
||||
return TRUE;
|
||||
}
|
||||
if (strlen(path) && isalpha(path[0]) && path[1] == ':')
|
||||
{ /* drive letter */
|
||||
return TRUE;
|
||||
}
|
||||
#else /* !WIN32 */
|
||||
if (path[0] == DIRECTORY_SEPARATOR[0])
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
|
||||
@@ -568,6 +568,14 @@ char *path_dirname(const char *path);
|
||||
*/
|
||||
char *path_basename(const char *path);
|
||||
|
||||
/**
|
||||
* Check if a given path is absolute.
|
||||
*
|
||||
* @param path path to check
|
||||
* @return TRUE if absolute, FALSE if relative
|
||||
*/
|
||||
bool path_absolute(const char *path);
|
||||
|
||||
/**
|
||||
* Creates a directory and all required parent directories.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user