diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_appdir.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/appdir.c | 22 |
2 files changed, 18 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index dcacc2ca7b3..16488bdbf09 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -105,8 +105,11 @@ void BKE_appdir_app_templates(struct ListBase *templates); /** * Initialize path to program executable. + * + * \param strict: When true, use `argv0` unmodified (besides making absolute & normalizing). + * Otherwise other methods may be used to find the program path, including searching `$PATH`. */ -void BKE_appdir_program_path_init(const char *argv0); +void BKE_appdir_program_path_init(const char *argv0, bool strict); /** * Path to executable diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index 031d3647878..c19afdb4fb8 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -794,11 +794,11 @@ const char *BKE_appdir_folder_id_version(const int folder_id, * (must be #FILE_MAX minimum) * \param name: The name of the executable (usually `argv[0]`) to be checked */ -static void where_am_i(char *fullname, const size_t maxlen, const char *name) +static void where_am_i(char *fullname, const size_t maxlen, const char *name, const bool strict) { #ifdef WITH_BINRELOC /* Linux uses `binreloc` since `argv[0]` is not reliable, call `br_init(NULL)` first. */ - { + if (!strict) { const char *path = NULL; path = br_find_exe(NULL); if (path) { @@ -810,7 +810,7 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name) #endif #ifdef _WIN32 - { + if (!strict) { wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); if (GetModuleFileNameW(0, fullname_16, maxlen)) { conv_utf_16_to_8(fullname_16, fullname, maxlen); @@ -834,18 +834,24 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name) if (name[0] == '.') { BLI_path_abs_from_cwd(fullname, maxlen); #ifdef _WIN32 - BLI_path_program_extensions_add_win32(fullname, maxlen); + if (!strict) { + BLI_path_program_extensions_add_win32(fullname, maxlen); + } #endif } else if (BLI_path_slash_rfind(name)) { /* Full path. */ BLI_strncpy(fullname, name, maxlen); #ifdef _WIN32 - BLI_path_program_extensions_add_win32(fullname, maxlen); + if (!strict) { + BLI_path_program_extensions_add_win32(fullname, maxlen); + } #endif } else { - BLI_path_program_search(fullname, maxlen, name); + if (!strict) { + BLI_path_program_search(fullname, maxlen, name); + } } /* Remove "/./" and "/../" so string comparisons can be used on the path. */ BLI_path_normalize(NULL, fullname); @@ -858,9 +864,9 @@ static void where_am_i(char *fullname, const size_t maxlen, const char *name) } } -void BKE_appdir_program_path_init(const char *argv0) +void BKE_appdir_program_path_init(const char *argv0, const bool strict) { - where_am_i(g_app.program_filepath, sizeof(g_app.program_filepath), argv0); + where_am_i(g_app.program_filepath, sizeof(g_app.program_filepath), argv0, strict); BLI_split_dir_part(g_app.program_filepath, g_app.program_dirname, sizeof(g_app.program_dirname)); } |