1/* $NetBSD: trace.c,v 1.4 2014/01/26 21:43:45 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#include <sys/cdefs.h> 14#if 0 15#ifndef lint 16static 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 "; 17#endif /* not lint */ 18#else 19__RCSID("$NetBSD: trace.c,v 1.4 2014/01/26 21:43:45 christos Exp $"); 20#endif 21 22#include <sys/queue.h> 23 24#include <bitstring.h> 25#include <stdio.h> 26 27#ifdef __STDC__ 28#include <stdarg.h> 29#else 30#include <varargs.h> 31#endif 32 33#include "common.h" 34 35#ifdef TRACE 36 37static FILE *tfp; 38 39/* 40 * vtrace_end -- 41 * End tracing. 42 * 43 * PUBLIC: void vtrace_end __P((void)); 44 */ 45void 46vtrace_end(void) 47{ 48 if (tfp != NULL && tfp != stderr) 49 (void)fclose(tfp); 50} 51 52/* 53 * vtrace_init -- 54 * Initialize tracing. 55 * 56 * PUBLIC: void vtrace_init __P((const char *)); 57 */ 58void 59vtrace_init(const char *name) 60{ 61 if (name == NULL || (tfp = fopen(name, "w")) == NULL) 62 tfp = stderr; 63 vtrace("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nTRACE\n"); 64} 65 66/* 67 * vtrace -- 68 * Debugging trace routine. 69 * 70 * PUBLIC: void vtrace __P((const char *, ...)); 71 */ 72void 73vtrace(const char *fmt, ...) 74{ 75 va_list ap; 76 77 if (tfp == NULL) 78 vtrace_init(NULL); 79 80 va_start(ap, fmt); 81 (void)vfprintf(tfp, fmt, ap); 82 va_end(ap); 83 84 (void)fflush(tfp); 85} 86#endif 87