error.h revision 90111
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Kenneth Almquist. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 3. All advertising materials mentioning features or use of this software 171556Srgrimes * must display the following acknowledgement: 181556Srgrimes * This product includes software developed by the University of 191556Srgrimes * California, Berkeley and its contributors. 201556Srgrimes * 4. Neither the name of the University nor the names of its contributors 211556Srgrimes * may be used to endorse or promote products derived from this software 221556Srgrimes * without specific prior written permission. 231556Srgrimes * 241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341556Srgrimes * SUCH DAMAGE. 351556Srgrimes * 3617987Speter * @(#)error.h 8.2 (Berkeley) 5/4/95 3750471Speter * $FreeBSD: head/bin/sh/error.h 90111 2002-02-02 06:50:57Z imp $ 381556Srgrimes */ 391556Srgrimes 401556Srgrimes/* 411556Srgrimes * Types of operations (passed to the errmsg routine). 421556Srgrimes */ 431556Srgrimes 441556Srgrimes#define E_OPEN 01 /* opening a file */ 451556Srgrimes#define E_CREAT 02 /* creating a file */ 461556Srgrimes#define E_EXEC 04 /* executing a program */ 471556Srgrimes 481556Srgrimes 491556Srgrimes/* 501556Srgrimes * We enclose jmp_buf in a structure so that we can declare pointers to 511556Srgrimes * jump locations. The global variable handler contains the location to 521556Srgrimes * jump to when an exception occurs, and the global variable exception 5346684Skris * contains a code identifying the exception. To implement nested 541556Srgrimes * exception handlers, the user should save the value of handler on entry 551556Srgrimes * to an inner scope, set handler to point to a jmploc structure for the 561556Srgrimes * inner scope, and restore handler on exit from the scope. 571556Srgrimes */ 581556Srgrimes 591556Srgrimes#include <setjmp.h> 6038521Scracauer#include <signal.h> 611556Srgrimes 621556Srgrimesstruct jmploc { 631556Srgrimes jmp_buf loc; 641556Srgrimes}; 651556Srgrimes 661556Srgrimesextern struct jmploc *handler; 6738530Scracauerextern volatile sig_atomic_t exception; 681556Srgrimes 691556Srgrimes/* exceptions */ 701556Srgrimes#define EXINT 0 /* SIGINT received */ 711556Srgrimes#define EXERROR 1 /* a generic error */ 721556Srgrimes#define EXSHELLPROC 2 /* execute a shell procedure */ 7320425Ssteve#define EXEXEC 3 /* command execution failed */ 741556Srgrimes 751556Srgrimes 761556Srgrimes/* 771556Srgrimes * These macros allow the user to suspend the handling of interrupt signals 781556Srgrimes * over a period of time. This is similar to SIGHOLD to or sigblock, but 791556Srgrimes * much more efficient and portable. (But hacking the kernel is so much 801556Srgrimes * more fun than worrying about efficiency and portability. :-)) 811556Srgrimes */ 821556Srgrimes 8338521Scracauerextern volatile sig_atomic_t suppressint; 8438521Scracauerextern volatile sig_atomic_t intpending; 851556Srgrimes 861556Srgrimes#define INTOFF suppressint++ 8717987Speter#define INTON { if (--suppressint == 0 && intpending) onint(); } 881556Srgrimes#define FORCEINTON {suppressint = 0; if (intpending) onint();} 891556Srgrimes#define CLEAR_PENDING_INT intpending = 0 901556Srgrimes#define int_pending() intpending 911556Srgrimes 9290111Simpvoid exraise(int); 9390111Simpvoid onint(void); 9490111Simpvoid error(const char *, ...) __printf0like(1, 2); 9590111Simpvoid exerror(int, const char *, ...) __printf0like(2, 3); 9690111Simpchar *errmsg(int, int); 971556Srgrimes 981556Srgrimes 991556Srgrimes/* 1001556Srgrimes * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 1011556Srgrimes * so we use _setjmp instead. 1021556Srgrimes */ 1031556Srgrimes 1041556Srgrimes#ifdef BSD 1051556Srgrimes#define setjmp(jmploc) _setjmp(jmploc) 1061556Srgrimes#define longjmp(jmploc, val) _longjmp(jmploc, val) 1071556Srgrimes#endif 108