diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 8 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 30 |
2 files changed, 25 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9e2970f6013..3cffecae187 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -324,8 +324,14 @@ void BLI_path_frame_strip(char *path, char *ext) ATTR_NONNULL(); */ bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL(); /** + * Checks for a relative path (ignoring Blender's "//") prefix + * (unlike `!BLI_path_is_rel(path)`). + * When false, #BLI_path_abs_from_cwd would expand the absolute path. + */ +bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); +/** * Checks for relative path, expanding them relative to the current working directory. - * Returns true if the expansion was performed. + * \returns true if the expansion was performed. * * \note Should only be called with command line paths. * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index c40eed711f5..de71188abfe 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1002,25 +1002,30 @@ bool BLI_path_abs(char *path, const char *basepath) return wasrelative; } -bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) +bool BLI_path_is_abs_from_cwd(const char *path) { -#ifdef DEBUG_STRSIZE - memset(path, 0xff, sizeof(*path) * maxlen); -#endif - bool wasrelative = true; - const int filelen = strlen(path); + bool is_abs = false; + const int path_len_clamp = BLI_strnlen(path, 3); #ifdef WIN32 - if ((filelen >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path)) { - wasrelative = false; + if ((ppath_len_clamp >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path)) { + is_abs = true; } #else - if (filelen >= 2 && path[0] == '/') { - wasrelative = false; + if (path_len_clamp >= 2 && path[0] == '/') { + is_abs = true; } #endif + return is_abs; +} - if (wasrelative) { +bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) +{ +#ifdef DEBUG_STRSIZE + memset(path, 0xff, sizeof(*path) * maxlen); +#endif + + if (!BLI_path_is_abs_from_cwd(path)) { char cwd[FILE_MAX]; /* in case the full path to the blend isn't used */ if (BLI_current_working_dir(cwd, sizeof(cwd))) { @@ -1031,9 +1036,10 @@ bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) else { printf("Could not get the current working directory - $PWD for an unknown reason.\n"); } + return true; } - return wasrelative; + return false; } #ifdef _WIN32 |