summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-04-22 10:10:39 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-04-22 10:10:39 +1000
commit4943f2895fa8eac08eee63c1df091d7d63bcc3f4 (patch)
treecb272ed3c2b444c805e843f79ceb635e6f8ca21c /tools
parenta95ca2c82115f0585ca4c17591d9cd2879ad3358 (diff)
downloadlibevdev-4943f2895fa8eac08eee63c1df091d7d63bcc3f4.tar.gz
tools: allow numeric axis values in tweak-device
Not all axes a device may have are assigned a semantic name. https://bugs.freedesktop.org/show_bug.cgi?id=95029 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/libevdev-tweak-device.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/tools/libevdev-tweak-device.c b/tools/libevdev-tweak-device.c
index fc35c13..a051e08 100644
--- a/tools/libevdev-tweak-device.c
+++ b/tools/libevdev-tweak-device.c
@@ -24,6 +24,7 @@
#include <config.h>
#include <getopt.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -94,6 +95,40 @@ parse_resolution_argument(const char *arg, int *xres, int *yres)
return true;
}
+static inline bool
+safe_atoi(const char *str, int *val)
+{
+ char *endptr;
+ long v;
+
+ v = strtol(str, &endptr, 10);
+ if (str == endptr)
+ return false;
+ if (*str != '\0' && *endptr != '\0')
+ return false;
+
+ if (v > INT_MAX || v < INT_MIN)
+ return false;
+
+ *val = v;
+ return true;
+}
+
+static int
+parse_event_code(int type, const char *str)
+{
+ int code;
+
+ code = libevdev_event_code_from_name(type, str);
+ if (code != -1)
+ return code;
+
+ if (safe_atoi(str, &code))
+ return code;
+
+ return -1;
+}
+
static int
parse_options_abs(int argc, char **argv, unsigned int *changes,
int *axis, struct input_absinfo *absinfo)
@@ -122,8 +157,7 @@ parse_options_abs(int argc, char **argv, unsigned int *changes,
switch (c) {
case OPT_ABS:
- *axis = libevdev_event_code_from_name(EV_ABS,
- optarg);
+ *axis = parse_event_code(EV_ABS, optarg);
if (*axis == -1)
goto error;
break;
@@ -176,8 +210,7 @@ parse_options_led(int argc, char **argv, int *led, int *led_state)
switch (c) {
case OPT_LED:
- *led = libevdev_event_code_from_name(EV_LED,
- optarg);
+ *led = parse_event_code(EV_LED, optarg);
if (*led == -1)
goto error;
break;