Author: fireball Date: Mon Jul 22 13:28:56 2013 New Revision: 59553
URL: http://svn.reactos.org/svn/reactos?rev=59553&view=rev Log: [PING] - Alexander Yastrebov: Properly write data into the standard output device depending whether it's a char or a block device.
CORE-6628 #resolve #comment Patch committed in revision 59552, thank you Alexander and sorry that it took so long!
Modified: trunk/reactos/base/applications/network/ping/ping.c
Modified: trunk/reactos/base/applications/network/ping/ping.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/p... ============================================================================== --- trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] Mon Jul 22 13:28:56 2013 @@ -143,10 +143,13 @@ va_list valist;
WCHAR Buf[1024]; + CHAR AnsiBuf[1024]; LPWSTR pBuf = Buf; + PCHAR pAnsiBuf = AnsiBuf; LPWSTR Format; DWORD written; UINT DataLength; + int AnsiLength;
va_start(valist, uID);
@@ -169,7 +172,28 @@ return; }
- WriteConsole(hStdOutput, pBuf, DataLength, &written, NULL); + if(GetFileType(hStdOutput) == FILE_TYPE_CHAR) + { + /* Is a console or a printer */ + WriteConsole(hStdOutput, pBuf, DataLength, &written, NULL); + } + else + { + /* Is a pipe, socket, file or other */ + AnsiLength = WideCharToMultiByte(CP_ACP, 0, pBuf, DataLength,\ + NULL, 0, NULL, NULL); + + if(AnsiLength >= sizeof(AnsiBuf)) + pAnsiBuf = (PCHAR)HeapAlloc(GetProcessHeap(), 0, AnsiLength); + + AnsiLength = WideCharToMultiByte(CP_OEMCP, 0, pBuf, DataLength,\ + pAnsiBuf, AnsiLength, " ", NULL); + + WriteFile(hStdOutput, pAnsiBuf, AnsiLength, &written, NULL); + + if(pAnsiBuf != AnsiBuf) + HeapFree(NULL, 0, pAnsiBuf); + }
if(pBuf != Buf) LocalFree(pBuf);