]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/c: add print_version() macro
authorKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 11:47:17 +0000 (13:47 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 11:47:17 +0000 (13:47 +0200)
Let's consolidate the version printing code. It also seems better to
use exit() after --version, because it's handled in different way by
ASAN.

It's strange, but ASAN reports leaks after return in main(). Note that
we do not use free-before-exit.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.bfs.c
disk-utils/mkfs.c
misc-utils/blkid.c
sys-utils/mount.c
sys-utils/umount.c

index 5bf8fdfd890beabdf5cacba64e25da38c68f50f9..77f253f1ed6b684b1b39c497a7926238f6084203 100644 (file)
@@ -91,12 +91,6 @@ static void __attribute__((__noreturn__)) usage(void)
        exit(EXIT_SUCCESS);
 }
 
-static void __attribute__ ((__noreturn__)) print_version(void)
-{
-       printf(UTIL_LINUX_VERSION);
-       exit(EXIT_SUCCESS);
-}
-
 int main(int argc, char **argv)
 {
        char *device, *volume, *fsname;
@@ -134,7 +128,7 @@ int main(int argc, char **argv)
                errtryhelp(EXIT_FAILURE);
        }
        if (argc == 2 && !strcmp(argv[1], "-V"))
-               print_version();
+               print_version(EXIT_SUCCESS);
 
        volume = fsname = "      ";     /* is there a default? */
        inodes = 0;
@@ -169,7 +163,7 @@ int main(int argc, char **argv)
                        break;
 
                case VERSION_OPTION:
-                       print_version();
+                       print_version(EXIT_SUCCESS);
                case 'h':
                        usage();
                default:
index 5bcd9613cdd7a83b2860c11c63c9115db9cf5727..fbd575e7e0f349cbc347ab0e7a1b5304dc1c6305 100644 (file)
@@ -61,12 +61,6 @@ static void __attribute__((__noreturn__)) usage(void)
        exit(EXIT_SUCCESS);
 }
 
-static void __attribute__ ((__noreturn__)) print_version(void)
-{
-       printf(UTIL_LINUX_VERSION);
-       exit(EXIT_SUCCESS);
-}
-
 int main(int argc, char **argv)
 {
        char *progname;         /* name of executable to be called */
@@ -89,7 +83,7 @@ int main(int argc, char **argv)
        atexit(close_stdout);
 
        if (argc == 2 && !strcmp(argv[1], "-V"))
-               print_version();
+               print_version(EXIT_SUCCESS);
 
        /* Check commandline options. */
        opterr = 0;
@@ -106,7 +100,7 @@ int main(int argc, char **argv)
                case 'h':
                        usage();
                case VERSION_OPTION:
-                       print_version();
+                       print_version(EXIT_SUCCESS);
                default:
                        optind--;
                        more = 1;
index e94edfcf21c7421309cdbfdaba008a166b00899a..c03e1bb8d3aa037cf5064aefe899331d71aa60fb 100644 (file)
@@ -62,13 +62,6 @@ struct blkid_control {
                raw_chars:1;
 };
 
-static void print_version(FILE *out)
-{
-       fprintf(out, _("%s from %s  (libblkid %s, %s)\n"),
-               program_invocation_short_name, PACKAGE_STRING,
-               LIBBLKID_VERSION, LIBBLKID_DATE);
-}
-
 static void __attribute__((__noreturn__)) usage(void)
 {
        FILE *out = stdout;
@@ -793,7 +786,9 @@ int main(int argc, char **argv)
                        break;
                case 'V':
                case 'v':
-                       print_version(stdout);
+                       fprintf(stdout, _("%s from %s  (libblkid %s, %s)\n"),
+                               program_invocation_short_name, PACKAGE_STRING,
+                               LIBBLKID_VERSION, LIBBLKID_DATE);
                        err = 0;
                        goto exit;
                case 'w':
index b91d4779a71d26dbc32de9dca39673e65c846570..b1b43251e73bf0b4833ac0137f1c0266388c372e 100644 (file)
@@ -73,7 +73,7 @@ static void __attribute__((__noreturn__)) exit_non_root(const char *option)
        errx(MNT_EX_USAGE, _("only root can do that"));
 }
 
-static void __attribute__((__noreturn__)) print_version(void)
+static void __attribute__((__noreturn__)) mount_print_version(void)
 {
        const char *ver = NULL;
        const char **features = NULL, **p;
@@ -708,7 +708,7 @@ int main(int argc, char **argv)
                        mnt_context_enable_verbose(cxt, TRUE);
                        break;
                case 'V':
-                       print_version();
+                       mount_print_version();
                        break;
                case 'w':
                        append_option(cxt, "rw");
index b021088d2fa886af6bd887ff7f01e54e9ef5ee97..929da8d91b5c79d55831afa1a8deb106092895c9 100644 (file)
@@ -53,7 +53,7 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)
 }
 
 
-static void __attribute__((__noreturn__)) print_version(void)
+static void __attribute__((__noreturn__)) umount_print_version(void)
 {
        const char *ver = NULL;
        const char **features = NULL, **p;
@@ -549,7 +549,7 @@ int main(int argc, char **argv)
                        mnt_context_enable_verbose(cxt, TRUE);
                        break;
                case 'V':
-                       print_version();
+                       umount_print_version();
                        break;
                case 'N':
                {