error.h revision 90111
1298770Sdelphij/*- 2298770Sdelphij * Copyright (c) 1991, 1993 3298770Sdelphij * The Regents of the University of California. All rights reserved. 4298770Sdelphij * 5298770Sdelphij * This code is derived from software contributed to Berkeley by 6298770Sdelphij * Kenneth Almquist. 7298770Sdelphij * 8298770Sdelphij * Redistribution and use in source and binary forms, with or without 9298770Sdelphij * modification, are permitted provided that the following conditions 10298770Sdelphij * are met: 11298770Sdelphij * 1. Redistributions of source code must retain the above copyright 12298770Sdelphij * notice, this list of conditions and the following disclaimer. 13298770Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 14298770Sdelphij * notice, this list of conditions and the following disclaimer in the 15298770Sdelphij * documentation and/or other materials provided with the distribution. 16298770Sdelphij * 3. All advertising materials mentioning features or use of this software 17298770Sdelphij * must display the following acknowledgement: 18298770Sdelphij * This product includes software developed by the University of 19298770Sdelphij * California, Berkeley and its contributors. 20298770Sdelphij * 4. Neither the name of the University nor the names of its contributors 21298770Sdelphij * may be used to endorse or promote products derived from this software 22298770Sdelphij * without specific prior written permission. 23298770Sdelphij * 24298770Sdelphij * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25298770Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26298770Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27298770Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28298770Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29298770Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30298770Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31298770Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32298770Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33298770Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34298770Sdelphij * SUCH DAMAGE. 35298770Sdelphij * 36298770Sdelphij * @(#)error.h 8.2 (Berkeley) 5/4/95 37298770Sdelphij * $FreeBSD: head/bin/sh/error.h 90111 2002-02-02 06:50:57Z imp $ 38298770Sdelphij */ 39298770Sdelphij 40298770Sdelphij/* 41298770Sdelphij * Types of operations (passed to the errmsg routine). 42298770Sdelphij */ 43298770Sdelphij 44298770Sdelphij#define E_OPEN 01 /* opening a file */ 45298770Sdelphij#define E_CREAT 02 /* creating a file */ 46298770Sdelphij#define E_EXEC 04 /* executing a program */ 47298770Sdelphij 48298770Sdelphij 49298770Sdelphij/* 50298770Sdelphij * We enclose jmp_buf in a structure so that we can declare pointers to 51298770Sdelphij * jump locations. The global variable handler contains the location to 52298770Sdelphij * jump to when an exception occurs, and the global variable exception 53298770Sdelphij * contains a code identifying the exception. To implement nested 54298770Sdelphij * exception handlers, the user should save the value of handler on entry 55298770Sdelphij * to an inner scope, set handler to point to a jmploc structure for the 56298770Sdelphij * inner scope, and restore handler on exit from the scope. 57298770Sdelphij */ 58298770Sdelphij 59298770Sdelphij#include <setjmp.h> 60298770Sdelphij#include <signal.h> 61298770Sdelphij 62298770Sdelphijstruct jmploc { 63298770Sdelphij jmp_buf loc; 64298770Sdelphij}; 65298770Sdelphij 66298770Sdelphijextern struct jmploc *handler; 67298770Sdelphijextern volatile sig_atomic_t exception; 68298770Sdelphij 69298770Sdelphij/* exceptions */ 70298770Sdelphij#define EXINT 0 /* SIGINT received */ 71298770Sdelphij#define EXERROR 1 /* a generic error */ 72298770Sdelphij#define EXSHELLPROC 2 /* execute a shell procedure */ 73298770Sdelphij#define EXEXEC 3 /* command execution failed */ 74298770Sdelphij 75298770Sdelphij 76298770Sdelphij/* 77298770Sdelphij * These macros allow the user to suspend the handling of interrupt signals 78298770Sdelphij * over a period of time. This is similar to SIGHOLD to or sigblock, but 79298770Sdelphij * much more efficient and portable. (But hacking the kernel is so much 80298770Sdelphij * more fun than worrying about efficiency and portability. :-)) 81298770Sdelphij */ 82298770Sdelphij 83298770Sdelphijextern volatile sig_atomic_t suppressint; 84298770Sdelphijextern volatile sig_atomic_t intpending; 85298770Sdelphij 86298770Sdelphij#define INTOFF suppressint++ 87298770Sdelphij#define INTON { if (--suppressint == 0 && intpending) onint(); } 88298770Sdelphij#define FORCEINTON {suppressint = 0; if (intpending) onint();} 89298770Sdelphij#define CLEAR_PENDING_INT intpending = 0 90298770Sdelphij#define int_pending() intpending 91 92void exraise(int); 93void onint(void); 94void error(const char *, ...) __printf0like(1, 2); 95void exerror(int, const char *, ...) __printf0like(2, 3); 96char *errmsg(int, int); 97 98 99/* 100 * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 101 * so we use _setjmp instead. 102 */ 103 104#ifdef BSD 105#define setjmp(jmploc) _setjmp(jmploc) 106#define longjmp(jmploc, val) _longjmp(jmploc, val) 107#endif 108