1 /* $NetBSD: printf.c,v 1.1 2009/08/07 20:57:57 haad Exp $ */ 2 3 /* 4 * CDDL HEADER START 5 * 6 * The contents of this file are subject to the terms of the 7 * Common Development and Distribution License (the "License"). 8 * You may not use this file except in compliance with the License. 9 * 10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 * or http://www.opensolaris.org/os/licensing. 12 * See the License for the specific language governing permissions 13 * and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 * If applicable, add the following below this CDDL HEADER, with the 18 * fields enclosed by brackets "[]" replaced with your own identifying 19 * information: Portions Copyright [yyyy] [name of copyright owner] 20 * 21 * CDDL HEADER END 22 */ 23 /* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 29 30 #include <sys/param.h> 31 #include <sys/types.h> 32 #include <sys/systm.h> 33 #include <sys/cmn_err.h> 34 35 static char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" }; 36 static char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" }; 37 38 void 39 vcmn_err(int ce, const char *fmt, va_list adx) 40 { 41 char buf[256]; 42 43 if (ce == CE_PANIC) { 44 vprintf(fmt, adx); 45 panic("panic"); 46 } 47 48 if ((uint_t)ce < CE_IGNORE) { 49 strcpy(buf, ce_prefix[ce]); 50 vsnprintf(buf + strlen(ce_prefix[ce]), sizeof(buf), 51 fmt, adx); 52 strlcat(buf, ce_suffix[ce], sizeof(buf)); 53 printf("%s", buf); 54 } 55 } 56 57 void 58 cmn_err(int ce, const char *fmt, ...) 59 { 60 va_list adx; 61 62 va_start(adx, fmt); 63 vcmn_err(ce, fmt, adx); 64 va_end(adx); 65 } 66