Make sure to set umask() before calling mkstemp().