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