/* WHS misc
 *
 * p_signal.c - portable signal handling
 *
 * Lower level API dependencies:
 *   - unix signals
 *
 *
 * By W.H.Scholten, dd 1999
 *
 * This file is public domain.
 */


#include <errno.h>

#include <signal.h>


typedef void    sigfunc_t(int);

/*---------------------------------------------------------------------------*
 * Choice whether to restart all system calls after signal delivery (e.g.    *
 * not wanted in case SIGALRM is used to time out system calls)              *
 */
sigfunc_t *p_signal_restart(int signo, sigfunc_t *func, int restart)
{
	struct sigaction      act, oact;

	act.sa_handler = func;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	if (!restart) {
#ifdef  SA_INTERRUPT
		act.sa_flags |= SA_INTERRUPT;   /* SunOS 4.x */
#endif
	} else {
#ifdef  SA_RESTART
		act.sa_flags |= SA_RESTART;     /* SVR4, 4.4BSD */
#endif
	}
	if (sigaction(signo, &act, &oact) < 0)
		return (SIG_ERR);

	return(oact.sa_handler);
}


/*---------------------------------------------------------------------------*
 * Restart all system calls after signal delivery                            *
 */
sigfunc_t *p_signal(int signo, sigfunc_t *func)
{
	return p_signal_restart(signo, func, 1);
}

/*      EOF p_signal.c */
