From c03e1547b115c5ae9f85f9e1b2169c2c5487335d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 30 Nov 2015 18:20:50 +0100 Subject: [PATCH] (linuxraw_joypad) Cleanups --- input/drivers_joypad/linuxraw_joypad.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/input/drivers_joypad/linuxraw_joypad.c b/input/drivers_joypad/linuxraw_joypad.c index 51e456a590..69c0fcd1a9 100644 --- a/input/drivers_joypad/linuxraw_joypad.c +++ b/input/drivers_joypad/linuxraw_joypad.c @@ -41,7 +41,7 @@ struct linuxraw_joypad }; static struct linuxraw_joypad linuxraw_pads[MAX_USERS]; -static int g_notify; +static int g_inotify; static bool g_hotplug; static void linuxraw_poll_pad(struct linuxraw_joypad *pad) @@ -124,7 +124,7 @@ static void handle_plugged_pad(void) if (!event_buf) return; - while ((rc = read(g_notify, event_buf, event_size)) >= 0) + while ((rc = read(g_inotify, event_buf, event_size)) >= 0) { struct inotify_event *event = (struct inotify_event*)&event_buf[0]; @@ -205,12 +205,6 @@ retry: } } -static void linuxraw_joypad_setup_notify(void) -{ - fcntl(g_notify, F_SETFL, fcntl(g_notify, F_GETFL) | O_NONBLOCK); - inotify_add_watch(g_notify, "/dev/input", IN_DELETE | IN_CREATE | IN_ATTRIB); -} - static bool linuxraw_joypad_init(void *data) { unsigned i; @@ -250,12 +244,13 @@ static bool linuxraw_joypad_init(void *data) input_config_autoconfigure_joypad(¶ms); } - g_notify = inotify_init(); + g_inotify = inotify_init(); - if (g_notify >= 0) + if (g_inotify >= 0) { - linuxraw_joypad_setup_notify(); - epoll_add(g_notify, NULL); + fcntl(g_inotify, F_SETFL, fcntl(g_inotify, F_GETFL) | O_NONBLOCK); + inotify_add_watch(g_inotify, "/dev/input", IN_DELETE | IN_CREATE | IN_ATTRIB); + epoll_add(g_inotify, NULL); } g_hotplug = true; @@ -278,9 +273,9 @@ static void linuxraw_joypad_destroy(void) for (i = 0; i < MAX_USERS; i++) linuxraw_pads[i].fd = -1; - if (g_notify >= 0) - close(g_notify); - g_notify = -1; + if (g_inotify >= 0) + close(g_inotify); + g_inotify = -1; epoll_free(true);