aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-07-29 15:23:21 +0200
committerTharre <tharre3@gmail.com>2014-07-29 15:23:21 +0200
commit2a5673b6bf86f4ba89aabf6ec5c82a2d5479d4ae (patch)
tree1c13fb96b20396c5e9b73ad409a17b72e346d93a
parent058398673a656dd3d58fccb90a94a16fcfc27e71 (diff)
downloadredo-2a5673b6bf86f4ba89aabf6ec5c82a2d5479d4ae.tar.gz
redo-2a5673b6bf86f4ba89aabf6ec5c82a2d5479d4ae.tar.xz
redo-2a5673b6bf86f4ba89aabf6ec5c82a2d5479d4ae.zip
Create .redo and set REDO_ROOT to cwd
-rw-r--r--src/redo.c22
-rw-r--r--src/util.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/redo.c b/src/redo.c
index 68d401e..b1870db 100644
--- a/src/redo.c
+++ b/src/redo.c
@@ -1,9 +1,31 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "build.h"
#include "util.h"
+#include "dbg.h"
+
+/* TODO: for some reason this header is not included */
+int setenv(const char *name, const char *value, int overwrite);
int main(int argc, char *argv[]) {
+ /* create .redo directory */
+ if (mkdir(".redo", 0744))
+ fatal(ERRM_MKDIR, ".redo");
+
+ /* 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);
+
if (argc < 2) {
build_target("all");
} else {
diff --git a/src/util.h b/src/util.h
index 789a404..af6aaf3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -21,6 +21,7 @@
#define ERRM_FORK _PROGNAME": failed to fork() new process"
#define ERRM_REALPATH _PROGNAME": failed to get realpath() of %s"
#define ERRM_STAT _PROGNAME": failed to aquire stat() information about %s"
+#define ERRM_MKDIR _PROGNAME": failed to mkdir() %s"
#define safe_malloc(size) safe_malloc_(size, _FILENAME, __LINE__)
#define safe_realloc(ptr, size) safe_realloc_(ptr, size, _FILENAME, __LINE__)