]> git.lyx.org Git - lyx.git/blobdiff - src/support/tempname.C
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / tempname.C
index f15ec1a6f0d63fc38a93e6a2eb9cb69b5dd1b930..408e332a80b0d92b79517fc5c7fe9d31a1a10f5a 100644 (file)
@@ -1,17 +1,30 @@
+/**
+ * \file tempname.C
+ * 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 <cstdlib>
 #include <unistd.h>
 
-#include "LString.h"
 #include "support/lyxlib.h"
 #include "support/filetools.h"
-#include "support/lstrings.h"
+#include "support/tostr.h"
 #include "debug.h"
 #include "os.h"
 
-using std::endl;
+#include <boost/scoped_array.hpp>
 
+using boost::scoped_array;
+
+using std::string;
+using std::endl;
 
 namespace {
 
@@ -32,7 +45,7 @@ int make_tempfile(char * templ)
 } // namespace anon
 
 
-string const lyx::tempName(string const & dir, string const & mask)
+string const lyx::support::tempName(string const & dir, string const & mask)
 {
        string const tmpdir(dir.empty() ? os::getTmpDir() : dir);
        string tmpfl(AddName(tmpdir, mask));
@@ -40,15 +53,14 @@ string const lyx::tempName(string const & dir, string const & mask)
        tmpfl += "XXXXXX";
 
        // The supposedly safe mkstemp version
-       char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0'
-       tmpfl.copy(tmpl, string::npos);
+       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);
+       int const tmpf = make_tempfile(tmpl.get());
        if (tmpf != -1) {
-               string const t(tmpl);
+               string const t(tmpl.get());
                ::close(tmpf);
-               delete [] tmpl;
                lyxerr[Debug::FILES] << "Temporary file `" << t
                                     << "' created." << endl;
                return t;
@@ -56,7 +68,6 @@ string const lyx::tempName(string const & dir, string const & mask)
                lyxerr[Debug::FILES]
                        << "LyX Error: Unable to create temporary file."
                        << endl;
-               delete [] tmpl;
                return string();
        }
 }