diff options
author | Tharre <tharre3@gmail.com> | 2014-08-12 17:18:20 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2014-08-12 17:18:20 +0200 |
commit | 325c8e3992bf7b73714d10a5d2202c89ddbac189 (patch) | |
tree | 145bc56cd19144a43df0055e0a3623078031516c /src/build.c | |
parent | 575076fac483fca12a179dd40e15183b49cb6c8f (diff) | |
download | redo-325c8e3992bf7b73714d10a5d2202c89ddbac189.tar.gz redo-325c8e3992bf7b73714d10a5d2202c89ddbac189.tar.xz redo-325c8e3992bf7b73714d10a5d2202c89ddbac189.zip |
Add the magic number to the dependency record.
The magic number will be used later to determine if a target has already
been rebuild.
Diffstat (limited to 'src/build.c')
-rw-r--r-- | src/build.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/build.c b/src/build.c index 73fc757..d217a23 100644 --- a/src/build.c +++ b/src/build.c @@ -285,8 +285,8 @@ void add_dep(const char *target, int indent) { fp = fopen(dep_path, "w"); if (!fp) fatal(ERRM_FOPEN, dep_path); - /* skip the first n bytes that are reserved for the hash */ - fseek(fp, 20, SEEK_SET); + /* skip the first n bytes that are reserved for the hash + magic number */ + fseek(fp, 20 + sizeof(unsigned int), SEEK_SET); } else { fatal(ERRM_FOPEN, dep_path); } @@ -329,7 +329,9 @@ void hash_file(const char *target, unsigned char (*hash)[20]) { /* Calculate and store the hash of target in the right dependency file */ void write_dep_hash(const char *target) { + assert(getenv("REDO_MAGIC")); unsigned char hash[SHA_DIGEST_LENGTH]; + int magic = atoi(getenv("REDO_MAGIC")); hash_file(target, &hash); @@ -341,6 +343,9 @@ void write_dep_hash(const char *target) { if (write(out, hash, sizeof hash) < (ssize_t) sizeof hash) fatal("redo: failed to write hash to '%s'", dep_path); + if (write(out, &magic, sizeof(unsigned int)) < (ssize_t) sizeof(unsigned int)) + fatal("redo: failed to write magic number to '%s'", dep_path); + if (close(out)) fatal("redo: failed to close file descriptor."); free(dep_path); |