add :refresh command
[cmus.git] / debug.c
blobf8dd2c42f6bb609591c8af53ab9963217dc35280
1 /*
2 * Copyright 2004-2005 Timo Hirvonen
3 */
5 #include <debug.h>
6 #include <prog.h>
8 #include <stdio.h>
9 #include <stdarg.h>
11 #if DEBUG > 1
12 static FILE *debug_stream = NULL;
13 #endif
15 void debug_init(void)
17 #if DEBUG > 1
18 const char *debug_filename = "/tmp/cmus-debug";
20 debug_stream = fopen(debug_filename, "w");
21 if (debug_stream == NULL)
22 die_errno("error opening `%s' for writing", debug_filename);
23 #endif
26 /* This function must be defined even if debugging is disabled in the program
27 * because debugging might still be enabled in some plugin.
29 void __debug_bug(const char *function, const char *fmt, ...)
31 const char *format = "\n%s: BUG: ";
32 va_list ap;
34 /* debug_stream exists only if debugging is enabled */
35 #if DEBUG > 1
36 fprintf(debug_stream, format, function);
37 va_start(ap, fmt);
38 vfprintf(debug_stream, fmt, ap);
39 va_end(ap);
40 #endif
42 /* always print bug message to stderr */
43 fprintf(stderr, format, function);
44 va_start(ap, fmt);
45 vfprintf(stderr, fmt, ap);
46 va_end(ap);
47 exit(127);
50 void __debug_print(const char *function, const char *fmt, ...)
52 #if DEBUG > 1
53 va_list ap;
55 fprintf(debug_stream, "%s: ", function);
56 va_start(ap, fmt);
57 vfprintf(debug_stream, fmt, ap);
58 va_end(ap);
59 fflush(debug_stream);
60 #endif