From b2a3f4f62375f2571725075c2622b8bf4e555b80 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 14 Aug 2014 18:19:15 +0200 Subject: Make redo actually create the directories it needs --- src/redo.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/redo.c') diff --git a/src/redo.c b/src/redo.c index 40946dc..6cf68c3 100644 --- a/src/redo.c +++ b/src/redo.c @@ -11,6 +11,7 @@ #include "build.h" #include "util.h" #include "dbg.h" +#include "filepath.h" /* Returns the amount of digits a number n has in decimal. */ @@ -19,26 +20,22 @@ static inline int digits(unsigned n) { } int main(int argc, char *argv[]) { - /* create .redo directory */ - if (mkdir(".redo/deps", 0744)) - if (errno != EEXIST) /* TODO: unsafe, dir could be a file or broken symlink */ - fatal(ERRM_MKDIR, ".redo/deps"); + /* create the dependency store if it doesn't already exist */ + mkdirp(".redo"); + mkdirp(".redo/deps"); /* set REDO_ROOT */ char *cwd = getcwd(NULL, 0); if (!cwd) fatal("redo: failed to obtain cwd"); - if (setenv("REDO_ROOT", cwd, 0)) fatal("redo: failed to setenv %s to %s", "REDO_ROOT", cwd); - free(cwd); - srand(time(NULL)); /* TODO: error checking */ - unsigned magic = rand(); - + /* set REDO_MAGIC */ + srand(time(NULL)); char magic_str[digits(UINT_MAX) + 1]; - sprintf(magic_str, "%u", magic); + sprintf(magic_str, "%u", rand()); debug("magic number: %s\n", magic_str); -- cgit v1.2.3-70-g09d2