conf: make prepend_dir and globdir NULL aware

Allows sysroot to be left NULL.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
Andrew Gregory 2024-02-29 00:02:22 -08:00 committed by Allan McRae
parent 016fd2633e
commit cddad6fccd

View file

@ -1098,12 +1098,16 @@ static char *escape_glob_pattern(const char *pattern)
static char *prepend_dir(const char *dir, const char *path)
{
if(dir == NULL) {
return strdup(path);
} else {
char *newpath;
size_t dlen = strlen(dir);
const char *sep = dlen && dir[dlen - 1] == '/' ? "" : "/";
while(path[0] == '/') { path++; }
return pm_asprintf(&newpath, "%s%s%s", dir, sep, path) == -1 ? NULL : newpath;
}
}
static int globdir(const char *dir, const char *pattern, int flags,
int (*errfunc) (const char *epath, int eerrno), glob_t *globbuf)
@ -1111,6 +1115,10 @@ static int globdir(const char *dir, const char *pattern, int flags,
int gret;
char *fullpattern = NULL, *escaped_dir = NULL;
if(dir == NULL) {
return glob(pattern, flags, errfunc, globbuf);
}
if((escaped_dir = escape_glob_pattern(dir)) == NULL) {
goto nospace;
}