VirtualBox

Changeset 28915 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Apr 29, 2010 6:12:35 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60863
Message:

iprt: More path conversion avoidance.

Location:
trunk/src/VBox/Runtime/r3
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/darwin/pathhost-darwin.cpp

    r28880 r28915  
    4141
    4242
    43 int rtPathToNative(char **ppszNativePath, const char *pszPath)
     43int rtPathToNative(const char **ppszNativePath, const char *pszPath, const char *pszBasePath)
    4444{
    4545    /** @todo We should decompose the string here, but the file system will do
    4646     *        that for us if we don't, so why bother. */
    4747    *ppszNativePath = (char *)pszPath;
     48    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
    4849    return VINF_SUCCESS;
    4950}
    5051
    5152
    52 int rtPathToNativeEx(char **ppszNativePath, const char *pszPath, const char *pszBasePath)
     53void rtPathFreeNative(char const *pszNativePath, const char *pszPath)
    5354{
    54     NOREF(pszBasePath);
    55     return rtPathToNative(ppszNativePath, pszPath);
    56 }
    57 
    58 
    59 void rtPathFreeNative(char *pszNativePath, const char *pszPath)
    60 {
    61     Assert((const char *)pszNativePath == pszPath || !pszNativePath);
     55    Assert(pszNativePath == pszPath || !pszNativePath);
    6256    NOREF(pszNativePath);
    6357    NOREF(pszPath);
     
    6559
    6660
    67 int rtPathFromNative(char **ppszPath, const char *pszNativePath)
     61int rtPathFromNative(char const **ppszPath, const char *pszNativePath, const char *pszBasePath)
    6862{
    6963    /** @todo We must compose the codepoints in the string here.  We get file names
    7064     *        in normalization form D so we'll end up with normalization form C
    7165     *        whatever approach we take. */
    72     return RTStrDupEx(ppszPath, pszNativePath);
     66    int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
     67    if (RT_SUCCESS(rc))
     68        *ppszPath = pszNativePath;
     69    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
     70    return rc;
    7371}
    7472
    7573
    76 int rtPathFromNativeEx(char **ppszPath, const char *pszNativePath, const char *pszBasePath)
     74void rtPathFreeIprt(const char *pszPath, const char *pszNativePath)
    7775{
    78     NOREF(pszBasePath);
    79     return rtPathFromNative(ppszPath, pszNativePath);
     76    Assert(pszPath == pszNativePath || !pszPath);
     77    NOREF(pszPath); NOREF(pszNativePath);
    8078}
    8179
     80
     81int rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath)
     82{
     83    /** @todo We must compose the codepoints in the string here.  We get file names
     84     *        in normalization form D so we'll end up with normalization form C
     85     *        whatever approach we take. */
     86    int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
     87    if (RT_SUCCESS(rc))
     88        rc = RTStrCopyEx(pszPath, cbPath, pszNativePath, RTSTR_MAX);
     89    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
     90    return rc;
     91}
     92
  • trunk/src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp

    r28800 r28915  
    4949    AssertReturn(pszImageName, VERR_INTERNAL_ERROR);
    5050
    51     char *pszTmp;
    52     int rc = rtPathFromNative(&pszTmp, pszImageName);
     51    int rc = rtPathFromNativeCopy(pszPath, cchPath, pszImageName, NULL);
    5352    AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, strlen(pszImageName), pszPath), rc);
    54 
    55     size_t cch = strlen(pszTmp);
    56     AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    57 
    58     memcpy(pszPath, pszTmp, cch + 1);
    59     RTStrFree(pszTmp);
    6053
    6154    return VINF_SUCCESS;
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r28800 r28915  
    648648     * Hand it over to the native part.
    649649     */
    650     rc = rtOpenDirNative(pDir, szRealPath);
     650    rc = rtDirNativeOpen(pDir, szRealPath);
    651651    if (RT_SUCCESS(rc))
    652652        *ppDir = pDir;
  • trunk/src/VBox/Runtime/r3/freebsd/rtProcInitExePath-freebsd.cpp

    r28800 r28915  
    5656    if (sysctl(aiName, RT_ELEMENTS(aiName), pszPath, &cchExePath, NULL, 0) == 0)
    5757    {
    58 
    59         char *pszTmp = NULL;
    60         int rc = rtPathFromNative(&pszTmp, pszPath);
     58        const char *pszTmp;
     59        int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    6160        AssertMsgRCReturn(rc, ("rc=%Rrc pszPath=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchExePath, pszPath), rc);
    62 
    63         size_t cch = strlen(pszTmp);
    64         AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    65 
    66         memcpy(pszPath, pszTmp, cch + 1);
    67         RTStrFree(pszTmp);
    68 
    69         return VINF_SUCCESS;
     61        if (pszTmp != pszPath)
     62        {
     63            rc = RTStrCopy(pszPath, cchPath, pszTmp);
     64            rtPathFreeIprt(pszTmp, pszPath);
     65        }
     66        return rc;
    7067    }
    7168
     
    8481        pszPath[cchLink] = '\0';
    8582
    86         char *pszTmp = NULL;
     83        char const *pszTmp;
    8784        int rc = rtPathFromNative(&pszTmp, pszPath);
    8885        AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchLink, pszPath), rc);
    89 
    90         size_t cch = strlen(pszTmp);
    91         AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    92 
    93         memcpy(pszPath, pszTmp, cch + 1);
    94         RTStrFree(pszTmp);
    95 
    96         return VINF_SUCCESS;
     86        if (pszTmp != pszPath)
     87        {
     88            rc = RTStrCopy(pszPath, cchPath, pszTmp);
     89            rtPathFreeIprt(pszTmp);
     90        }
     91        return rc;
    9792    }
    9893
     
    111106            if (*pszImageName == '/') /* this may not always be absolute, despite the docs. :-( */
    112107            {
    113                 char *pszTmp = NULL;
    114                 int rc = rtPathFromNative(&pszTmp, pszImageName);
     108                char const *pszTmp;
     109                int rc = rtPathFromNative(&pszTmp, pszImageName, NULL);
    115110                AssertMsgRCReturn(rc, ("rc=%Rrc pszImageName=\"%s\"\n", rc, pszImageName), rc);
    116 
    117                 size_t cch = strlen(pszTmp);
    118                 AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    119 
    120                 memcpy(pszPath, pszTmp, cch + 1);
    121                 RTStrFree(pszTmp);
    122 
    123                 return VINF_SUCCESS;
     111                if (pszTmp != pszPath)
     112                {
     113                    rc = RTStrCopy(pszPath, cchPath, pszTmp);
     114                    rtPathFreeIprt(pszTmp, pszPath);
     115                }
     116                return rc;
    124117            }
    125118            /** @todo Try search the PATH for the file name or append the current
  • trunk/src/VBox/Runtime/r3/linux/rtProcInitExePath-linux.cpp

    r28800 r28915  
    5050        pszPath[cchLink] = '\0';
    5151
    52         char *pszTmp = NULL;
    53         int rc = rtPathFromNative(&pszTmp, pszPath);
     52        char const *pszTmp;
     53        int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    5454        AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchLink, pszPath), rc);
    55 
    56         size_t cch = strlen(pszTmp);
    57         AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    58 
    59         memcpy(pszPath, pszTmp, cch + 1);
    60         RTStrFree(pszTmp);
    61 
    62         return VINF_SUCCESS;
     55        if (pszTmp != pszPath)
     56        {
     57            rc = RTStrCopy(pszPath, cchPath, pszTmp);
     58            rtPathFreeIprt(pszTmp, pszPath);
     59        }
     60        return rc;
    6361    }
    6462
  • trunk/src/VBox/Runtime/r3/os2/rtProcInitExePath-os2.cpp

    r28800 r28915  
    4848    _execname(pszPath, cchPath);
    4949
    50     char *pszTmp;
    51     int rc = rtPathFromNative(&pszTmp, pszPath);
     50    char const *pszTmp;
     51    int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    5252    AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchPath, pszPath), rc);
    53 
    54     size_t cch = strlen(pszTmp);
    55     AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    56 
    57     memcpy(pszPath, pszTmp, cch + 1);
    58     RTStrFree(pszTmp);
    59 
    60     return VINF_SUCCESS;
     53    if (pszTmp != pszPath)
     54    {
     55        rc = RTStrCopy(pszPath, cchPath, pszTmp);
     56        rtPathFreeIprt(pszTmp, pszPath);
     57    }
     58    return rc;
    6159}
    6260
  • trunk/src/VBox/Runtime/r3/path.cpp

    r28800 r28915  
    7171{
    7272#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE)
    73     char *pszUtf8Path;
    74     int rc;
    75     rc = rtPathFromNative(&pszUtf8Path, RTPATH_APP_PRIVATE);
    76     if (RT_SUCCESS(rc))
    77     {
    78         size_t cchPathPrivateNoArch = strlen(pszUtf8Path);
    79         if (cchPathPrivateNoArch < cchPath)
    80             memcpy(pszPath, pszUtf8Path, cchPathPrivateNoArch + 1);
    81         else
    82             rc = VERR_BUFFER_OVERFLOW;
    83         RTStrFree(pszUtf8Path);
    84     }
    85     return rc;
     73    return RTStrCopyEx(pszPath, cchPath, RTPATH_APP_PRIVATE, RTSTR_MAX);
    8674#else
    8775    return RTPathExecDir(pszPath, cchPath);
     
    10593{
    10694#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH)
    107     char *pszUtf8Path;
    108     int rc;
    109     rc = rtPathFromNative(&pszUtf8Path, RTPATH_APP_PRIVATE_ARCH);
    110     if (RT_SUCCESS(rc))
    111     {
    112         size_t cchPathPrivateArch = strlen(pszUtf8Path);
    113         if (cchPathPrivateArch < cchPath)
    114             memcpy(pszPath, pszUtf8Path, cchPathPrivateArch + 1);
    115         else
    116             rc = VERR_BUFFER_OVERFLOW;
    117         RTStrFree(pszUtf8Path);
    118     }
    119     return rc;
     95    return RTStrCopyEx(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH, RTSTR_MAX);
    12096#else
    12197    return RTPathExecDir(pszPath, cchPath);
     
    140116{
    141117#if !defined(RT_OS_WINDOWS) && defined(RTPATH_SHARED_LIBS)
    142     char *pszUtf8Path;
    143     int rc;
    144     rc = rtPathFromNative(&pszUtf8Path, RTPATH_SHARED_LIBS);
    145     if (RT_SUCCESS(rc))
    146     {
    147         size_t cchPathSharedLibs = strlen(pszUtf8Path);
    148         if (cchPathSharedLibs < cchPath)
    149             memcpy(pszPath, pszUtf8Path, cchPathSharedLibs + 1);
    150         else
    151             rc = VERR_BUFFER_OVERFLOW;
    152         RTStrFree(pszUtf8Path);
    153     }
    154     return rc;
     118    return RTStrCopyEx(pszPath, cchPath, RTPATH_SHARED_LIBS, RTSTR_MAX);
    155119#else
    156120    return RTPathExecDir(pszPath, cchPath);
     
    173137{
    174138#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_DOCS)
    175     char *pszUtf8Path;
    176     int rc;
    177     rc = rtPathFromNative(&pszUtf8Path, RTPATH_APP_DOCS);
    178     if (RT_SUCCESS(rc))
    179     {
    180         size_t cchPathAppDocs = strlen(pszUtf8Path);
    181         if (cchPathAppDocs < cchPath)
    182             memcpy(pszPath, pszUtf8Path, cchPathAppDocs + 1);
    183         else
    184             rc = VERR_BUFFER_OVERFLOW;
    185         RTStrFree(pszUtf8Path);
    186     }
    187     return rc;
     139    return RTStrCopyEx(pszPath, cchPath, RTPATH_APP_DOCS, RTSTR_MAX);
    188140#else
    189141    return RTPathExecDir(pszPath, cchPath);
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r28877 r28915  
    6262{
    6363    bool fRc = false;
    64     char *pszNativePath;
    65     int rc = rtPathToNative(&pszNativePath, pszPath);
     64    char const *pszNativePath;
     65    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    6666    if (RT_SUCCESS(rc))
    6767    {
     
    8484    if (rtFsModeIsValidPermissions(fMode))
    8585    {
    86         char *pszNativePath;
    87         rc = rtPathToNative(&pszNativePath, pszPath);
     86        char const *pszNativePath;
     87        rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    8888        if (RT_SUCCESS(rc))
    8989        {
     
    124124RTDECL(int) RTDirRemove(const char *pszPath)
    125125{
    126     char *pszNativePath;
    127     int rc = rtPathToNative(&pszNativePath, pszPath);
     126    char const *pszNativePath;
     127    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    128128    if (RT_SUCCESS(rc))
    129129    {
     
    174174
    175175
    176 int rtOpenDirNative(PRTDIR pDir, char *pszPathBuf)
     176int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf)
    177177{
    178178    /*
    179179     * Convert to a native path and try opendir.
    180180     */
    181     char *pszNativePath;
    182     int rc = rtPathToNative(&pszNativePath, pDir->pszPath);
     181    char const *pszNativePath;
     182    int rc = rtPathToNative(&pszNativePath, pDir->pszPath, NULL);
    183183    if (RT_SUCCESS(rc))
    184184    {
     
    267267        if (!pDir->pszName)
    268268        {
    269             int rc = rtPathFromNativeEx(&pDir->pszName, pDir->Data.d_name, pDir->pszPath);
     269            int rc = rtPathFromNative(&pDir->pszName, pDir->Data.d_name, pDir->pszPath);
    270270            if (RT_FAILURE(rc))
    271271            {
     
    278278            ||  pDir->pfnFilter(pDir, pDir->pszName))
    279279            break;
    280         RTStrFree(pDir->pszName);
     280        rtPathFreeIprt(pDir->pszName, pDir->Data.d_name);
    281281        pDir->pszName = NULL;
    282282#else
     
    377377            pDir->fDataUnread  = false;
    378378#ifndef RT_DONT_CONVERT_FILENAMES
    379             RTStrFree(pDir->pszName);
     379            rtPathFreeIprt(pDir->pszName, pDir->Data.d_name);
    380380            pDir->pszName = NULL;
    381381#endif
     
    502502            pDir->fDataUnread  = false;
    503503#ifndef RT_DONT_CONVERT_FILENAMES
    504             RTStrFree(pDir->pszName);
     504            rtPathFreeIprt(pDir->pszName, pDir->Data.d_name);
    505505            pDir->pszName = NULL;
    506506#endif
  • trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp

    r28877 r28915  
    9292{
    9393    bool fRc = false;
    94     char *pszNativePath;
    95     int rc = rtPathToNative(&pszNativePath, pszPath);
     94    char const *pszNativePath;
     95    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    9696    if (RT_SUCCESS(rc))
    9797    {
     
    205205    int iErr = errno;
    206206#else
    207     char *pszNativeFilename;
    208     rc = rtPathToNative(&pszNativeFilename, pszFilename);
     207    char const *pszNativeFilename;
     208    rc = rtPathToNative(&pszNativeFilename, pszFilename, NULL);
    209209    if (RT_FAILURE(rc))
    210210        return (rc);
     
    372372RTR3DECL(int)  RTFileDelete(const char *pszFilename)
    373373{
    374     char *pszNativeFilename;
    375     int rc = rtPathToNative(&pszNativeFilename, pszFilename);
     374    char const *pszNativeFilename;
     375    int rc = rtPathToNative(&pszNativeFilename, pszFilename, NULL);
    376376    if (RT_SUCCESS(rc))
    377377    {
  • trunk/src/VBox/Runtime/r3/posix/fs-posix.cpp

    r28877 r28915  
    5656     * Convert the path and query the information.
    5757     */
    58     char *pszNativeFsPath;
    59     int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
     58    char const *pszNativeFsPath;
     59    int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL);
    6060    if (RT_SUCCESS(rc))
    6161    {
     
    103103     * We're simply return the device id.
    104104     */
    105     char *pszNativeFsPath;
    106     int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
     105    char const *pszNativeFsPath;
     106    int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL);
    107107    if (RT_SUCCESS(rc))
    108108    {
     
    134134     * Convert the path and query the information.
    135135     */
    136     char *pszNativeFsPath;
    137     int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
     136    char const *pszNativeFsPath;
     137    int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL);
    138138    if (RT_SUCCESS(rc))
    139139    {
  • trunk/src/VBox/Runtime/r3/posix/path-posix.cpp

    r28911 r28915  
    6262     * Convert input.
    6363     */
    64     char *pszNativePath;
    65     int rc = rtPathToNative(&pszNativePath, pszPath);
     64    char const *pszNativePath;
     65    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    6666    if (RT_SUCCESS(rc))
    6767    {
     
    7373        const char *psz = realpath(pszNativePath, szTmpPath);
    7474        if (psz)
    75         {
    76             /*
    77              * Convert result and copy it to the return buffer.
    78              */
    79             char *pszUtf8RealPath;
    80             rc = rtPathFromNative(&pszUtf8RealPath, szTmpPath);
    81             if (RT_SUCCESS(rc))
    82             {
    83                 size_t cch = strlen(pszUtf8RealPath) + 1;
    84                 if (cch <= cchRealPath)
    85                     memcpy(pszRealPath, pszUtf8RealPath, cch);
    86                 else
    87                     rc = VERR_BUFFER_OVERFLOW;
    88                 RTStrFree(pszUtf8RealPath);
    89             }
    90         }
     75            rc = rtPathFromNativeCopy(pszRealPath, cchRealPath, szTmpPath, NULL);
    9176        else
    9277            rc = RTErrConvertFromErrno(errno);
     
    360345     * Convert it to UTF-8 and copy it to the return buffer.
    361346     */
    362     char *pszUtf8Path;
    363     rc = rtPathFromNative(&pszUtf8Path, pPasswd->pw_dir);
    364     if (RT_SUCCESS(rc))
    365     {
    366         size_t cchHome = strlen(pszUtf8Path);
    367         if (cchHome < cchPath)
    368             memcpy(pszPath, pszUtf8Path, cchHome + 1);
    369         else
    370             rc = VERR_BUFFER_OVERFLOW;
    371         RTStrFree(pszUtf8Path);
    372     }
    373     return rc;
     347    return rtPathFromNativeCopy(pszPath, cchPath, pPasswd->pw_dir, NULL);
    374348}
    375349#endif
     
    389363     * Get HOME env. var it and validate it's existance.
    390364     */
    391     int rc = VERR_PATH_NOT_FOUND;
    392     const char *pszHome = RTEnvGet("HOME");
     365    int         rc      = VERR_PATH_NOT_FOUND;
     366    const char *pszHome = RTEnvGet("HOME"); /** @todo Codeset confusion in RTEnv. */
    393367    if (pszHome)
    394368
     
    397371        if (    !stat(pszHome, &st)
    398372            &&  S_ISDIR(st.st_mode))
    399         {
    400             /*
    401              * Convert it to UTF-8 and copy it to the return buffer.
    402              */
    403             char *pszUtf8Path;
    404             rc = rtPathFromNative(&pszUtf8Path, pszHome);
    405             if (RT_SUCCESS(rc))
    406             {
    407                 size_t cchHome = strlen(pszUtf8Path);
    408                 if (cchHome < cchPath)
    409                     memcpy(pszPath, pszUtf8Path, cchHome + 1);
    410                 else
    411                     rc = VERR_BUFFER_OVERFLOW;
    412                 RTStrFree(pszUtf8Path);
    413             }
    414         }
     373            rc = rtPathFromNativeCopy(pszPath, cchPath, pszHome, NULL);
    415374    }
    416375    return rc;
     
    480439     * Convert the filename.
    481440     */
    482     char *pszNativePath;
    483     int rc = rtPathToNative(&pszNativePath, pszPath);
     441    char const *pszNativePath;
     442    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    484443    if (RT_SUCCESS(rc))
    485444    {
     
    545504     * Convert the paths.
    546505     */
    547     char *pszNativePath;
    548     int rc = rtPathToNative(&pszNativePath, pszPath);
     506    char const *pszNativePath;
     507    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    549508    if (RT_SUCCESS(rc))
    550509    {
     
    663622     * Convert the paths.
    664623     */
    665     char *pszNativeSrc;
    666     int rc = rtPathToNative(&pszNativeSrc, pszSrc);
     624    char const *pszNativeSrc;
     625    int rc = rtPathToNative(&pszNativeSrc, pszSrc, NULL);
    667626    if (RT_SUCCESS(rc))
    668627    {
    669         char *pszNativeDst;
    670         rc = rtPathToNative(&pszNativeDst, pszDst);
     628        char const *pszNativeDst;
     629        rc = rtPathToNative(&pszNativeDst, pszDst, NULL);
    671630        if (RT_SUCCESS(rc))
    672631        {
     
    836795     * Convert the path and check if it exists using stat().
    837796     */
    838     char *pszNativePath;
    839     int rc = rtPathToNative(&pszNativePath, pszPath);
     797    char const *pszNativePath;
     798    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    840799    if (RT_SUCCESS(rc))
    841800    {
     
    860819    char szNativeCurDir[RTPATH_MAX];
    861820    if (getcwd(szNativeCurDir, sizeof(szNativeCurDir)) != NULL)
    862     {
    863         char *pszCurDir;
    864         rc = rtPathFromNative(&pszCurDir, szNativeCurDir);
    865         if (RT_SUCCESS(rc))
    866         {
    867             size_t cchCurDir = strlen(pszCurDir);
    868             if (cchCurDir < cchPath)
    869             {
    870                 memcpy(pszPath, pszCurDir, cchCurDir + 1);
    871                 RTStrFree(pszCurDir);
    872                 return VINF_SUCCESS;
    873             }
    874 
    875             rc = VERR_BUFFER_OVERFLOW;
    876             RTStrFree(pszCurDir);
    877         }
    878     }
     821        rc = rtPathFromNativeCopy(pszPath, cchPath, szNativeCurDir, NULL);
    879822    else
    880823        rc = RTErrConvertFromErrno(errno);
     
    894837     * Change the directory.
    895838     */
    896     char *pszNativePath;
    897     int rc = rtPathToNative(&pszNativePath, pszPath);
     839    char const *pszNativePath;
     840    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
    898841    if (RT_SUCCESS(rc))
    899842    {
  • trunk/src/VBox/Runtime/r3/posix/pathhost-posix.cpp

    r28912 r28915  
    177177
    178178
    179 int rtPathToNative(char **ppszNativePath, const char *pszPath)
     179int rtPathToNative(char const **ppszNativePath, const char *pszPath, const char *pszBasePath)
    180180{
    181181    *ppszNativePath = NULL;
     
    185185    {
    186186        if (g_fPassthruUtf8 || !*pszPath)
    187             *ppszNativePath = (char *)pszPath;
     187            *ppszNativePath = pszPath;
    188188        else
    189189            rc = rtStrConvert(pszPath, strlen(pszPath), "UTF-8",
    190                               ppszNativePath, 0, g_szFsCodeset,
     190                              (char **)ppszNativePath, 0, g_szFsCodeset,
    191191                              2, g_enmUtf8ToFsIdx);
    192192    }
     193    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
    193194    return rc;
    194195}
    195196
    196197
    197 int rtPathToNativeEx(char **ppszNativePath, const char *pszPath, const char *pszBasePath)
    198 {
    199     /* We don't query the FS for codeset preferences yet, so nothing special to do here. */
    200     NOREF(pszBasePath);
    201     return rtPathToNative(ppszNativePath, pszPath);
    202 }
    203 
    204 
    205 void rtPathFreeNative(char *pszNativePath, const char *pszPath)
     198void rtPathFreeNative(char const *pszNativePath, const char *pszPath)
    206199{
    207200    if (    pszNativePath != pszPath
    208201        &&  pszNativePath)
    209         RTStrFree(pszNativePath);
    210 }
    211 
    212 
    213 int rtPathFromNative(char **ppszPath, const char *pszNativePath)
     202        RTStrFree((char *)pszNativePath);
     203}
     204
     205
     206int rtPathFromNative(const char **ppszPath, const char *pszNativePath, const char *pszBasePath)
    214207{
    215208    *ppszPath = NULL;
     
    235228        else
    236229            rc = rtStrConvert(pszNativePath, strlen(pszNativePath), g_szFsCodeset,
    237                               ppszPath, 0, "UTF-8",
     230                              (char **)ppszPath, 0, "UTF-8",
    238231                              2, g_enmFsToUtf8Idx);
    239232    }
     233    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
    240234    return rc;
    241235}
    242236
    243237
    244 int rtPathFromNativeEx(char **ppszPath, const char *pszNativePath, const char *pszBasePath)
    245 {
    246     /* We don't query the FS for codeset preferences yet, so nothing special to do here. */
    247     NOREF(pszBasePath);
    248     return rtPathFromNative(ppszPath, pszNativePath);
    249 }
    250 
     238void rtPathFreeIprt(const char *pszPath, const char *pszNativePath)
     239{
     240    if (   pszPath != pszNativePath
     241        && !pszPath)
     242        RTStrFree((char *)pszPath);
     243}
     244
     245
     246int rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath)
     247{
     248    int rc = RTOnce(&g_OnceInitPathConv, rtPathConvInitOnce, NULL, NULL);
     249    if (RT_SUCCESS(rc))
     250    {
     251        if (g_fPassthruUtf8 || !*pszNativePath)
     252            rc = RTStrCopyEx(pszPath, cbPath, pszNativePath, RTSTR_MAX);
     253        else if (cbPath)
     254            rc = rtStrConvert(pszNativePath, strlen(pszNativePath), g_szFsCodeset,
     255                              &pszPath, cbPath, "UTF-8",
     256                              2, g_enmFsToUtf8Idx);
     257        else
     258            rc = VERR_BUFFER_OVERFLOW;
     259    }
     260
     261    NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
     262    return rc;
     263}
     264
  • trunk/src/VBox/Runtime/r3/solaris/rtProcInitExePath-solaris.cpp

    r28800 r28915  
    5252        pszPath[cchLink] = '\0';
    5353
    54         char *pszTmp = NULL;
    55         int rc = rtPathFromNative(&pszTmp, pszPath);
     54        char const *pszTmp;
     55        int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    5656        AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchLink, pszPath), rc);
    57 
    58         size_t cch = strlen(pszTmp);
    59         AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
    60 
    61         memcpy(pszPath, pszTmp, cch + 1);
    62         RTStrFree(pszTmp);
    63 
    64         return VINF_SUCCESS;
     57        if (pszTmp != pszPath)
     58        {
     59            rc = RTStrCopy(pszPath, cchPath, pszTmp);
     60            rtPathFreeIprt(pszTmp, pszPath);
     61        }
     62        return rc;
    6563    }
    6664
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r28800 r28915  
    130130
    131131
    132 int rtOpenDirNative(PRTDIR pDir, char *pszPathBuf)
     132int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf)
    133133{
    134134    /*
Note: See TracChangeset for help on using the changeset viewer.

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