MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / cvt_wprintf

Function cvt_wprintf

Libraries/unrar/consio.cpp:65–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64#ifndef SILENT
65static void cvt_wprintf(FILE *dest,const wchar *fmt,va_list arglist)
66{
67 // This buffer is for format string only, not for entire output,
68 // so it can be short enough.
69 wchar fmtw[1024];
70 PrintfPrepareFmt(fmt,fmtw,ASIZE(fmtw));
71#ifdef _WIN_ALL
72 safebuf wchar Msg[MaxMsgSize];
73 if (dest==stdout && StdoutRedirected || dest==stderr && StderrRedirected)
74 {
75 HANDLE hOut=GetStdHandle(dest==stdout ? STD_OUTPUT_HANDLE:STD_ERROR_HANDLE);
76 vswprintf(Msg,ASIZE(Msg),fmtw,arglist);
77 DWORD Written;
78 if (RedirectCharset==RCH_UNICODE)
79 WriteFile(hOut,Msg,(DWORD)wcslen(Msg)*sizeof(*Msg),&Written,NULL);
80 else
81 {
82 // Avoid Unicode for redirect in Windows, it does not work with pipes.
83 safebuf char MsgA[MaxMsgSize];
84 if (RedirectCharset==RCH_UTF8)
85 WideToUtf(Msg,MsgA,ASIZE(MsgA));
86 else
87 WideToChar(Msg,MsgA,ASIZE(MsgA));
88 if (RedirectCharset==RCH_DEFAULT || RedirectCharset==RCH_OEM)
89 CharToOemA(MsgA,MsgA); // Console tools like 'more' expect OEM encoding.
90
91 // We already converted \n to \r\n above, so we use WriteFile instead
92 // of C library to avoid unnecessary additional conversion.
93 WriteFile(hOut,MsgA,(DWORD)strlen(MsgA),&Written,NULL);
94 }
95 return;
96 }
97 // MSVC2008 vfwprintf writes every character to console separately
98 // and it is too slow. We use direct WriteConsole call instead.
99 vswprintf(Msg,ASIZE(Msg),fmtw,arglist);
100 HANDLE hOut=GetStdHandle(dest==stderr ? STD_ERROR_HANDLE:STD_OUTPUT_HANDLE);
101 DWORD Written;
102 WriteConsole(hOut,Msg,(DWORD)wcslen(Msg),&Written,NULL);
103#else
104 vfwprintf(dest,fmtw,arglist);
105 // We do not use setbuf(NULL) in Unix (see comments in InitConsole).
106 fflush(dest);
107#endif
108}
109
110
111void mprintf(const wchar *fmt,...)

Callers 2

mprintfFunction · 0.85
eprintfFunction · 0.85

Calls 3

PrintfPrepareFmtFunction · 0.85
WideToUtfFunction · 0.85
WideToCharFunction · 0.85

Tested by

no test coverage detected