generate a unique temporary file name from the template, creates and opens the file.
luarocks install mkstemp
local mkstemp = require('mkstemp')
local f, err, pathname = mkstemp('/tmp/lua_XXXXXX')
assert(f, err)
print(pathname) -- /tmp/lua_Wo6kHb
the following functions return the error
object created by https://github.com/mah0x211/lua-errno module.
this function takes the given file name template tmpl
and overwrites a portion of it to create a file name and the template file.
see man mkstemp
for more details.
Parameters
tmpl:string
: filename template.
Returns
f:file
: a lua file handle.err:error
:error
object on failure.pathname:string
: pathname of the created file.