Changeset 85382 in vbox for trunk/src/VBox/Runtime/common/path
- Timestamp:
- Jul 18, 2020 11:33:58 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathFindCommon.cpp
r85374 r85382 35 35 36 36 37 RTDECL(size_t) RTPathFindCommonEx( const char * const *papcszPaths, size_t cPaths, char szSeparator)37 RTDECL(size_t) RTPathFindCommonEx(size_t cPaths, const char * const *papszPaths, uint32_t fFlags) 38 38 { 39 Assert PtrReturn(papcszPaths, 0);40 Assert Return(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); 42 42 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 ? '\\' : '/'; 44 61 45 62 size_t cch = 0; … … 48 65 for (size_t i = 0; i < cPaths; ++i) 49 66 { 50 const char *pcszPath = pap cszPaths[i];67 const char *pcszPath = papszPaths[i]; 51 68 if ( pcszPath 52 69 && pcszPath[cch] 53 && pcszPath[cch] == p cszRef[cch])70 && pcszPath[cch] == pszRef[cch]) 54 71 continue; 55 72 56 73 while ( cch 57 && p cszRef[--cch] != szSeparator) { }74 && pszRef[--cch] != chNaiveSep) { } 58 75 59 76 return cch ? cch + 1 : 0; 60 77 } 61 } 62 while (++cch); 78 } while (++cch); 63 79 64 80 return 0; … … 67 83 68 84 69 RTDECL(size_t) RTPathFindCommon( const char * const *papcszPaths, size_t cPaths)85 RTDECL(size_t) RTPathFindCommon(size_t cPaths, const char * const *papszPaths) 70 86 { 71 return RTPathFindCommonEx( papcszPaths, cPaths, RTPATH_SLASH);87 return RTPathFindCommonEx(cPaths, papszPaths, RTPATH_STR_F_STYLE_HOST); 72 88 } 73 89 RT_EXPORT_SYMBOL(RTPathFindCommon);
Note:
See TracChangeset
for help on using the changeset viewer.