Make sure _open_osfhandle actually returns a valid handle before assigning buffer.

This commit is contained in:
Shyotl
2011-06-16 22:46:33 -05:00
parent a6e29b5c5e
commit ed51cdfb57

View File

@@ -351,26 +351,48 @@ void create_console()
// redirect unbuffered STDOUT to the console
l_std_handle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
fp = _fdopen( h_con_handle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
if (h_con_handle == -1)
{
llwarns << "create_console() failed to open stdout handle" << llendl;
}
else
{
fp = _fdopen( h_con_handle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
}
// redirect unbuffered STDIN to the console
l_std_handle = (long)GetStdHandle(STD_INPUT_HANDLE);
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
fp = _fdopen( h_con_handle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
if (h_con_handle == -1)
{
llwarns << "create_console() failed to open stdin handle" << llendl;
}
else
{
fp = _fdopen( h_con_handle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
}
// redirect unbuffered STDERR to the console
l_std_handle = (long)GetStdHandle(STD_ERROR_HANDLE);
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
fp = _fdopen( h_con_handle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IOFBF, 1024 ); //Assigning a buffer improves speed a LOT, esp on vista/win7
//_IOLBF is borked.
if (h_con_handle == -1)
{
llwarns << "create_console() failed to open stderr handle" << llendl;
}
else
{
fp = _fdopen( h_con_handle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IOFBF, 1024 ); //Assigning a buffer improves speed a LOT, esp on vista/win7
//_IOLBF is borked.
}
}
LLAppViewerWin32::LLAppViewerWin32(const char* cmd_line) :
mCmdLine(cmd_line)
{