#include <sys/stat.h>
#endif
-using std::string;
-using std::vector;
-
#ifndef ROOTSEP
#define ROOTSEP ':'
#endif
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. */