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*837416c3Scy152378 * 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 #pragma ident "%Z%%M% %I% %E% SMI" 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include <stdio.h> 39*837416c3Scy152378 #include <sys/ccompile.h> 40*837416c3Scy152378 #include <inttypes.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 437c478bd9Sstevel@tonic-gate extern "C" { 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate void out_init(const char *myname); 477c478bd9Sstevel@tonic-gate void out_fini(void); 487c478bd9Sstevel@tonic-gate void out(int flags, const char *fmt, ...); 497c478bd9Sstevel@tonic-gate void outfl(int flags, const char *fname, int line, const char *fmt, ...); 5080ab886dSwesolows void out_exit(int code) __NORETURN; 517c478bd9Sstevel@tonic-gate void out_altfp(FILE *fp); 527c478bd9Sstevel@tonic-gate int out_errcount(void); 537c478bd9Sstevel@tonic-gate int out_warncount(void); 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* flags for out() */ 567c478bd9Sstevel@tonic-gate #define O_OK 0x0000 /* simple output pseudo-flag */ 577c478bd9Sstevel@tonic-gate #define O_DIE 0x0001 /* O_PROG, stderr, bump exit code, call out_exit() */ 587c478bd9Sstevel@tonic-gate #define O_ERR 0x0002 /* O_PROG, stderr, bump exit code */ 597c478bd9Sstevel@tonic-gate #define O_WARN 0x0004 /* O_PROG, stderr, do nothing unless Warn is set */ 607c478bd9Sstevel@tonic-gate #define O_SYS 0x0008 /* append errno text to message */ 617c478bd9Sstevel@tonic-gate #define O_STAMP 0x0010 /* append a timestamp */ 627c478bd9Sstevel@tonic-gate #define O_ALTFP 0x0020 /* write output to alternate file pointer */ 637c478bd9Sstevel@tonic-gate #define O_PROG 0x0040 /* prepend program name to message */ 647c478bd9Sstevel@tonic-gate #define O_NONL 0x0080 /* don't append a newline to message */ 657c478bd9Sstevel@tonic-gate #define O_DEBUG 0x0100 /* do nothing unless Debug is set */ 667c478bd9Sstevel@tonic-gate #define O_VERB 0x0200 /* do nothing unless Verbose is set */ 677c478bd9Sstevel@tonic-gate #define O_VERB2 0x0400 /* do nothing unless Verbose >= 2 */ 687c478bd9Sstevel@tonic-gate #define O_VERB3 0x2000 /* do nothing unless Verbose >= 3 */ 697c478bd9Sstevel@tonic-gate #define O_USAGE 0x0800 /* stderr, usage message */ 707c478bd9Sstevel@tonic-gate #define O_ABORT 0x1000 /* call abort() after issuing any output */ 717c478bd9Sstevel@tonic-gate 7247911a7dScy152378 #ifdef DEBUG 7347911a7dScy152378 747c478bd9Sstevel@tonic-gate #define ASSERT(cnd) \ 757c478bd9Sstevel@tonic-gate ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \ 767c478bd9Sstevel@tonic-gate "assertion failure: %s", #cnd), 0))) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #define ASSERTinfo(cnd, info) \ 797c478bd9Sstevel@tonic-gate ((void)((cnd) || (outfl(O_ABORT, __FILE__, __LINE__, \ 807c478bd9Sstevel@tonic-gate "assertion failure: %s (%s = %s)", #cnd, #info, info), 0))) 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define ASSERTeq(lhs, rhs, tostring) \ 837c478bd9Sstevel@tonic-gate ((void)(((lhs) == (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \ 847c478bd9Sstevel@tonic-gate "assertion failure: %s (%s) == %s (%s)", #lhs, \ 857c478bd9Sstevel@tonic-gate tostring(lhs), #rhs, tostring(rhs)), 0))) 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #define ASSERTne(lhs, rhs, tostring) \ 887c478bd9Sstevel@tonic-gate ((void)(((lhs) != (rhs)) || (outfl(O_ABORT, __FILE__, __LINE__, \ 897c478bd9Sstevel@tonic-gate "assertion failure: %s (%s) != %s (%s)", #lhs, \ 907c478bd9Sstevel@tonic-gate tostring(lhs), #rhs, tostring(rhs)), 0))) 917c478bd9Sstevel@tonic-gate 9247911a7dScy152378 #else 9347911a7dScy152378 9447911a7dScy152378 #define ASSERT(cnd) ((void)0) 9547911a7dScy152378 #define ASSERTinfo(cnd, info) ((void)0) 9647911a7dScy152378 #define ASSERTeq(lhs, rhs, tostring) ((void)0) 9747911a7dScy152378 #define ASSERTne(lhs, rhs, tostring) ((void)0) 9847911a7dScy152378 9947911a7dScy152378 #endif 10047911a7dScy152378 1017c478bd9Sstevel@tonic-gate extern int Debug; 1027c478bd9Sstevel@tonic-gate extern int Verbose; 1037c478bd9Sstevel@tonic-gate extern int Warn; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * so you can say things like: 1077c478bd9Sstevel@tonic-gate * printf("\t%10d fault statement%s\n", OUTS(Faultcount)); 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate #define OUTS(i) (i), ((i) == 1) ? "" : "s" 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate #endif 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #endif /* _ESC_COMMON_OUT_H */ 116