Call basename() in a portable way.
Pull a copy of the filename string before calling basename(). Change the loop to not return on its own, so we can put a free() statement at the bottom.
This commit is contained in:
parent
6718ba1851
commit
33f5799a81
@ -58,21 +58,26 @@ static int procline(struct str *l, int);
|
||||
bool
|
||||
file_matching(const char *fname)
|
||||
{
|
||||
char *fname_base;
|
||||
char *fname_base, *fname_buf;
|
||||
bool ret;
|
||||
|
||||
ret = finclude ? false : true;
|
||||
fname_base = basename(fname);
|
||||
fname_buf = strdup(fname);
|
||||
if (fname_buf == NULL)
|
||||
err(2, "strdup");
|
||||
fname_base = basename(fname_buf);
|
||||
|
||||
for (unsigned int i = 0; i < fpatterns; ++i) {
|
||||
if (fnmatch(fpattern[i].pat, fname, 0) == 0 ||
|
||||
fnmatch(fpattern[i].pat, fname_base, 0) == 0) {
|
||||
if (fpattern[i].mode == EXCL_PAT)
|
||||
return (false);
|
||||
else
|
||||
if (fpattern[i].mode == EXCL_PAT) {
|
||||
ret = false;
|
||||
break;
|
||||
} else
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
free(fname_buf);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user