xref: /titanic_52/usr/src/cmd/fm/eversholt/common/out.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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 2006 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 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 void out_init(const char *myname);
45 void out_fini(void);
46 void out(int flags, const char *fmt, ...);
47 void outfl(int flags, const char *fname, int line, const char *fmt, ...);
48 void out_exit(int code) __NORETURN;
49 void out_altfp(FILE *fp);
50 int out_errcount(void);
51 int out_warncount(void);
52 
53 /* flags for out() */
54 #define	O_OK	0x0000	/* simple output pseudo-flag */
55 #define	O_DIE	0x0001	/* O_PROG, stderr, bump exit code, call out_exit() */
56 #define	O_ERR	0x0002	/* O_PROG, stderr, bump exit code */
57 #define	O_WARN	0x0004	/* O_PROG, stderr, do nothing unless Warn is set */
58 #define	O_SYS	0x0008	/* append errno text to message */
59 #define	O_STAMP	0x0010	/* append a timestamp */
60 #define	O_ALTFP	0x0020	/* write output to alternate file pointer */
61 #define	O_PROG	0x0040	/* prepend program name to message */
62 #define	O_NONL	0x0080	/* don't append a newline to message */
63 #define	O_DEBUG	0x0100	/* do nothing unless Debug is set */
64 #define	O_VERB	0x0200	/* do nothing unless Verbose is set */
65 #define	O_VERB2	0x0400	/* do nothing unless Verbose >= 2 */
66 #define	O_VERB3	0x2000	/* do nothing unless Verbose >= 3 */
67 #define	O_USAGE	0x0800	/* stderr, usage message */
68 #define	O_ABORT	0x1000	/* call abort() after issuing any output */
69 
70 #define	ASSERT(cnd) \
71 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
72 	    "assertion failure: %s", #cnd), 0)))
73 
74 #define	ASSERTinfo(cnd, info) \
75 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
76 	    "assertion failure: %s (%s = %s)", #cnd, #info, info), 0)))
77 
78 #define	ASSERTeq(lhs, rhs, tostring) \
79 	((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
80 	    "assertion failure: %s (%s) == %s (%s)", #lhs, \
81 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
82 
83 #define	ASSERTne(lhs, rhs, tostring) \
84 	((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
85 	    "assertion failure: %s (%s) != %s (%s)", #lhs, \
86 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
87 
88 extern int Debug;
89 extern int Verbose;
90 extern int Warn;
91 
92 /*
93  * so you can say things like:
94  *	printf("\t%10d fault statement%s\n", OUTS(Faultcount));
95  */
96 #define	OUTS(i) (i), ((i) == 1) ? "" : "s"
97 
98 #ifdef	__cplusplus
99 }
100 #endif
101 
102 #endif	/* _ESC_COMMON_OUT_H */
103