I'm trying to use Lua's os.tmpname() on Windows (which uses tmpnam() under the hood), and I'm a bit puzzled by the filenames it is returning.
> print(os.tmpname())
\s3e8.
If I feed it directly to Lua like io.open(os.tmpname(), "w"), it will attempt to create the file in the root directory of the current drive. This seems pretty inappropriate, since we often don't have the permission to do that.
But according to this thread:
https://mingw-users.narkive.com/L7VR1gxX/temporary-file-woes
This is apparently supposed to be a path relative to the current directory. They mentioned this snippet from a Microsoft documentation:
Note than when a file name is prepended with a back slash and no path information, such as \fname21, this indicates that the name is valid for the current working directory.
But I can no longer find the documentation they mentioned in the thread. I googled around, trying to find the latest documentation and found this: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/tempnam-wtempnam-tmpnam-wtmpnam?view=msvc-160
This is the generation rules mentioned in the documentation above:
_tempnam will generate a unique file name for a directory chosen by the following rules:
If the TMP environment variable is defined and set to a valid directory name, unique file names will be generated for the directory specified by TMP.
If the TMP environment variable is not defined or if it is set to the name of a directory that does not exist, _tempnam will use the dir parameter as the path for which it will generate unique names.
If the TMP environment variable is not defined or if it is set to the name of a directory that does not exist, and if dir is either NULL or set to the name of a directory that does not exist, _tempnam will use the current working directory to generate unique names. Currently, if both TMP and dir specify names of directories that do not exist, the _tempnam function call will fail.
I do have the TMP environment variable defined, but Lua always generates the kind of paths I mentioned at the top.
So really, I have two questions:
- Is this actually supposed to be a relative path?
- If so why does it always generate a relative path, instead of using the standard
TMPvariables?
I'm testing this with Lua 5.2 from LuaBinaries and the Lua statically built into shinchiro's mpv builds.