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
+2 -2
View File
@@ -173,9 +173,9 @@ enumerator_t* enumerator_create_directory(const char *path)
return NULL;
}
/* append a '/' if not already done */
if (this->full[len-1] != '/')
if (!path_is_separator(this->full[len-1]))
{
this->full[len++] = '/';
this->full[len++] = DIRECTORY_SEPARATOR[0];
this->full[len] = '\0';
}
this->full_end = &this->full[len];