]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/file-name.cc
Web-ja: update introduction
[lilypond.git] / flower / file-name.cc
index 71b3bf27b5063a469acf05bec3c26bd18cc9f605..990e3d6d9161d983860b0c380e1a1139b17edf9c 100644 (file)
@@ -33,9 +33,6 @@ using namespace std;
 #include <sys/stat.h>
 #endif
 
-using std::string;
-using std::vector;
-
 #ifndef ROOTSEP
 #define ROOTSEP ':'
 #endif
@@ -80,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. */