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