]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/findfs.c
Make the ways of using output stream consistent in usage()
[thirdparty/util-linux.git] / misc-utils / findfs.c
index 7935232eba4b8a879d580020eb6d08ad69974e77..7b32dbda33188b2eae7ef802ae91ef6def8e7ec0 100644 (file)
 #include "nls.h"
 #include "closestream.h"
 #include "c.h"
-#include "exitcodes.h"
 
 /* Exit codes used by findfs. */
 #define FINDFS_SUCCESS         0       /* no errors */
 #define FINDFS_NOT_FOUND       1       /* label or uuid cannot be found */
 #define FINDFS_USAGE_ERROR     2       /* user did something unexpected */
 
-static void __attribute__((__noreturn__)) usage(int rc)
+static void __attribute__((__noreturn__)) usage(void)
 {
-       FILE *out = rc ? stderr : stdout;
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] {LABEL,UUID,PARTUUID,PARTLABEL}=<value>\n"),
                program_invocation_short_name);
@@ -33,10 +32,9 @@ static void __attribute__((__noreturn__)) usage(int rc)
        fputs(_("Find a filesystem by label or UUID.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
+       fprintf(out, USAGE_HELP_OPTIONS(16));
        fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
-       exit(rc);
+       exit(FINDFS_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -52,22 +50,23 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
-       if (argc != 2)
+       if (argc != 2) {
                /* we return '2' for backward compatibility
                 * with version from e2fsprogs */
-               usage(FINDFS_USAGE_ERROR);
+               warnx(_("bad usage"));
+               errtryhelp(FINDFS_USAGE_ERROR);
+       }
 
        while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
                switch (c) {
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
+                       print_version(FINDFS_SUCCESS);
                case 'h':
-                       usage(FINDFS_SUCCESS);
+                       usage();
                default:
-                       errtryhelp(EXIT_FAILURE);
+                       errtryhelp(FINDFS_USAGE_ERROR);
                }
 
        dev = blkid_evaluate_tag(argv[1], NULL, NULL);
@@ -77,4 +76,3 @@ int main(int argc, char **argv)
        puts(dev);
        return FINDFS_SUCCESS;
 }
-