diff options
-rw-r--r-- | src/build.c | 13 | ||||
-rw-r--r-- | src/filepath.c | 10 | ||||
-rw-r--r-- | src/filepath.h | 3 |
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 |