Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* signal.c: Don't compile this program. This is only the implementation of signal(3), *
- * but without existence of main(). So it can't be compiled unless a specific flag -c *
- * is given to the compiler e.g. gcc -c. signal(3) complies with POSIX.1. But it is *
- * only a wrapper function. signal(3) is actually implemented using sigaction(2). */
- #include <signal.h>
- typedef void Sigfunc(int);
- Sigfunc *signal(int signo, Sigfunc *func)
- {
- struct sigaction act, oact;
- act.sa_handler = func;
- sigemptyset(&act.sa_mask); /* Empty signal set. */
- act.sa_flags = 0;
- /* the purpose of generating SIGALRM is normally to place a timeout *
- * on an I/O operation. If SIGALRM caught, system calls will never *
- * restart regardless of SA_RESTART. */
- if (signo == SIGALRM) {
- #ifdef SA_INTERRUPT
- act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */
- #endif
- } else {
- #ifdef SA_RESTART
- act.sa_flags |= SA_RESTART; /* SVR4 & BSD */
- #endif
- }
- /* The 1st arg to sigaction(2) is signal number to be caught. *
- * The 2nd arg is ptr to the current disposition. *
- * The 3rd arg is ptr to the old disposition. */
- if (sigaction(signo, &act, &oact) == -1)
- return SIG_ERR;
- return oact.sa_handler; /* the previous disposition of the signal */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement