summaryrefslogtreecommitdiffstats
path: root/usr.bin/whereis/whereis.c
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>2008-06-20 08:39:42 +0000
committerjoerg <joerg@FreeBSD.org>2008-06-20 08:39:42 +0000
commitd5a0f1178fb64a6b3759c1e685d3c0074406c6ff (patch)
tree52cbc99118110bb9a36d2edc617faea45da76d64 /usr.bin/whereis/whereis.c
parentc5556f0762ea142f2348d3870881beaaead0b8dd (diff)
downloadFreeBSD-src-d5a0f1178fb64a6b3759c1e685d3c0074406c6ff.zip
FreeBSD-src-d5a0f1178fb64a6b3759c1e685d3c0074406c6ff.tar.gz
Make the search for sources in PATH_PORTS more accurate. I only
noticed that a "whereis -qs qemu" matched the distfiles subdir of qemu rather than /usr/ports/emulators/qemu. It now ignores all dot entries in /usr/ports, plus all entries starting with a capital letter (maintenance stuff like Templates, but also includes subdir CVS), plus /usr/ports/distfiles which is simply a magic name in that respect.
Diffstat (limited to 'usr.bin/whereis/whereis.c')
-rw-r--r--usr.bin/whereis/whereis.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c
index 70feb8a..0829f77 100644
--- a/usr.bin/whereis/whereis.c
+++ b/usr.bin/whereis/whereis.c
@@ -329,9 +329,28 @@ defaults(void)
if ((dir = opendir(PATH_PORTS)) == NULL)
err(EX_OSERR, "opendir" PATH_PORTS ")");
while ((dirp = readdir(dir)) != NULL) {
+ /*
+ * Not everything below PATH_PORTS is of
+ * interest. First, all dot files and
+ * directories (e. g. .snap) can be ignored.
+ * Also, all subdirectories starting with a
+ * capital letter are not going to be
+ * examined, as they are used for internal
+ * purposes (Mk, Tools, ...). This also
+ * matches a possible CVS subdirectory.
+ * Finally, the distfiles subdirectory is also
+ * special, and should not be considered to
+ * avoid false matches.
+ */
if (dirp->d_name[0] == '.' ||
- strcmp(dirp->d_name, "CVS") == 0)
- /* ignore dot entries and CVS subdir */
+ /*
+ * isupper() not used on purpose: the
+ * check is supposed to default to the C
+ * locale instead of the current user's
+ * locale.
+ */
+ (dirp->d_name[0] >= 'A' && dirp->d_name[0] <= 'Z') ||
+ strcmp(dirp->d_name, "distfiles") == 0)
continue;
if ((b = malloc(sizeof PATH_PORTS + 1 + dirp->d_namlen))
== NULL)
OpenPOWER on IntegriCloud