xref: /titanic_41/usr/src/cmd/fm/eversholt/common/out.h (revision 5fbb41393be5d63f75952b1d72d4df2642d22557)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * out.h -- public definitions for output module
27  *
28  * general output & error handling routines.  the routine out() is
29  * the most commonly used routine in this module -- called by virtually
30  * all other modules.
31  */
32 
33 #ifndef	_ESC_COMMON_OUT_H
34 #define	_ESC_COMMON_OUT_H
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #include <stdio.h>
39 #include <sys/ccompile.h>
40 #include <inttypes.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 void out_init(const char *myname);
47 void out_fini(void);
48 void out(int flags, const char *fmt, ...);
49 void outfl(int flags, const char *fname, int line, const char *fmt, ...);
50 void out_exit(int code) __NORETURN;
51 void out_altfp(FILE *fp);
52 int out_errcount(void);
53 int out_warncount(void);
54 
55 /* flags for out() */
56 #define	O_OK	0x0000	/* simple output pseudo-flag */
57 #define	O_DIE	0x0001	/* O_PROG, stderr, bump exit code, call out_exit() */
58 #define	O_ERR	0x0002	/* O_PROG, stderr, bump exit code */
59 #define	O_WARN	0x0004	/* O_PROG, stderr, do nothing unless Warn is set */
60 #define	O_SYS	0x0008	/* append errno text to message */
61 #define	O_STAMP	0x0010	/* append a timestamp */
62 #define	O_ALTFP	0x0020	/* write output to alternate file pointer */
63 #define	O_PROG	0x0040	/* prepend program name to message */
64 #define	O_NONL	0x0080	/* don't append a newline to message */
65 #define	O_DEBUG	0x0100	/* do nothing unless Debug is set */
66 #define	O_VERB	0x0200	/* do nothing unless Verbose is set */
67 #define	O_VERB2	0x0400	/* do nothing unless Verbose >= 2 */
68 #define	O_VERB3	0x2000	/* do nothing unless Verbose >= 3 */
69 #define	O_USAGE	0x0800	/* stderr, usage message */
70 #define	O_ABORT	0x1000	/* call abort() after issuing any output */
71 
72 #ifdef DEBUG
73 
74 #define	ASSERT(cnd) \
75 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
76 	    "assertion failure: %s", #cnd), 0)))
77 
78 #define	ASSERTinfo(cnd, info) \
79 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
80 	    "assertion failure: %s (%s = %s)", #cnd, #info, info), 0)))
81 
82 #define	ASSERTeq(lhs, rhs, tostring) \
83 	((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
84 	    "assertion failure: %s (%s) == %s (%s)", #lhs, \
85 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
86 
87 #define	ASSERTne(lhs, rhs, tostring) \
88 	((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
89 	    "assertion failure: %s (%s) != %s (%s)", #lhs, \
90 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
91 
92 #else
93 
94 #define	ASSERT(cnd) ((void)0)
95 #define	ASSERTinfo(cnd, info) ((void)0)
96 #define	ASSERTeq(lhs, rhs, tostring) ((void)0)
97 #define	ASSERTne(lhs, rhs, tostring) ((void)0)
98 
99 #endif
100 
101 extern int Debug;
102 extern int Verbose;
103 extern int Warn;
104 
105 /*
106  * so you can say things like:
107  *	printf("\t%10d fault statement%s\n", OUTS(Faultcount));
108  */
109 #define	OUTS(i) (i), ((i) == 1) ? "" : "s"
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif	/* _ESC_COMMON_OUT_H */
116