xref: /onnv-gate/usr/src/lib/lvm/libsvm/common/debug.c (revision 11411:c2fe1bf96826)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11411SSurya.Prakki@Sun.COM  * Common Development and Distribution License (the "License").
6*11411SSurya.Prakki@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*11411SSurya.Prakki@Sun.COM 
220Sstevel@tonic-gate /*
23*11411SSurya.Prakki@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <stdio.h>
280Sstevel@tonic-gate #include <stdarg.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <limits.h>
310Sstevel@tonic-gate #include <string.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /* The following defines are for tracing output (from libsmpicommon) */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #define	LOG		0x1	/* write message to log file */
360Sstevel@tonic-gate #define	SCR		0x2	/* write message to the screen */
370Sstevel@tonic-gate #define	LOGSCR		LOG|SCR /* write message to the log and screen */
380Sstevel@tonic-gate #define	LEVEL0		0x0001  /* message level 0 */
390Sstevel@tonic-gate #define	LEVEL1		0x0002  /* message level 1 */
400Sstevel@tonic-gate #define	LEVEL2		0x0004  /* message level 2 */
410Sstevel@tonic-gate #define	LEVEL3		0x0010  /* message level 3 */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate extern int get_trace_level(void);
440Sstevel@tonic-gate extern int write_status(unsigned char, unsigned int, char *, ...);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate const char libsvm_str[] = "LIB_SVM: ";
470Sstevel@tonic-gate const int libsvm_len = sizeof (libsvm_str);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*PRINTFLIKE1*/
500Sstevel@tonic-gate void
debug_printf(char * fmt,...)510Sstevel@tonic-gate debug_printf(char *fmt, ...)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	va_list ap;
540Sstevel@tonic-gate 	char *cp;
550Sstevel@tonic-gate 	char *buf;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	if (get_trace_level() > 5) {
580Sstevel@tonic-gate 		if ((buf = calloc(PATH_MAX, sizeof (char))) == NULL)
590Sstevel@tonic-gate 			return;
600Sstevel@tonic-gate 		(void) strcpy(buf, libsvm_str);
610Sstevel@tonic-gate 		/*
620Sstevel@tonic-gate 		 * libsvm_len - 1 is because the length includes NULL
630Sstevel@tonic-gate 		 */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 		cp = buf + (libsvm_len - 1);
660Sstevel@tonic-gate 		va_start(ap, fmt);
670Sstevel@tonic-gate 		if (vsnprintf(cp, (PATH_MAX - (libsvm_len - 1)),
68*11411SSurya.Prakki@Sun.COM 		    fmt, ap) >= 0) {
69*11411SSurya.Prakki@Sun.COM 			(void) write_status(LOGSCR, LEVEL0, buf);
700Sstevel@tonic-gate 		}
710Sstevel@tonic-gate 		free(buf);
720Sstevel@tonic-gate 		va_end(ap);
730Sstevel@tonic-gate 	}
740Sstevel@tonic-gate }
75