From 6593f9241bd1722ed981467388f2ed952f1137e0 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 2 Aug 2023 17:19:16 +0200 Subject: [PATCH] libc: Add wrapper for poll() --- libc/CMakeLists.txt | 1 + libc/include/sys/poll.h | 20 ++++++++++++++++++++ libc/src/sys/poll.cpp | 13 +++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 libc/include/sys/poll.h create mode 100644 libc/src/sys/poll.cpp diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 54c95acf..bb4a0d7a 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -32,6 +32,7 @@ set(SOURCES src/sys/pstat.cpp src/sys/resource.cpp src/sys/socket.cpp + src/sys/poll.cpp ) if(${LUNA_ARCH} STREQUAL "x86_64") diff --git a/libc/include/sys/poll.h b/libc/include/sys/poll.h new file mode 100644 index 00000000..3a878c0c --- /dev/null +++ b/libc/include/sys/poll.h @@ -0,0 +1,20 @@ +/* sys/poll.h: Wait for events on multiple file descriptors. */ + +#ifndef _SYS_POLL_H +#define _SYS_POLL_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Wait for events on multiple file descriptors. */ + int poll(struct pollfd* fds, nfds_t nfds, int timeout); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libc/src/sys/poll.cpp b/libc/src/sys/poll.cpp new file mode 100644 index 00000000..90fd69b5 --- /dev/null +++ b/libc/src/sys/poll.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +extern "C" +{ + int poll(struct pollfd* fds, nfds_t nfds, int timeout) + { + long rc = syscall(SYS_poll, fds, nfds, timeout); + __errno_return(rc, int); + } +}