00001 /*- 00002 * Copyright (c) 1991, 1993 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * This code is derived from software contributed to Berkeley by 00006 * Kenneth Almquist. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 4. Neither the name of the University nor the names of its contributors 00017 * may be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00024 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00026 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00027 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00028 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00029 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 * @(#)error.h 8.2 (Berkeley) 5/4/95 00033 * $FreeBSD: src/bin/sh/error.h,v 1.17 2004/04/06 20:06:51 markm Exp $ 00034 */ 00035 00036 /* 00037 * We enclose jmp_buf in a structure so that we can declare pointers to 00038 * jump locations. The global variable handler contains the location to 00039 * jump to when an exception occurs, and the global variable exception 00040 * contains a code identifying the exception. To implement nested 00041 * exception handlers, the user should save the value of handler on entry 00042 * to an inner scope, set handler to point to a jmploc structure for the 00043 * inner scope, and restore handler on exit from the scope. 00044 */ 00045 00046 #include <setjmp.h> 00047 #include <signal.h> 00048 00049 struct jmploc { 00050 jmp_buf loc; 00051 }; 00052 00053 extern struct jmploc *handler; 00054 extern volatile sig_atomic_t exception; 00055 00056 /* exceptions */ 00057 #define EXINT 0 /* SIGINT received */ 00058 #define EXERROR 1 /* a generic error */ 00059 #define EXSHELLPROC 2 /* execute a shell procedure */ 00060 #define EXEXEC 3 /* command execution failed */ 00061 00062 00063 /* 00064 * These macros allow the user to suspend the handling of interrupt signals 00065 * over a period of time. This is similar to SIGHOLD to or sigblock, but 00066 * much more efficient and portable. (But hacking the kernel is so much 00067 * more fun than worrying about efficiency and portability. :-)) 00068 */ 00069 00070 extern volatile sig_atomic_t suppressint; 00071 extern volatile sig_atomic_t intpending; 00072 00073 #define INTOFF suppressint++ 00074 #define INTON { if (--suppressint == 0 && intpending) onint(); } 00075 #define FORCEINTON {suppressint = 0; if (intpending) onint();} 00076 #define CLEAR_PENDING_INT intpending = 0 00077 #define int_pending() intpending 00078 00079 #define __printf0like(a,b) 00080 00081 void exraise(int); 00082 void onint(void); 00083 void error(const char *, ...) __printf0like(1, 2); 00084 void exerror(int, const char *, ...) __printf0like(2, 3); 00085 00086 00087 /* 00088 * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 00089 * so we use _setjmp instead. 00090 */ 00091 00092 #ifdef BSD 00093 #ifndef __minix 00094 #define setjmp(jmploc) _setjmp(jmploc) 00095 #define longjmp(jmploc, val) _longjmp(jmploc, val) 00096 #endif 00097 #endif 00098 00099 /* 00100 * $PchId: error.h,v 1.5 2006/04/10 14:36:43 philip Exp $ 00101 */
1.5.8