7 #include "support/lyxlib.h"
8 #include "support/filetools.h"
13 extern string system_tempdir;
16 int make_tempfile(char * templ)
19 return ::mkstemp(templ);
22 // This probably just barely works...
24 return ::open(templ, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
31 string const lyx::tempName(string const & dir, string const & mask)
33 string const tmpdir(dir.empty() ? system_tempdir : dir);
34 string tmpfl(AddName(tmpdir, mask));
35 tmpfl += tostr(getpid());
38 // The supposedly safe mkstemp version
39 char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0'
40 tmpfl.copy(tmpl, string::npos);
41 tmpl[tmpfl.length()] = '\0'; // terminator
43 int const tmpf = make_tempfile(tmpl);
48 lyxerr[Debug::FILES] << "Temporary file `" << t
49 << "' created." << endl;
53 << "LyX Error: Unable to create temporary file."