[Libreoffice] warning: the use of `tmpnam' is dangerous, better use `mkstemp'

Jesús Corrius jesus at softcatala.org
Thu Jun 9 14:43:03 PDT 2011

On Thu, Jun 9, 2011 at 11:24 PM, Julien Nabet <serval2412 at yahoo.fr> wrote:
> Hello,
> I had this warning by compiling hwpfilter during some cppcheck cleaning. I
> knew nothing about it so I read some links given by Google.
> It seems mkstemp is safer since it permits "to avoid race conditions".
> In the Unix man of tmpnam, we can read this :
> "
>       Never use this function.  Use mkstemp(3) or tmpfile(3) instead.
> "
> I'm just a beginner in C++ so what's your opinion about it ?

Functions are only dangerous if you don't use them properly ;)

tmpnam exists in the Windows CRT, but not mkstemp so this change will
break the build on Windows. An easy way to fix the build would be to
define mkstemp to be _mkstemp if the platform is Win32.

The best option probably (don't throw tomatoes at me!) would be to use
something similar to this for windows (maybe in sal?):


Jesús Corrius <jesus at softcatala.org>
Document Foundation founding member
Mobile: +34 661 11 38 26
Skype: jcorrius | Twitter: @jcorrius

More information about the LibreOffice mailing list