| 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 "hdr/signal_macros.h" |
| 11 |
#include "src/__support/common.h" |
| 12 |
#include "src/__support/macros/config.h" |
| 13 |
#include "src/signal/sigaction.h" |
| 14 |
|
| 15 |
namespace LIBC_NAMESPACE_DECL { |
| 16 |
|
| 17 |
// Our LLVM_LIBC_FUNCTION macro doesn't handle function pointer return types. |
| 18 |
using signal_handler = void (*)(int); |
| 19 |
|
| 20 |
LLVM_LIBC_FUNCTION(signal_handler, signal, |
| 21 |
(int signum, signal_handler handler)) { |
| 22 |
struct sigaction action, old; |
| 23 |
action.sa_handler = handler; |
| 24 |
action.sa_flags = SA_RESTART; |
| 25 |
// Errno will already be set so no need to worry about changing errno here. |
| 26 |
return LIBC_NAMESPACE::sigaction(signum, &action, &old) == -1 |
| 27 |
? SIG_ERR |
| 28 |
: old.sa_handler; |
| 29 |
} |
| 30 |
|
| 31 |
} // namespace LIBC_NAMESPACE_DECL |