lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 29 Nov '05, at 3:48 PM, Chris Marrin wrote:

It is much better to use tmpfile() which returns a FILE* directly, so it can be atomic and avoid duplicate names. It works on both win32 and Linux, and I assume on most other Unices (including Mac OSX).


tmpfile(3) does work on OS X, although there are some stern warnings, which I think apply to all platforms, in the man page:

     These interfaces are provided from System V and ANSI compatibility only.

     Most historic implementations of these functions provide only a limited
     number of possible temporary file names (usually 26) before file names
     will start being recycled.  System V implementations of these functions
     (and of mktemp(3)) use the access(2) system call to determine whether or
     not the temporary file may be created.  This has obvious ramifications
     for setuid or setgid programs, complicating the portable use of these
     interfaces in such programs.

     The tmpfile() interface should not be used in software expected to be
     used on other systems if there is any possibility that the user does not
     wish the temporary file to be publicly readable and writable.

mkstemp or mkstemps are better choices, since they allow greater control over the filename and allow a great scope of randomization. But I'm not sure how standard they are (the man page just says that they're in BSD.)

--Jens