2013-12-06 12:04:52 +01:00
|
|
|
/* $NetBSD: trace.c,v 1.3 2013/11/29 16:36:11 christos Exp $ */
|
2013-01-22 12:03:53 +01:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Rob Zimmermann. All rights reserved.
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for redistribution information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifndef lint
|
2013-12-06 12:04:52 +01:00
|
|
|
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 ";
|
2013-01-22 12:03:53 +01:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <bitstring.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#ifdef TRACE
|
|
|
|
|
|
|
|
static FILE *tfp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vtrace_end --
|
|
|
|
* End tracing.
|
|
|
|
*
|
|
|
|
* PUBLIC: void vtrace_end __P((void));
|
|
|
|
*/
|
|
|
|
void
|
2013-12-06 12:04:52 +01:00
|
|
|
vtrace_end(void)
|
2013-01-22 12:03:53 +01:00
|
|
|
{
|
|
|
|
if (tfp != NULL && tfp != stderr)
|
|
|
|
(void)fclose(tfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vtrace_init --
|
|
|
|
* Initialize tracing.
|
|
|
|
*
|
2013-12-06 12:04:52 +01:00
|
|
|
* PUBLIC: void vtrace_init __P((const char *));
|
2013-01-22 12:03:53 +01:00
|
|
|
*/
|
|
|
|
void
|
2013-12-06 12:04:52 +01:00
|
|
|
vtrace_init(const char *name)
|
2013-01-22 12:03:53 +01:00
|
|
|
{
|
|
|
|
if (name == NULL || (tfp = fopen(name, "w")) == NULL)
|
|
|
|
tfp = stderr;
|
|
|
|
vtrace("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nTRACE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vtrace --
|
|
|
|
* Debugging trace routine.
|
|
|
|
*
|
|
|
|
* PUBLIC: void vtrace __P((const char *, ...));
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vtrace(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (tfp == NULL)
|
|
|
|
vtrace_init(NULL);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)vfprintf(tfp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
(void)fflush(tfp);
|
|
|
|
}
|
|
|
|
#endif
|