VirtualBox

Changeset 80764 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Sep 13, 2019 6:52:50 AM (5 years ago)
Author:
vboxsync
Message:

IPRT: Optimized RTEnvPutEx. bugref:9341

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/env-win.cpp

    r76553 r80764  
    173173}
    174174
    175 RTDECL(int) RTEnvSetUtf8(const char *pszVar, const char *pszValue)
    176 {
    177     AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME);
    178 
     175
     176/**
     177 * Worker common to RTEnvSetUtf8() and rtEnvSetExWorker().
     178 */
     179int rtEnvSetUtf8Worker(const char *pchVar, size_t cchVar, const char *pszValue)
     180{
    179181    size_t cwcVar;
    180     int rc = RTStrCalcUtf16LenEx(pszVar, RTSTR_MAX, &cwcVar);
     182    int rc = RTStrCalcUtf16LenEx(pchVar, cchVar, &cwcVar);
    181183    if (RT_SUCCESS(rc))
    182184    {
    183185        size_t cwcValue;
    184         rc = RTStrCalcUtf16LenEx(pszVar, RTSTR_MAX, &cwcValue);
     186        rc = RTStrCalcUtf16LenEx(pszValue, RTSTR_MAX, &cwcValue);
    185187        if (RT_SUCCESS(rc))
    186188        {
     
    188190            if (pwszTmp)
    189191            {
    190                 rc = RTStrToUtf16Ex(pszVar, RTSTR_MAX, &pwszTmp, cwcVar + 1, NULL);
     192                rc = RTStrToUtf16Ex(pchVar, cchVar, &pwszTmp, cwcVar + 1, NULL);
    191193                if (RT_SUCCESS(rc))
    192194                {
     
    212214
    213215
     216RTDECL(int) RTEnvSetUtf8(const char *pszVar, const char *pszValue)
     217{
     218    size_t cchVar = strlen(pszVar);
     219    AssertReturn(memchr(pszVar, '=', cchVar) == NULL, VERR_ENV_INVALID_VAR_NAME);
     220    return rtEnvSetUtf8Worker(pszVar, cchVar, pszValue);
     221}
     222
     223
    214224RTDECL(int) RTEnvUnsetBad(const char *pszVar)
    215225{
  • trunk/src/VBox/Runtime/r3/win/utf8-win.cpp

    r76553 r80764  
    3939
    4040
     41
    4142RTR3DECL(int)  RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag)
     43{
     44    return RTStrUtf8ToCurrentCPExTag(ppszString, pszString, RTSTR_MAX, pszTag);
     45}
     46
     47
     48RTR3DECL(int)  RTStrUtf8ToCurrentCPExTag(char **ppszString, const char *pszString, size_t cchString, const char *pszTag)
    4249{
    4350    Assert(ppszString);
     
    4754     * Check for zero length input string.
    4855     */
    49     if (!*pszString)
     56    if (cchString < 1 || !*pszString)
    5057    {
    5158        *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
     
    6168     */
    6269    PRTUTF16 pwszString = NULL;
    63     int rc = RTStrToUtf16(pszString, &pwszString);
     70    int rc = RTStrToUtf16Ex(pszString, cchString, &pwszString, 0, NULL);
    6471    if (RT_FAILURE(rc))
    6572        return rc;
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