7 #include "support/lyxlib.h"
8 #include "support/filetools.h"
9 #include "support/lstrings.h"
19 int make_tempfile(char * templ)
21 #if defined(HAVE_MKSTEMP)
22 return ::mkstemp(templ);
23 #elif defined(HAVE_MKTEMP)
24 // This probably just barely works...
26 return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
35 string const lyx::tempName(string const & dir, string const & mask)
37 string const tmpdir(dir.empty() ? os::getTmpDir() : dir);
38 string tmpfl(AddName(tmpdir, mask));
39 tmpfl += tostr(getpid());
42 // The supposedly safe mkstemp version
43 char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0'
44 tmpfl.copy(tmpl, string::npos);
45 tmpl[tmpfl.length()] = '\0'; // terminator
47 int const tmpf = make_tempfile(tmpl);
52 lyxerr[Debug::FILES] << "Temporary file `" << t
53 << "' created." << endl;
57 << "LyX Error: Unable to create temporary file."