Suppress warning: the use of `mktemp' is dangerous

Konstantin picture Konstantin · Apr 12, 2009 · Viewed 15.4k times · Source

How can I suppress following warning from gcc linker:

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

I do know that it's better to use mkstemp() but for some reason I have to use mktemp() function.

Answer

quinmars picture quinmars · Apr 12, 2009

I guess you need the path because you pass it to a library that only accepts path names as argument and not file descriptors or FILE pointers. If so you can create a temp dir with mkdtemp and place your file there, the actual name is then unimportant because the path is already unique because of the directory.