diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-05-11 12:20:50 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-05-13 09:41:50 +1000 |
commit | ffd4874798ba54f86acac75779a15b4babeaa5f3 (patch) | |
tree | 8c6d1954542686e82734fa4f0999cddddd9284dd /include | |
parent | c4f9c3a07dbb05b81c8e2193a083102f710ebb27 (diff) |
include: add version_compare helper function
Compare two version numbers in the major.minor form.
Switch the few users of manual version switching over to the new function.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/misc.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/misc.h b/include/misc.h index 803f5bade..bdcc8cc1e 100644 --- a/include/misc.h +++ b/include/misc.h @@ -223,6 +223,24 @@ pad_to_int32(const int bytes) { extern char** xstrtokenize(const char *str, const char* separators); +/** + * Compare the two version numbers comprising of major.minor. + * + * @return A value less than 0 if a is less than b, 0 if a is equal to b, + * or a value greater than 0 + */ +static inline int +version_compare(uint16_t a_major, uint16_t a_minor, + uint16_t b_major, uint16_t b_minor) +{ + int a, b; + + a = a_major << 16 | a_minor; + b = b_major << 16 | b_minor; + + return (a - b); +} + /* some macros to help swap requests, replies, and events */ #define LengthRestB(stuff) \ |