1//===-- Linux implementation of signal ------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "src/signal/signal.h"
10#include "src/signal/sigaction.h"
11
12#include "src/__support/common.h"
13
14#include <signal.h>
15
16namespace LIBC_NAMESPACE {
17
18LLVM_LIBC_FUNCTION(sighandler_t, signal, (int signum, sighandler_t handler)) {
19 struct sigaction action, old;
20 action.sa_handler = handler;
21 action.sa_flags = SA_RESTART;
22 // Errno will already be set so no need to worry about changing errno here.
23 return LIBC_NAMESPACE::sigaction(signal: signum, libc_new: &action, libc_old: &old) == -1
24 ? SIG_ERR
25 : old.sa_handler;
26}
27
28} // namespace LIBC_NAMESPACE
29

source code of libc/src/signal/linux/signal.cpp