Changeset 78048 in vbox for trunk/src/VBox/Runtime/common/path
- Timestamp:
- Apr 9, 2019 1:21:09 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 129883
- Location:
- trunk/src/VBox/Runtime/common/path
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathAbsDup.cpp
r76553 r78048 31 31 #include "internal/iprt.h" 32 32 #include <iprt/path.h> 33 #include <iprt/errcore.h> 33 34 #include <iprt/err.h> 34 35 #include <iprt/param.h> 35 36 #include <iprt/string.h> … … 45 46 RTDECL(char *) RTPathAbsDup(const char *pszPath) 46 47 { 48 /* Try with a static buffer first. */ 47 49 char szPath[RTPATH_MAX]; 48 50 int rc = RTPathAbs(pszPath, szPath, sizeof(szPath)); 49 51 if (RT_SUCCESS(rc)) 50 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 } 51 71 return NULL; 52 72 } -
trunk/src/VBox/Runtime/common/path/RTPathAbsEx.cpp
r76553 r78048 49 49 * @param pszPath The path to resolve. 50 50 * @param pszAbsPath Where to store the absolute path. 51 * @param c chAbsPathSize of the buffer.51 * @param cbAbsPath Size of the buffer. 52 52 */ 53 RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t c chAbsPath)53 RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cbAbsPath) 54 54 { 55 #if 1 55 56 if ( pszBase 56 57 && pszPath … … 58 59 ) 59 60 { 60 # if defined(RT_OS_WINDOWS)61 # if defined(RT_OS_WINDOWS) 61 62 /* The format for very long paths is not supported. */ 62 63 if ( RTPATH_IS_SLASH(pszBase[0]) … … 66 67 ) 67 68 return VERR_INVALID_NAME; 68 # endif69 # endif 69 70 70 71 /** @todo there are a couple of things which isn't 100% correct, although the … … 96 97 memcpy(&szTmpPath[cchBase + 1], pszPath, cchPath + 1); 97 98 } 98 return RTPathAbs(szTmpPath, pszAbsPath, c chAbsPath);99 return RTPathAbs(szTmpPath, pszAbsPath, cbAbsPath); 99 100 } 100 101 101 102 /* Fallback to the non *Ex version */ 102 return RTPathAbs(pszPath, pszAbsPath, cchAbsPath); 103 return RTPathAbs(pszPath, pszAbsPath, cbAbsPath); 104 #else 105 return RTPathAbsExEx(pszBase, pszPath, RTPATH_STR_F_STYLE_HOST, pszAbsPath, &cbAbsPath); 106 #endif 103 107 } 104 108 -
trunk/src/VBox/Runtime/common/path/RTPathParse.cpp.h
r76553 r78048 59 59 } 60 60 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 61 else if ( RTPATH_IS_SLASH(pszPath[1]) 62 && !RTPATH_IS_SLASH(pszPath[2]) 63 && pszPath[2]) 64 { 65 /* UNC - skip to the end of the potential namespace or computer name. */ 61 else if (RTPATH_IS_SLASH(pszPath[1])) 62 { 63 /* UNC - there are exactly two prefix slashes followed by a namespace 64 or computer name, which can be empty on windows. */ 66 65 offCur = 2; 67 66 while (!RTPATH_IS_SLASH(pszPath[offCur]) && pszPath[offCur]) 68 67 offCur++; 69 68 70 /* If there is another slash, we considered it a valid UNC path, if 71 not it's just a root path with an extra slash thrown in. */ 69 /* Special fun for windows. */ 70 fProps = RTPATH_PROP_UNC | RTPATH_PROP_ABSOLUTE; 71 if ( offCur == 3 72 && (pszPath[2] == '.' || pszPath[2] == '?')) 73 fProps |= RTPATH_PROP_SPECIAL_UNC; 74 72 75 if (RTPATH_IS_SLASH(pszPath[offCur])) 73 76 { 74 fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_UNC | RTPATH_PROP_ABSOLUTE; 75 offCur++; 76 cchPath = offCur; 77 } 78 else 79 { 80 fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_RELATIVE; 81 offCur = 1; 82 cchPath = 1; 83 } 77 fProps |= RTPATH_PROP_ROOT_SLASH; 78 offCur++; 79 } 80 cchPath = offCur; 84 81 } 85 82 #endif -
trunk/src/VBox/Runtime/common/path/RTPathParsedReassemble.cpp
r76553 r78048 48 48 AssertReturn(RTPATH_STR_F_IS_VALID(fFlags, 0) && !(fFlags & RTPATH_STR_F_MIDDLE), VERR_INVALID_FLAGS); 49 49 AssertPtrReturn(pszDstPath, VERR_INVALID_POINTER); 50 AssertReturn(cbDstPath > pParsed->cchPath, VERR_BUFFER_OVERFLOW); 50 51 /* 52 * Recalculate the length. 53 */ 54 uint32_t const cComps = pParsed->cComps; 55 uint32_t idxComp = 0; 56 uint32_t cchPath = 0; 57 if (RTPATH_PROP_HAS_ROOT_SPEC(pParsed->fProps)) 58 { 59 cchPath = pParsed->aComps[0].cch; 60 idxComp++; 61 } 62 bool fNeedSlash = false; 63 while (idxComp < cComps) 64 { 65 uint32_t const cchComp = pParsed->aComps[idxComp].cch; 66 idxComp++; 67 if (cchComp > 0) 68 { 69 cchPath += cchComp + fNeedSlash; 70 fNeedSlash = true; 71 } 72 } 73 if ((pParsed->fProps & RTPATH_PROP_DIR_SLASH) && fNeedSlash) 74 cchPath += 1; 75 pParsed->cchPath = cchPath; 76 if (cbDstPath > cchPath) 77 { /* likely */ } 78 else 79 { 80 if (cbDstPath) 81 *pszDstPath = '\0'; 82 return VERR_BUFFER_OVERFLOW; 83 } 51 84 52 85 /* … … 74 107 /* 75 108 * Do the joining. 109 * Note! Using memmove here as we want to support pszSrcPath == pszDstPath. 76 110 */ 77 uint32_t const cchOrgPath = pParsed->cchPath; 78 uint32_t cchDstPath = 0; 79 uint32_t const cComps = pParsed->cComps; 80 uint32_t idxComp = 0; 81 char *pszDst = pszDstPath; 82 uint32_t cchComp; 111 char *pszDst = pszDstPath; 112 idxComp = 0; 113 fNeedSlash = false; 83 114 84 115 if (RTPATH_PROP_HAS_ROOT_SPEC(pParsed->fProps)) 85 116 { 86 cchComp = pParsed->aComps[0].cch; 87 cchDstPath += cchComp; 88 AssertReturn(cchDstPath <= cchOrgPath, VERR_INVALID_PARAMETER); 89 memcpy(pszDst, &pszSrcPath[pParsed->aComps[0].off], cchComp); 117 uint32_t cchComp = pParsed->aComps[0].cch; 118 memmove(pszDst, &pszSrcPath[pParsed->aComps[0].off], cchComp); 90 119 91 /* fix the slashes */120 /* fix the slashes (harmless for unix style) */ 92 121 char chOtherSlash = chSlash == '\\' ? '/' : '\\'; 93 122 while (cchComp-- > 0) … … 102 131 while (idxComp < cComps) 103 132 { 104 cchComp = pParsed->aComps[idxComp].cch; 105 cchDstPath += cchComp; 106 AssertReturn(cchDstPath <= cchOrgPath, VERR_INVALID_PARAMETER); 107 memcpy(pszDst, &pszSrcPath[pParsed->aComps[idxComp].off], cchComp); 108 pszDst += cchComp; 133 uint32_t const cchComp = pParsed->aComps[idxComp].cch; 134 if (cchComp > 0) 135 { 136 if (fNeedSlash) 137 *pszDst++ = chSlash; 138 fNeedSlash = true; 139 memmove(pszDst, &pszSrcPath[pParsed->aComps[idxComp].off], cchComp); 140 pszDst += cchComp; 141 } 109 142 idxComp++; 110 if (idxComp != cComps || (pParsed->fProps & RTPATH_PROP_DIR_SLASH))111 {112 cchDstPath++;113 AssertReturn(cchDstPath <= cchOrgPath, VERR_INVALID_PARAMETER);114 *pszDst++ = chSlash;115 }116 143 } 117 144 145 if ((pParsed->fProps & RTPATH_PROP_DIR_SLASH) && fNeedSlash) 146 *pszDst++ = chSlash; 118 147 *pszDst = '\0'; 119 148
Note:
See TracChangeset
for help on using the changeset viewer.