How do I find the 'temp' directory in Linux? I am writing a platform neutral C++ function that returns the temp directory. In Mac and Windows, there is an API that returns these results. In Linux, I'm stumped.
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
Check following variables:
TMPDIR
P_tmpdir
macroIf all fails try to use the directory
/tmp
.You can also use
tempnam
function to generate a unique temporary file name.Edit: Fair point from the commenter.
tmpnam
isn't a good choice these days; usemktemp
/mkstemp
instead.Historical answer: Be POSIX compliant, and use tmpnam (which will give you a full filename in a temporary location).
Use the value of the $TMPDIR environment variable, and if that doesn't exist, use
/tmp
.In standard c, you could try: P_tmpdir
The accepted sequence, specifically from a GNU standpoint, is:
If you are adding an extension or module, check to see if the core provides a function for this purpose. For example, PHP exports php_get_temporary_directory() from main/php_open_temporary_file.h.