blob: 20423b08fa7811b6140e54f881395c0bff79dc1e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}
|