fatal.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 135 行

C
135
字号
#ifndef lintstatic	char	*sccsid = "@(#)fatal.c	4.1	(ULTRIX)	7/17/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1984 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/	/* fatal.c 1.2 83/07/09 decvax!jmcg */	/* fatal.c -- from system III distribution *//****************************************************************** * * 9Jul83 -- jmcg *	Longjmp takes two arguments in 4.2BSD.  It's sufficient to *	make it non-zero. * * 25 Aug 88 -- reeves *	Remove hardwired Fjmp size ******************************************************************/# include	"sys/types.h"# include	"macros.h"# include	"fatal.h"/*	General purpose error handler.	Typically, low level subroutines which detect error conditions	(an open or create routine, for example) return the	value of calling fatal with an appropriate error message string.	E.g.,	return(fatal("can't do it"));	Higher level routines control the execution of fatal	via the global word Fflags.	The macros FSAVE and FRSTR in <fatal.h> can be used by higher	level subroutines to save and restore the Fflags word. 	The argument to fatal is a pointer to an error message string.	The action of this routine is driven completely from	the "Fflags" global word (see <fatal.h>).	The following discusses the interpretation of the various bits	of Fflags. 	The FTLMSG bit controls the writing of the error	message on file descriptor 2.  The message is preceded	by the string "ERROR: ", unless the global character pointer	"Ffile" is non-zero, in which case the message is preceded	by the string "ERROR [<Ffile>]: ".  A newline is written	after the user supplied message. 	If the FTLCLN bit is on, clean_up is called with an	argument of 0 (see clean.c). 	If the FTLFUNC bit is on, the function pointed to by the global	function pointer "Ffunc" is called with the user supplied	error message pointer as argument.	(This feature can be used to log error messages). 	The FTLACT bits determine how fatal should return.	If the FTLJMP bit is on longjmp(Fjmp) is	called (Fjmp is a global jmp_buf, see	setjmp, longjmp documentation). 	If the FTLEXIT bit is on the value of userexit(1) is	passed as an argument to exit(II)	(see userexit.c). 	If none of the FTLACT bits are on	(the default value for Fflags is 0), the global word	"Fvalue" (initialized to -1) is returned. 	If all fatal globals have their default values, fatal simply	returns -1.*/int	Fcnt;int	Fflags;char	*Ffile;int	Fvalue = -1;int	(*Ffunc)();jmp_buf	Fjmp;fatal(msg)char *msg;{	++Fcnt;	if (Fflags & FTLMSG) {		write(2,"ERROR",5);		if (Ffile) {			write(2," [",2);			write(2,Ffile,length(Ffile));			write(2,"]",1);		}		write(2,": ",2);		write(2,msg,length(msg));		write(2,"\n",1);	}	if (Fflags & FTLCLN)		clean_up(0);	if (Fflags & FTLFUNC)		(*Ffunc)(msg);	switch (Fflags & FTLACT) {	case FTLJMP:		longjmp(Fjmp, 1);	case FTLEXIT:		exit(userexit(1));	case FTLRET:		return(Fvalue);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?