VirtualBox

Ignore:
Timestamp:
Mar 7, 2013 6:59:34 PM (12 years ago)
Author:
vboxsync
Message:

Forward-ported r84173 from 4.2: FE/VBoxManage/GuestCtrl: Do UTF-8 conversion on process execution output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r44959 r44960  
    526526    else
    527527    {
    528         /** @todo implement the dos2unix/unix2dos conversions */
    529         vrc = RTStrmWrite(pStrmOutput, aOutputData.raw(), aOutputData.size());
    530         if (RT_FAILURE(vrc))
    531             RTMsgError("Unable to write output, rc=%Rrc\n", vrc);
     528        size_t cbOutputData = aOutputData.size();
     529        if (cbOutputData > 0)
     530        {
     531            BYTE *pBuf = aOutputData.raw();
     532            AssertPtr(pBuf);
     533            pBuf[cbOutputData - 1] = 0; /* Properly terminate buffer. */
     534
     535            /** @todo implement the dos2unix/unix2dos conversions */
     536
     537            /*
     538             * If aOutputData is text data from the guest process' stdout or stderr,
     539             * it has a platform dependent line ending. So standardize on
     540             * Unix style, as RTStrmWrite does the LF -> CR/LF replacement on
     541             * Windows. Otherwise we end up with CR/CR/LF on Windows.
     542             */
     543
     544            char *pszBufUTF8;
     545            vrc = RTStrCurrentCPToUtf8(&pszBufUTF8, (const char*)aOutputData.raw());
     546            if (RT_SUCCESS(vrc))
     547            {
     548                cbOutputData = strlen(pszBufUTF8);
     549
     550                ULONG cbOutputDataPrint = cbOutputData;
     551                for (char *s = pszBufUTF8, *d = s;
     552                     s - pszBufUTF8 < (ssize_t)cbOutputData;
     553                     s++, d++)
     554                {
     555                    if (*s == '\r')
     556                    {
     557                        /* skip over CR, adjust destination */
     558                        d--;
     559                        cbOutputDataPrint--;
     560                    }
     561                    else if (s != d)
     562                        *d = *s;
     563                }
     564
     565                vrc = RTStrmWrite(pStrmOutput, pszBufUTF8, cbOutputDataPrint);
     566                if (RT_FAILURE(vrc))
     567                    RTMsgError("Unable to write output, rc=%Rrc\n", vrc);
     568
     569                RTStrFree(pszBufUTF8);
     570            }
     571            else
     572                RTMsgError("Unable to convert output, rc=%Rrc\n", vrc);
     573        }
    532574    }
    533575
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette