diff options
author | Nico Weber <thakis@chromium.org> | 2013-04-09 00:18:30 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2013-04-09 04:13:20 (GMT) |
commit | c78e1eea9a385340a1d47d5402f5a7c41f99c95d (patch) | |
tree | 227c665ad08787d6652d138fe0b72af5d33c73b1 /src | |
parent | ba1642091f67f3e71da1fe2768dd54146beb9c63 (diff) | |
download | Ninja-c78e1eea9a385340a1d47d5402f5a7c41f99c95d.zip Ninja-c78e1eea9a385340a1d47d5402f5a7c41f99c95d.tar.gz Ninja-c78e1eea9a385340a1d47d5402f5a7c41f99c95d.tar.bz2 |
Write the depslog version in binary instead of text.
This way, it doubles as a byte-order marker. The header is now exactly one
line in a hex editor, and it's still relatively easy to look at the version
in a text editor.
Diffstat (limited to 'src')
-rw-r--r-- | src/deps_log.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index 5590a32..8946e32 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -25,10 +25,10 @@ #include "state.h" #include "util.h" -namespace { -const char kFileSignature[] = "# ninja deps v%d\n"; +// The version is stored as 4 bytes after the signature and also serves as a +// byte order mark. Signature and version combined are 16 bytes long. +const char kFileSignature[] = "# ninjadeps\n"; const int kCurrentVersion = 1; -} // anonymous namespace DepsLog::~DepsLog() { Close(); @@ -47,7 +47,11 @@ bool DepsLog::OpenForWrite(const string& path, string* err) { fseek(file_, 0, SEEK_END); if (ftell(file_) == 0) { - if (fprintf(file_, kFileSignature, kCurrentVersion) < 0) { + if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, file_) < 1) { + *err = strerror(errno); + return false; + } + if (fwrite(&kCurrentVersion, 4, 1, file_) < 1) { *err = strerror(errno); return false; } @@ -137,7 +141,10 @@ bool DepsLog::Load(const string& path, State* state, string* err) { return false; } int version = 0; - sscanf(buf, kFileSignature, &version); + if (fread(&version, 4, 1, f) < 1) { + *err = strerror(errno); + return false; + } if (version != kCurrentVersion) { *err = "bad deps log signature or version; starting over"; fclose(f); |