summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2020-06-02 10:29:15 -0400
committerNat Goodspeed <nat@lindenlab.com>2020-07-01 13:33:29 -0400
commit4708662091760f90a7782b726a5a7d89f376ce53 (patch)
treeecd7c7520c6730738332a9dc021701d62858f16d
parenta075a73920de2d025bd41070e05ad2b051d02ece (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. (cherry picked from commit 13b78a0c5a788c617866e3530c65dae616e6520f)
-rw-r--r--indra/newview/llappviewerwin32.cpp59
1 files changed, 29 insertions, 30 deletions
diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp
index 9a8a5f16bb..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;
- intptr_t 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 = reinterpret_cast<decltype(l_std_handle)>(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 = reinterpret_cast<decltype(l_std_handle)>(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 = reinterpret_cast<decltype(l_std_handle)>(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)