I'm writing tests for a library that need to create a directories to test some functional it should provide. I did some research and found that there is a library function:
#include <stdio.h>
char *tmpnam(char *s);
And it is possible to call it with NULL to unique path. The problem is the linker warns me as follows:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'
Also as suggested in this answer to use the function. But this hardcoding /tmp in the beginning looks strage. Also checking the environment variables TMP, TMPDIR, etc looks complicated.
Maybe there is some POSIX function which checks theses variables for me? Also is there any other pitfalls of using tmpnam except shared static buffer and race conditions?