2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-01-16 22:41:13 -02:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
2019-06-07 06:49:03 -03:00
|
|
|
#include <sys/select.h>
|
2020-06-21 14:54:41 -03:00
|
|
|
#include <sys/time.h>
|
2021-02-05 08:16:30 -03:00
|
|
|
#include <syscall.h>
|
2019-01-16 22:41:13 -02:00
|
|
|
|
2019-01-23 03:53:01 -02:00
|
|
|
extern "C" {
|
|
|
|
|
|
2020-06-21 14:54:41 -03:00
|
|
|
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout_tv)
|
2019-01-16 22:41:13 -02:00
|
|
|
{
|
2020-06-21 14:54:41 -03:00
|
|
|
timespec* timeout_ts = nullptr;
|
|
|
|
|
timespec timeout;
|
|
|
|
|
if (timeout_tv) {
|
|
|
|
|
timeout_ts = &timeout;
|
|
|
|
|
TIMEVAL_TO_TIMESPEC(timeout_tv, timeout_ts);
|
|
|
|
|
}
|
|
|
|
|
return pselect(nfds, readfds, writefds, exceptfds, timeout_ts, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pselect(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const timespec* timeout, const sigset_t* sigmask)
|
|
|
|
|
{
|
|
|
|
|
Syscall::SC_select_params params { nfds, readfds, writefds, exceptfds, timeout, sigmask };
|
2019-01-16 22:41:13 -02:00
|
|
|
int rc = syscall(SC_select, ¶ms);
|
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
|
}
|
2019-01-23 03:53:01 -02:00
|
|
|
}
|