xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/out.h (revision 6277:1ae6f93f8c0a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51717Swesolows  * Common Development and Distribution License (the "License").
61717Swesolows  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211717Swesolows 
220Sstevel@tonic-gate /*
23*6277Scy152378  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * out.h -- public definitions for output module
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  * general output & error handling routines.  the routine out() is
290Sstevel@tonic-gate  * the most commonly used routine in this module -- called by virtually
300Sstevel@tonic-gate  * all other modules.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifndef	_ESC_COMMON_OUT_H
340Sstevel@tonic-gate #define	_ESC_COMMON_OUT_H
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include <stdio.h>
39*6277Scy152378 #include <sys/ccompile.h>
40*6277Scy152378 #include <inttypes.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate void out_init(const char *myname);
470Sstevel@tonic-gate void out_fini(void);
480Sstevel@tonic-gate void out(int flags, const char *fmt, ...);
490Sstevel@tonic-gate void outfl(int flags, const char *fname, int line, const char *fmt, ...);
501717Swesolows void out_exit(int code) __NORETURN;
510Sstevel@tonic-gate void out_altfp(FILE *fp);
520Sstevel@tonic-gate int out_errcount(void);
530Sstevel@tonic-gate int out_warncount(void);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /* flags for out() */
560Sstevel@tonic-gate #define	O_OK	0x0000	/* simple output pseudo-flag */
570Sstevel@tonic-gate #define	O_DIE	0x0001	/* O_PROG, stderr, bump exit code, call out_exit() */
580Sstevel@tonic-gate #define	O_ERR	0x0002	/* O_PROG, stderr, bump exit code */
590Sstevel@tonic-gate #define	O_WARN	0x0004	/* O_PROG, stderr, do nothing unless Warn is set */
600Sstevel@tonic-gate #define	O_SYS	0x0008	/* append errno text to message */
610Sstevel@tonic-gate #define	O_STAMP	0x0010	/* append a timestamp */
620Sstevel@tonic-gate #define	O_ALTFP	0x0020	/* write output to alternate file pointer */
630Sstevel@tonic-gate #define	O_PROG	0x0040	/* prepend program name to message */
640Sstevel@tonic-gate #define	O_NONL	0x0080	/* don't append a newline to message */
650Sstevel@tonic-gate #define	O_DEBUG	0x0100	/* do nothing unless Debug is set */
660Sstevel@tonic-gate #define	O_VERB	0x0200	/* do nothing unless Verbose is set */
670Sstevel@tonic-gate #define	O_VERB2	0x0400	/* do nothing unless Verbose >= 2 */
680Sstevel@tonic-gate #define	O_VERB3	0x2000	/* do nothing unless Verbose >= 3 */
690Sstevel@tonic-gate #define	O_USAGE	0x0800	/* stderr, usage message */
700Sstevel@tonic-gate #define	O_ABORT	0x1000	/* call abort() after issuing any output */
710Sstevel@tonic-gate 
725609Scy152378 #ifdef DEBUG
735609Scy152378 
740Sstevel@tonic-gate #define	ASSERT(cnd) \
750Sstevel@tonic-gate 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
760Sstevel@tonic-gate 	    "assertion failure: %s", #cnd), 0)))
770Sstevel@tonic-gate 
780Sstevel@tonic-gate #define	ASSERTinfo(cnd, info) \
790Sstevel@tonic-gate 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
800Sstevel@tonic-gate 	    "assertion failure: %s (%s = %s)", #cnd, #info, info), 0)))
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #define	ASSERTeq(lhs, rhs, tostring) \
830Sstevel@tonic-gate 	((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
840Sstevel@tonic-gate 	    "assertion failure: %s (%s) == %s (%s)", #lhs, \
850Sstevel@tonic-gate 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #define	ASSERTne(lhs, rhs, tostring) \
880Sstevel@tonic-gate 	((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
890Sstevel@tonic-gate 	    "assertion failure: %s (%s) != %s (%s)", #lhs, \
900Sstevel@tonic-gate 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
910Sstevel@tonic-gate 
925609Scy152378 #else
935609Scy152378 
945609Scy152378 #define	ASSERT(cnd) ((void)0)
955609Scy152378 #define	ASSERTinfo(cnd, info) ((void)0)
965609Scy152378 #define	ASSERTeq(lhs, rhs, tostring) ((void)0)
975609Scy152378 #define	ASSERTne(lhs, rhs, tostring) ((void)0)
985609Scy152378 
995609Scy152378 #endif
1005609Scy152378 
1010Sstevel@tonic-gate extern int Debug;
1020Sstevel@tonic-gate extern int Verbose;
1030Sstevel@tonic-gate extern int Warn;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * so you can say things like:
1070Sstevel@tonic-gate  *	printf("\t%10d fault statement%s\n", OUTS(Faultcount));
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate #define	OUTS(i) (i), ((i) == 1) ? "" : "s"
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate #ifdef	__cplusplus
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate #endif
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #endif	/* _ESC_COMMON_OUT_H */
116