include/c: add print_version() macro
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>
This commit is contained in:
parent
31c66833cb
commit
68224d108d
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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':
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue