From 4178479ee52433020d58297636296f5fe41300ff Mon Sep 17 00:00:00 2001 From: Junior Rantila Date: Tue, 23 Nov 2021 21:03:53 +0100 Subject: [PATCH] LibCore: Add wrapper for signal() --- Userland/Libraries/LibCore/System.cpp | 13 +++++++++++++ Userland/Libraries/LibCore/System.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 4ebecf6a16..c572f56367 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,18 @@ ErrorOr sigaction(int signal, struct sigaction const* action, struct sigac return {}; } +#ifdef __APPLE__ +ErrorOr signal(int signal, sig_t handler) +#else +ErrorOr 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 fstat(int fd) { struct stat st = {}; diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 6bffc771c3..bb9f857c33 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -31,6 +31,11 @@ ErrorOr mount(int source_fd, StringView target, StringView fs_type, int fl #endif ErrorOr sigaction(int signal, struct sigaction const* action, struct sigaction* old_action); +#ifdef __APPLE__ +ErrorOr signal(int signal, sig_t handler); +#else +ErrorOr signal(int signal, sighandler_t handler); +#endif ErrorOr fstat(int fd); ErrorOr fcntl(int fd, int command, ...); ErrorOr mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});