summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/sys/select.cpp
blob: be306ec868cb828794c12b8b276641ee43d4c55c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <errno.h>
#include <stdio.h>
#include <sys/select.h>
#include <sys/time.h>
#include <syscall.h>

extern "C" {

int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout_tv)
{
    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 };
    int rc = syscall(SC_select, &params);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}
}