]> git.lyx.org Git - lyx.git/blobdiff - src/support/getcwd.C
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / getcwd.C
index edf38b3ce59662364881f77d9d2031bfcfce4864..95f7c5ddd9d19dad423e8470492aa438bddfd236 100644 (file)
@@ -1,3 +1,13 @@
+/**
+ * \file getcwd.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 <cerrno>
@@ -5,7 +15,16 @@
 
 #include "support/lyxlib.h"
 
-static inline
+#include <boost/scoped_array.hpp>
+
+using boost::scoped_array;
+
+using std::string;
+
+
+namespace {
+
+inline
 char * l_getcwd(char * buffer, size_t size)
 {
 #ifndef __EMX__
@@ -15,24 +34,25 @@ char * l_getcwd(char * buffer, size_t size)
 #endif
 }
 
+} // namespace anon
+
 
 // Returns current working directory
-string const lyx::getcwd()
+string const lyx::support::getcwd()
 {
-       int n = 256;    // Assume path is less than 256 chars
+       int n = 256;    // Assume path is less than 256 chars
        char * err;
-       char * tbuf = new char[n];
-       
-       // Safe. Hopefully all getcwds behave this way!
-       while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) {
+       scoped_array<char> tbuf(new char[n]);
+
+       // Safe. Hopefully all getcwds behave this way!
+       while (((err = l_getcwd(tbuf.get(), n)) == 0) && (errno == ERANGE)) {
                // Buffer too small, double the buffersize and try again
-               delete[] tbuf;
-               n = 2 * n;
-               tbuf = new char[n];
-       }
+               n *= 2;
+               tbuf.reset(new char[n]);
+       }
 
        string result;
-       if (err) result = tbuf;
-       delete[] tbuf;
+       if (err)
+               result = tbuf.get();
        return result;
 }