LibCore: Add wrapper for signal()

This commit is contained in:
Junior Rantila 2021-11-23 21:03:53 +01:00 committed by Brian Gianforcaro
parent 8eca395e4c
commit 4178479ee5
Notes: sideshowbarker 2024-07-17 22:34:39 +09:00
2 changed files with 18 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include <AK/String.h>
#include <LibCore/System.h>
#include <LibSystem/syscall.h>
#include <cstring>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/ioctl.h>
@ -115,6 +116,18 @@ ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigac
return {};
}
#ifdef __APPLE__
ErrorOr<sig_t> signal(int signal, sig_t handler)
#else
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler)
#endif
{
auto old_handler = ::signal(signal, handler);
if (old_handler == SIG_ERR)
return Error::from_syscall("signal"sv, -errno);
return old_handler;
}
ErrorOr<struct stat> fstat(int fd)
{
struct stat st = {};

View file

@ -31,6 +31,11 @@ ErrorOr<void> mount(int source_fd, StringView target, StringView fs_type, int fl
#endif
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
#ifdef __APPLE__
ErrorOr<sig_t> signal(int signal, sig_t handler);
#else
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler);
#endif
ErrorOr<struct stat> fstat(int fd);
ErrorOr<int> fcntl(int fd, int command, ...);
ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});