Changeset 78153 in vbox for trunk/src/VBox/Runtime/common/path
- Timestamp:
- Apr 17, 2019 12:30:08 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 130068
- Location:
- trunk/src/VBox/Runtime/common/path
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathAbsDup.cpp
r78048 r78153 32 32 #include <iprt/path.h> 33 33 34 #include <iprt/err.h>35 #include <iprt/param.h>36 #include <iprt/string.h>37 38 34 39 35 /** … … 46 42 RTDECL(char *) RTPathAbsDup(const char *pszPath) 47 43 { 48 /* Try with a static buffer first. */ 49 char szPath[RTPATH_MAX]; 50 int rc = RTPathAbs(pszPath, szPath, sizeof(szPath)); 51 if (RT_SUCCESS(rc)) 52 return RTStrDup(szPath); 53 54 /* If it looks like we ran out of buffer space, double the size until 55 we reach 64 KB. */ 56 if (rc == VERR_FILENAME_TOO_LONG || rc == VERR_BUFFER_OVERFLOW) 57 { 58 size_t cbBuf = RTPATH_MAX; 59 do 60 { 61 cbBuf *= 2; 62 char *pszBuf = RTStrAlloc(cbBuf); 63 if (!pszBuf) 64 break; 65 rc = RTPathAbs(pszPath, pszBuf, cbBuf); 66 if (RT_SUCCESS(rc)) 67 return pszBuf; 68 RTStrFree(pszBuf); 69 } while (cbBuf <= _32K); 70 } 71 return NULL; 44 return RTPathAbsExDup(NULL, pszPath, RTPATH_STR_F_STYLE_HOST); 72 45 } 73 46 -
trunk/src/VBox/Runtime/common/path/RTPathAbsEx.cpp
r78098 r78153 185 185 { 186 186 Assert(pBaseParsed->cComps > 1); 187 if (iLast >= 0 || (pParsed->fProps & RTPATH_PROP_DIR_SLASH)) 187 if ( iLast >= 0 188 || (pParsed->fProps & RTPATH_PROP_DIR_SLASH) 189 || (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH) ) 188 190 pBaseParsed->fProps |= RTPATH_PROP_DIR_SLASH; 189 191 else … … 191 193 } 192 194 195 /* Apply the trailing flash flag to the input path: */ 196 if ( iLast >= 0 197 && (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH)) 198 pParsed->fProps |= RTPATH_PROP_DIR_SLASH; 199 193 200 /* 194 201 * Combine the two. RTPathParsedReassemble can handle in place stuff, as … … 207 214 rc = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, 208 215 &pszAbsPath[cchBaseInPlace], *pcbAbsPath - cchBaseInPlace); 209 *pcbAbsPath = cchBaseInPlace + pParsed->cchPath;210 216 if (RT_SUCCESS(rc)) 217 { 218 *pcbAbsPath = cchBaseInPlace + pParsed->cchPath; 211 219 Assert(*pcbAbsPath == strlen(pszAbsPath)); 220 } 221 else 222 *pcbAbsPath = cchBaseInPlace + pParsed->cchPath + 1; 212 223 } 213 224 else … … 219 230 { 220 231 RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, 0); 221 *pcbAbsPath = pBaseParsed->cchPath + pParsed->cchPath ;232 *pcbAbsPath = pBaseParsed->cchPath + pParsed->cchPath + 1; 222 233 } 223 234 else 224 *pcbAbsPath = pBaseParsed->cchPath ;235 *pcbAbsPath = pBaseParsed->cchPath + 1; 225 236 } 226 237 … … 448 459 i++; 449 460 } 461 462 /* 463 * Before we continue, ensure trailing slash if requested. 464 */ 465 if ( (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH) 466 && iLast > 0) 467 pParsed->fProps |= RTPATH_PROP_DIR_SLASH; 450 468 451 469 /* … … 527 545 { 528 546 int rc2 = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, 0); 529 Assert(rc2 == VERR_BUFFER_OVERFLOW); RT_NOREF(rc2);547 Assert(rc2 == VERR_BUFFER_OVERFLOW); 530 548 531 549 char *pszTmp = (char *)RTMemTmpAlloc(RTPATH_BIG_MAX); 532 550 if (pszTmp) 533 551 { 534 rc = RTPathGetCurrentDrive(pszTmp, RTPATH_BIG_MAX);535 if (RT_SUCCESS(rc ))552 rc2 = RTPathGetCurrentDrive(pszTmp, RTPATH_BIG_MAX); 553 if (RT_SUCCESS(rc2)) 536 554 *pcbAbsPath = strlen(pszTmp) + pParsed->cchPath + 1; 537 555 else … … 570 588 pParsed->aComps[i].cch = 0; 571 589 } 590 591 if ( (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH) 592 && pParsed->cComps > 1) 593 pParsed->fProps |= RTPATH_PROP_DIR_SLASH; 594 572 595 int rc = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, *pcbAbsPath); 573 596 *pcbAbsPath = pParsed->cchPath + (rc == VERR_BUFFER_OVERFLOW); … … 589 612 590 613 AssertCompile(RTPATH_STR_F_STYLE_HOST == 0); 591 AssertReturn( RTPATH_STR_F_IS_VALID(fFlags, RTPATHABS_F_STOP_AT_BASE | RTPATHABS_F_STOP_AT_CWD )614 AssertReturn( RTPATH_STR_F_IS_VALID(fFlags, RTPATHABS_F_STOP_AT_BASE | RTPATHABS_F_STOP_AT_CWD | RTPATHABS_F_ENSURE_TRAILING_SLASH) 592 615 && !(fFlags & RTPATH_STR_F_MIDDLE), VERR_INVALID_FLAGS); 593 616 if ((fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_HOST) -
trunk/src/VBox/Runtime/common/path/RTPathAbsExDup.cpp
r78104 r78153 39 39 RTDECL(char *) RTPathAbsExDup(const char *pszBase, const char *pszPath, uint32_t fFlags) 40 40 { 41 char szPath[RTPATH_MAX]; 42 size_t cbPath = sizeof(szPath); 43 int rc = RTPathAbsEx(pszBase, pszPath, fFlags, szPath, &cbPath); 44 if (RT_SUCCESS(rc)) 45 return RTStrDup(szPath); 41 unsigned cTries = 16; 42 size_t cbAbsPath = RTPATH_MAX / 2; 43 for (;;) 44 { 45 char *pszAbsPath = RTStrAlloc(cbAbsPath); 46 if (pszAbsPath) 47 { 48 size_t cbActual = cbAbsPath; 49 int rc = RTPathAbsEx(pszBase, pszPath, fFlags, pszAbsPath, &cbActual); 50 if (RT_SUCCESS(rc)) 51 { 52 if (cbActual < cbAbsPath / 2) 53 RTStrRealloc(&pszAbsPath, cbActual + 1); 54 return pszAbsPath; 55 } 46 56 47 if (rc == VERR_BUFFER_OVERFLOW) 48 { 49 size_t cbPrevPath = sizeof(szPath); 50 uint32_t cTries = 8; 51 while (cTries-- > 0) 52 { 53 cbPath = RT_MAX(RT_ALIGN_Z(cbPath + 16, 64), cbPrevPath + 256); 54 cbPrevPath = cbPath; 55 char *pszAbsPath = (char *)RTStrAlloc(cbPath); 56 if (pszAbsPath) 57 { 58 rc = RTPathAbsEx(pszBase, pszPath, fFlags, pszAbsPath, &cbPath); 59 if (RT_SUCCESS(rc)) 60 return pszAbsPath; 61 RTStrFree(pszAbsPath); 62 } 63 else 57 RTStrFree(pszAbsPath); 58 59 if (rc != VERR_BUFFER_OVERFLOW) 64 60 break; 61 62 if (--cTries == 0) 63 break; 64 65 cbAbsPath = RT_MAX(RT_ALIGN_Z(cbActual + 16, 64), cbAbsPath + 256); 65 66 } 67 else 68 break; 66 69 } 67 70 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.