Skip to content

Support writing logs to Git-Bash mintty terminal; reduce the number of "GetStdHandle()" calls #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/yr_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ hook_wwdebug_printf(char const *fmt, ...)
va_list ap;
va_start(ap,fmt);
static bool already_consoled = false;
static HANDLE h = 0;

if (!already_consoled) {
AllocConsole();
already_consoled = true;
h = GetStdHandle(STD_OUTPUT_HANDLE);
WWDebug_Printf("Allocated the console\n");
}

HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

size_t fmt_len = strnlen(fmt,99);

if (fmt_len >= 99)
Expand All @@ -41,7 +41,9 @@ hook_wwdebug_printf(char const *fmt, ...)
return;
LPDWORD ret;

WriteConsole(h,wwdebug_buf,len, 0, 0);
// In some terminals (e.g., mintty from Git-Bash), "WriteConsole(h, ...)"
// writes NOTHING because "GetFileType(h) == FILE_TYPE_PIPE".
WriteFile(h,wwdebug_buf,len, 0, 0);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion sym.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setcglob 0x004068E0, WWDebug_Printf
setcglob 0x00A8ED6B, Debug_Map

setcglob 0x007E12CC, _imp__GetStdHandle
setcglob 0x007E1344, _imp__WriteConsoleA
setcglob 0x007E11A0, _imp__WriteFile
setcglob 0x007E1218, _imp__AllocConsole
setcglob 0x007E11A8, _imp__GetModuleFileNameA
setcglob 0x007E11A4, _imp__GetCurrentProcess_hack
Expand Down