lua-users home
lua-l archive

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


On Wednesday, April 22, 2015 12:03:44 PM 书呆彭 wrote:
> NOTE: on a windows platform, use ``os.getenv("TMP") .. os.tmpname()``
> instead.

Don't you mean ``os.getenv("TEMP)``? [1]

If you are working in a modern BSD-like environment, see if mkstemps [2] is 
available. This is the only temporary name function I know of that allows you 
to control the suffix. mkstemp is exposed by Luaposix [3] but it requires the 
template to end with "XXXXXX". Similarly, Windows has GetTempFileName [4] but 
always adds ".TMP".

If you must name temporary files a particular way, you'll have to roll your own 
generator using a sufficiently unpredictable source of names (UUIDs are good 
enough, usually) and the POSIX exclusive create flags for security.

[1] http://blogs.msdn.com/b/oldnewthing/archive/2015/04/17/10608077.aspx
[2] http://man.cx/mkstemps
[3] http://luaposix.github.io/luaposix/modules/posix.stdlib.html#mkstemp
[4] https://msdn.microsoft.com/en-us/library/windows/desktop/aa364991(v=vs.85).aspx

-- 
tom <telliamed@whoopdedo.org>