Skip to content

Commit 516e3a0

Browse files
ITotalJusticefincs
authored andcommitted
sock_poll: fix poll() not ignoring negative fds.
1 parent 43ac48a commit 516e3a0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

libctru/source/services/soc/soc_poll.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
2727
memcpy(tmp_fds, fds, sizeof(struct pollfd) * nfds);
2828

2929
for(i = 0; i < nfds; ++i) {
30-
tmp_fds[i].fd = soc_get_fd(fds[i].fd);
31-
if(tmp_fds[i].fd < 0) {
32-
errno = -tmp_fds[i].fd;
33-
free(tmp_fds);
34-
return -1;
30+
if (fds[i].fd >= 0) {
31+
tmp_fds[i].fd = soc_get_fd(fds[i].fd);
32+
if(tmp_fds[i].fd < 0) {
33+
errno = -tmp_fds[i].fd;
34+
free(tmp_fds);
35+
return -1;
36+
}
37+
}
38+
// negative fds are ignored, however 3ds poll only
39+
// ignores fd's that are -1.
40+
// this forces negative fds to -1 so they are ignored without error.
41+
else {
42+
tmp_fds[i].fd = -1;
3543
}
3644
tmp_fds[i].revents = 0;
3745
}

0 commit comments

Comments
 (0)