lua-users home
lua-l archive

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

If you are single threaded, I have used schemes like

filename = os.getenv"TEMP" .. "myprog" .. tostring(getpid()) .. tostring(seq)

At least you get to choose where the file goes. tmpname() (as you point out)
is not good on windows.


On 12/1/05, Frederico Rodrigues Abraham <> wrote:
> yea, i saw this function, but i only want the filename so i can pass to
> a library who does the fopen...
> since i'm single-thread, i guess tmpname() will do fine...
> thanks
> -- Fred
> > 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!
> >