summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Kempf <andreaskem@web.de>2019-12-23 13:33:48 (GMT)
committerJan Niklas Hasse <jhasse@bixense.com>2019-12-27 14:54:42 (GMT)
commit35169ddf478c2d18e4ce4bbd006f08bca5e21095 (patch)
treefd5df4fbba5607e437e7825245400aca8a8a0c3a /src
parenta67718de4e5e4f78b6f66c6a3ecd0432941c7df3 (diff)
downloadNinja-35169ddf478c2d18e4ce4bbd006f08bca5e21095.zip
Ninja-35169ddf478c2d18e4ce4bbd006f08bca5e21095.tar.gz
Ninja-35169ddf478c2d18e4ce4bbd006f08bca5e21095.tar.bz2
Fix error handling for getcwd
Quoting from the Linux man page for errno, "The value in errno is significant only when the return value of the call indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions); a function that succeeds is allowed to change errno. The value of errno is never set to zero by any system call or library function." Successful calls to getcwd are allowed to set errno causing the compilation database not to be written. Spurious failures of this nature were observed on AIX. Adjust the error handling for getcwd so that errno is only checked if the call returned NULL.
Diffstat (limited to 'src')
-rw-r--r--src/ninja.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index c24f09d..f39d1a6 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -803,12 +803,14 @@ int NinjaMain::ToolCompilationDatabase(const Options* options, int argc,
bool first = true;
vector<char> cwd;
+ char* success = NULL;
do {
cwd.resize(cwd.size() + 1024);
errno = 0;
- } while (!getcwd(&cwd[0], cwd.size()) && errno == ERANGE);
- if (errno != 0 && errno != ERANGE) {
+ success = getcwd(&cwd[0], cwd.size());
+ } while (!success && errno == ERANGE);
+ if (!success) {
Error("cannot determine working directory: %s", strerror(errno));
return 1;
}