summaryrefslogtreecommitdiff
path: root/src/m_misc.c
diff options
context:
space:
mode:
authorSimon Howard2007-01-06 00:34:50 +0000
committerSimon Howard2007-01-06 00:34:50 +0000
commitcb7cf979369b5b3b4db0154368e379ae8ab8aa25 (patch)
tree60ec72d798bb044af479cf0edcf00ae7f77f3c55 /src/m_misc.c
parenta4fec80d22871128288632ec47e21f5f4b99f27b (diff)
downloadchocolate-doom-cb7cf979369b5b3b4db0154368e379ae8ab8aa25.tar.gz
chocolate-doom-cb7cf979369b5b3b4db0154368e379ae8ab8aa25.tar.bz2
chocolate-doom-cb7cf979369b5b3b4db0154368e379ae8ab8aa25.zip
Choose the locations for temporary files more intelligently.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 821
Diffstat (limited to 'src/m_misc.c')
-rw-r--r--src/m_misc.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/m_misc.c b/src/m_misc.c
index 5b98960a..13ca6768 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -198,6 +198,37 @@ int M_ReadFile(char const *name, byte **buffer)
return length;
}
+// Returns the path to a temporary file of the given name, stored
+// inside the system temporary directory.
+//
+// The returned value must be freed with Z_Free after use.
+
+char *M_TempFile(char *s)
+{
+ char *result;
+ char *tempdir;
+
+#ifdef _WIN32
+
+ // Check the TEMP environment variable to find the location.
+
+ temp = getenv("TEMP");
+
+ if (temp == NULL)
+ {
+ tempdir = ".";
+ }
+#else
+ // In Unix, just use /tmp.
+
+ tempdir = "/tmp";
+#endif
+
+ result = Z_Malloc(strlen(tempdir) + strlen(s) + 2, PU_STATIC, 0);
+ sprintf(result, "%s%c%s", tempdir, DIR_SEPARATOR, s);
+
+ return result;
+}
//
// DEFAULTS