A program I'm working on needs a temporary directory. However, I would like to stick to POSIX.1-2001. With this constraint, is there a way around using tmpnam
? I know the security problems, but that isn't a concern of mine. The reason for me not to use it is that it is marked obsolete in POSIX.1-2008. At what point will obsolete functions be removed?
In POSIX 2001 (2004), you'll probably have to use mktemp()
to create the name and then mkdir()
to create a directory with that name. This could lead to TOCTOU (time-of-check, time-of-use) problems with symlinks etc. However, with that said, the mktemp()
function does not appear in POSIX 2008 (so functions are removed sometimes), but it is probably in the library of every system still. The tmpnam()
function is present in both versions of POSIX.
In POSIX 2008, you'd be able to use mkdtemp()
instead, which has security advantages.