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