diff options
author | dzwdz | 2023-12-25 18:36:02 +0100 |
---|---|---|
committer | dzwdz | 2023-12-25 18:36:02 +0100 |
commit | 4e1a6f1b3c543b9fbeb882a9e97551f7c58ca65a (patch) | |
tree | 8c2048c751db8b98e3033a61b6ad5bbd11a303a9 /src/libc/select.c | |
parent | 64d4330810a37dd9c41a82ae6cc420850ca1e7da (diff) |
ports: curl :^)
had to do a lot of hacky stuff, but it's there.
worked on this on and off for a while now
Diffstat (limited to 'src/libc/select.c')
-rw-r--r-- | src/libc/select.c | 47 |
1 files changed, 47 insertions, 0 deletions
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 <errno.h> +#include <sys/select.h> +#include <stdio.h> + +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<<fd); + } +} + +int FD_ISSET(int fd, fd_set *set) { + return 0 <= fd && fd < FD_SETSIZE && (*set & (1 << fd)); +} + +void FD_SET(int fd, fd_set *set) { + if (0 <= fd && fd < FD_SETSIZE) { + *set = *set | (1<<fd); + } +} + +void FD_ZERO(fd_set *set) { + *set = 0; +} |