diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-06-17 10:19:00 +0200 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2011-09-15 15:16:20 +0200 |
commit | 2bf8848fb5c85ace0f445c0820a0c173cf76bf43 (patch) | |
tree | 44f2a3074b9f7f50420a670662cff61b258f86f4 | |
parent | 0288bf24f91eca9f433ebad91a7eb6c0e3e29133 (diff) | |
download | libusb-2bf8848fb5c85ace0f445c0820a0c173cf76bf43.tar.gz |
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]
-rw-r--r-- | libusb/os/linux_usbfs.c | 34 |
1 files 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. |