3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
17 #include "support/lyxlib.h"
18 #include "support/filetools.h"
19 #include "support/tostr.h"
28 int make_tempfile(char * templ)
30 #if defined(HAVE_MKSTEMP)
31 return ::mkstemp(templ);
32 #elif defined(HAVE_MKTEMP)
33 // This probably just barely works...
35 return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
44 string const lyx::support::tempName(string const & dir, string const & mask)
46 string const tmpdir(dir.empty() ? os::getTmpDir() : dir);
47 string tmpfl(AddName(tmpdir, mask));
48 tmpfl += tostr(getpid());
51 // The supposedly safe mkstemp version
52 char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0'
53 tmpfl.copy(tmpl, string::npos);
54 tmpl[tmpfl.length()] = '\0'; // terminator
56 int const tmpf = make_tempfile(tmpl);
61 lyxerr[Debug::FILES] << "Temporary file `" << t
62 << "' created." << endl;
66 << "LyX Error: Unable to create temporary file."