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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <stdio.h> 30 #include <stdarg.h> 31 #include <stdlib.h> 32 #include <limits.h> 33 #include <string.h> 34 35 /* The following defines are for tracing output (from libsmpicommon) */ 36 37 #define LOG 0x1 /* write message to log file */ 38 #define SCR 0x2 /* write message to the screen */ 39 #define LOGSCR LOG|SCR /* write message to the log and screen */ 40 #define LEVEL0 0x0001 /* message level 0 */ 41 #define LEVEL1 0x0002 /* message level 1 */ 42 #define LEVEL2 0x0004 /* message level 2 */ 43 #define LEVEL3 0x0010 /* message level 3 */ 44 45 extern int get_trace_level(void); 46 extern int write_status(unsigned char, unsigned int, char *, ...); 47 48 const char libsvm_str[] = "LIB_SVM: "; 49 const int libsvm_len = sizeof (libsvm_str); 50 51 /*PRINTFLIKE1*/ 52 void 53 debug_printf(char *fmt, ...) 54 { 55 va_list ap; 56 char *cp; 57 char *buf; 58 59 if (get_trace_level() > 5) { 60 if ((buf = calloc(PATH_MAX, sizeof (char))) == NULL) 61 return; 62 (void) strcpy(buf, libsvm_str); 63 /* 64 * libsvm_len - 1 is because the length includes NULL 65 */ 66 67 cp = buf + (libsvm_len - 1); 68 va_start(ap, fmt); 69 if (vsnprintf(cp, (PATH_MAX - (libsvm_len - 1)), 70 fmt, ap) >= 0) { 71 write_status(LOGSCR, LEVEL0, buf); 72 } 73 free(buf); 74 va_end(ap); 75 } 76 } 77