]> 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 8dea9a6adf4689f991785a2d74f0d3ea66c402da..408e332a80b0d92b79517fc5c7fe9d31a1a10f5a 100644 (file)
@@ -3,9 +3,9 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * 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/tostr.h"
 #include "debug.h"
 #include "os.h"
 
+#include <boost/scoped_array.hpp>
+
+using boost::scoped_array;
+
+using std::string;
 using std::endl;
 
 namespace {
@@ -49,15 +53,14 @@ string const lyx::support::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;
@@ -65,7 +68,6 @@ string const lyx::support::tempName(string const & dir, string const & mask)
                lyxerr[Debug::FILES]
                        << "LyX Error: Unable to create temporary file."
                        << endl;
-               delete [] tmpl;
                return string();
        }
 }