On 24 September 2012 12:26, Simon Josefsson <[email protected]> wrote: > Reuben Thomas <[email protected]> writes: > >> I'm trying to rewrite some code that uses tmpname to use mkstemp. >> Unfortunately, I can't see a simple way to get a good location for >> temporary files independently of tmpname. P_tmpdir is obsolescent and >> optional, and it seems that there's no other POSIX way to get at "the >> path commonly known as /tmp". > > Am I missing something, or why couldn't you use getenv("TMPDIR")? It is > defined by POSIX: > > http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html > > If it is not available, falling back to "/tmp" would not be an error as > far as I can tell. POSIX environments should have TMPDIR defined.
That's interesting: on my Ubuntu system I can find no trace of TMPDIR in the system settings or default user settings, and I therefore mistakenly assumed it wouldn't help. I imagine TMPDIR is not set because /tmp is guaranteed by the FHS, so your scheme certainly covers this case too. Thanks! -- http://rrt.sc3d.org
