#ifdef DEBUG
static FILE *debug_fp = NULL;
+static HANDLE debug_hdl = INVALID_HANDLE_VALUE;
static int debug_got_console = 0;
static void dputs(char *buf)
DWORD dw;
if (!debug_got_console) {
- AllocConsole();
- debug_got_console = 1;
+ if (AllocConsole()) {
+ debug_got_console = 1;
+ debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE);
+ }
}
if (!debug_fp) {
debug_fp = fopen("debug.log", "w");
}
- WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw,
- NULL);
+ if (debug_hdl != INVALID_HANDLE_VALUE) {
+ WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL);
+ }
fputs(buf, debug_fp);
fflush(debug_fp);
}