error.h revision 127958
156160Sru/*-
2146515Sru * Copyright (c) 1991, 1993
356160Sru *	The Regents of the University of California.  All rights reserved.
4146515Sru *
5116525Sru * This code is derived from software contributed to Berkeley by
656160Sru * Kenneth Almquist.
756160Sru *
856160Sru * Redistribution and use in source and binary forms, with or without
956160Sru * modification, are permitted provided that the following conditions
1056160Sru * are met:
1156160Sru * 1. Redistributions of source code must retain the above copyright
1256160Sru *    notice, this list of conditions and the following disclaimer.
1356160Sru * 2. Redistributions in binary form must reproduce the above copyright
1456160Sru *    notice, this list of conditions and the following disclaimer in the
1556160Sru *    documentation and/or other materials provided with the distribution.
1656160Sru * 4. Neither the name of the University nor the names of its contributors
1756160Sru *    may be used to endorse or promote products derived from this software
1856160Sru *    without specific prior written permission.
1956160Sru *
2056160Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2156160Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2256160Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23114472Sru * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2456160Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2556160Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26114472Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27114472Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2856160Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2956160Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3056160Sru * SUCH DAMAGE.
3156160Sru *
3256160Sru *	@(#)error.h	8.2 (Berkeley) 5/4/95
3356160Sru * $FreeBSD: head/bin/sh/error.h 127958 2004-04-06 20:06:54Z markm $
3456160Sru */
3556160Sru
3656160Sru/*
3756160Sru * We enclose jmp_buf in a structure so that we can declare pointers to
3856160Sru * jump locations.  The global variable handler contains the location to
3956160Sru * jump to when an exception occurs, and the global variable exception
4056160Sru * contains a code identifying the exception.  To implement nested
41146515Sru * exception handlers, the user should save the value of handler on entry
4256160Sru * to an inner scope, set handler to point to a jmploc structure for the
4356160Sru * inner scope, and restore handler on exit from the scope.
4456160Sru */
4556160Sru
4656160Sru#include <setjmp.h>
4756160Sru#include <signal.h>
4856160Sru
49146515Srustruct jmploc {
5056160Sru	jmp_buf loc;
5156160Sru};
5256160Sru
5356160Sruextern struct jmploc *handler;
5456160Sruextern volatile sig_atomic_t exception;
5556160Sru
5656160Sru/* exceptions */
5756160Sru#define EXINT 0		/* SIGINT received */
5856160Sru#define EXERROR 1	/* a generic error */
5956160Sru#define EXSHELLPROC 2	/* execute a shell procedure */
6056160Sru#define EXEXEC 3	/* command execution failed */
6156160Sru
6256160Sru
6356160Sru/*
64146515Sru * These macros allow the user to suspend the handling of interrupt signals
6556160Sru * over a period of time.  This is similar to SIGHOLD to or sigblock, but
6656160Sru * much more efficient and portable.  (But hacking the kernel is so much
6756160Sru * more fun than worrying about efficiency and portability. :-))
68100513Sru */
6956160Sru
7056160Sruextern volatile sig_atomic_t suppressint;
7156160Sruextern volatile sig_atomic_t intpending;
7256160Sru
7356160Sru#define INTOFF suppressint++
7456160Sru#define INTON { if (--suppressint == 0 && intpending) onint(); }
7556160Sru#define FORCEINTON {suppressint = 0; if (intpending) onint();}
7656160Sru#define CLEAR_PENDING_INT intpending = 0
7756160Sru#define int_pending() intpending
7856160Sru
7956160Sruvoid exraise(int);
8056160Sruvoid onint(void);
8156160Sruvoid error(const char *, ...) __printf0like(1, 2);
8256160Sruvoid exerror(int, const char *, ...) __printf0like(2, 3);
83100513Sru
8456160Sru
85100513Sru/*
8656160Sru * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
8756160Sru * so we use _setjmp instead.
8856160Sru */
8956160Sru
90100513Sru#define setjmp(jmploc)	_setjmp(jmploc)
91100513Sru#define longjmp(jmploc, val)	_longjmp(jmploc, val)
92100513Sru