From 2bf8848fb5c85ace0f445c0820a0c173cf76bf43 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Fri, 17 Jun 2011 10:19:00 +0200 Subject: [PATCH] Linux: Handle single- and two-digit kernel versions like 3.0 and 4 The code has been tested with various version strings. [stuge: Remove bogus string length check and optimize for newer kernels] --- libusb/os/linux_usbfs.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index ca75779..69a2773 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -220,25 +220,33 @@ static clockid_t find_monotonic_clock(void) static int check_flag_bulk_continuation(void) { struct utsname uts; - int major, minor, sublevel; + int atoms, major, minor, sublevel; if (uname(&uts) < 0) return -1; - if (strlen(uts.release) < 4) + atoms = sscanf(uts.release, "%d.%d.%d", &major, &minor, &sublevel); + if (atoms < 1) + return -1; + + if (major > 2) + return 1; + if (major < 2) return 0; - if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &sublevel) != 3) + + if (atoms < 2) return 0; - if (major < 2) + + /* major == 2 */ + if (minor < 6) return 0; - if (major == 2) { - if (minor < 6) - return 0; - if (minor == 6) { - if (sublevel < 32) - return 0; - } - } - return 1; + if (minor > 6) /* Does not exist, just here for correctness */ + return 1; + + /* 2.6.x */ + if (3 == atoms && sublevel >= 32) + return 1; + + return 0; } /* Return 1 if filename exists inside dirname in sysfs. -- 2.7.4