svn commit: r303444 - head/usr.bin/grep
Ed Schouten
ed at FreeBSD.org
Thu Jul 28 15:19:49 UTC 2016
Author: ed
Date: Thu Jul 28 15:19:47 2016
New Revision: 303444
URL: https://svnweb.freebsd.org/changeset/base/303444
Log:
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.
Modified:
head/usr.bin/grep/util.c
Modified: head/usr.bin/grep/util.c
==============================================================================
--- head/usr.bin/grep/util.c Thu Jul 28 15:17:12 2016 (r303443)
+++ head/usr.bin/grep/util.c Thu Jul 28 15:19:47 2016 (r303444)
@@ -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);
}
More information about the svn-src-head
mailing list