error.h revision 3044
1204076Spjd/*-
2204076Spjd * Copyright (c) 1991, 1993
3204076Spjd *	The Regents of the University of California.  All rights reserved.
4204076Spjd *
5204076Spjd * This code is derived from software contributed to Berkeley by
6204076Spjd * Kenneth Almquist.
7204076Spjd *
8204076Spjd * Redistribution and use in source and binary forms, with or without
9204076Spjd * modification, are permitted provided that the following conditions
10204076Spjd * are met:
11204076Spjd * 1. Redistributions of source code must retain the above copyright
12204076Spjd *    notice, this list of conditions and the following disclaimer.
13204076Spjd * 2. Redistributions in binary form must reproduce the above copyright
14204076Spjd *    notice, this list of conditions and the following disclaimer in the
15204076Spjd *    documentation and/or other materials provided with the distribution.
16204076Spjd * 3. All advertising materials mentioning features or use of this software
17204076Spjd *    must display the following acknowledgement:
18204076Spjd *	This product includes software developed by the University of
19204076Spjd *	California, Berkeley and its contributors.
20204076Spjd * 4. Neither the name of the University nor the names of its contributors
21204076Spjd *    may be used to endorse or promote products derived from this software
22204076Spjd *    without specific prior written permission.
23204076Spjd *
24204076Spjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27204076Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31204076Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34204076Spjd * SUCH DAMAGE.
35204076Spjd *
36204076Spjd *	@(#)error.h	8.1 (Berkeley) 5/31/93
37204076Spjd *	$Id$
38204076Spjd */
39204076Spjd
40204076Spjd/*
41204076Spjd * Types of operations (passed to the errmsg routine).
42204076Spjd */
43204076Spjd
44204076Spjd#define E_OPEN 01	/* opening a file */
45204076Spjd#define E_CREAT 02	/* creating a file */
46204076Spjd#define E_EXEC 04	/* executing a program */
47204076Spjd
48204076Spjd
49/*
50 * We enclose jmp_buf in a structure so that we can declare pointers to
51 * jump locations.  The global variable handler contains the location to
52 * jump to when an exception occurs, and the global variable exception
53 * contains a code identifying the exeception.  To implement nested
54 * exception handlers, the user should save the value of handler on entry
55 * to an inner scope, set handler to point to a jmploc structure for the
56 * inner scope, and restore handler on exit from the scope.
57 */
58
59#include <setjmp.h>
60
61struct jmploc {
62	jmp_buf loc;
63};
64
65extern struct jmploc *handler;
66extern int exception;
67
68/* exceptions */
69#define EXINT 0		/* SIGINT received */
70#define EXERROR 1	/* a generic error */
71#define EXSHELLPROC 2	/* execute a shell procedure */
72
73
74/*
75 * These macros allow the user to suspend the handling of interrupt signals
76 * over a period of time.  This is similar to SIGHOLD to or sigblock, but
77 * much more efficient and portable.  (But hacking the kernel is so much
78 * more fun than worrying about efficiency and portability. :-))
79 */
80
81extern volatile int suppressint;
82extern volatile int intpending;
83extern char *commandname;	/* name of command--printed on error */
84
85#define INTOFF suppressint++
86#define INTON if (--suppressint == 0 && intpending) onint(); else
87#define FORCEINTON {suppressint = 0; if (intpending) onint();}
88#define CLEAR_PENDING_INT intpending = 0
89#define int_pending() intpending
90
91#ifdef __STDC__
92void exraise(int);
93void onint(void);
94void error2(char *, char *);
95void error(char *, ...);
96char *errmsg(int, int);
97#else
98void exraise();
99void onint();
100void error2();
101void error();
102char *errmsg();
103#endif
104
105
106/*
107 * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
108 * so we use _setjmp instead.
109 */
110
111#ifdef BSD
112#define setjmp(jmploc)	_setjmp(jmploc)
113#define longjmp(jmploc, val)	_longjmp(jmploc, val)
114#endif
115