diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-10-03 11:39:30 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-10-03 11:50:42 +0300 |
commit | 0863ae0a5836ab91e44c86b4e32715e847631bba (patch) | |
tree | ea1c8bf7898d6f00a88a3608419055a953931d06 /source/blender/blenkernel/intern/appdir.c | |
parent | cacd84a318dfc61e4e7e612c7ca71759c1078602 (diff) |
Cleanup: move temp directory environment checks into a loop
Minimizes ifdef'd code for WIN32.
Diffstat (limited to 'source/blender/blenkernel/intern/appdir.c')
-rw-r--r-- | source/blender/blenkernel/intern/appdir.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index 062716feffc..e5bcc2e836b 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -901,29 +901,25 @@ static void where_is_temp(char *fullname, char *basename, const size_t maxlen, c BLI_strncpy(fullname, userdir, maxlen); } -#ifdef WIN32 if (fullname[0] == '\0') { - const char *tmp = BLI_getenv("TEMP"); /* Windows */ - if (tmp && BLI_is_dir(tmp)) { - BLI_strncpy(fullname, tmp, maxlen); - } - } + const char *env_vars[] = { +#ifdef WIN32 + "TEMP", #else - /* Other OS's - Try TMP and TMPDIR */ - if (fullname[0] == '\0') { - const char *tmp = BLI_getenv("TMP"); - if (tmp && BLI_is_dir(tmp)) { - BLI_strncpy(fullname, tmp, maxlen); - } - } - - if (fullname[0] == '\0') { - const char *tmp = BLI_getenv("TMPDIR"); - if (tmp && BLI_is_dir(tmp)) { - BLI_strncpy(fullname, tmp, maxlen); + /* Non standard (could be removed). */ + "TMP", + /* Posix standard. */ + "TMPDIR", +#endif + }; + for (int i = 0; i < ARRAY_SIZE(env_vars); i++) { + const char *tmp = BLI_getenv(env_vars[i]); /* Windows */ + if (tmp && (tmp[0] != '\0') && BLI_is_dir(tmp)) { + BLI_strncpy(fullname, tmp, maxlen); + break; + } } } -#endif if (fullname[0] == '\0') { BLI_strncpy(fullname, "/tmp/", maxlen); @@ -940,14 +936,13 @@ static void where_is_temp(char *fullname, char *basename, const size_t maxlen, c const size_t ln = strlen(tmp_name) + 1; if (ln <= maxlen) { #ifdef WIN32 - if (_mktemp_s(tmp_name, ln) == 0) { - BLI_dir_create_recursive(tmp_name); - } + const bool ok = (_mktemp_s(tmp_name, ln) == 0); #else - if (mkdtemp(tmp_name) == NULL) { + const bool ok = (mkdtemp(tmp_name) == NULL); +#endif + if (ok) { BLI_dir_create_recursive(tmp_name); } -#endif } if (BLI_is_dir(tmp_name)) { BLI_strncpy(basename, fullname, maxlen); |