2
* debug.c - Debugging output
11
#include <sys/types.h>
17
#define MAX_DEBUG 1000
18
#define DEBUG_FILENAME "gnuchess.debug"
20
/* Default to stderr */
21
static int debug_fd = 2;
23
int dbg_open(const char *name)
25
int flags = O_WRONLY | O_CREAT | O_APPEND;
29
debug_fd = open(DEBUG_FILENAME, flags, mode);
31
debug_fd = open(name, flags, mode);
37
dbg_printf("--- Opening debug log ---\n");
43
/* We don't want to close stderr */
47
dbg_printf("--- Closing debug log ---\n");
48
return close(debug_fd);
51
int dbg_printf(const char *fmt, ...)
57
gettimeofday(&tv, NULL);
58
sprintf(buf, "%010ld.%06ld: ", tv.tv_sec, tv.tv_usec);
59
write(debug_fd, buf, strlen(buf));
62
vsnprintf(buf, MAX_DEBUG, fmt, ap);
65
return write(debug_fd, buf, strlen(buf));
70
int dbg_open(const char *name __attribute__((unused)) ) { return 0; }
71
int dbg_printf(const char *fmt __attribute__((unused)), ...) { return 0; }
72
int dbg_close(void) { return 0; }