185993067SJohn Birrell /*
285993067SJohn Birrell  * CDDL HEADER START
385993067SJohn Birrell  *
485993067SJohn Birrell  * The contents of this file are subject to the terms of the
585993067SJohn Birrell  * Common Development and Distribution License (the "License").
685993067SJohn Birrell  * You may not use this file except in compliance with the License.
785993067SJohn Birrell  *
885993067SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
985993067SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
1085993067SJohn Birrell  * See the License for the specific language governing permissions
1185993067SJohn Birrell  * and limitations under the License.
1285993067SJohn Birrell  *
1385993067SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
1485993067SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1585993067SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
1685993067SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
1785993067SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
1885993067SJohn Birrell  *
1985993067SJohn Birrell  * CDDL HEADER END
206643637fSMartin Matuska  */
216643637fSMartin Matuska /*
226643637fSMartin Matuska  * Copyright 2007 John Birrell <jb@FreeBSD.org>. All rights reserved.
236643637fSMartin Matuska  * Copyright 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
2485993067SJohn Birrell  */
2585993067SJohn Birrell 
266643637fSMartin Matuska #include <sys/assfail.h>
2785993067SJohn Birrell #include <sys/cmn_err.h>
2885993067SJohn Birrell 
2985993067SJohn Birrell void
vcmn_err(int ce,const char * fmt,va_list adx)3085993067SJohn Birrell vcmn_err(int ce, const char *fmt, va_list adx)
3185993067SJohn Birrell {
3285993067SJohn Birrell 	char buf[256];
33528bf6e4SAndriy Gapon 	const char *prefix;
3485993067SJohn Birrell 
35528bf6e4SAndriy Gapon 	prefix = NULL; /* silence unwitty compilers */
3685993067SJohn Birrell 	switch (ce) {
3785993067SJohn Birrell 	case CE_CONT:
38528bf6e4SAndriy Gapon 		prefix = "Solaris(cont): ";
3985993067SJohn Birrell 		break;
4085993067SJohn Birrell 	case CE_NOTE:
41528bf6e4SAndriy Gapon 		prefix = "Solaris: NOTICE: ";
4285993067SJohn Birrell 		break;
4385993067SJohn Birrell 	case CE_WARN:
44528bf6e4SAndriy Gapon 		prefix = "Solaris: WARNING: ";
4585993067SJohn Birrell 		break;
4685993067SJohn Birrell 	case CE_PANIC:
47528bf6e4SAndriy Gapon 		prefix = "Solaris(panic): ";
4885993067SJohn Birrell 		break;
4985993067SJohn Birrell 	case CE_IGNORE:
5085993067SJohn Birrell 		break;
5185993067SJohn Birrell 	default:
5285993067SJohn Birrell 		panic("Solaris: unknown severity level");
5385993067SJohn Birrell 	}
54528bf6e4SAndriy Gapon 	if (ce == CE_PANIC) {
55528bf6e4SAndriy Gapon 		vsnprintf(buf, sizeof(buf), fmt, adx);
56528bf6e4SAndriy Gapon 		panic("%s%s", prefix, buf);
57528bf6e4SAndriy Gapon 	}
58528bf6e4SAndriy Gapon 	if (ce != CE_IGNORE) {
59528bf6e4SAndriy Gapon 		printf("%s", prefix);
60528bf6e4SAndriy Gapon 		vprintf(fmt, adx);
6159e407dfSAndriy Gapon 		printf("\n");
62528bf6e4SAndriy Gapon 	}
6385993067SJohn Birrell }
6485993067SJohn Birrell 
6585993067SJohn Birrell void
cmn_err(int type,const char * fmt,...)6685993067SJohn Birrell cmn_err(int type, const char *fmt, ...)
6785993067SJohn Birrell {
6885993067SJohn Birrell 	va_list ap;
6985993067SJohn Birrell 
7085993067SJohn Birrell 	va_start(ap, fmt);
7185993067SJohn Birrell 	vcmn_err(type, fmt, ap);
7285993067SJohn Birrell 	va_end(ap);
7385993067SJohn Birrell }
746643637fSMartin Matuska 
756643637fSMartin Matuska int
assfail(const char * a,const char * f,int l)763666c491SSteven Hartland assfail(const char *a, const char *f, int l)
773666c491SSteven Hartland {
786643637fSMartin Matuska 
796643637fSMartin Matuska 	panic("solaris assert: %s, file: %s, line: %d", a, f, l);
806643637fSMartin Matuska 
816643637fSMartin Matuska 	return (0);
826643637fSMartin Matuska }
836643637fSMartin Matuska 
846643637fSMartin Matuska void
assfail3(const char * a,uintmax_t lv,const char * op,uintmax_t rv,const char * f,int l)856643637fSMartin Matuska assfail3(const char *a, uintmax_t lv, const char *op, uintmax_t rv,
863666c491SSteven Hartland     const char *f, int l)
873666c491SSteven Hartland {
886643637fSMartin Matuska 
896643637fSMartin Matuska 	panic("solaris assert: %s (0x%jx %s 0x%jx), file: %s, line: %d",
906643637fSMartin Matuska 	    a, lv, op, rv, f, l);
916643637fSMartin Matuska }
92