152419Sjulian/*- 252419Sjulian * Copyright (c) 1991, 1993 352419Sjulian * The Regents of the University of California. All rights reserved. 452419Sjulian * 552419Sjulian * This code is derived from software contributed to Berkeley by 670700Sjulian * Kenneth Almquist. 752419Sjulian * 852419Sjulian * Redistribution and use in source and binary forms, with or without 952419Sjulian * modification, are permitted provided that the following conditions 1052419Sjulian * are met: 1152419Sjulian * 1. Redistributions of source code must retain the above copyright 1252419Sjulian * notice, this list of conditions and the following disclaimer. 1352419Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1452419Sjulian * notice, this list of conditions and the following disclaimer in the 1552419Sjulian * documentation and/or other materials provided with the distribution. 1652419Sjulian * 4. Neither the name of the University nor the names of its contributors 1770700Sjulian * may be used to endorse or promote products derived from this software 1852419Sjulian * without specific prior written permission. 1952419Sjulian * 2052419Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2152419Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2252419Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2352419Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2452419Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2552419Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2652419Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2752419Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2852419Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2952419Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3052419Sjulian * SUCH DAMAGE. 3152419Sjulian * 3252419Sjulian * @(#)error.h 8.2 (Berkeley) 5/4/95 3352419Sjulian * $FreeBSD$ 3452419Sjulian */ 3552419Sjulian 3667506Sjulian/* 3767506Sjulian * We enclose jmp_buf in a structure so that we can declare pointers to 3852419Sjulian * jump locations. The global variable handler contains the location to 3952419Sjulian * jump to when an exception occurs, and the global variable exception 4052419Sjulian * contains a code identifying the exception. To implement nested 4152419Sjulian * exception handlers, the user should save the value of handler on entry 4252419Sjulian * to an inner scope, set handler to point to a jmploc structure for the 4352419Sjulian * inner scope, and restore handler on exit from the scope. 4452419Sjulian */ 4552419Sjulian 4652419Sjulian#include <setjmp.h> 4752419Sjulian#include <signal.h> 4852419Sjulian 4952419Sjulianstruct jmploc { 5052419Sjulian jmp_buf loc; 5152419Sjulian}; 5252419Sjulian 5370700Sjulianextern struct jmploc *handler; 5452419Sjulianextern volatile sig_atomic_t exception; 5552419Sjulian 5652419Sjulian/* exceptions */ 5752843Sphk#define EXINT 0 /* SIGINT received */ 5852816Sarchie#define EXERROR 1 /* a generic error */ 5952419Sjulian#define EXEXEC 2 /* command execution failed */ 6052419Sjulian#define EXEXIT 3 /* call exitshell(exitstatus) */ 6152419Sjulian 6252419Sjulian 6352419Sjulian/* 6453913Sarchie * These macros allow the user to suspend the handling of interrupt signals 6552419Sjulian * over a period of time. This is similar to SIGHOLD to or sigblock, but 6659756Speter * much more efficient and portable. (But hacking the kernel is so much 6759756Speter * more fun than worrying about efficiency and portability. :-)) 6870784Sjulian */ 6970700Sjulian 7070700Sjulianextern volatile sig_atomic_t suppressint; 7152419Sjulianextern volatile sig_atomic_t intpending; 7270784Sjulian 7370784Sjulian#define INTOFF suppressint++ 7470784Sjulian#define INTON { if (--suppressint == 0 && intpending) onint(); } 7570784Sjulian#define is_int_on() suppressint 7670784Sjulian#define SETINTON(s) suppressint = (s) 7770784Sjulian#define FORCEINTON {suppressint = 0; if (intpending) onint();} 7870784Sjulian#define CLEAR_PENDING_INT intpending = 0 7970784Sjulian#define int_pending() intpending 8070784Sjulian 8170784Sjulianvoid exraise(int) __dead2; 8270784Sjulianvoid onint(void); 8370784Sjulianvoid warning(const char *, ...) __printflike(1, 2); 8470784Sjulianvoid error(const char *, ...) __printf0like(1, 2) __dead2; 8570700Sjulianvoid exerror(int, const char *, ...) __printf0like(2, 3) __dead2; 8670700Sjulian 8770700Sjulian 8870700Sjulian/* 8952419Sjulian * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 9070700Sjulian * so we use _setjmp instead. 9170700Sjulian */ 9252419Sjulian 9370700Sjulian#define setjmp(jmploc) _setjmp(jmploc) 9470700Sjulian#define longjmp(jmploc, val) _longjmp(jmploc, val) 9552722Sjulian