lua-users home
lua-l archive

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

See io.tmpfile in Lua 5.1 beta.

Also, take a look at luaconf.h; if you define LUA_USE_POSIX (or LUA_USE_MKSTEMP), it will use mkstemp instead of tmpnam.

On 29-Nov-05, at 6:48 PM, Chris Marrin wrote:

Frederico Rodrigues Abraham wrote:
   well i solved it using tmpname(NULL,NULL)... it considers the
temporary directory of the system.
   when i use tmpnam() on windows on a non-writable root, the filename
generated (\something) is not writable...
   i guess it's an implementation bug

FYI, tmpnam is considered a very bad function to use. If two processes or threads use it at the same time, it can generate a duplicate filename. 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). That might be a better function to wrap. It has the added benefit of deleting the file automatically when you close it!

chris marrin                ,""$,          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'