VirtualBox

Changeset 93640 in vbox


Ignore:
Timestamp:
Feb 7, 2022 2:02:44 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
149785
Message:

Runtime: bugref:9955: Added conversion from console codepage to UTF-8 in Windows needed for proper handling the password containing national characters from console.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r93115 r93640  
    277277 */
    278278RTR3DECL(int)  RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag);
     279
     280/**
     281 * Allocates tmp buffer, translates pszString from console codepage to UTF-8.
     282 *
     283 * @returns iprt status code.
     284 * @param   ppszString      Receives pointer of allocated UTF-8 string.
     285 *                          The returned pointer must be freed using RTStrFree().
     286 * @param   pszString       Native string to convert.
     287 */
     288#define RTStrConsoleCPToUtf8(ppszString, pszString)     RTStrConsoleCPToUtf8Tag((ppszString), (pszString), RTSTR_TAG)
     289
     290/**
     291 * Allocates tmp buffer, translates pszString from console codepage to UTF-8.
     292 *
     293 * @returns iprt status code.
     294 * @param   ppszString      Receives pointer of allocated UTF-8 string.
     295 *                          The returned pointer must be freed using RTStrFree().
     296 * @param   pszString       Native string to convert.
     297 * @param   pszTag          Allocation tag used for statistics and such.
     298 */
     299RTR3DECL(int)  RTStrConsoleCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag);
    279300
    280301#endif /* IN_RING3 */
  • trunk/src/VBox/Runtime/r3/posix/utf8-posix.cpp

    r93544 r93640  
    693693}
    694694
     695
     696RTR3DECL(int)  RTStrConsoleCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
     697{
     698    return RTStrCurrentCPToUtf8Tag(ppszString, pszString, pszTag);
     699}
  • trunk/src/VBox/Runtime/r3/win/utf8-win.cpp

    r93115 r93640  
    117117}
    118118
    119 
    120 RTR3DECL(int)  RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
     119static int rtStrCPToUtf8Tag(char **ppszString, const char *pszString, uint32_t uCodePage, const char *pszTag)
    121120{
    122121    Assert(ppszString);
     
    143142     */
    144143    int rc;
    145     int cwc = MultiByteToWideChar(CP_ACP, 0, pszString, -1, NULL, 0);
     144    int cwc = MultiByteToWideChar((UINT)uCodePage, 0, pszString, -1, NULL, 0);
    146145    if (cwc > 0)
    147146    {
     
    155154             * Do the translation.
    156155             */
    157             if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, pwszString, cwc) > 0)
     156            if (MultiByteToWideChar((UINT)uCodePage, 0, pszString, -1, pwszString, cwc) > 0)
    158157            {
    159158                /*
     
    183182}
    184183
     184
     185RTR3DECL(int)  RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
     186{
     187    return rtStrCPToUtf8Tag(ppszString, pszString, CP_ACP, pszTag);
     188}
     189
     190
     191RTR3DECL(int)  RTStrConsoleCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
     192{
     193    return rtStrCPToUtf8Tag(ppszString, pszString, GetConsoleCP(), pszTag);
     194}
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