blob: 20423b08fa7811b6140e54f881395c0bff79dc1e (
plain) (
tree)
|
|
/* 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;
}
|