Commit | Line | Data |
---|---|---|
65a7653c KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * 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 5.1 (Berkeley) %G% | |
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(); else | |
60 | #define FORCEINTON {suppressint = 0; if (intpending) onint();} | |
61 | #define CLEAR_PENDING_INT intpending = 0 | |
62 | #define int_pending() intpending | |
63 | ||
64 | #ifdef __STDC__ | |
65 | void exraise(int); | |
66 | void onint(void); | |
67 | void error2(char *, char *); | |
68 | void error(char *, ...); | |
69 | char *errmsg(int, int); | |
70 | #else | |
71 | void exraise(); | |
72 | void onint(); | |
73 | void error2(); | |
74 | void error(); | |
75 | char *errmsg(); | |
76 | #endif | |
77 | ||
78 | ||
79 | /* | |
80 | * BSD setjmp saves the signal mask, which violates ANSI C and takes time, | |
81 | * so we use _setjmp instead. | |
82 | */ | |
83 | ||
84 | #ifdef BSD | |
85 | #define setjmp(jmploc) _setjmp(jmploc) | |
86 | #define longjmp(jmploc, val) _longjmp(jmploc, val) | |
87 | #endif |