|
From: Lars H. <lhe...@us...> - 2003-11-25 13:04:56
|
Hans-Bernhard Broeker writes: > On Tue, 25 Nov 2003, Petr Mikulik wrote: > > > Man page of tmpnam() and of tempnam() says: > > Never use this function. Use mkstemp(3) instead. > > > > Is there any safe and portable way to create a file in a temporary > > directory, like /tmp or C:\TMP? > > <stdio.h>: FILE *tmpfile(void) > > It may not be particularly safe, but it's as portable as they come, being > an ANSI/ISO C Standard Library function. You get no control whatsoever > about the directory it places the file in, though. It is quite difficult to do this portably and securly (avoiding races). It's probably best to create a temporary directory (mkdtemp() if available), chmod 700 it, and create all temp files in that directory. I've written some not terribly intelligent code like this for amavis. |