I need to create a temporary file in my C program, write some data to it, and then invoke an external command (via exec or system) to do some processing on the file I just created. I did not write the external command nor is it feasible to integrate it into my program so I don't think I can share an already open descriptor with it. Therefore, I need to know the name of the temp file created.
The tempname() function does this, but unfortunately it recommends that you don't use itself, due to a possible race condition between getting the name and opening the file, and neither of the functions it recommends (tmpfile and mkstemp) provide a way to find out the actual name of the file created.