<p>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.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>

[{'answer_id': 31080, 'author': 'jm.', 'author_id': 814, 'author_profile': 'https://Stackoverflow.com/users/814', 'pm_score': 1, 'selected': False, 'text': '<p>In standard c, you could try: P_tmpdir</p>\n'}, {'answer_id': 31081, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 4, 'selected': False, 'text': "<p>Use the value of the $TMPDIR environment variable, and if that doesn't exist, use <code>/tmp</code>.</p>\n"}, {'answer_id': 31083, 'author': 'Adam Wright', 'author_id': 1200, 'author_profile': 'https://Stackoverflow.com/users/1200', 'pm_score': 4, 'selected': False, 'text': "<p>Edit: Fair point from the commenter. <code>tmpnam</code> isn't a good choice these days; use <code>mktemp</code>/<code>mkstemp</code> instead.</p>\n\n<p><em>Historical answer: Be POSIX compliant, and use tmpnam (which will give you a full filename in a temporary location).</em></p>\n"}, {'answer_id': 31100, 'author': 'Greg Dan', 'author_id': 3315, 'author_profile': 'https://Stackoverflow.com/users/3315', 'pm_score': 5, 'selected': False, 'text': '<p>Check following variables:</p>\n\n<ul>\n<li>The environment variable <code>TMPDIR</code></li>\n<li>The value of the <a href="http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html#index-P_005ftmpdir-1608" rel="noreferrer"><code>P_tmpdir</code> macro</a></li>\n</ul>\n\n<p>If all fails try to use the directory <code>/tmp</code>.</p>\n\n<p>You can also use <code>tempnam</code> function to generate a unique temporary file name.</p>\n'}, {'answer_id': 18500978, 'author': 'Borgboy', 'author_id': 2708979, 'author_profile': 'https://Stackoverflow.com/users/2708979', 'pm_score': 4, 'selected': False, 'text': '<p>The accepted sequence, specifically from a GNU standpoint, is:</p>\n\n<ol>\n<li>Check the environmental variable <strong>TMPDIR</strong> (<em>getenv("TMPDIR")</em>) only if\nthe program is not running as <strong>SUID/SGID</strong> (<em>issetugid() == 0</em>)</li>\n<li>Otherwise use <strong>P_tmpdir</strong> if it is defined and is valid</li>\n<li>and finally, should those fail, use <strong>_PATH_TMP</strong> available from paths.h</li>\n</ol>\n\n<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/31068', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3313/']