heirloom-ed

diff sigset.c @ 0:1493bea5ac22

Initial version of the standalone heirloom-ed
author markus schnalke <meillo@marmaro.de>
date Mon, 05 Sep 2011 16:31:35 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sigset.c	Mon Sep 05 16:31:35 2011 +0200
     1.3 @@ -0,0 +1,55 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004 Gunnar Ritter
     1.6 + *
     1.7 + * This software is provided 'as-is', without any express or implied
     1.8 + * warranty. In no event will the authors be held liable for any damages
     1.9 + * arising from the use of this software.
    1.10 + *
    1.11 + * Permission is granted to anyone to use this software for any purpose,
    1.12 + * including commercial applications, and to alter it and redistribute
    1.13 + * it freely, subject to the following restrictions:
    1.14 + *
    1.15 + * 1. The origin of this software must not be misrepresented; you must not
    1.16 + *    claim that you wrote the original software. If you use this software
    1.17 + *    in a product, an acknowledgment in the product documentation would be
    1.18 + *    appreciated but is not required.
    1.19 + *
    1.20 + * 2. Altered source versions must be plainly marked as such, and must not be
    1.21 + *    misrepresented as being the original software.
    1.22 + *
    1.23 + * 3. This notice may not be removed or altered from any source distribution.
    1.24 + */
    1.25 +/*	Sccsid @(#)sigset.c	1.7 (gritter) 1/22/06	*/
    1.26 +
    1.27 +#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
    1.28 +	defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
    1.29 +#include <signal.h>
    1.30 +#include "sigset.h"
    1.31 +
    1.32 +void (*sigset(int sig, void (*func)(int)))(int)
    1.33 +{
    1.34 +	struct sigaction nact, oact;
    1.35 +	sigset_t	nset, oset;
    1.36 +
    1.37 +	if (sig <= 0)
    1.38 +		return SIG_ERR;
    1.39 +	sigemptyset(&nset);
    1.40 +	sigaddset(&nset, sig);
    1.41 +	if (sigprocmask(func==SIG_HOLD?SIG_BLOCK:SIG_UNBLOCK, &nset, &oset) < 0)
    1.42 +		return SIG_ERR;
    1.43 +	nact.sa_handler = func;
    1.44 +	nact.sa_flags = 0;
    1.45 +	if (sig == SIGCHLD && func == SIG_IGN)
    1.46 +		nact.sa_flags |= SA_NOCLDSTOP|SA_NOCLDWAIT;
    1.47 +	sigemptyset(&nact.sa_mask);
    1.48 +	sigaddset(&nact.sa_mask, sig);
    1.49 +	if (sigaction(sig, func==SIG_HOLD?(struct sigaction *)0:&nact, &oact)
    1.50 +			== -1)
    1.51 +		return SIG_ERR;
    1.52 +	if (sigismember(&oset, sig))
    1.53 +		return SIG_HOLD;
    1.54 +	else
    1.55 +		return (oact.sa_handler);
    1.56 +}
    1.57 +#endif	/* __FreeBSD__ || __dietlibc__ || __NetBSD__ || __OpenBSD__ ||
    1.58 +	__DragonFly__ || __APPLE__ */