1 /* $NetBSD: trace.c,v 1.3 2013/11/29 16:36:11 christos Exp $ */ 2 /*- 3 * Copyright (c) 1996 4 * Rob Zimmermann. All rights reserved. 5 * Copyright (c) 1996 6 * Keith Bostic. All rights reserved. 7 * 8 * See the LICENSE file for redistribution information. 9 */ 10 11 #include "config.h" 12 13 #ifndef lint 14 static const char sccsid[] = "Id: trace.c,v 8.4 1997/08/03 15:04:23 bostic Exp (Berkeley) Date: 1997/08/03 15:04:23 "; 15 #endif /* not lint */ 16 17 #include <sys/queue.h> 18 19 #include <bitstring.h> 20 #include <stdio.h> 21 22 #ifdef __STDC__ 23 #include <stdarg.h> 24 #else 25 #include <varargs.h> 26 #endif 27 28 #include "common.h" 29 30 #ifdef TRACE 31 32 static FILE *tfp; 33 34 /* 35 * vtrace_end -- 36 * End tracing. 37 * 38 * PUBLIC: void vtrace_end __P((void)); 39 */ 40 void 41 vtrace_end(void) 42 { 43 if (tfp != NULL && tfp != stderr) 44 (void)fclose(tfp); 45 } 46 47 /* 48 * vtrace_init -- 49 * Initialize tracing. 50 * 51 * PUBLIC: void vtrace_init __P((const char *)); 52 */ 53 void 54 vtrace_init(const char *name) 55 { 56 if (name == NULL || (tfp = fopen(name, "w")) == NULL) 57 tfp = stderr; 58 vtrace("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nTRACE\n"); 59 } 60 61 /* 62 * vtrace -- 63 * Debugging trace routine. 64 * 65 * PUBLIC: void vtrace __P((const char *, ...)); 66 */ 67 void 68 vtrace(const char *fmt, ...) 69 { 70 va_list ap; 71 72 if (tfp == NULL) 73 vtrace_init(NULL); 74 75 va_start(ap, fmt); 76 (void)vfprintf(tfp, fmt, ap); 77 va_end(ap); 78 79 (void)fflush(tfp); 80 } 81 #endif 82