Changeset 81203 in vbox for trunk/src/VBox/Runtime/common/path
- Timestamp:
- Oct 10, 2019 10:23:32 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 133859
- Location:
- trunk/src/VBox/Runtime/common/path
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathParse.cpp.h
r78048 r81203 205 205 fProps |= RTPATH_PROP_FILENAME; 206 206 207 /* look for an ?*/207 /* Look for a suffix: */ 208 208 uint32_t offSuffix = offStart + cchComp; 209 while ( offSuffix--> offStart)209 while (--offSuffix > offStart) 210 210 if (pszPath[offSuffix] == '.') 211 211 { 212 212 uint32_t cchSuffix = offStart + cchComp - offSuffix; 213 if (cchSuffix > 1 && offStart != offSuffix)213 if (cchSuffix > 1) 214 214 { 215 215 pParsed->cchSuffix = cchSuffix; -
trunk/src/VBox/Runtime/common/path/RTPathParseSimple.cpp
r76553 r81203 32 32 #include <iprt/path.h> 33 33 34 #include <iprt/assert.h> 35 #include <iprt/ctype.h> 36 34 37 35 38 /** … … 53 56 RTDECL(size_t) RTPathParseSimple(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff) 54 57 { 55 const char *psz = pszPath; 56 ssize_t offRoot = 0; 57 const char *pszName = pszPath; 58 /* 59 * First deal with the root as it is always more fun that you'd think. 60 */ 61 const char *psz = pszPath; 62 size_t cchRoot = 0; 63 64 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 65 if (RT_C_IS_ALPHA(*psz) && RTPATH_IS_VOLSEP(psz[1])) 66 { 67 /* Volume specifier. */ 68 cchRoot = 2; 69 psz += 2; 70 } 71 else if (RTPATH_IS_SLASH(*psz) && RTPATH_IS_SLASH(psz[1])) 72 { 73 /* UNC - there are exactly two prefix slashes followed by a namespace 74 or computer name, which can be empty on windows. */ 75 cchRoot = 2; 76 psz += 2; 77 while (!RTPATH_IS_SLASH(*psz) && *psz) 78 { 79 cchRoot++; 80 psz++; 81 } 82 } 83 #endif 84 while (RTPATH_IS_SLASH(*psz)) 85 { 86 cchRoot++; 87 psz++; 88 } 89 90 /* 91 * Do the remainder. 92 */ 93 const char *pszName = psz; 58 94 const char *pszLastDot = NULL; 59 60 95 for (;; psz++) 61 96 { 62 97 switch (*psz) 63 98 { 99 default: 100 break; 101 64 102 /* handle separators. */ 65 103 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 66 case ':':67 pszName = psz + 1;68 offRoot = pszName - psz;69 break;70 71 104 case '\\': 72 105 #endif 73 106 case '/': 74 107 pszName = psz + 1; 108 pszLastDot = NULL; 75 109 break; 76 110 … … 91 125 { 92 126 ssize_t offSuff = -1; 93 if (pszLastDot) 127 if ( pszLastDot 128 && pszLastDot != pszName 129 && pszLastDot[1] != '\0') 94 130 { 95 131 offSuff = pszLastDot - pszPath; 96 if (offSuff <= offName) 97 offSuff = -1; 132 Assert(offSuff > offName); 98 133 } 99 134 *poffSuff = offSuff; … … 102 137 if (pcchDir) 103 138 { 104 s size_t off =offName - 1;105 while ( off >= offRoot && RTPATH_IS_SLASH(pszPath[off]))106 off--;107 *pcchDir = RT_MAX(off, offRoot) + 1;139 size_t cch = offName < 0 ? psz - pszPath : offName - 1 < (ssize_t)cchRoot ? cchRoot : offName - 1; 140 while (cch > cchRoot && RTPATH_IS_SLASH(pszPath[cch - 1])) 141 cch--; 142 *pcchDir = cch; 108 143 } 109 144
Note:
See TracChangeset
for help on using the changeset viewer.