3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
17 #include "support/lyxlib.h"
18 #include "support/filetools.h"
19 #include "support/tostr.h"
29 int make_tempfile(char * templ)
31 #if defined(HAVE_MKSTEMP)
32 return ::mkstemp(templ);
33 #elif defined(HAVE_MKTEMP)
34 // This probably just barely works...
36 return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
45 string const lyx::tempName(string const & dir, string const & mask)
47 string const tmpdir(dir.empty() ? os::getTmpDir() : dir);
48 string tmpfl(AddName(tmpdir, mask));
49 tmpfl += tostr(getpid());
52 // The supposedly safe mkstemp version
53 char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0'
54 tmpfl.copy(tmpl, string::npos);
55 tmpl[tmpfl.length()] = '\0'; // terminator
57 int const tmpf = make_tempfile(tmpl);
62 lyxerr[Debug::FILES] << "Temporary file `" << t
63 << "' created." << endl;
67 << "LyX Error: Unable to create temporary file."