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