diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 25 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 10 |
2 files changed, 16 insertions, 19 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 658c55cd75f..473ec1c67fa 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1202,7 +1202,7 @@ bool BLI_path_abs(char *path, const char *basepath) * \note Should only be done with command line paths. * this is _not_ something blenders internal paths support like the "//" prefix */ -bool BLI_path_cwd(char *path) +bool BLI_path_cwd(char *path, const size_t maxlen) { bool wasrelative = true; const int filelen = strlen(path); @@ -1216,24 +1216,15 @@ bool BLI_path_cwd(char *path) #endif if (wasrelative) { - char cwd[FILE_MAX] = ""; - BLI_current_working_dir(cwd, sizeof(cwd)); /* in case the full path to the blend isn't used */ - - if (cwd[0] == '\0') { - printf("Could not get the current working directory - $PWD for an unknown reason.\n"); - } - else { - /* uses the blend path relative to cwd important for loading relative linked files. - * - * cwd should contain c:\ etc on win32 so the relbase can be NULL - * relbase being NULL also prevents // being misunderstood as relative to the current - * blend file which isn't a feature we want to use in this case since were dealing - * with a path from the command line, rather than from inside Blender */ - + char cwd[FILE_MAX]; + /* in case the full path to the blend isn't used */ + if (BLI_current_working_dir(cwd, sizeof(cwd))) { char origpath[FILE_MAX]; BLI_strncpy(origpath, path, FILE_MAX); - - BLI_make_file_string(NULL, path, cwd, origpath); + BLI_join_dirfile(path, maxlen, cwd, origpath); + } + else { + printf("Could not get the current working directory - $PWD for an unknown reason.\n"); } } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 7fdf6ec8101..04d5e35355a 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -91,8 +91,14 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy) { const char *pwd = getenv("PWD"); if (pwd) { - BLI_strncpy(dir, pwd, maxncpy); - return dir; + size_t srclen = BLI_strnlen(pwd, maxncpy); + if (srclen != maxncpy) { + memcpy(dir, pwd, srclen); + return dir; + } + else { + return NULL; + } } return getcwd(dir, maxncpy); |