Lexer lex(0, 0);
istringstream is(s);
lex.setStream(is);
- FileName const name(tempName());
+ FileName const name = FileName::tempName();
switch (readFile(lex, name, true)) {
case failure:
return false;
// lyx2lyx would fail
return wrongversion;
- FileName const tmpfile(tempName());
+ FileName const tmpfile = FileName::tempName();
if (tmpfile.empty()) {
Alert::error(_("Conversion failed"),
bformat(_("%1$s is from a different"
// anyway.
bool failed = false;
- FileName const tmp_ret(tempName(FileName(), "lyxauto"));
+ FileName const tmp_ret = FileName::tempName(FileName(), "lyxauto");
if (!tmp_ret.empty()) {
buffer_.writeFile(tmp_ret);
// assume successful write of tmp_ret
if (!vcs)
return string();
- FileName const tmpf(tempName(FileName(), "lyxvclog"));
+ FileName const tmpf = FileName::tempName(FileName(), "lyxvclog");
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string();
if (format != FORMAT) {
LYXERR(Debug::TCLASS, "Converting layout file from format "
<< format << " to " << FORMAT);
- FileName const tempfile(tempName());
+ FileName const tempfile = FileName::tempName();
error = !layout2layout(filename, tempfile);
if (!error)
error = read(tempfile, rt);
FileName filename;
zipped_ = filename_.isZippedFile();
if (zipped_) {
- unzipped_filename_ = tempName(FileName(), filename_.toFilesystemEncoding());
+ unzipped_filename_ = FileName::tempName(FileName(),
+ filename_.toFilesystemEncoding());
if (unzipped_filename_.empty()) {
setStatus(ErrorConverting);
LYXERR(Debug::GRAPHICS, "\tCould not create temporary file.");
// Add some stuff to create a uniquely named temporary file.
// This file is deleted in loadImage after it is loaded into memory.
- FileName const to_file_base(tempName(FileName(), "CacheItem"));
+ FileName const to_file_base = FileName::tempName(FileName(), "CacheItem");
remove_loaded_file_ = true;
// Remove the temp file, we only want the name...
// Remember to remove the temp file because we only want the name...
static int counter = 0;
string const tmp = "gconvert" + convert<string>(counter++);
- FileName const to_base(tempName(FileName(), tmp));
+ FileName const to_base = FileName::tempName(FileName(), tmp);
to_base.removeFile();
// Create a copy of the file in case the original name contains
TempName::TempName()
{
- FileName const tempname(tempName(FileName(), "lyxext"));
+ FileName const tempname = FileName::tempName(FileName(), "lyxext");
// FIXME: This is unsafe
tempname.removeFile();
// must have an extension for the converter code to work correctly.
{
// In order to avoid parsing problems with command interpreters
// we pass input data through a file
- FileName const cas_tmpfile(tempName(FileName(), "casinput"));
+ FileName const cas_tmpfile = FileName::tempName(FileName(), "casinput");
if (cas_tmpfile.empty()) {
lyxerr << "Warning: cannot create temporary file."
<< endl;
#include "support/FileName.h"
#include "support/FileNameList.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
+#include "support/Package.h"
#include "support/qstring_helpers.h"
#include <QDateTime>
#include <QTime>
#include <boost/assert.hpp>
+#include <boost/scoped_array.hpp>
#include <map>
#include <sstream>
# include <windows.h>
#endif
-#include <fcntl.h>
#include <cerrno>
+#include <fcntl.h>
+
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#if defined(HAVE_MKSTEMP) && ! defined(HAVE_DECL_MKSTEMP)
+extern "C" int mkstemp(char *);
+#endif
+
+#if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
+# ifdef HAVE_IO_H
+# include <io.h>
+# endif
+# ifdef HAVE_PROCESS_H
+# include <process.h>
+# endif
+#endif
using namespace std;
{
LYXERR(Debug::FILES, "isDirWriteable: " << *this);
- FileName const tmpfl(tempName(*this, "lyxwritetest"));
+ FileName const tmpfl = FileName::tempName(*this, "lyxwritetest");
if (tmpfl.empty())
return false;
}
+static int make_tempfile(char * templ)
+{
+#if defined(HAVE_MKSTEMP)
+ return ::mkstemp(templ);
+#elif defined(HAVE_MKTEMP)
+ // This probably just barely works...
+ ::mktemp(templ);
+# if defined (HAVE_OPEN)
+# if (!defined S_IRUSR)
+# define S_IRUSR S_IREAD
+# define S_IWUSR S_IWRITE
+# endif
+ return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+# elif defined (HAVE__OPEN)
+ return ::_open(templ,
+ _O_RDWR | _O_CREAT | _O_EXCL,
+ _S_IREAD | _S_IWRITE);
+# else
+# error No open() function.
+# endif
+#else
+#error FIX FIX FIX
+#endif
+}
+
+
FileName FileName::tempName(FileName const & dir, string const & mask)
{
- return support::tempName(dir, mask);
+ string const tmpdir = dir.empty() ?
+ package().temp_dir().absFilename() : dir.absFilename();
+ string tmpfl = to_filesystem8bit(from_utf8(addName(tmpdir, mask)));
+#if defined (HAVE_GETPID)
+ tmpfl += convert<string>(getpid());
+#elif defined (HAVE__GETPID)
+ tmpfl += convert<string>(_getpid());
+#else
+# error No getpid() function
+#endif
+ tmpfl += "XXXXXX";
+
+ // The supposedly safe mkstemp version
+ // FIXME: why not using std::string directly?
+ boost::scoped_array<char> tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0'
+ tmpfl.copy(tmpl.get(), string::npos);
+ tmpl[tmpfl.length()] = '\0'; // terminator
+
+ int const tmpf = make_tempfile(tmpl.get());
+ if (tmpf != -1) {
+ string const t(to_utf8(from_filesystem8bit(tmpl.get())));
+#if defined (HAVE_CLOSE)
+ ::close(tmpf);
+#elif defined (HAVE__CLOSE)
+ ::_close(tmpf);
+#else
+# error No x() function.
+#endif
+ LYXERR(Debug::FILES, "Temporary file `" << t << "' created.");
+ return FileName(t);
+ }
+ LYXERR(Debug::FILES, "LyX Error: Unable to create temporary file.");
+ return FileName();
}
SignalSlot.cpp \
SignalSlot.h \
SignalSlotPrivate.h \
- tempname.cpp \
textutils.h \
Translator.h \
Timeout.cpp \
LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
<< "createTmpDir: mask=`" << mask << '\'');
- FileName const tmpfl(tempName(tempdir, mask));
- // lyx::tempName actually creates a file to make sure that it
+ FileName const tmpfl = FileName::tempName(tempdir, mask);
+ // FileName::tempName actually creates a file to make sure that it
// stays unique. So we have to delete it before we can create
// a dir with the same name. Note also that we are not thread
// safe because of the gap between unlink and mkdir. (Lgb)
/// FIXME: same here
void abort();
-/// (securely) create a temporary file in the given dir with the given mask
-/// \p mask must be in filesystem encoding
-FileName const tempName(FileName const & dir = FileName(),
- std::string const & mask = std::string());
-
/**
* Returns true if var is approximately equal to number with allowed error
+++ /dev/null
-/**
- * \file tempname.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "support/lyxlib.h"
-
-#include "support/convert.h"
-#include "support/debug.h"
-#include "support/filetools.h"
-#include "support/Package.h"
-
-#include <boost/scoped_array.hpp>
-
-#include <cstdlib>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#if defined(HAVE_MKSTEMP) && ! defined(HAVE_DECL_MKSTEMP)
-extern "C" int mkstemp(char *);
-#endif
-
-#if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
-# include <fcntl.h>
-# ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-# endif
-# ifdef HAVE_IO_H
-# include <io.h>
-# endif
-# ifdef HAVE_PROCESS_H
-# include <process.h>
-# endif
-#endif
-
-using namespace std;
-
-using boost::scoped_array;
-
-namespace lyx {
-namespace support {
-
-namespace {
-
-inline
-int make_tempfile(char * templ)
-{
-#if defined(HAVE_MKSTEMP)
- return ::mkstemp(templ);
-#elif defined(HAVE_MKTEMP)
- // This probably just barely works...
- ::mktemp(templ);
-# if defined (HAVE_OPEN)
-# if (!defined S_IRUSR)
-# define S_IRUSR S_IREAD
-# define S_IWUSR S_IWRITE
-# endif
- return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
-# elif defined (HAVE__OPEN)
- return ::_open(templ,
- _O_RDWR | _O_CREAT | _O_EXCL,
- _S_IREAD | _S_IWRITE);
-# else
-# error No open() function.
-# endif
-#else
-#error FIX FIX FIX
-#endif
-}
-
-} // namespace anon
-
-
-FileName const tempName(FileName const & dir, string const & mask)
-{
- string const tmpdir = dir.empty()
- ? package().temp_dir().absFilename() : dir.absFilename();
- string tmpfl = to_filesystem8bit(from_utf8(addName(tmpdir, mask)));
-#if defined (HAVE_GETPID)
- tmpfl += convert<string>(getpid());
-#elif defined (HAVE__GETPID)
- tmpfl += convert<string>(_getpid());
-#else
-# error No getpid() function
-#endif
- tmpfl += "XXXXXX";
-
- // The supposedly safe mkstemp version
- scoped_array<char> tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0'
- tmpfl.copy(tmpl.get(), string::npos);
- tmpl[tmpfl.length()] = '\0'; // terminator
-
- int const tmpf = make_tempfile(tmpl.get());
- if (tmpf != -1) {
- string const t(to_utf8(from_filesystem8bit(tmpl.get())));
-#if defined (HAVE_CLOSE)
- ::close(tmpf);
-#elif defined (HAVE__CLOSE)
- ::_close(tmpf);
-#else
-# error No x() function.
-#endif
- LYXERR(Debug::FILES, "Temporary file `" << t << "' created.");
- return FileName(t);
- }
- LYXERR(Debug::FILES, "LyX Error: Unable to create temporary file.");
- return FileName();
-}
-
-} // namespace support
-} // namespace lyx