From 4e1a6f1b3c543b9fbeb882a9e97551f7c58ca65a Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 25 Dec 2023 18:36:02 +0100 Subject: ports: curl :^) had to do a lot of hacky stuff, but it's there. worked on this on and off for a while now --- src/libc/select.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/libc/select.c (limited to 'src/libc/select.c') diff --git a/src/libc/select.c b/src/libc/select.c new file mode 100644 index 0000000..e3e95e4 --- /dev/null +++ b/src/libc/select.c @@ -0,0 +1,47 @@ +#include +#include +#include + +static int +countset(int nfds, fd_set *set) +{ + int count = 0; + if (set == NULL) return 0; + for (int i = 0; i < nfds; i++) { + if (FD_ISSET(i, set)) { + count++; + } + } + return count; +} + +int +select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + (void)timeout; + FD_ZERO(exceptfds); + if (countset(nfds, readfds) != 0) { + return errno = ENOSYS, -1; + } + return countset(nfds, writefds); /* assume everything is ready for writing */ +} + +void FD_CLR(int fd, fd_set *set) { + if (0 <= fd && fd < FD_SETSIZE) { + *set = *set & ~(1<