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>2020-10-03 11:39:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-10-03 11:50:42 +0300
commit0863ae0a5836ab91e44c86b4e32715e847631bba (patch)
treeea1c8bf7898d6f00a88a3608419055a953931d06
parentcacd84a318dfc61e4e7e612c7ca71759c1078602 (diff)
Cleanup: move temp directory environment checks into a loop
Minimizes ifdef'd code for WIN32.
-rw-r--r--source/blender/blenkernel/intern/appdir.c43
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);