From d49393b339c47733c2eda207b8ba03d61db0a5a3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 23 Jul 2022 14:39:44 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamepad_create_attachment_monitor.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libgamepad_create_attachment_monitor.c (limited to 'libgamepad_create_attachment_monitor.c') 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; +} -- cgit v1.2.3-70-g09d2