]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/whereis.c
lsblk: keep functions names consistent
[thirdparty/util-linux.git] / misc-utils / whereis.c
index 697d66626d8ae1bebdb69754a61b4e011b38dfd3..828106ffe79ed9b8f9a42d9a221084ce002d1d7f 100644 (file)
@@ -57,7 +57,7 @@
 
 #include "debug.h"
 
-UL_DEBUG_DEFINE_MASK(whereis);
+static UL_DEBUG_DEFINE_MASK(whereis);
 UL_DEBUG_DEFINE_MASKNAMES(whereis) = UL_DEBUG_EMPTY_MASKNAMES;
 
 #define WHEREIS_DEBUG_INIT     (1 << 1)
@@ -72,6 +72,9 @@ UL_DEBUG_DEFINE_MASKNAMES(whereis) = UL_DEBUG_EMPTY_MASKNAMES;
 #define DBG(m, x)       __UL_DBG(whereis, WHEREIS_DEBUG_, m, x)
 #define ON_DBG(m, x)    __UL_DBG_CALL(whereis, WHEREIS_DEBUG_, m, x)
 
+#define UL_DEBUG_CURRENT_MASK  UL_DEBUG_MASK(whereis)
+#include "debugobj.h"
+
 static char uflag = 0;
 
 /* supported types */
@@ -96,6 +99,11 @@ struct wh_dirlist {
 static const char *bindirs[] = {
        "/usr/bin",
        "/usr/sbin",
+#if defined(MULTIARCHTRIPLET)
+       "/lib/" MULTIARCHTRIPLET,
+       "/usr/lib/" MULTIARCHTRIPLET,
+       "/usr/local/lib/" MULTIARCHTRIPLET,
+#endif
        "/usr/lib",
        "/usr/lib64",
        "/bin",
@@ -170,7 +178,7 @@ static const char *srcdirs[] = {
 
 static void whereis_init_debug(void)
 {
-       __UL_INIT_DEBUG(whereis, WHEREIS_DEBUG_, 0, WHEREIS_DEBUG);
+       __UL_INIT_DEBUG_FROM_ENV(whereis, WHEREIS_DEBUG_, 0, WHEREIS_DEBUG);
 }
 
 static const char *whereis_type_to_name(int type)
@@ -183,8 +191,10 @@ static const char *whereis_type_to_name(int type)
        }
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
+
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [-BMS <dir>... -f] <name>\n"), program_invocation_short_name);
 
@@ -201,9 +211,11 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -f         terminate <dirs> argument list\n"), out);
        fputs(_(" -u         search for unusual entries\n"), out);
        fputs(_(" -l         output effective lookup paths\n"), out);
-       fprintf(out, USAGE_MAN_TAIL("whereis(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       fputs(USAGE_SEPARATOR, out);
+       printf(USAGE_HELP_OPTIONS(16));
+       printf(USAGE_MAN_TAIL("whereis(1)"));
+       exit(EXIT_SUCCESS);
 }
 
 static void dirlist_add_dir(struct wh_dirlist **ls0, int type, const char *dir)
@@ -446,7 +458,7 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
        DBG(SEARCH, ul_debug("lookup dirs for '%s' (%s), want: %s %s %s",
                                patbuf, pattern,
                                want & BIN_DIR ? "bin" : "",
-                               want & MAN_DIR ? "min" : "",
+                               want & MAN_DIR ? "man" : "",
                                want & SRC_DIR ? "src" : ""));
        p = strrchr(patbuf, '.');
        if (p)
@@ -502,8 +514,18 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       if (argc == 1)
-               usage(stderr);
+       if (argc <= 1) {
+               warnx(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       } else {
+               /* first arg may be one of our standard longopts */
+               if (!strcmp(argv[1], "--help"))
+                       usage();
+               if (!strcmp(argv[1], "--version")) {
+                       printf(UTIL_LINUX_VERSION);
+                       exit(EXIT_SUCCESS);
+               }
+       }
 
        whereis_init_debug();
 
@@ -547,8 +569,10 @@ int main(int argc, char **argv)
                                opt_f_missing = 0;
                                break;
                        case 'B':
-                               if (*(arg + 1))
-                                       usage(stderr);
+                               if (*(arg + 1)) {
+                                       warnx(_("bad usage"));
+                                       errtryhelp(EXIT_FAILURE);
+                               }
                                i++;
                                free_dirlist(&ls, BIN_DIR);
                                construct_dirlist_from_argv(
@@ -556,8 +580,10 @@ int main(int argc, char **argv)
                                opt_f_missing = 1;
                                break;
                        case 'M':
-                               if (*(arg + 1))
-                                       usage(stderr);
+                               if (*(arg + 1)) {
+                                       warnx(_("bad usage"));
+                                       errtryhelp(EXIT_FAILURE);
+                               }
                                i++;
                                free_dirlist(&ls, MAN_DIR);
                                construct_dirlist_from_argv(
@@ -565,8 +591,10 @@ int main(int argc, char **argv)
                                opt_f_missing = 1;
                                break;
                        case 'S':
-                               if (*(arg + 1))
-                                       usage(stderr);
+                               if (*(arg + 1)) {
+                                       warnx(_("bad usage"));
+                                       errtryhelp(EXIT_FAILURE);
+                               }
                                i++;
                                free_dirlist(&ls, SRC_DIR);
                                construct_dirlist_from_argv(
@@ -604,9 +632,10 @@ int main(int argc, char **argv)
                                printf(UTIL_LINUX_VERSION);
                                return EXIT_SUCCESS;
                        case 'h':
-                               usage(stdout);
+                               usage();
                        default:
-                               usage(stderr);
+                               warnx(_("bad usage"));
+                               errtryhelp(EXIT_FAILURE);
                        }
 
                        if (arg_i < i)          /* moved to the next argv[] item */