147111Sbostic /*- 260698Sbostic * Copyright (c) 1991, 1993 360698Sbostic * The Regents of the University of California. All rights reserved. 447111Sbostic * 547111Sbostic * This code is derived from software contributed to Berkeley by 647111Sbostic * Kenneth Almquist. 747111Sbostic * 847111Sbostic * %sccs.include.redist.c% 947111Sbostic * 10*69272Schristos * @(#)error.h 8.2 (Berkeley) 05/04/95 1147111Sbostic */ 1247111Sbostic 1347111Sbostic /* 1447111Sbostic * Types of operations (passed to the errmsg routine). 1547111Sbostic */ 1647111Sbostic 1747111Sbostic #define E_OPEN 01 /* opening a file */ 1847111Sbostic #define E_CREAT 02 /* creating a file */ 1947111Sbostic #define E_EXEC 04 /* executing a program */ 2047111Sbostic 2147111Sbostic 2247111Sbostic /* 2347111Sbostic * We enclose jmp_buf in a structure so that we can declare pointers to 2447111Sbostic * jump locations. The global variable handler contains the location to 2547111Sbostic * jump to when an exception occurs, and the global variable exception 2647111Sbostic * contains a code identifying the exeception. To implement nested 2747111Sbostic * exception handlers, the user should save the value of handler on entry 2847111Sbostic * to an inner scope, set handler to point to a jmploc structure for the 2947111Sbostic * inner scope, and restore handler on exit from the scope. 3047111Sbostic */ 3147111Sbostic 3247111Sbostic #include <setjmp.h> 3347111Sbostic 3447111Sbostic struct jmploc { 3547111Sbostic jmp_buf loc; 3647111Sbostic }; 3747111Sbostic 3847111Sbostic extern struct jmploc *handler; 3947111Sbostic extern int exception; 4047111Sbostic 4147111Sbostic /* exceptions */ 4247111Sbostic #define EXINT 0 /* SIGINT received */ 4347111Sbostic #define EXERROR 1 /* a generic error */ 4447111Sbostic #define EXSHELLPROC 2 /* execute a shell procedure */ 4547111Sbostic 4647111Sbostic 4747111Sbostic /* 4847111Sbostic * These macros allow the user to suspend the handling of interrupt signals 4947111Sbostic * over a period of time. This is similar to SIGHOLD to or sigblock, but 5047111Sbostic * much more efficient and portable. (But hacking the kernel is so much 5147111Sbostic * more fun than worrying about efficiency and portability. :-)) 5247111Sbostic */ 5347111Sbostic 5447111Sbostic extern volatile int suppressint; 5547111Sbostic extern volatile int intpending; 5647111Sbostic extern char *commandname; /* name of command--printed on error */ 5747111Sbostic 5847111Sbostic #define INTOFF suppressint++ 59*69272Schristos #define INTON { if (--suppressint == 0 && intpending) onint(); } 6047111Sbostic #define FORCEINTON {suppressint = 0; if (intpending) onint();} 6147111Sbostic #define CLEAR_PENDING_INT intpending = 0 6247111Sbostic #define int_pending() intpending 6347111Sbostic 64*69272Schristos void exraise __P((int)); 65*69272Schristos void onint __P((void)); 66*69272Schristos void error2 __P((char *, char *)); 67*69272Schristos void error __P((char *, ...)); 68*69272Schristos char *errmsg __P((int, int)); 6947111Sbostic 7047111Sbostic 7147111Sbostic /* 7247111Sbostic * BSD setjmp saves the signal mask, which violates ANSI C and takes time, 7347111Sbostic * so we use _setjmp instead. 7447111Sbostic */ 7547111Sbostic 7647111Sbostic #ifdef BSD 7747111Sbostic #define setjmp(jmploc) _setjmp(jmploc) 7847111Sbostic #define longjmp(jmploc, val) _longjmp(jmploc, val) 7947111Sbostic #endif 80