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>
This commit is contained in:
Peter Hutterer 2011-05-11 12:20:50 +10:00
commit ffd4874798
6 changed files with 94 additions and 16 deletions

View file

@ -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) \