]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/file-name.cc
Doc-es: various updates.
[lilypond.git] / flower / file-name.cc
index 24db2021b0600edc3d5451cbe462ae9b2ab5078c..990e3d6d9161d983860b0c380e1a1139b17edf9c 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <limits.h>
 
+using namespace std;
 
 #include "config.hh"
 
@@ -32,9 +33,6 @@
 #include <sys/stat.h>
 #endif
 
-using std::string;
-using std::vector;
-
 #ifndef ROOTSEP
 #define ROOTSEP ':'
 #endif
@@ -79,9 +77,21 @@ dir_name (const string &file_name)
 string
 get_working_directory ()
 {
-  char cwd[PATH_MAX];
-  // getcwd returns NULL upon a failure, contents of cwd would be undefined!
-  return string (getcwd (cwd, PATH_MAX));
+#ifdef PATH_MAX
+  vector<char> cwd (PATH_MAX);
+#else
+  vector<char> cwd (1024);
+#endif
+  while (getcwd (cwd.data (), cwd.size ()) == NULL)
+    {
+      if (errno != ERANGE)
+        {
+          // getcwd () fails.
+          return "";
+        }
+      cwd.resize (cwd.size () * 2);
+    }
+  return string (cwd.data ());
 }
 
 /* Join components to full file_name. */