X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/374330e25a6b51c40436fa869a381dd510790f6e..c82bda5269af866d4d6390cbe795a01fd3f9dc75:/misc.c diff --git a/misc.c b/misc.c index 370eea07..eb522256 100644 --- a/misc.c +++ b/misc.c @@ -13,8 +13,10 @@ static FILE *fp = NULL; void mlog(char *file, int line) { - if (!fp) + if (!fp) { fp = fopen("putty_mem.log", "w"); + setvbuf(fp, NULL, _IONBF, BUFSIZ); + } if (fp) fprintf (fp, "%s:%d: ", file, line); } @@ -65,3 +67,29 @@ void safefree(void *ptr) { fprintf(fp, "freeing null pointer - no action taken\n"); #endif } + +#ifdef DEBUG +static FILE *debug_fp = NULL; +static int debug_got_console = 0; + +void dprintf(char *fmt, ...) { + char buf[2048]; + DWORD dw; + va_list ap; + + if (!debug_got_console) { + AllocConsole(); + debug_got_console = 1; + } + if (!debug_fp) { + debug_fp = fopen("debug.log", "w"); + } + + va_start(ap, fmt); + vsprintf(buf, fmt, ap); + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL); + fputs(buf, debug_fp); + fflush(debug_fp); + va_end(ap); +} +#endif