[Bf-blender-cvs] [0863ae0a583] master: Cleanup: move temp directory environment checks into a loop
Campbell Barton
noreply at git.blender.org
Sat Oct 3 10:52:36 CEST 2020
Commit: 0863ae0a5836ab91e44c86b4e32715e847631bba
Author: Campbell Barton
Date: Sat Oct 3 18:39:30 2020 +1000
Branches: master
https://developer.blender.org/rB0863ae0a5836ab91e44c86b4e32715e847631bba
Cleanup: move temp directory environment checks into a loop
Minimizes ifdef'd code for WIN32.
===================================================================
M source/blender/blenkernel/intern/appdir.c
===================================================================
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);
More information about the Bf-blender-cvs
mailing list