summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ninja.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 947e352..7ee40df 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -495,9 +495,13 @@ void EncodeJSONString(const char *str) {
int ToolCompilationDatabase(Globals* globals, int argc, char* argv[]) {
bool first = true;
- char cwd[PATH_MAX];
+ vector<char> cwd;
- if (!getcwd(cwd, PATH_MAX)) {
+ do {
+ cwd.resize(cwd.size() + 1024);
+ errno = 0;
+ } while (!getcwd(&cwd[0], cwd.size()) && errno == ERANGE);
+ if (errno != 0 && errno != ERANGE) {
Error("cannot determine working directory: %s", strerror(errno));
return 1;
}
@@ -511,7 +515,7 @@ int ToolCompilationDatabase(Globals* globals, int argc, char* argv[]) {
putchar(',');
printf("\n {\n \"directory\": \"");
- EncodeJSONString(cwd);
+ EncodeJSONString(&cwd[0]);
printf("\",\n \"command\": \"");
EncodeJSONString((*e)->EvaluateCommand().c_str());
printf("\",\n \"file\": \"");