VirtualBox

Changeset 93543 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 2, 2022 12:40:40 PM (3 years ago)
Author:
vboxsync
Message:

IPRT: Default to UTF-8 on macOS when nothing else is given in the environment. bugref:10153

Location:
trunk/src/VBox/Runtime/r3/posix
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp

    r93487 r93543  
    14471447        }
    14481448        else
     1449#ifdef RT_OS_DARWIN /* @bugref{10153}: Darwin defaults to UTF-8. */
     1450            pszEncoding = "UTF-8";
     1451#else
    14491452            pszEncoding = "ASCII";
     1453#endif
    14501454    }
    14511455
  • trunk/src/VBox/Runtime/r3/posix/utf8-posix.cpp

    r93115 r93543  
    4040#include <errno.h>
    4141#include <locale.h>
     42#ifdef RT_OS_DARWIN
     43# include <stdlib.h>
     44#endif
    4245
    4346/* iconv prototype changed with 165+ (thanks to PSARC/2010/160 Bugster 7037400) */
     
    107110DECLHIDDEN(const char *) rtStrGetLocaleCodeset(void)
    108111{
     112#ifdef RT_OS_DARWIN
     113    /*
     114     * @bugref{10153}: If no locale specified in the environment (typically the
     115     *      case when launched via Finder, LaunchPad or similar) default to UTF-8.
     116     */
     117    static int8_t volatile s_fIsUtf8 = -1;
     118    int8_t fIsUtf8 = s_fIsUtf8;
     119    if (fIsUtf8)
     120    {
     121        if (fIsUtf8 == true)
     122            return "UTF-8";
     123
     124        /* Initialize: */
     125        fIsUtf8 = true;
     126        static const char * const s_papszVariables[] = { "LC_ALL", "LC_CTYPE", "LANG" };
     127        for (size_t i = 0; i < RT_ELEMENTS(s_papszVariables); i++)
     128        {
     129            const char *pszValue = getenv(s_papszVariables[i]);
     130            if (pszValue && *pszValue)
     131            {
     132                fIsUtf8 = false;
     133                break;
     134            }
     135        }
     136        s_fIsUtf8 = fIsUtf8;
     137        if (fIsUtf8 == true)
     138            return "UTF-8";
     139    }
     140#endif
    109141    return nl_langinfo(CODESET);
    110142}
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