aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.c9
-rw-r--r--src/redo.c17
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);
diff --git a/src/redo.c b/src/redo.c
index 69f9ade..0209a4f 100644
--- a/src/redo.c
+++ b/src/redo.c
@@ -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 {