error.h revision 38521
1339631Sphilip/*- 2339631Sphilip * Copyright (c) 1991, 1993 3192886Sedwin * The Regents of the University of California. All rights reserved. 4192886Sedwin * 5153761Swollman * This code is derived from software contributed to Berkeley by 62742Swollman * Kenneth Almquist. 786464Swollman * 82742Swollman * Redistribution and use in source and binary forms, with or without 92742Swollman * modification, are permitted provided that the following conditions 102742Swollman * are met: 112742Swollman * 1. Redistributions of source code must retain the above copyright 122742Swollman * notice, this list of conditions and the following disclaimer. 132742Swollman * 2. Redistributions in binary form must reproduce the above copyright 1486222Swollman * notice, this list of conditions and the following disclaimer in the 1586222Swollman * documentation and/or other materials provided with the distribution. 162742Swollman * 3. All advertising materials mentioning features or use of this software 17270817Spluknet * must display the following acknowledgement: 18270817Spluknet * This product includes software developed by the University of 19270817Spluknet * California, Berkeley and its contributors. 20270817Spluknet * 4. Neither the name of the University nor the names of its contributors 21270817Spluknet * may be used to endorse or promote products derived from this software 22270817Spluknet * without specific prior written permission. 23270817Spluknet * 2458787Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2558787Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2658787Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 272742Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 282742Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 299908Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 302742Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31270817Spluknet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32270817Spluknet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 339908Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34169811Swollman * SUCH DAMAGE. 35169811Swollman * 36270817Spluknet * @(#)error.h 8.2 (Berkeley) 5/4/95 37270817Spluknet * $Id: error.h,v 1.7 1997/02/22 13:58:23 peter Exp $ 38270817Spluknet */ 39270817Spluknet 40270817Spluknet/* 41270817Spluknet * Types of operations (passed to the errmsg routine). 42270817Spluknet */ 43270817Spluknet 44270817Spluknet#define E_OPEN 01 /* opening a file */ 452742Swollman#define E_CREAT 02 /* creating a file */ 46270817Spluknet#define E_EXEC 04 /* executing a program */ 47270817Spluknet 48169811Swollman 49316350Sbapt/* 50316350Sbapt * We enclose jmp_buf in a structure so that we can declare pointers to 51169811Swollman * jump locations. The global variable handler contains the location to 529908Swollman * jump to when an exception occurs, and the global variable exception 5320094Swollman * contains a code identifying the exeception. To implement nested 54149514Swollman * exception handlers, the user should save the value of handler on entry 5520094Swollman * to an inner scope, set handler to point to a jmploc structure for the 5620094Swollman * inner scope, and restore handler on exit from the scope. 5720094Swollman */ 5820094Swollman 5920094Swollman#include <setjmp.h> 6020094Swollman#include <signal.h> 6120094Swollman 6220094Swollmanstruct jmploc { 6320094Swollman jmp_buf loc; 6420094Swollman}; 65307362Sbapt 66307362Sbaptextern struct jmploc *handler; 67307362Sbaptextern int exception; 68307362Sbapt 69307362Sbapt/* exceptions */ 70307362Sbapt#define EXINT 0 /* SIGINT received */ 71307362Sbapt#define EXERROR 1 /* a generic error */ 72307362Sbapt#define EXSHELLPROC 2 /* execute a shell procedure */ 7320094Swollman#define EXEXEC 3 /* command execution failed */ 74270817Spluknet 75270817Spluknet 76270817Spluknet/* 77270817Spluknet * These macros allow the user to suspend the handling of interrupt signals 78270817Spluknet * over a period of time. This is similar to SIGHOLD to or sigblock, but 79270817Spluknet * much more efficient and portable. (But hacking the kernel is so much 802742Swollman * more fun than worrying about efficiency and portability. :-)) 81270817Spluknet */ 82270817Spluknet 8320094Swollmanextern volatile sig_atomic_t suppressint; 84270817Spluknetextern volatile sig_atomic_t intpending; 85270817Spluknetextern char *commandname; /* name of command--printed on error */ 86270817Spluknet 872742Swollman#define INTOFF suppressint++ 889908Swollman#define INTON { if (--suppressint == 0 && intpending) onint(); } 892742Swollman#define FORCEINTON {suppressint = 0; if (intpending) onint();} 90270817Spluknet#define CLEAR_PENDING_INT intpending = 0 91270817Spluknet#define int_pending() intpending 92270817Spluknet 93270817Spluknetvoid exraise __P((int)); 94270817Spluknetvoid onint __P((void)); 95270817Spluknetvoid error __P((char *, ...)); 96270817Spluknetvoid exerror __P((int, char *, ...)); 97270817Spluknetchar *errmsg __P((int, int)); 98270817Spluknet 99270817Spluknet 100270817Spluknet/* 101270817Spluknet * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 102270817Spluknet * so we use _setjmp instead. 103270817Spluknet */ 104270817Spluknet 1052742Swollman#ifdef BSD 1062742Swollman#define setjmp(jmploc) _setjmp(jmploc) 107270817Spluknet#define longjmp(jmploc, val) _longjmp(jmploc, val) 108270817Spluknet#endif 109270817Spluknet