xref: /illumos-gate/usr/src/cmd/fm/eversholt/common/out.h (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
580ab886dSwesolows  * Common Development and Distribution License (the "License").
680ab886dSwesolows  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2180ab886dSwesolows 
227c478bd9Sstevel@tonic-gate /*
23*837416c3Scy  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  * out.h -- public definitions for output module
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * general output & error handling routines.  the routine out() is
297c478bd9Sstevel@tonic-gate  * the most commonly used routine in this module -- called by virtually
307c478bd9Sstevel@tonic-gate  * all other modules.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	_ESC_COMMON_OUT_H
347c478bd9Sstevel@tonic-gate #define	_ESC_COMMON_OUT_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <stdio.h>
37*837416c3Scy #include <sys/ccompile.h>
38*837416c3Scy #include <inttypes.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate void out_init(const char *myname);
457c478bd9Sstevel@tonic-gate void out_fini(void);
467c478bd9Sstevel@tonic-gate void out(int flags, const char *fmt, ...);
477c478bd9Sstevel@tonic-gate void outfl(int flags, const char *fname, int line, const char *fmt, ...);
4880ab886dSwesolows void out_exit(int code) __NORETURN;
497c478bd9Sstevel@tonic-gate void out_altfp(FILE *fp);
507c478bd9Sstevel@tonic-gate int out_errcount(void);
517c478bd9Sstevel@tonic-gate int out_warncount(void);
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /* flags for out() */
547c478bd9Sstevel@tonic-gate #define	O_OK	0x0000	/* simple output pseudo-flag */
557c478bd9Sstevel@tonic-gate #define	O_DIE	0x0001	/* O_PROG, stderr, bump exit code, call out_exit() */
567c478bd9Sstevel@tonic-gate #define	O_ERR	0x0002	/* O_PROG, stderr, bump exit code */
577c478bd9Sstevel@tonic-gate #define	O_WARN	0x0004	/* O_PROG, stderr, do nothing unless Warn is set */
587c478bd9Sstevel@tonic-gate #define	O_SYS	0x0008	/* append errno text to message */
597c478bd9Sstevel@tonic-gate #define	O_STAMP	0x0010	/* append a timestamp */
607c478bd9Sstevel@tonic-gate #define	O_ALTFP	0x0020	/* write output to alternate file pointer */
617c478bd9Sstevel@tonic-gate #define	O_PROG	0x0040	/* prepend program name to message */
627c478bd9Sstevel@tonic-gate #define	O_NONL	0x0080	/* don't append a newline to message */
637c478bd9Sstevel@tonic-gate #define	O_DEBUG	0x0100	/* do nothing unless Debug is set */
647c478bd9Sstevel@tonic-gate #define	O_VERB	0x0200	/* do nothing unless Verbose is set */
657c478bd9Sstevel@tonic-gate #define	O_VERB2	0x0400	/* do nothing unless Verbose >= 2 */
667c478bd9Sstevel@tonic-gate #define	O_VERB3	0x2000	/* do nothing unless Verbose >= 3 */
677c478bd9Sstevel@tonic-gate #define	O_USAGE	0x0800	/* stderr, usage message */
687c478bd9Sstevel@tonic-gate #define	O_ABORT	0x1000	/* call abort() after issuing any output */
697c478bd9Sstevel@tonic-gate 
7047911a7dScy #ifdef DEBUG
7147911a7dScy 
727c478bd9Sstevel@tonic-gate #define	ASSERT(cnd) \
737c478bd9Sstevel@tonic-gate 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
747c478bd9Sstevel@tonic-gate 	    "assertion failure: %s", #cnd), 0)))
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	ASSERTinfo(cnd, info) \
777c478bd9Sstevel@tonic-gate 	((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
787c478bd9Sstevel@tonic-gate 	    "assertion failure: %s (%s = %s)", #cnd, #info, info), 0)))
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	ASSERTeq(lhs, rhs, tostring) \
817c478bd9Sstevel@tonic-gate 	((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
827c478bd9Sstevel@tonic-gate 	    "assertion failure: %s (%s) == %s (%s)", #lhs, \
837c478bd9Sstevel@tonic-gate 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	ASSERTne(lhs, rhs, tostring) \
867c478bd9Sstevel@tonic-gate 	((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \
877c478bd9Sstevel@tonic-gate 	    "assertion failure: %s (%s) != %s (%s)", #lhs, \
887c478bd9Sstevel@tonic-gate 	    tostring(lhs), #rhs, tostring(rhs)), 0)))
897c478bd9Sstevel@tonic-gate 
9047911a7dScy #else
9147911a7dScy 
9247911a7dScy #define	ASSERT(cnd) ((void)0)
9347911a7dScy #define	ASSERTinfo(cnd, info) ((void)0)
9447911a7dScy #define	ASSERTeq(lhs, rhs, tostring) ((void)0)
9547911a7dScy #define	ASSERTne(lhs, rhs, tostring) ((void)0)
9647911a7dScy 
9747911a7dScy #endif
9847911a7dScy 
997c478bd9Sstevel@tonic-gate extern int Debug;
1007c478bd9Sstevel@tonic-gate extern int Verbose;
1017c478bd9Sstevel@tonic-gate extern int Warn;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * so you can say things like:
1057c478bd9Sstevel@tonic-gate  *	printf("\t%10d fault statement%s\n", OUTS(Faultcount));
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate #define	OUTS(i) (i), ((i) == 1) ? "" : "s"
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #endif	/* _ESC_COMMON_OUT_H */
114