From b894a5eca37d8f9bdec070f54fd584bed665b500 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 19 Nov 2012 12:12:38 +0100 Subject: [PATCH] Accept relative rootdir via xbps_handle::rootdir (found by pancake). --- lib/initend.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/initend.c b/lib/initend.c index 87ee2361..806b3f8b 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -167,7 +167,23 @@ xbps_init(struct xbps_handle *xhp) xhp->rootdir = "/"; else xhp->rootdir = cfg_getstr(xhp->cfg, "rootdir"); + } else { + if (xhp->rootdir[0] != '/') { + /* relative path */ + char *buf, path[PATH_MAX-1]; + size_t len; + + if (getcwd(path, sizeof(path)) == NULL) + return ENOTSUP; + + len = strlen(xhp->rootdir) + strlen(path) + 2; + buf = malloc(len); + assert(buf); + snprintf(buf, len, "%s/%s", path, xhp->rootdir); + xhp->rootdir = buf; + } } + if (xhp->cachedir == NULL) { if (xhp->cfg == NULL) xhp->cachedir = XBPS_CACHE_PATH;