diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2015-01-29 06:57:08 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2015-01-29 06:57:45 +1000 |
commit | 3e81e4adca50ba5765cd1d8fe252d52917a224c9 (patch) | |
tree | 8c864ff2939a661a4f81549bd596d2f3c47fe76e | |
parent | 412c1ad90de654d152d1d9813f81a6e9d08283fe (diff) | |
download | external_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.tar.gz external_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.tar.bz2 external_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.zip |
Handle holes in the event node lists
The current code simply counts the number of directory entries and takes
that as the maximum event node given. That isn't true if we have a hole in the
event range after removing a device, making the last device in the list
unaccessible.
Fix this by actually looking at the event node numbers.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | evtest.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -684,6 +684,7 @@ static char* scan_devices(void) struct dirent **namelist; int i, ndev, devnum; char *filename; + int max_device = 0; ndev = scandir(DEV_INPUT_EVENT, &namelist, is_event_device, versionsort); if (ndev <= 0) @@ -706,13 +707,18 @@ static char* scan_devices(void) fprintf(stderr, "%s: %s\n", fname, name); close(fd); + + sscanf(namelist[i]->d_name, "event%d", &devnum); + if (devnum > max_device) + max_device = devnum; + free(namelist[i]); } - fprintf(stderr, "Select the device event number [0-%d]: ", ndev - 1); + fprintf(stderr, "Select the device event number [0-%d]: ", max_device); scanf("%d", &devnum); - if (devnum >= ndev || devnum < 0) + if (devnum > max_device || devnum < 0) return NULL; asprintf(&filename, "%s/%s%d", |