Some changes to how wchar_t strings are handled to make wchar debug messages
appear on stdout. This was SVN commit r2769.
This commit is contained in:
parent
a88915825f
commit
3c61029ff1
@ -350,7 +350,7 @@ ErrorReaction display_error(const wchar_t* description, int flags,
|
||||
// display in output window; double-click will navigate to error location.
|
||||
const char* slash = strrchr(file, DIR_SEP);
|
||||
const char* filename = slash? slash+1 : file;
|
||||
debug_wprintf(L"%hs(%d): %s\n", filename, line, description);
|
||||
debug_wprintf(L"%hs(%d): %ls\n", filename, line, description);
|
||||
|
||||
// allocate memory for the stack trace. this needs to be quite large,
|
||||
// so preallocating is undesirable. it must work even if the heap is
|
||||
|
@ -421,10 +421,39 @@ void debug_heap_enable(DebugHeapChecks what)
|
||||
|
||||
void debug_wprintf(const wchar_t* fmt, ...)
|
||||
{
|
||||
wchar_t buf[512];
|
||||
int ret;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vwprintf(fmt, args);
|
||||
ret = vswprintf(buf, ARRAY_SIZE(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
char errbuf[256];
|
||||
strerror_r(errno, errbuf, ARRAY_SIZE(errbuf));
|
||||
printf("debug_wprintf: %s (%ls)\n", errbuf, fmt);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
// According to fwide(3) and assorted manpage, FILEs are in single character or in
|
||||
// wide character mode. When a FILE is in single character mode, wide character writes
|
||||
// will fail, and no conversion is done automatically. Thus the manual conversion.
|
||||
size_t convbuflen = wcstombs(NULL, buf, 0)+1;
|
||||
char* convbuf = (char*)malloc(convbuflen);
|
||||
ret = wcstombs(convbuf, buf, convbuflen);
|
||||
|
||||
if (ret < 0 || ret >= convbuflen) {
|
||||
printf("debug_wprintf: wcstombs failed\n");
|
||||
free(convbuf);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
fputs(convbuf, stdout);
|
||||
free(convbuf);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user