aboutsummaryrefslogtreecommitdiffstats
path: root/libgamepad_create_attachment_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgamepad_create_attachment_monitor.c')
-rw-r--r--libgamepad_create_attachment_monitor.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libgamepad_create_attachment_monitor.c b/libgamepad_create_attachment_monitor.c
new file mode 100644
index 0000000..20423b0
--- /dev/null
+++ b/libgamepad_create_attachment_monitor.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libgamepad_create_attachment_monitor(LIBGAMEPAD_ATTACHMENT_MONITOR **monitorp)
+{
+ *monitorp = calloc(1, sizeof(*monitorp));
+ if (!*monitorp)
+ return -1;
+
+ (*monitorp)->udev = udev_new();
+ if (!(*monitorp)->udev)
+ goto fail;
+
+ (*monitorp)->monitor = udev_monitor_new_from_netlink((*monitorp)->udev, "udev");
+ if (!(*monitorp)->monitor)
+ goto fail_have_udev;
+
+ if (udev_monitor_enable_receiving((*monitorp)->monitor))
+ goto fail_have_monitor;
+
+ return udev_monitor_get_fd((*monitorp)->monitor);
+
+fail_have_monitor:
+ udev_monitor_unref((*monitorp)->monitor);
+fail_have_udev:
+ udev_unref((*monitorp)->udev);
+fail:
+ free(*monitorp);
+ *monitorp = NULL;
+ return -1;
+}