xref: /minix3/bin/sh/error.h (revision d90bee97498b3043241050f61aed100786c59df4)
1*d90bee97SLionel Sambuc /*	$NetBSD: error.h,v 1.19 2012/03/15 02:02:20 joerg Exp $	*/
2*d90bee97SLionel Sambuc 
3*d90bee97SLionel Sambuc /*-
4*d90bee97SLionel Sambuc  * Copyright (c) 1991, 1993
5*d90bee97SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
6*d90bee97SLionel Sambuc  *
7*d90bee97SLionel Sambuc  * This code is derived from software contributed to Berkeley by
8*d90bee97SLionel Sambuc  * Kenneth Almquist.
9*d90bee97SLionel Sambuc  *
10*d90bee97SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11*d90bee97SLionel Sambuc  * modification, are permitted provided that the following conditions
12*d90bee97SLionel Sambuc  * are met:
13*d90bee97SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14*d90bee97SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15*d90bee97SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16*d90bee97SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17*d90bee97SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18*d90bee97SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
19*d90bee97SLionel Sambuc  *    may be used to endorse or promote products derived from this software
20*d90bee97SLionel Sambuc  *    without specific prior written permission.
21*d90bee97SLionel Sambuc  *
22*d90bee97SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*d90bee97SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*d90bee97SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*d90bee97SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*d90bee97SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*d90bee97SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*d90bee97SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*d90bee97SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*d90bee97SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*d90bee97SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*d90bee97SLionel Sambuc  * SUCH DAMAGE.
33*d90bee97SLionel Sambuc  *
34*d90bee97SLionel Sambuc  *	@(#)error.h	8.2 (Berkeley) 5/4/95
35*d90bee97SLionel Sambuc  */
36*d90bee97SLionel Sambuc 
37*d90bee97SLionel Sambuc #include <stdarg.h>
38*d90bee97SLionel Sambuc 
39*d90bee97SLionel Sambuc /*
40*d90bee97SLionel Sambuc  * Types of operations (passed to the errmsg routine).
41*d90bee97SLionel Sambuc  */
42*d90bee97SLionel Sambuc 
43*d90bee97SLionel Sambuc #define E_OPEN 01	/* opening a file */
44*d90bee97SLionel Sambuc #define E_CREAT 02	/* creating a file */
45*d90bee97SLionel Sambuc #define E_EXEC 04	/* executing a program */
46*d90bee97SLionel Sambuc 
47*d90bee97SLionel Sambuc 
48*d90bee97SLionel Sambuc /*
49*d90bee97SLionel Sambuc  * We enclose jmp_buf in a structure so that we can declare pointers to
50*d90bee97SLionel Sambuc  * jump locations.  The global variable handler contains the location to
51*d90bee97SLionel Sambuc  * jump to when an exception occurs, and the global variable exception
52*d90bee97SLionel Sambuc  * contains a code identifying the exeception.  To implement nested
53*d90bee97SLionel Sambuc  * exception handlers, the user should save the value of handler on entry
54*d90bee97SLionel Sambuc  * to an inner scope, set handler to point to a jmploc structure for the
55*d90bee97SLionel Sambuc  * inner scope, and restore handler on exit from the scope.
56*d90bee97SLionel Sambuc  */
57*d90bee97SLionel Sambuc 
58*d90bee97SLionel Sambuc #include <setjmp.h>
59*d90bee97SLionel Sambuc 
60*d90bee97SLionel Sambuc struct jmploc {
61*d90bee97SLionel Sambuc 	jmp_buf loc;
62*d90bee97SLionel Sambuc };
63*d90bee97SLionel Sambuc 
64*d90bee97SLionel Sambuc extern struct jmploc *handler;
65*d90bee97SLionel Sambuc extern int exception;
66*d90bee97SLionel Sambuc extern int exerrno;	/* error for EXEXEC */
67*d90bee97SLionel Sambuc 
68*d90bee97SLionel Sambuc /* exceptions */
69*d90bee97SLionel Sambuc #define EXINT 0		/* SIGINT received */
70*d90bee97SLionel Sambuc #define EXERROR 1	/* a generic error */
71*d90bee97SLionel Sambuc #define EXSHELLPROC 2	/* execute a shell procedure */
72*d90bee97SLionel Sambuc #define EXEXEC 3	/* command execution failed */
73*d90bee97SLionel Sambuc 
74*d90bee97SLionel Sambuc 
75*d90bee97SLionel Sambuc /*
76*d90bee97SLionel Sambuc  * These macros allow the user to suspend the handling of interrupt signals
77*d90bee97SLionel Sambuc  * over a period of time.  This is similar to SIGHOLD to or sigblock, but
78*d90bee97SLionel Sambuc  * much more efficient and portable.  (But hacking the kernel is so much
79*d90bee97SLionel Sambuc  * more fun than worrying about efficiency and portability. :-))
80*d90bee97SLionel Sambuc  */
81*d90bee97SLionel Sambuc 
82*d90bee97SLionel Sambuc extern volatile int suppressint;
83*d90bee97SLionel Sambuc extern volatile int intpending;
84*d90bee97SLionel Sambuc 
85*d90bee97SLionel Sambuc #define INTOFF suppressint++
86*d90bee97SLionel Sambuc #define INTON { if (--suppressint == 0 && intpending) onint(); }
87*d90bee97SLionel Sambuc #define FORCEINTON {suppressint = 0; if (intpending) onint();}
88*d90bee97SLionel Sambuc #define CLEAR_PENDING_INT intpending = 0
89*d90bee97SLionel Sambuc #define int_pending() intpending
90*d90bee97SLionel Sambuc 
91*d90bee97SLionel Sambuc #if ! defined(SHELL_BUILTIN)
92*d90bee97SLionel Sambuc void exraise(int) __dead;
93*d90bee97SLionel Sambuc void onint(void);
94*d90bee97SLionel Sambuc void error(const char *, ...) __dead __printflike(1, 2);
95*d90bee97SLionel Sambuc void exerror(int, const char *, ...) __dead __printflike(2, 3);
96*d90bee97SLionel Sambuc const char *errmsg(int, int);
97*d90bee97SLionel Sambuc #endif /* ! SHELL_BUILTIN */
98*d90bee97SLionel Sambuc 
99*d90bee97SLionel Sambuc void sh_err(int, const char *, ...) __dead __printflike(2, 3);
100*d90bee97SLionel Sambuc void sh_verr(int, const char *, va_list) __dead __printflike(2, 0);
101*d90bee97SLionel Sambuc void sh_errx(int, const char *, ...) __dead __printflike(2, 3);
102*d90bee97SLionel Sambuc void sh_verrx(int, const char *, va_list) __dead __printflike(2, 0);
103*d90bee97SLionel Sambuc void sh_warn(const char *, ...) __printflike(1, 2);
104*d90bee97SLionel Sambuc void sh_vwarn(const char *, va_list) __printflike(1, 0);
105*d90bee97SLionel Sambuc void sh_warnx(const char *, ...) __printflike(1, 2);
106*d90bee97SLionel Sambuc void sh_vwarnx(const char *, va_list) __printflike(1, 0);
107*d90bee97SLionel Sambuc 
108*d90bee97SLionel Sambuc void sh_exit(int) __dead;
109*d90bee97SLionel Sambuc 
110*d90bee97SLionel Sambuc 
111*d90bee97SLionel Sambuc /*
112*d90bee97SLionel Sambuc  * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
113*d90bee97SLionel Sambuc  * so we use _setjmp instead.
114*d90bee97SLionel Sambuc  */
115*d90bee97SLionel Sambuc 
116*d90bee97SLionel Sambuc #if defined(BSD) && !defined(__SVR4)
117*d90bee97SLionel Sambuc #define setjmp(jmploc)	_setjmp(jmploc)
118*d90bee97SLionel Sambuc #define longjmp(jmploc, val)	_longjmp(jmploc, val)
119*d90bee97SLionel Sambuc #endif
120