path: Also accept / as directory separator on Windows

This adds helper functions to determine the first or last directory separator
in a string and to check if a given character is a separator.

Paths starting with a separator are now also considered absolute on
Windows as these are rooted at the current drive.

Note that it's fine to use DIRECTORY_SEPARATOR when combining strings as
Windows API calls accept both forward and backward slashes as separators.

Co-authored-by: Michał Skalski <[email protected]>

References #3684.
This commit is contained in:
Tobias Brunner
2021-02-03 17:27:57 +01:00
co-authored by Michał Skalski
parent 3de65f8d67
commit e6a6fc33b6
5 changed files with 225 additions and 42 deletions
@@ -337,7 +337,7 @@ METHOD(attest_db_t, set_directory, bool,
/* remove trailing '/' or '\' character if not root directory */
len = strlen(dir);
if (len > 1 && dir[len-1] == DIRECTORY_SEPARATOR[0])
if (len > 1 && path_is_separator(dir[len-1]))
{
dir[len-1] = '\0';
}