VirtualBox

Ignore:
Timestamp:
Jul 18, 2020 11:33:58 AM (5 years ago)
Author:
vboxsync
Message:

iprt/path.h: Adjustments and a bunch of todos for RTPathFindCommon[Ex].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/path/RTPathFindCommon.cpp

    r85374 r85382  
    3535
    3636
    37 RTDECL(size_t) RTPathFindCommonEx(const char * const *papcszPaths, size_t cPaths, char szSeparator)
     37RTDECL(size_t) RTPathFindCommonEx(size_t cPaths, const char * const *papszPaths, uint32_t fFlags)
    3838{
    39     AssertPtrReturn(papcszPaths, 0);
    40     AssertReturn(cPaths, 0);
    41     AssertReturn(szSeparator != '\0', 0);
     39    AssertReturn(cPaths > 0, 0);
     40    AssertPtrReturn(papszPaths, 0);
     41    AssertReturn(RTPATH_STR_F_IS_VALID(fFlags, 0), 0);
    4242
    43     const char *pcszRef = papcszPaths[0]; /* The reference we're comparing with. */
     43    /** @todo r=bird: Extremely naive code.
     44     * - The original idea of taking either '/' or '\\' as separators is very out of
     45     *   touch with the rest of path.h.  On DOS based systems we need to handle both
     46     *   of those as well as ':'.
     47     * - Why compare pszRef with itself?
     48     * - Why derefernece pszRef[cch] for each other path.
     49     * - Why perform NULL checks for each outer iteration.
     50     * - Why perform '\0' check before comparing with pszRef[cch]?
     51     *   It's sufficient to check if pszRef[cch] is '\0'.
     52     * - Why backtrack to the last path separator?  It won't return the expected
     53     *   result for cPaths=1, unless the path ends with a separator.
     54     * - Multiple consequtive path separators must be treated as a single one (most
     55     *   of the time anyways - UNC crap).
     56     */
     57    const char *pszRef = papszPaths[0]; /* The reference we're comparing with. */
     58    const char chNaiveSep = (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_HOST
     59                          ? RTPATH_SLASH
     60                          : (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_DOS ? '\\' : '/';
    4461
    4562    size_t cch = 0;
     
    4865        for (size_t i = 0; i < cPaths; ++i)
    4966        {
    50             const char *pcszPath = papcszPaths[i];
     67            const char *pcszPath = papszPaths[i];
    5168            if (   pcszPath
    5269                && pcszPath[cch]
    53                 && pcszPath[cch] == pcszRef[cch])
     70                && pcszPath[cch] == pszRef[cch])
    5471                continue;
    5572
    5673            while (   cch
    57                    && pcszRef[--cch] != szSeparator) { }
     74                   && pszRef[--cch] != chNaiveSep) { }
    5875
    5976            return cch ? cch + 1 : 0;
    6077        }
    61     }
    62     while (++cch);
     78    } while (++cch);
    6379
    6480    return 0;
     
    6783
    6884
    69 RTDECL(size_t) RTPathFindCommon(const char * const *papcszPaths, size_t cPaths)
     85RTDECL(size_t) RTPathFindCommon(size_t cPaths, const char * const *papszPaths)
    7086{
    71     return RTPathFindCommonEx(papcszPaths, cPaths, RTPATH_SLASH);
     87    return RTPathFindCommonEx(cPaths, papszPaths, RTPATH_STR_F_STYLE_HOST);
    7288}
    7389RT_EXPORT_SYMBOL(RTPathFindCommon);
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