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:
parent
016fd2633e
commit
cddad6fccd
1 changed files with 13 additions and 5 deletions
|
@ -1098,11 +1098,15 @@ static char *escape_glob_pattern(const char *pattern)
|
||||||
|
|
||||||
static char *prepend_dir(const char *dir, const char *path)
|
static char *prepend_dir(const char *dir, const char *path)
|
||||||
{
|
{
|
||||||
char *newpath;
|
if(dir == NULL) {
|
||||||
size_t dlen = strlen(dir);
|
return strdup(path);
|
||||||
const char *sep = dlen && dir[dlen - 1] == '/' ? "" : "/";
|
} else {
|
||||||
while(path[0] == '/') { path++; }
|
char *newpath;
|
||||||
return pm_asprintf(&newpath, "%s%s%s", dir, sep, path) == -1 ? NULL : 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,
|
static int globdir(const char *dir, const char *pattern, int flags,
|
||||||
|
@ -1111,6 +1115,10 @@ static int globdir(const char *dir, const char *pattern, int flags,
|
||||||
int gret;
|
int gret;
|
||||||
char *fullpattern = NULL, *escaped_dir = NULL;
|
char *fullpattern = NULL, *escaped_dir = NULL;
|
||||||
|
|
||||||
|
if(dir == NULL) {
|
||||||
|
return glob(pattern, flags, errfunc, globbuf);
|
||||||
|
}
|
||||||
|
|
||||||
if((escaped_dir = escape_glob_pattern(dir)) == NULL) {
|
if((escaped_dir = escape_glob_pattern(dir)) == NULL) {
|
||||||
goto nospace;
|
goto nospace;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue