]> git.lyx.org Git - lyx.git/blobdiff - src/support/getcwd.C
fix compiler warnings about unused parameter
[lyx.git] / src / support / getcwd.C
index edf38b3ce59662364881f77d9d2031bfcfce4864..1a0c3f213f5ea2826d53de0682603835dd847dc0 100644 (file)
@@ -1,38 +1,73 @@
+/**
+ * \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 "support/lyxlib.h"
+#include "support/os.h"
+
+#include <boost/scoped_array.hpp>
+
 #include <cerrno>
-#include <unistd.h>
 
-#include "support/lyxlib.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
+using boost::scoped_array;
 
-static inline
+using std::string;
+
+
+namespace lyx {
+namespace support {
+
+namespace {
+
+inline
 char * l_getcwd(char * buffer, size_t size)
 {
-#ifndef __EMX__
-       return ::getcwd(buffer, size);
+#ifdef _WIN32
+       GetCurrentDirectory(size, buffer);
+       return buffer;
 #else
-       return ::_getcwd2(buffer, size);
+       return ::getcwd(buffer, size);
 #endif
 }
 
+} // namespace anon
+
 
 // Returns current working directory
-string const lyx::getcwd()
+FileName const 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;
-       return result;
+       if (err)
+               result = tbuf.get();
+       return FileName(os::internal_path(to_utf8(from_filesystem8bit(result))));
 }
+
+} // namespace support
+} // namespace lyx