tools-common: add a function displaying the version info
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 13 Jan 2017 14:26:55 +0000 (15:26 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 13 Jan 2017 14:26:55 +0000 (15:26 +0100)
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tools-common.c
tools-common.h

index 713a7036df862146f0bae569630fa28634697c78..1ba234aa270d61e1fcbc740417cf52df42ffae48 100644 (file)
@@ -13,7 +13,9 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <stdarg.h>
+#include <libgen.h>
 
 #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);
+}
index e31d43835291476c7b6f9bb7744d6a26d4b11099..391c93b8be65acb34f7687040eb78e24dc6d5320 100644 (file)
@@ -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__ */