summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-24 10:12:32 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-24 15:33:18 +0200
commit476f02bfa397959ba8a553a36cf5eaffc82b8f07 (patch)
tree2ededf3d652071c7c6c5bdc91b137418a7c923c3 /lib.c
parentd84b53aa06fbcf529deb413e18c5c4f3e562c6dc (diff)
lib: simplify include_path()
Align the path resolving logic with compiler.c and use strrchr() and a width limited printf pattern to extract the directory name portion. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/lib.c b/lib.c
index 1cbde6d..4c9ff81 100644
--- a/lib.c
+++ b/lib.c
@@ -2324,19 +2324,12 @@ include_path(const char *curpath, const char *incpath)
if (*incpath == '/')
return realpath(incpath, NULL);
- if (curpath) {
- dup = strdup(curpath);
+ dup = curpath ? strrchr(curpath, '/') : NULL;
- if (!dup)
- return NULL;
-
- len = asprintf(&res, "%s/%s", dirname(dup), incpath);
-
- free(dup);
- }
- else {
+ if (dup)
+ len = asprintf(&res, "%.*s/%s", (int)(dup - curpath), curpath, incpath);
+ else
len = asprintf(&res, "./%s", incpath);
- }
if (len == -1)
return NULL;