Debian Codegraph @

lib/debug.c

raw
1 /*
2 * debug.c: debugging messages
3 * Copyright (C) 2007, 2010 Colin Watson.
4 *
5 * This file is part of libpipeline.
6 *
7 * libpipeline is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * libpipeline is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with libpipeline; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <errno.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "pipeline-private.h"
34
35 int debug_level = 0;
36
37 void init_debug (void)
38 {
39 static int inited = 0;
40 const char *pipeline_debug;
41
42 if (inited)
43 return;
44 inited = 1;
45
46 pipeline_debug = getenv ("PIPELINE_DEBUG");
47 if (pipeline_debug && !strcmp (pipeline_debug, "1"))
48 debug_level = 1;
49 }
50
51 static void PIPELINE_ATTR_FORMAT_PRINTF (1, 0)
52 vdebug (const char *message, va_list args)
53 {
54 if (debug_level)
55 vfprintf (stderr, message, args);
56 }
57
58 void debug (const char *message, ...)
59 {
60 init_debug ();
61
62 if (debug_level) {
63 va_list args;
64
65 va_start (args, message);
66 vdebug (message, args);
67 va_end (args);
68 }
69 }