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

402
Vistas
warning: the use of `tmpnam' is dangerous, better use `mkstemp'

(Note: This is not a duplicate question)

I'm using the libc function tmpnam, and getting the following warning:

warning: the use of 'tmpnam' is dangerous, better use 'mkstemp'

My question isn't "how to disable the warning", but rather "what function should I be using instead"? mkstemp doesn't help, because I'm not trying to create a temporary file - I'm creating a temporary directory. And AFAIK, there isn't an API function for that.

So if I'm not supposed to use tmpnam, what am I supposed to use?

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

0

You're looking for mkdtemp:

mkdtemp - create a unique temporary directory

e.g.,

#include <stdlib.h>
#include <string.h>
...
char templatebuf[80];
char *mkdirectory = mkdtemp(strcpy(templatebuf, "/tmp/mkprogXXXXXX"));

using strcpy to ensure the parameter passed to mkdtemp is writable (c89), or

#include <stdlib.h>
...
char templatebuf[] = "/tmp/mkprogXXXXXX";
char *mkdirectory = mkdtemp(templatebuf);

with c99.

Since the feature is "new" (only standardized within the past ten years, though provided in the mid-1990s on Linux), you need to turn the feature on in the header files with a preprocessor definition (which may differ from one platform to another). The simplest for Linux is to define _GNU_SOURCE, e.g.,

gcc -D_GNU_SOURCE -o foo foo.c
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