1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 04:22:47 -05:00

Move dprintf and the debug system out into misc.c, to centralise it.

Saves binary space and also allows redirection of debug statements
to a file `debug.log'.

[originally from svn r791]
This commit is contained in:
Simon Tatham
2000-11-01 19:54:46 +00:00
parent 6928fbb1e3
commit 84077ea5ee
2 changed files with 27 additions and 20 deletions

26
misc.c
View File

@ -67,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