BLI_path: add BLI_path_is_win32_drive_only check

This commit is contained in:
Campbell Barton
2023-05-27 15:00:37 +10:00
parent 30c1efad84
commit 9371349281
4 changed files with 10 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ bool BLI_path_name_at_index(const char *__restrict path,
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
bool BLI_path_is_win32_drive(const char *path);
bool BLI_path_is_win32_drive_only(const char *path);
bool BLI_path_is_win32_drive_with_slash(const char *path);
/** \} */

View File

@@ -307,7 +307,7 @@ static bool dir_create_recursive(char *dirname, int len)
*dirname_parent_end = '\0';
#ifdef WIN32
/* Check special case `c:\foo`, don't try create `c:`, harmless but unnecessary. */
if (dirname[0] && !(isalpha(dirname[0]) && (dirname[1] == ':') && dirname[2] == '\0'))
if (dirname[0] && !BLI_path_is_win32_drive_only(dirname))
#endif
{
const int mode = BLI_exists(dirname);

View File

@@ -568,6 +568,11 @@ bool BLI_path_is_win32_drive(const char *path)
return isalpha(path[0]) && (path[1] == ':');
}
bool BLI_path_is_win32_drive_only(const char *path)
{
return isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0');
}
bool BLI_path_is_win32_drive_with_slash(const char *path)
{
return isalpha(path[0]) && (path[1] == ':') && ELEM(path[2], '\\', '/');

View File

@@ -2759,9 +2759,9 @@ static void file_expand_directory(bContext *C)
{
BLI_windows_get_default_root_dir(params->dir);
}
/* change "C:" --> "C:\", #28102. */
else if ((isalpha(params->dir[0]) && (params->dir[1] == ':')) && (params->dir[2] == '\0')) {
params->dir[2] = '\\';
/* Change `C:` --> `C:\`, #28102. */
else if (BLI_path_is_win32_drive_only(params->dir)) {
params->dir[2] = SEP;
params->dir[3] = '\0';
}
else if (BLI_path_is_unc(params->dir)) {