xref: /titanic_41/usr/src/lib/lvm/libsvm/common/debug.c (revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <stdlib.h>
30 #include <limits.h>
31 #include <string.h>
32 
33 /* The following defines are for tracing output (from libsmpicommon) */
34 
35 #define	LOG		0x1	/* write message to log file */
36 #define	SCR		0x2	/* write message to the screen */
37 #define	LOGSCR		LOG|SCR /* write message to the log and screen */
38 #define	LEVEL0		0x0001  /* message level 0 */
39 #define	LEVEL1		0x0002  /* message level 1 */
40 #define	LEVEL2		0x0004  /* message level 2 */
41 #define	LEVEL3		0x0010  /* message level 3 */
42 
43 extern int get_trace_level(void);
44 extern int write_status(unsigned char, unsigned int, char *, ...);
45 
46 const char libsvm_str[] = "LIB_SVM: ";
47 const int libsvm_len = sizeof (libsvm_str);
48 
49 /*PRINTFLIKE1*/
50 void
51 debug_printf(char *fmt, ...)
52 {
53 	va_list ap;
54 	char *cp;
55 	char *buf;
56 
57 	if (get_trace_level() > 5) {
58 		if ((buf = calloc(PATH_MAX, sizeof (char))) == NULL)
59 			return;
60 		(void) strcpy(buf, libsvm_str);
61 		/*
62 		 * libsvm_len - 1 is because the length includes NULL
63 		 */
64 
65 		cp = buf + (libsvm_len - 1);
66 		va_start(ap, fmt);
67 		if (vsnprintf(cp, (PATH_MAX - (libsvm_len - 1)),
68 		    fmt, ap) >= 0) {
69 			(void) write_status(LOGSCR, LEVEL0, buf);
70 		}
71 		free(buf);
72 		va_end(ap);
73 	}
74 }
75