aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2017-01-31 23:48:53 +0100
committerTharre <tharre3@gmail.com>2017-01-31 23:53:41 +0100
commit921268159d96efeb136fcfd29e8ba3212fd0a507 (patch)
tree0a557a29ce38a61efffd4d89278f28b397d5398b /src
parenta1b25d96c528370c71c64a0e13570be435dcd0f9 (diff)
downloadredo-921268159d96efeb136fcfd29e8ba3212fd0a507.tar.gz
redo-921268159d96efeb136fcfd29e8ba3212fd0a507.tar.xz
redo-921268159d96efeb136fcfd29e8ba3212fd0a507.zip
Add make_abs() utility function
Diffstat (limited to 'src')
-rw-r--r--src/build.c13
-rw-r--r--src/filepath.c10
-rw-r--r--src/filepath.h3
3 files changed, 14 insertions, 12 deletions
diff --git a/src/build.c b/src/build.c
index ffeeab2..0796e11 100644
--- a/src/build.c
+++ b/src/build.c
@@ -1,6 +1,6 @@
/* build.c
*
- * Copyright (c) 2014-2016 Tharre
+ * Copyright (c) 2014-2017 Tharre
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
@@ -555,17 +555,10 @@ static int handle_c(dep_info *dep) {
dsv_init(&ctx_prereq, 2);
while (!dsv_parse_file(&ctx_prereq, prereqfd)) {
- char *target, *abs = NULL;
- if (!is_absolute(ctx_prereq.fields[1])) {
- abs = concat(3, getenv("REDO_ROOT"), "/", ctx_prereq.fields[1]);
- target = abs;
- } else {
- target = ctx_prereq.fields[1];
- }
-
+ char *target = make_abs(getenv("REDO_ROOT"), ctx_prereq.fields[1]);
int outofdate = update_target(target, ctx_prereq.fields[0][0]);
- free(abs);
+ free(target);
free(ctx_prereq.fields[0]);
free(ctx_prereq.fields[1]);
diff --git a/src/filepath.c b/src/filepath.c
index 2186881..b752e08 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -1,6 +1,6 @@
/* filepath.c
*
- * Copyright (c) 2014 Tharre
+ * Copyright (c) 2014-2017 Tharre
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
@@ -125,3 +125,11 @@ void mkpath(char *path, mode_t mode) {
*p = '/';
}
}
+
+/* Make path absolute by prepending root, if path isn't already absolute. */
+char *make_abs(char *root, char *path) {
+ if (!is_absolute(path))
+ return concat(3, root, "/", path);
+ else
+ return xstrdup(path);
+}
diff --git a/src/filepath.h b/src/filepath.h
index 2735e45..13382af 100644
--- a/src/filepath.h
+++ b/src/filepath.h
@@ -1,6 +1,6 @@
/* filepath.h
*
- * Copyright (c) 2014 Tharre
+ * Copyright (c) 2014-2017 Tharre
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
@@ -19,5 +19,6 @@ extern char *xbasename(const char *path);
extern bool fexists(const char *target);
extern off_t fsize(const char *fn);
extern void mkpath(char *path, mode_t mode);
+extern char *make_abs(char *root, char *path);
#endif