aboutsummaryrefslogtreecommitdiffstats
path: root/abspath.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--abspath.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/abspath.c b/abspath.c
index 60454ff..57cd644 100644
--- a/abspath.c
+++ b/abspath.c
@@ -8,7 +8,7 @@ libsimple_abspath(const char *path, const char *relto)
{
size_t size;
int add_slash;
- char *p, *ret;
+ char *p, *ret, *relto_free = NULL;
if (*path == '/') {
ret = strdup(path);
@@ -18,6 +18,13 @@ libsimple_abspath(const char *path, const char *relto)
while (path[0] == '.' && path[1] == '/')
path = &path[2];
+ if (relto) {
+ relto_free = libsimple_getcwd();
+ if (!relto_free)
+ return NULL;
+ relto = relto_free;
+ }
+
add_slash = (strchr(relto, '\0')[-1] != '/');
size = strlen(relto) + strlen(path) + (size_t)(1 + add_slash);
@@ -28,6 +35,7 @@ libsimple_abspath(const char *path, const char *relto)
*p++ = '/';
stpcpy(p, path);
}
+ free(relto_free);
return ret;
}