diff options
Diffstat (limited to 'ninja/src/util.cc')
-rw-r--r-- | ninja/src/util.cc | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/ninja/src/util.cc b/ninja/src/util.cc index 47a5de2ffbe..ae94d346bc5 100644 --- a/ninja/src/util.cc +++ b/ninja/src/util.cc @@ -197,7 +197,7 @@ bool CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits, case '\\': bits |= bits_mask; *c = '/'; - NINJA_FALLTHROUGH; + // Intentional fallthrough. case '/': bits_mask <<= 1; } @@ -318,8 +318,13 @@ int ReadFile(const string& path, string* contents, string* err) { // This makes a ninja run on a set of 1500 manifest files about 4% faster // than using the generic fopen code below. err->clear(); - HANDLE f = ::CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); + HANDLE f = ::CreateFile(path.c_str(), + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_FLAG_SEQUENTIAL_SCAN, + NULL); if (f == INVALID_HANDLE_VALUE) { err->assign(GetLastErrorString()); return -ENOENT; @@ -346,19 +351,9 @@ int ReadFile(const string& path, string* contents, string* err) { return -errno; } - struct stat st; - if (fstat(fileno(f), &st) < 0) { - err->assign(strerror(errno)); - fclose(f); - return -errno; - } - - // +1 is for the resize in ManifestParser::Load - contents->reserve(st.st_size + 1); - char buf[64 << 10]; size_t len; - while (!feof(f) && (len = fread(buf, 1, sizeof(buf), f)) > 0) { + while ((len = fread(buf, 1, sizeof(buf), f)) > 0) { contents->append(buf, len); } if (ferror(f)) { @@ -442,12 +437,8 @@ string GetLastErrorString() { return msg; } -void Win32Fatal(const char* function, const char* hint) { - if (hint) { - Fatal("%s: %s (%s)", function, GetLastErrorString().c_str(), hint); - } else { - Fatal("%s: %s", function, GetLastErrorString().c_str()); - } +void Win32Fatal(const char* function) { + Fatal("%s: %s", function, GetLastErrorString().c_str()); } #endif @@ -587,7 +578,7 @@ double GetLoadAverage() { string ElideMiddle(const string& str, size_t width) { const int kMargin = 3; // Space for "...". string result = str; - if (result.size() > width) { + if (result.size() + kMargin > width) { size_t elide_size = (width - kMargin) / 2; result = result.substr(0, elide_size) + "..." |