diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2020-06-02 10:29:15 -0400 | 
|---|---|---|
| committer | Andrey Lihatskiy <alihatskiy@productengine.com> | 2020-06-02 23:58:04 +0300 | 
| commit | 13b78a0c5a788c617866e3530c65dae616e6520f (patch) | |
| tree | c90b53628e8e5feb6daa11d8420dd55694f6081d | |
| parent | 38a2b3db2be5262a3b4c6e505fc89118f858ba04 (diff) | |
SL-13361: Distill redundant create_console() code to set_stream().
There are separate stanzas in llappviewerwin32.cpp's create_console() function
for each of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE and STD_ERROR_HANDLE. SL-13361
wants to add more code to each. Factor out new local set_stream() function and
make create_console() call it three times.
| -rw-r--r-- | indra/newview/llappviewerwin32.cpp | 59 | 
1 files changed, 29 insertions, 30 deletions
| diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp index d208e135bb..1f66177c37 100644 --- a/indra/newview/llappviewerwin32.cpp +++ b/indra/newview/llappviewerwin32.cpp @@ -501,11 +501,12 @@ void LLAppViewerWin32::disableWinErrorReporting()  const S32 MAX_CONSOLE_LINES = 500; -static bool create_console() -{ -	int h_con_handle; -	long l_std_handle; +namespace { + +FILE* set_stream(const char* which, DWORD handle_id, const char* mode); +bool create_console() +{  	CONSOLE_SCREEN_BUFFER_INFO coninfo;  	FILE *fp; @@ -518,50 +519,48 @@ static bool create_console()  	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);  	// redirect unbuffered STDOUT to the console -	l_std_handle = (long)GetStdHandle(STD_OUTPUT_HANDLE); -	h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT); -	if (h_con_handle == -1) +	FILE* fp = set_stream("stdout", STD_OUTPUT_HANDLE, "w"); +	if (fp)  	{ -		LL_WARNS() << "create_console() failed to open stdout handle" << LL_ENDL; -	} -	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); -	if (h_con_handle == -1) -	{ -		LL_WARNS() << "create_console() failed to open stdin handle" << LL_ENDL; -	} -	else +	fp = set_stream("stdin", STD_INPUT_HANDLE, "r"); +	if (fp)  	{ -		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 = set_stream("stderr", STD_ERROR_HANDLE, "w"); +	if (fp) +	{ +		*stderr = *fp; +	} + +	return isConsoleAllocated; +} + +FILE* set_stream(const char* which, DWORD handle_id, const char* mode) +{ +	long l_std_handle = (long)GetStdHandle(handle_id); +	int h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);  	if (h_con_handle == -1)  	{ -		LL_WARNS() << "create_console() failed to open stderr handle" << LL_ENDL; +		LL_WARNS() << "create_console() failed to open " << which << " handle" << LL_ENDL; +		return nullptr;  	}  	else  	{ -		fp = _fdopen( h_con_handle, "w" ); -		*stderr = *fp; -		setvbuf( stderr, NULL, _IONBF, 0 ); +		FILE* fp = _fdopen( h_con_handle, mode ); +		setvbuf( fp, NULL, _IONBF, 0 ); +		return fp;  	} - -    return isConsoleAllocated;  } +} // anonymous namespace +  LLAppViewerWin32::LLAppViewerWin32(const char* cmd_line) :  	mCmdLine(cmd_line),  	mIsConsoleAllocated(false) | 
