aboutsummaryrefslogtreecommitdiffstats
path: root/src/build.c
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2017-08-26 18:16:11 +0200
committerTharre <tharre3@gmail.com>2017-08-26 23:10:09 +0200
commit3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e (patch)
treef1a63e437e9d99c0cec9969ce9bc56eacb50cb7d /src/build.c
parent5d35df94d62b76cb55c14e70b079ceb2c400b326 (diff)
downloadredo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.tar.gz
redo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.tar.xz
redo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.zip
Use the proper RNG called PCG instead of rand()
Fixes #7.
Diffstat (limited to 'src/build.c')
-rw-r--r--src/build.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/build.c b/src/build.c
index 19628cf..83a8a7b 100644
--- a/src/build.c
+++ b/src/build.c
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
+#include <inttypes.h>
#include <libgen.h> /* dirname(), basename() */
@@ -394,6 +395,14 @@ void add_prereq_path(const char *target, const char *parent, int ident) {
free(reltarget);
}
+static uint32_t get_magic_number() {
+ uint32_t magic;
+ if (sscanf(getenv("REDO_MAGIC"), "%"SCNu32, &magic) < 1)
+ die("redo: failed to parse REDO_MAGIC (%s)", getenv("REDO_MAGIC"));
+
+ return magic;
+}
+
/* Update hash & ctime information stored in the given dep_info struct */
static void update_dep_info(dep_info *dep, const char *target) {
FILE *fp = fopen(target, "rb");
@@ -419,10 +428,10 @@ static void write_dep_information(dep_info *dep) {
sha1_to_hex(dep->hash, hash);
char *flags = (dep->flags & DEP_SOURCE) ? "s" : "l";
- int magic = atoi(getenv("REDO_MAGIC"));
+ uint32_t magic = get_magic_number();
/* TODO: casting time_t to long long is probably not entirely portable */
- if (fprintf(fd, "%s:%lld.%.9ld:%010d:%s\n", hash,
+ if (fprintf(fd, "%s:%lld.%.9ld:%"PRIu32":%s\n", hash,
(long long)dep->ctime.tv_sec, dep->ctime.tv_nsec, magic, flags) < 0)
fatal("redo: failed to write to %s", dep->path);