Hi
This should be more pleasant regarding to coding styles, and add the
missing paths '/usr/local/include' and '/usr/include' to the sourcedirs
as well.
Reading PATH variable instead of relying on hard-coded binary paths
Signed-off-by: Peter Reineke<preineke@xxxxxxx>
---
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 931ff77..3ba8abc 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -57,62 +57,9 @@ void findv(char **, int, char *);
void find(char **, char *);
void findin(char *, char *);
int itsit(char *, char *);
+char **get_path();
-static char *bindirs[] = {
- "/bin",
- "/usr/bin",
- "/sbin",
- "/usr/sbin",
- "/etc",
- "/usr/etc",
- "/lib",
- "/usr/lib",
- "/lib64",
- "/usr/lib64",
- "/usr/games",
- "/usr/games/bin",
- "/usr/games/lib",
- "/usr/emacs/etc",
- "/usr/lib/emacs/*/etc",
- "/usr/TeX/bin",
- "/usr/tex/bin",
- "/usr/interviews/bin/LINUX",
-
- "/usr/X11R6/bin",
- "/usr/X386/bin",
- "/usr/bin/X11",
- "/usr/X11/bin",
- "/usr/X11R5/bin",
-
- "/usr/local/bin",
- "/usr/local/sbin",
- "/usr/local/etc",
- "/usr/local/lib",
- "/usr/local/games",
- "/usr/local/games/bin",
- "/usr/local/emacs/etc",
- "/usr/local/TeX/bin",
- "/usr/local/tex/bin",
- "/usr/local/bin/X11",
-
- "/usr/contrib",
- "/usr/hosts",
- "/usr/include",
-
- "/usr/g++-include",
-
- "/usr/ucb",
- "/usr/old",
- "/usr/new",
- "/usr/local",
- "/usr/libexec",
- "/usr/share",
-
- "/opt/*/bin",
-
- 0
-};
-
+static char **bindirs;
static char *mandirs[] = {
"/usr/man/*",
"/usr/share/man/*",
@@ -124,6 +71,8 @@ static char *mandirs[] = {
};
static char *srcdirs[] = {
+ "/usr/include",
+ "/usr/local/include",
"/usr/src/*",
"/usr/src/lib/libc/*",
"/usr/src/lib/libc/net/*",
@@ -152,7 +101,7 @@ main(int argc, char **argv) {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
-
+ bindirs = get_path();
argc--, argv++;
if (argc == 0) {
usage:
@@ -396,3 +345,26 @@ itsit(char *cp, char *dp) {
}
return (0);
}
+
+char
+**get_path()
+{
+ char *path;
+ path = getenv("PATH");
+ char *buf = strdup(path);
+ char *cp;
+ int count = 1; /* there is one entry more than there are colons */
+ for(cp = buf;*cp;cp++)
+ if (*cp == ':') count++;
+ char **dirs = malloc(sizeof(char*) * (count + 1));
+ /* another entry for the 0 */
+ char **dirp = dirs;
+ *(dirp++) = buf;
+ for(cp=buf;*cp;cp++)
+ if (*cp == ':') {
+ *cp = 0;
+ *(dirp++) = cp + 1;
+ }
+ dirp = 0;
+ return dirs;
+}
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html