foxygit / doom Log in
commit 63ef4e5d708303f2699612717bb54e780dce2227
Author:     Mr. Myth <141479854+Usinganame@users.noreply.github.com>
AuthorDate: Mon Jun 23 12:48:06 2025 -0500
Commit:     GitHub <noreply@github.com>
CommitDate: Mon Jun 23 19:48:06 2025 +0200

    Use $TMPDIR to find tempdir on Unix (#1748)

    * Properly check for tempdir on Unix

    * Properly check for tempdir on Unix

    * Use M_getenv()

    * Use M_getenv()

    * Revert "Use M_getenv()"

    This reverts commit eedd01409749c8e8edc1b0ca79081683dc67d911.

    * Revert "Use M_getenv()"

    This reverts commit 31437d6097047ba32092848ce980af57c4eb1791.

    * Use spaces instead of tabs

    * Consistancy and correct Unix environment variable

    * Consistancy
---
 src/m_misc.c        | 9 +++++++--
 src/setup/execute.c | 9 +++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/m_misc.c b/src/m_misc.c
index ba1e1889..daa58ff0 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -509,9 +509,14 @@ char *M_TempFile(const char *s)
         tempdir = ".";
     }
 #else
-    // In Unix, just use /tmp.
+    // Check the $TMPDIR environment variable to find the location.

-    tempdir = "/tmp";
+    tempdir = getenv("TMPDIR");
+
+    if (tempdir == NULL)
+    {
+        tempdir = "/tmp";
+    }
 #endif

     return M_StringJoin(tempdir, DIR_SEPARATOR_S, s, NULL);
diff --git a/src/setup/execute.c b/src/setup/execute.c
index 0a86dd7b..2dc0ba85 100644
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -68,9 +68,14 @@ static char *TempFile(const char *s)
         tempdir = ".";
     }
 #else
-    // In Unix, just use /tmp.
+    // Check the $TMPDIR environment variable to find the location.

-    tempdir = "/tmp";
+    tempdir = getenv("TMPDIR");
+
+    if (tempdir == NULL)
+    {
+        tempdir = "/tmp";
+    }
 #endif

     return M_StringJoin(tempdir, DIR_SEPARATOR_S, s, NULL);