xref: /original-bsd/bin/sh/error.h (revision b3c06cab)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Kenneth Almquist.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)error.h	8.2 (Berkeley) 05/04/95
11  */
12 
13 /*
14  * Types of operations (passed to the errmsg routine).
15  */
16 
17 #define E_OPEN 01	/* opening a file */
18 #define E_CREAT 02	/* creating a file */
19 #define E_EXEC 04	/* executing a program */
20 
21 
22 /*
23  * We enclose jmp_buf in a structure so that we can declare pointers to
24  * jump locations.  The global variable handler contains the location to
25  * jump to when an exception occurs, and the global variable exception
26  * contains a code identifying the exeception.  To implement nested
27  * exception handlers, the user should save the value of handler on entry
28  * to an inner scope, set handler to point to a jmploc structure for the
29  * inner scope, and restore handler on exit from the scope.
30  */
31 
32 #include <setjmp.h>
33 
34 struct jmploc {
35 	jmp_buf loc;
36 };
37 
38 extern struct jmploc *handler;
39 extern int exception;
40 
41 /* exceptions */
42 #define EXINT 0		/* SIGINT received */
43 #define EXERROR 1	/* a generic error */
44 #define EXSHELLPROC 2	/* execute a shell procedure */
45 
46 
47 /*
48  * These macros allow the user to suspend the handling of interrupt signals
49  * over a period of time.  This is similar to SIGHOLD to or sigblock, but
50  * much more efficient and portable.  (But hacking the kernel is so much
51  * more fun than worrying about efficiency and portability. :-))
52  */
53 
54 extern volatile int suppressint;
55 extern volatile int intpending;
56 extern char *commandname;	/* name of command--printed on error */
57 
58 #define INTOFF suppressint++
59 #define INTON { if (--suppressint == 0 && intpending) onint(); }
60 #define FORCEINTON {suppressint = 0; if (intpending) onint();}
61 #define CLEAR_PENDING_INT intpending = 0
62 #define int_pending() intpending
63 
64 void exraise __P((int));
65 void onint __P((void));
66 void error2 __P((char *, char *));
67 void error __P((char *, ...));
68 char *errmsg __P((int, int));
69 
70 
71 /*
72  * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
73  * so we use _setjmp instead.
74  */
75 
76 #ifdef BSD
77 #define setjmp(jmploc)	_setjmp(jmploc)
78 #define longjmp(jmploc, val)	_longjmp(jmploc, val)
79 #endif
80