From c13b2a2504393371e32a4fb4c01cfad8d7cc929e Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Wed, 5 Sep 2018 14:31:10 +1000 Subject: Fix T54152: --env-system-scripts fails on win32 --- source/blender/blenlib/BLI_path_util.h | 1 + source/blender/blenlib/intern/path_util.c | 23 ++++++++++++++++++++--- source/blender/blenlib/intern/storage.c | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index b4329bf81ac..e434e83416b 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -41,6 +41,7 @@ struct ListBase; void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1); void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1); +const char *BLI_getenv(const char *env) ATTR_NONNULL(1); void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file); void BLI_make_exist(char *dir); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 6272f2109d2..b28579febaf 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1095,7 +1095,7 @@ bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen) if ((type == 0) || S_ISDIR(type)) { /* typically 3-5, ".EXE", ".BAT"... etc */ const int ext_max = 12; - const char *ext = getenv("PATHEXT"); + const char *ext = BLI_getenv("PATHEXT"); if (ext) { const int name_len = strlen(name); char *filename = alloca(name_len + ext_max); @@ -1152,7 +1152,7 @@ bool BLI_path_program_search( const char separator = ':'; #endif - path = getenv("PATH"); + path = BLI_getenv("PATH"); if (path) { char filename[FILE_MAX]; const char *temp; @@ -1220,10 +1220,27 @@ void BLI_setenv(const char *env, const char *val) */ void BLI_setenv_if_new(const char *env, const char *val) { - if (getenv(env) == NULL) + if (BLI_getenv(env) == NULL) BLI_setenv(env, val); } +/** +* get an env var, result has to be used immediately +*/ +const char* BLI_getenv(const char *env) +{ +#ifdef _MSC_VER + static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/ + if (GetEnvironmentVariableA(env, buffer, sizeof(buffer))) + return buffer; + else + return NULL; +#else + return getenv(env); +#endif +} + + /** * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of * the lowest-level directory that does exist and we can read. diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index f69b35ce5a9..cfcc2bc4390 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -85,7 +85,7 @@ */ char *BLI_current_working_dir(char *dir, const size_t maxncpy) { - const char *pwd = getenv("PWD"); + const char *pwd = BLI_getenv("PWD"); if (pwd) { size_t srclen = BLI_strnlen(pwd, maxncpy); if (srclen != maxncpy) { -- cgit v1.2.3