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 | |
| 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')
| -rw-r--r-- | src/build.c | 9 | ||||
| -rw-r--r-- | src/redo.c | 17 | 
2 files changed, 24 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); @@ -3,12 +3,18 @@  #include <stdlib.h>  #include <sys/stat.h>  #include <sys/types.h> +#include <time.h> +#include <math.h> +#include <limits.h>  #include <unistd.h>  #include "build.h"  #include "util.h"  #include "dbg.h" +static inline int digits(unsigned n) { +  return (int) log10(n) + 1; +}  int main(int argc, char *argv[]) {      /* create .redo directory */ @@ -26,6 +32,17 @@ int main(int argc, char *argv[]) {      free(cwd); +    srand(time(NULL)); /* TODO: error checking */ +    unsigned magic = rand(); + +    char magic_str[digits(UINT_MAX) + 1]; +    sprintf(magic_str, "%u", magic); + +    printf("MAGIC: %s\n", magic_str); + +    if (setenv("REDO_MAGIC", magic_str, 0)) +        fatal("setenv()"); +      if (argc < 2) {          build_target("all");      } else {  | 
