bsd_signal() — BSD version of signal()

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <signal.h>

void (*bsd_signal(int sig, void (*func)(int)))(int);

General description

The bsd_signal() function provides a partially compatible interface for programs written to use the BSD form of the signal() function.

BSD signal() differs from ANSI signal() in that the SA_RESTART flag is set and the SA_RESETHAND is cleared when bsd_signal() is used. Whereas for signal() both of these flags are cleared and _SA_OLD_STYLE is set.

There are three functions available for establishing a signal's action, signal(), bsd_signal(), and sigaction(). The sigaction() function is the strategic way to establish a signal's action. The bsd_signal() and signal() functions are provided for compatibility with BSD and ANSI, respectively.

The argument sig is the signal type. See Table 1 for a list of the supported signal types or refer to the <signal.h> header. The argument func is the signal action. It may be set to SIG_DFL, SIG_IGN, or the address of a signal catching function that takes one input argument.

Special Behavior for C++

Because C and C++ linkage conventions are incompatible, bsd_signal() cannot receive a C++ function pointer as the start routine function pointer If you attempt to pass a C++ function pointer to bsd_signal(), the compiler will flag it as an error. You can pass a C or C++ function to bsd_signal() by declaring it as extern "C".

Usage notes

  1. The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.
  2. The bsd_signal() function has been marked obsolescent in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The sigaction() function is preferred for portability.

Returned value

If successful, bsd_signal() returns the previous action established for this signal type.

If unsuccessful, bsd_signal() returns SIG_ERR and sets errno to one of the following values:
Error Code
Description
EINVAL
The value of the argument sig was not a valid signal type, or an attempt was made to catch a signal that cannot be caught, or ignore a signal that cannot be ignored.

Related information