diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-08-24 10:12:32 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-08-24 15:33:18 +0200 |
commit | 476f02bfa397959ba8a553a36cf5eaffc82b8f07 (patch) | |
tree | 2ededf3d652071c7c6c5bdc91b137418a7c923c3 /lib.c | |
parent | d84b53aa06fbcf529deb413e18c5c4f3e562c6dc (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.c | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -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; |