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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * out.h -- public definitions for output module
28 * general output & error handling routines. the routine out() is
29 * the most commonly used routine in this module -- called by virtually
33 #ifndef _ESC_COMMON_OUT_H
34 #define _ESC_COMMON_OUT_H
36 #pragma ident "%Z%%M% %I% %E% SMI"
39 #include <sys/ccompile.h>
46 void out_init(const char *myname
);
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);
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 */
75 ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
76 "assertion failure: %s", #cnd), 0)))
78 #define ASSERTinfo(cnd, info) \
79 ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \
80 "assertion failure: %s (%s = %s)", #cnd, #info, info), 0)))
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)))
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)))
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)
106 * so you can say things like:
107 * printf("\t%10d fault statement%s\n", OUTS(Faultcount));
109 #define OUTS(i) (i), ((i) == 1) ? "" : "s"
115 #endif /* _ESC_COMMON_OUT_H */