How do I find the 'temp' directory in Linux? I am writing a platform neutral C++ function that returns the temp directory. In Mac an Windows, there is an API that returns these results. In Linux, I'm stomped.
+5
A:
Use the value of the $TMPDIR environment variable, and if that doesn't exist, use /tmp
.
Greg Hewgill
2008-08-27 19:59:13
+6
A:
Be POSIX compliant, and use tmpnam (which will give you a full filename in a temporary location).
Adam Wright
2008-08-27 20:00:04
+5
A:
Check following variables:
- The environment variable TMPDIR
- The value of the P_tmpdir macro
If all fails try to use the directory `/tmp'.
You can also use tempnam function to generate a unique temporary file name.
Greg Dan
2008-08-27 20:06:25
+1
A:
Not so much an answer as another question: would the method that you use on OS X not work on linux? After all, OS X is another POSIX.
Jason Baker
2008-08-27 20:06:27