From 4f73b850c5a215e6cce7a559650a3cf7ec89d433 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Sun, 16 Nov 2008 12:40:14 +0000 Subject: Added compile-vs-runtime library version checks --- demo-async.c | 2 ++ demo.c | 2 ++ termkey.c | 17 +++++++++++++++++ termkey.h.in | 5 +++++ 4 files changed, 26 insertions(+) diff --git a/demo-async.c b/demo-async.c index d4d0d46..0cb7066 100644 --- a/demo-async.c +++ b/demo-async.c @@ -11,6 +11,8 @@ void on_key(termkey_t *tk, termkey_key *key) } int main(int argc, char *argv[]) { + TERMKEY_CHECK_VERSION; + termkey_t *tk = termkey_new(0, 0); if(!tk) { diff --git a/demo.c b/demo.c index 96e2d24..7424d8f 100644 --- a/demo.c +++ b/demo.c @@ -3,6 +3,8 @@ #include "termkey.h" int main(int argc, char *argv[]) { + TERMKEY_CHECK_VERSION; + char buffer[50]; termkey_t *tk = termkey_new(0, 0); diff --git a/termkey.c b/termkey.c index bebaa9a..f099f5f 100644 --- a/termkey.c +++ b/termkey.c @@ -8,6 +8,23 @@ #include +void termkey_check_version(int major, int minor) +{ + if(major != TERMKEY_VERSION_MAJOR) { + fprintf(stderr, "libtermkey major version mismatch; %d (wants) != %d (library)\n", + major, TERMKEY_VERSION_MAJOR); + exit(1); + } + + if(minor > TERMKEY_VERSION_MINOR) { + fprintf(stderr, "libtermkey minor version mismatch; %d (wants) > %d (library)\n", + minor, TERMKEY_VERSION_MINOR); + exit(1); + } + + // Happy +} + static struct termkey_driver *drivers[] = { &termkey_driver_ti, &termkey_driver_csi, diff --git a/termkey.h.in b/termkey.h.in index 4849923..7f0dc49 100644 --- a/termkey.h.in +++ b/termkey.h.in @@ -7,6 +7,9 @@ #define TERMKEY_VERSION_MAJOR @@VERSION_MAJOR@@ #define TERMKEY_VERSION_MINOR @@VERSION_MINOR@@ +#define TERMKEY_CHECK_VERSION \ + termkey_check_version(TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR) + typedef enum { TERMKEY_SYM_UNKNOWN = -1, TERMKEY_SYM_NONE = 0, @@ -128,6 +131,8 @@ enum { TERMKEY_FLAG_NOTERMIOS = 1 << 4, // Do not make initial termios calls on construction }; +void termkey_check_version(int major, int minor); + termkey_t *termkey_new(int fd, int flags); void termkey_free(termkey_t *tk); void termkey_destroy(termkey_t *tk); -- cgit v1.2.3-70-g09d2