summaryrefslogtreecommitdiff
path: root/tools/list-local-devices.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-03-19 11:03:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-03-19 13:55:34 +1000
commit6447eb557b9972673647241b62967d3e3d2c41e0 (patch)
tree8e8e0a085dc6a7d637eab4fb337194fd2244e1f1 /tools/list-local-devices.c
parent7770a9bad9c3f28f53276a029c45837bd1ddbae4 (diff)
downloadlibwacom-6447eb557b9972673647241b62967d3e3d2c41e0.tar.gz
tools: switch from scandir to glib's opendir
Makes the code a bit simpler and we don't care much about the sorting of the device nodes anyway. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools/list-local-devices.c')
-rw-r--r--tools/list-local-devices.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/tools/list-local-devices.c b/tools/list-local-devices.c
index d60bbf3..8acccc9 100644
--- a/tools/list-local-devices.c
+++ b/tools/list-local-devices.c
@@ -90,18 +90,14 @@ static GOptionEntry opts[] = {
{ .long_name = NULL}
};
-static int event_devices_only(const struct dirent *dir) {
- return strncmp("event", dir->d_name, 5) == 0;
-}
-
int main(int argc, char **argv)
{
WacomDeviceDatabase *db;
- int i;
- struct dirent **namelist = NULL;
GOptionContext *context;
GError *error;
GList *tabletlist = NULL;
+ GDir *dir = NULL;
+ const char *filename;
context = g_option_context_new (NULL);
@@ -130,20 +126,22 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- i = scandir("/dev/input", &namelist, event_devices_only, alphasort);
-
- if (i < 0 || i == 0) {
- fprintf(stderr, "Failed to find any devices.\n");
- goto out;
+ dir = g_dir_open("/dev/input", 0, &error);
+ if (!dir) {
+ fprintf(stderr, "%s\n", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
}
- while (i--) {
+ while ((filename = g_dir_read_name(dir))) {
WacomDevice *dev;
char fname[PATH_MAX];
GList *found;
- snprintf(fname, sizeof(fname), "/dev/input/%s", namelist[i]->d_name);
- free(namelist[i]);
+ if (!g_str_has_prefix(filename, "event"))
+ continue;
+
+ snprintf(fname, sizeof(fname), "/dev/input/%s", filename);
dev = libwacom_new_from_path(db, fname, WFALLBACK_NONE, NULL);
if (!dev)
@@ -162,13 +160,13 @@ int main(int argc, char **argv)
}
}
+ if (!tabletlist)
+ fprintf(stderr, "Failed to find any devices.\n");
+
g_list_foreach(tabletlist, tablet_print, NULL);
-out:
- if (namelist)
- free(namelist);
g_list_free_full(tabletlist, tablet_destroy);
-
+ g_dir_close(dir);
libwacom_database_destroy (db);
return 0;
}