(Joypad drivers) Simplifications - put char string outside loop

This commit is contained in:
libretroadmin 2023-05-01 20:33:38 +02:00
parent b951a010fd
commit e7e647d181
2 changed files with 15 additions and 20 deletions

View File

@ -194,10 +194,8 @@ retry:
else if (event->mask & (IN_CREATE | IN_ATTRIB))
{
char path[PATH_MAX_LENGTH];
path[0] = '\0';
snprintf(path, sizeof(path), "/dev/input/%s", event->name);
strlcpy(path, "/dev/input/", sizeof(path));
strlcat(path, event->name, sizeof(path));
if ( !string_is_empty(linuxraw_pads[idx].ident)
&& linuxraw_joypad_init_pad(path, &linuxraw_pads[idx]))
@ -219,33 +217,27 @@ retry:
static void *linuxraw_joypad_init(void *data)
{
unsigned i;
int fd = epoll_create(32);
size_t i, _len;
char path[PATH_MAX_LENGTH];
int fd = epoll_create(32);
if (fd < 0)
return NULL;
linuxraw_epoll = fd;
_len = strlcpy(path, "/dev/input/js", sizeof(path));
for (i = 0; i < MAX_USERS; i++)
{
char path[PATH_MAX_LENGTH];
struct linuxraw_joypad *pad = (struct linuxraw_joypad*)&linuxraw_pads[i];
path[0] = '\0';
pad->fd = -1;
pad->ident = input_config_get_device_name_ptr(i);
snprintf(path, sizeof(path), "/dev/input/js%u", i);
snprintf(path + _len, sizeof(path) - _len, "%u", i);
input_autoconfigure_connect(
pad->ident,
NULL,
"linuxraw",
i,
0,
0);
input_autoconfigure_connect(pad->ident, NULL, "linuxraw",
i, 0, 0);
if (linuxraw_joypad_init_pad(path, pad))
linuxraw_poll_pad(pad);

View File

@ -230,23 +230,26 @@ static void parport_free_pad(struct parport_joypad *pad)
static void *parport_joypad_init(void *data)
{
unsigned i, j;
size_t i;
unsigned j;
char path[PATH_MAX_LENGTH];
bool found_enabled_button = false;
bool found_disabled_button = false;
char buf[PARPORT_NUM_BUTTONS * 3 + 1] = {0};
char pin[3 + 1] = {0};
size_t _len =
strlcpy(path, "/dev/parport", sizeof(path));
memset(buf, 0, PARPORT_NUM_BUTTONS * 3 + 1);
for (i = 0; i < MAX_USERS; i++)
{
char path[PATH_MAX_LENGTH] = {0};
struct parport_joypad *pad = &parport_pads[i];
pad->fd = -1;
pad->ident = input_config_get_device_name_ptr(i);
snprintf(path, sizeof(path), "/dev/parport%u", i);
snprintf(path + _len, sizeof(path) - _len, "%u", i);
if (parport_joypad_init_pad(path, pad))
{