/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef TRAP_H #define TRAP_H #include #include #include #if defined(sun) || defined(_AIX) typedef int __harg; #endif #if defined(hpux) || defined(ultrix) || defined(sun) || defined(_AIX) # define ssignal __ssignal_protect # include # undef ssignal # define ssignal _ssignal typedef void (*__sighandler_t)(__harg); extern const char *sys_siglist[NSIG]; __BEGIN_DECLS extern int ualarm(u_int timer, u_int interval); extern int usleep(u_int timer); __END_DECLS /* AIX defines SA_RESTART allready, but maybe wrong ?? */ # ifndef SA_RESTART # define SA_RESTART 0 # endif #else # include # if __FreeBSD__ == 2 || BSD4_4 typedef sig_t __sighandler_t; # endif #endif #define T_SINTR 1 #define T_BLOCK 2 #define T_DISCARD 4 #define SIG_NULL SIG_ERR /* since NULL == SIG_DFL */ __BEGIN_DECLS extern volatile bool israised[NSIG]; extern jmp_buf __signal_jmp[NSIG]; extern void __jsignal(); struct sigsave { bool ss_blk; struct sigaction ss_sa; jmp_buf ss_jmp; }; #define istimeout (israised[SIGALRM]) #define __timeout_jmp (__signal_jmp[SIGALRM]) #define __jtimeout __jsignal extern void svsignal(int sig, struct sigsave *ss); extern void rssignal(int sig, struct sigsave *ss); extern void ssignal(int sig, __sighandler_t hdl, int flags); extern void stimeout(int sec, __sighandler_t hdl, int flags); __END_DECLS #define atsignal(sig, flg) \ if(setjmp(__signal_jmp[sig]) == 0) \ { \ ssignal(sig, __jsignal, T_SINTR | flg); \ } \ else #define attimeout(sec) \ if(setjmp(__timeout_jmp) == 0) \ { \ ualarm(sec * 1000000, 0); \ ssignal(SIGALRM, __jtimeout, T_SINTR); \ } \ else #define isignal(sig) { ssignal(sig, SIG_IGN, 0); } #define dsignal(sig) { ssignal(sig, SIG_IGN, 0); } #define csignal(sig) { ssignal(sig, SIG_DFL, T_DISCARD); } #define ctimeout() { ualarm(0, 0); csignal(SIGALRM); } #endif /* TRAP_H */