[Libreoffice-commits] core.git: desktop/source

Mike Kaganski mike.kaganski at collabora.com
Sat Feb 18 20:37:34 UTC 2017


 desktop/source/app/cmdlinehelp.cxx |   34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

New commits:
commit 12899c07be2f927776ae12ea1abcefdc4bea8346
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Sat Feb 18 22:53:14 2017 +0300

    tdf#100826 related: initialize stdout/stdin/strerr properly
    
    The previous code doesn't work with VS2015.
    
    Change-Id: Ide75b2f978dda871874572a093039b5772a2b537
    Reviewed-on: https://gerrit.libreoffice.org/34409
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/desktop/source/app/cmdlinehelp.cxx b/desktop/source/app/cmdlinehelp.cxx
index 6498ec8..83baa1d 100644
--- a/desktop/source/app/cmdlinehelp.cxx
+++ b/desktop/source/app/cmdlinehelp.cxx
@@ -177,10 +177,7 @@ namespace desktop
             explicit lcl_Console(short nBufHeight)
                 : mConsoleMode(unknown)
             {
-                HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE),
-                    hOut = GetStdHandle(STD_OUTPUT_HANDLE),
-                    hErr = GetStdHandle(STD_ERROR_HANDLE);
-                if (hOut == nullptr) // application does not have associated standard handles
+                if (GetStdHandle(STD_OUTPUT_HANDLE) == nullptr) // application does not have associated standard handles
                 {
                     STARTUPINFOA aStartupInfo;
                     aStartupInfo.cb = sizeof(aStartupInfo);
@@ -188,9 +185,9 @@ namespace desktop
                     if ((aStartupInfo.dwFlags & STARTF_USESTDHANDLES) == STARTF_USESTDHANDLES)
                     {
                         // If standard handles had been passed to this process, use them
-                        hIn = aStartupInfo.hStdInput;
-                        hOut = aStartupInfo.hStdOutput;
-                        hErr = aStartupInfo.hStdError;
+                        SetStdHandle(STD_INPUT_HANDLE, aStartupInfo.hStdInput);
+                        SetStdHandle(STD_OUTPUT_HANDLE, aStartupInfo.hStdOutput);
+                        SetStdHandle(STD_ERROR_HANDLE, aStartupInfo.hStdError);
                     }
                     else
                     {
@@ -201,9 +198,7 @@ namespace desktop
                         else if (AllocConsole() != FALSE)
                             mConsoleMode = allocated;
 
-                        hIn = GetStdHandle(STD_INPUT_HANDLE);
-                        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
-                        hErr = GetStdHandle(STD_ERROR_HANDLE);
+                        HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
 
                         // Ensure that console buffer is enough to hold required data
                         CONSOLE_SCREEN_BUFFER_INFO cinfo;
@@ -216,21 +211,9 @@ namespace desktop
                     }
                 }
 
-                // stdin
-                int fileHandle = _open_osfhandle(reinterpret_cast<intptr_t>(hIn), _O_TEXT);
-                FILE *fp = _fdopen(fileHandle, "r");
-                *stdin = *fp;
-                setvbuf(stdin, nullptr, _IONBF, 0);
-                // stdout
-                fileHandle = _open_osfhandle(reinterpret_cast<intptr_t>(hOut), _O_TEXT);
-                fp = _fdopen(fileHandle, "w");
-                *stdout = *fp;
-                setvbuf(stdout, nullptr, _IONBF, 0);
-                // stderr
-                fileHandle = _open_osfhandle(reinterpret_cast<intptr_t>(hErr), _O_TEXT);
-                fp = _fdopen(fileHandle, "w");
-                *stderr = *fp;
-                setvbuf(stderr, nullptr, _IONBF, 0);
+                freopen("CON", "r", stdin);
+                freopen("CON", "w", stdout);
+                freopen("CON", "w", stderr);
 
                 std::ios::sync_with_stdio(true);
 
@@ -242,6 +225,7 @@ namespace desktop
 
             ~lcl_Console()
             {
+                fflush(stdout);
                 switch (mConsoleMode) {
                 case unknown:
                     // Don't free the console


More information about the Libreoffice-commits mailing list