util_version: new helper for displaying version info

This is so all utilities can have this flag and not just dtc.

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
Mike Frysinger 2013-04-10 14:29:09 -04:00 committed by Jon Loeliger
parent 97c122eacc
commit 31be4ce7ca
3 changed files with 13 additions and 4 deletions

5
dtc.c
View File

@ -21,8 +21,6 @@
#include "dtc.h" #include "dtc.h"
#include "srcpos.h" #include "srcpos.h"
#include "version_gen.h"
/* /*
* Command line options * Command line options
*/ */
@ -158,8 +156,7 @@ int main(int argc, char *argv[])
srcfile_add_search_path(optarg); srcfile_add_search_path(optarg);
break; break;
case 'v': case 'v':
printf("Version: %s\n", DTC_VERSION); util_version();
exit(0);
case 'H': case 'H':
if (streq(optarg, "legacy")) if (streq(optarg, "legacy"))
phandle_format = PHANDLE_LEGACY; phandle_format = PHANDLE_LEGACY;

7
util.c
View File

@ -34,6 +34,7 @@
#include "libfdt.h" #include "libfdt.h"
#include "util.h" #include "util.h"
#include "version_gen.h"
char *xstrdup(const char *s) char *xstrdup(const char *s)
{ {
@ -374,3 +375,9 @@ void utilfdt_print_data(const char *data, int len)
printf("]"); printf("]");
} }
} }
void util_version(void)
{
printf("Version: %s\n", DTC_VERSION);
exit(0);
}

5
util.h
View File

@ -168,4 +168,9 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size);
*/ */
void utilfdt_print_data(const char *data, int len); void utilfdt_print_data(const char *data, int len);
/**
* Show source version and exit
*/
void util_version(void) __attribute__((noreturn));
#endif /* _UTIL_H */ #endif /* _UTIL_H */