/*
sig.c

Author: Liraz Siri <liraz@bigfoot.com>

Copyright (c) 1999 Liraz Siri <liraz@bigfoot.com>, Ariel, Israel
              All rights reserved.

Created: Sun Oct  3 16:05:50 IST 1999

A thin layer above the libc signal API
*/
#include <stdio.h>
#include "sig.h"

void sig_handle(int signum)
{
        sig_unblock(signum);
        sig_block(signum);
}

void sig_handleall()
{
        sigset_t set;
        sigprocmask(0, NULL, &set);
        sigprocmask(SIG_UNBLOCK, &set, NULL);
        sigprocmask(SIG_BLOCK, &set, NULL);
}

int sig_block(int signum)
{
        sigset_t set;

        sigemptyset(&set);
        sigaddset(&set, signum);
        return sigprocmask(SIG_BLOCK, &set, NULL);
}

int sig_unblock(int signum)
{
        sigset_t set;

        sigemptyset(&set);
        sigaddset(&set, signum);
        return sigprocmask(SIG_UNBLOCK, &set, NULL);
}

void sig_ignore(int signum)
{
        signal(signum, SIG_IGN);
        sig_block(signum);
}

void sig_blockall()
{
        sigset_t set;
        sigfillset(&set);
        sigprocmask(SIG_SETMASK, &set, NULL);
}

void sig_unblockall()
{
        sigset_t set;
        sigemptyset(&set);
        sigprocmask(SIG_SETMASK, &set, NULL);
}

int sig_ispending(int signum)
{
        sigset_t set;

        sigpending(&set);
        return sigismember(&set, signum) > 0;
}

int sig_isblocked(int signum)
{
        sigset_t set;

        sigprocmask(0, NULL, &set);
        return sigismember(&set, signum) > 0;
}
