Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-10-08 07:05:58 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-08 07:05:58 +0300
commita5e631171bdcdb12f508528f391d3916014e23e8 (patch)
tree79cc6bb9d4d0c1425ac53d12496ebcba96c5ec21 /source/blender/blenlib/intern/path_util.c
parente47177e301d104a8b7110e4490bf587c86835bad (diff)
BLI_path api, minor changes to CWD handling
- BLI_current_working_dir's return value must be checked, since it may fail. - BLI_current_working_dir now behaves like getcwd, where a too-small target will return failure. - avoid buffer overrun with BLI_path_cwd, by taking a maxlen arg.
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c25
1 files changed, 8 insertions, 17 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");
}
}