Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Understanding Lua's os.tmpname() on Windows

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://docs.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:

  1. Is this actually supposed to be a relative path?
  2. If so why does it always generate a relative path, instead of using the standard TMP variables?

I'm testing this with Lua 5.2 from LuaBinaries and the Lua statically built into shinchiro's mpv builds.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

According to this thread on lua-users.org you can try passing null.

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

Also note the Lua 5.2 Reference Manual

When possible, you may prefer to use io.tmpfile, which automatically removes the file when the program ends.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda