xref: /netbsd-src/share/examples/puffs/pgfs/pgfs_debug.c (revision 49413e37758aefe75effb0f891d65c98cc944d13)
1*49413e37Syamt /*	$NetBSD: pgfs_debug.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
2*49413e37Syamt 
3*49413e37Syamt /*-
4*49413e37Syamt  * Copyright (c)2010,2011 YAMAMOTO Takashi,
5*49413e37Syamt  * All rights reserved.
6*49413e37Syamt  *
7*49413e37Syamt  * Redistribution and use in source and binary forms, with or without
8*49413e37Syamt  * modification, are permitted provided that the following conditions
9*49413e37Syamt  * are met:
10*49413e37Syamt  * 1. Redistributions of source code must retain the above copyright
11*49413e37Syamt  *    notice, this list of conditions and the following disclaimer.
12*49413e37Syamt  * 2. Redistributions in binary form must reproduce the above copyright
13*49413e37Syamt  *    notice, this list of conditions and the following disclaimer in the
14*49413e37Syamt  *    documentation and/or other materials provided with the distribution.
15*49413e37Syamt  *
16*49413e37Syamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*49413e37Syamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*49413e37Syamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*49413e37Syamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*49413e37Syamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*49413e37Syamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*49413e37Syamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*49413e37Syamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*49413e37Syamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*49413e37Syamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*49413e37Syamt  * SUCH DAMAGE.
27*49413e37Syamt  */
28*49413e37Syamt 
29*49413e37Syamt /*
30*49413e37Syamt  * debug code
31*49413e37Syamt  */
32*49413e37Syamt 
33*49413e37Syamt #include <sys/cdefs.h>
34*49413e37Syamt #ifndef lint
35*49413e37Syamt __RCSID("$NetBSD: pgfs_debug.c,v 1.1 2011/10/12 01:05:00 yamt Exp $");
36*49413e37Syamt #endif /* not lint */
37*49413e37Syamt 
38*49413e37Syamt #include <sys/syslimits.h>	/* PATH_MAX */
39*49413e37Syamt 
40*49413e37Syamt #include <stdarg.h>
41*49413e37Syamt #include <stdio.h>
42*49413e37Syamt 
43*49413e37Syamt #include "pgfs_debug.h"
44*49413e37Syamt 
45*49413e37Syamt bool pgfs_dodprintf = false;
46*49413e37Syamt 
47*49413e37Syamt void
_dprintf(const char * func,const char * fmt,...)48*49413e37Syamt _dprintf(const char *func, const char *fmt, ...)
49*49413e37Syamt {
50*49413e37Syamt 	char buf[PATH_MAX * 2];
51*49413e37Syamt 	va_list ap;
52*49413e37Syamt 
53*49413e37Syamt 	if (!pgfs_dodprintf) {
54*49413e37Syamt 		return;
55*49413e37Syamt 	}
56*49413e37Syamt 	va_start(ap, fmt);
57*49413e37Syamt 	vsnprintf(buf, sizeof(buf), fmt, ap);
58*49413e37Syamt 	va_end(ap);
59*49413e37Syamt 	fprintf(stderr, "%s: %s", func, buf);
60*49413e37Syamt }
61