Changeset 24221 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Oct 30, 2009 10:20:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathAbsEx.cpp
r21675 r24221 57 57 RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath) 58 58 { 59 if (pszBase && pszPath && !rtPathVolumeSpecLen(pszPath)) 59 if ( pszBase 60 && pszPath 61 && !rtPathVolumeSpecLen(pszPath) 62 ) 60 63 { 61 64 #if defined(RT_OS_WINDOWS) 62 65 /* The format for very long paths is not supported. */ 63 if ( (pszBase[0] == '/' || pszBase[0] == '\\') 64 && (pszBase[1] == '/' || pszBase[1] == '\\') 65 && pszBase[2] == '?' 66 && (pszBase[3] == '/' || pszBase[3] == '\\')) 66 if ( RTPATH_IS_SLASH(pszBase[0]) 67 && RTPATH_IS_SLASH(pszBase[1]) 68 && pszBase[2] == '?' 69 && RTPATH_IS_SLASH(pszBase[3]) 70 ) 67 71 return VERR_INVALID_NAME; 68 72 #endif 69 73 70 74 /** @todo there are a couple of things which isn't 100% correct, although the 71 * current code will have to work for now - I don't have time to fix it right now.75 * current code will have to do for now, no time to fix. 72 76 * 73 77 * 1) On Windows & OS/2 we confuse '/' with an abspath spec and will 74 78 * not necessarily resolve it on the right drive. 75 79 * 2) A trailing slash in the base might cause UNC names to be created. 76 * 3) The lengths total doesn't have to be less than max length77 * if the pszPath starts with a slash.78 80 */ 79 size_t cchBase = strlen(pszBase); 80 size_t cchPath = strlen(pszPath); 81 if (cchBase + cchPath >= RTPATH_MAX) 82 return VERR_FILENAME_TOO_LONG; 83 84 bool fRootSpec = pszPath[0] == '/' 85 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 86 || pszPath[0] == '\\' 87 #endif 88 ; 89 size_t cchVolSpec = rtPathVolumeSpecLen(pszBase); 90 char szPath[RTPATH_MAX]; 91 if (fRootSpec) 81 size_t const cchPath = strlen(pszPath); 82 char szTmpPath[RTPATH_MAX]; 83 if (RTPATH_IS_SLASH(pszPath[0])) 92 84 { 93 /* join the disk name from base and the path */ 94 memcpy(szPath, pszBase, cchVolSpec); 95 strcpy(&szPath[cchVolSpec], pszPath); 85 /* join the disk name from base and the path (DOS systems only) */ 86 size_t const cchVolSpec = rtPathVolumeSpecLen(pszBase); 87 if (cchVolSpec + cchPath + 1 > sizeof(szTmpPath)) 88 return VERR_FILENAME_TOO_LONG; 89 memcpy(szTmpPath, pszBase, cchVolSpec); 90 memcpy(&szTmpPath[cchVolSpec], pszPath, cchPath + 1); 96 91 } 97 92 else 98 93 { 99 94 /* join the base path and the path */ 100 strcpy(szPath, pszBase); 101 szPath[cchBase] = RTPATH_DELIMITER; 102 strcpy(&szPath[cchBase + 1], pszPath); 95 size_t const cchBase = strlen(pszBase); 96 if (cchBase + 1 + cchPath + 1 > sizeof(szTmpPath)) 97 return VERR_FILENAME_TOO_LONG; 98 memcpy(szTmpPath, pszBase, cchBase); 99 szTmpPath[cchBase] = RTPATH_DELIMITER; 100 memcpy(&szTmpPath[cchBase + 1], pszPath, cchPath + 1); 103 101 } 104 return RTPathAbs(sz Path, pszAbsPath, cchAbsPath);102 return RTPathAbs(szTmpPath, pszAbsPath, cchAbsPath); 105 103 } 106 104
Note:
See TracChangeset
for help on using the changeset viewer.