Replace "tmpnam" with "mkstemp" to create temporary files.

"mkstemp" creates the temporary file immediately after getting the
filename, which avoids security issues (read tmpnam(3) for details).
This also avoids a warning by gcc 4.9.2.