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 #include <stdio.h> 37 #include <sys/ccompile.h> 38 #include <inttypes.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 #ifdef DEBUG 71 72 #define ASSERT(cnd) \ 73 ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \ 74 "assertion failure: %s", #cnd), 0))) 75 76 #define ASSERTinfo(cnd, info) \ 77 ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \ 78 "assertion failure: %s (%s = %s)", #cnd, #info, info), 0))) 79 80 #define ASSERTeq(lhs, rhs, tostring) \ 81 ((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \ 82 "assertion failure: %s (%s) == %s (%s)", #lhs, \ 83 tostring(lhs), #rhs, tostring(rhs)), 0))) 84 85 #define ASSERTne(lhs, rhs, tostring) \ 86 ((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \ 87 "assertion failure: %s (%s) != %s (%s)", #lhs, \ 88 tostring(lhs), #rhs, tostring(rhs)), 0))) 89 90 #else 91 92 #define ASSERT(cnd) ((void)0) 93 #define ASSERTinfo(cnd, info) ((void)0) 94 #define ASSERTeq(lhs, rhs, tostring) ((void)0) 95 #define ASSERTne(lhs, rhs, tostring) ((void)0) 96 97 #endif 98 99 extern int Debug; 100 extern int Verbose; 101 extern int Warn; 102 103 /* 104 * so you can say things like: 105 * printf("\t%10d fault statement%s\n", OUTS(Faultcount)); 106 */ 107 #define OUTS(i) (i), ((i) == 1) ? "" : "s" 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* _ESC_COMMON_OUT_H */ 114