mkstemp() does not take file mode flags, so to get the correct file permissions on the file, we need to either use umask() (not thread-friendly) or fchmod().