aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-02-01 11:07:57 +0000
committerOmar Polo <op@omarpolo.com>2021-02-01 11:07:57 +0000
commitbcf5d929e608a3c61a79f5c021478760db54d271 (patch)
treecaa0512af97041a4eb19f66f998ee834806598fb /utils.c
parent6ff23c673989f92a42da0029728fe80ca3dde40f (diff)
ensure absolute paths in config-less mode
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index a87c927..c32ecb8 100644
--- a/utils.c
+++ b/utils.c
@@ -62,3 +62,21 @@ filesize(int fd)
return -1;
return len;
}
+
+char *
+absolutify_path(const char *path)
+{
+ char *wd, *r;
+
+ if (*path == '/') {
+ if ((r = strdup(path)) == NULL)
+ err(1, "strdup");
+ return r;
+ }
+
+ wd = getcwd(NULL, 0);
+ if (asprintf(&r, "%s/%s", wd, path) == -1)
+ err(1, "asprintf");
+ free(wd);
+ return r;
+}