From c87eace134fa3975b3b1a94dee4231cc5a8a086a Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 13 Jan 2017 15:26:55 +0100 Subject: [PATCH] tools-common: add a function displaying the version info Signed-off-by: Bartosz Golaszewski --- tools-common.c | 22 ++++++++++++++++++++++ tools-common.h | 1 + 2 files changed, 23 insertions(+) diff --git a/tools-common.c b/tools-common.c index 713a703..1ba234a 100644 --- a/tools-common.c +++ b/tools-common.c @@ -13,7 +13,9 @@ #include #include +#include #include +#include #define NORETURN __attribute__((noreturn)) @@ -54,3 +56,23 @@ void NORETURN PRINTF(1, 2) die_perror(const char *fmt, ...) exit(EXIT_FAILURE); } + +void print_version(void) +{ + char *prog, *tmp; + + tmp = strdup(progname); + if (!tmp) + prog = progname; + else + prog = basename(tmp); + + printf("%s (libgpiod) %s\n", prog, gpiod_version_string()); + printf("Copyright (C) 2017 Bartosz Golaszewski\n"); + printf("License GPLv3+: GNU GPL version 3 or later\n"); + printf("This is free software: you are free to change and redistribute it.\n"); + printf("There is NO WARRANTY, to the extent permitted by law.\n"); + + if (tmp) + free(tmp); +} diff --git a/tools-common.h b/tools-common.h index e31d438..391c93b 100644 --- a/tools-common.h +++ b/tools-common.h @@ -25,5 +25,6 @@ void set_progname(char *name); const char * get_progname(void); void die(const char *fmt, ...); void die_perror(const char *fmt, ...); +void print_version(void); #endif /* __GPIOD_TOOLS_COMMON_H__ */ -- 2.30.2