Changeset 96609 in vbox for trunk/src/VBox/Runtime/common/path
- Timestamp:
- Sep 6, 2022 2:13:23 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 153486
- Location:
- trunk/src/VBox/Runtime/common/path
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/path/RTPathAppend.cpp
r96407 r96609 47 47 RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend) 48 48 { 49 return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX );49 return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX, RTPATH_STR_F_STYLE_HOST); 50 50 } 51 51 -
trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp
r96407 r96609 46 46 #include <iprt/errcore.h> 47 47 #include <iprt/string.h> 48 49 #define RTPATH_TEMPLATE_CPP_H "RTPathAppendEx.cpp.h" 50 #include "rtpath-expand-template.cpp.h" 48 51 49 52 … … 115 118 116 119 117 RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax )120 RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax, uint32_t fFlags) 118 121 { 119 122 char *pszPathEnd = RTStrEnd(pszPath, cbPathDst); 120 123 AssertReturn(pszPathEnd, VERR_INVALID_PARAMETER); 124 Assert(RTPATH_STR_F_IS_VALID(fFlags, 0)); 121 125 122 126 /* … … 138 142 139 143 /* 140 * Balance slashes and check for buffer overflow.144 * Go to path style specific code now. 141 145 */ 142 if (!RTPATH_IS_SLASH(pszPathEnd[-1]))146 switch (fFlags & RTPATH_STR_F_STYLE_MASK) 143 147 { 144 if (!RTPATH_IS_SLASH(pszAppend[0])) 145 { 146 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 147 if ( (size_t)(pszPathEnd - pszPath) == 2 148 && pszPath[1] == ':' 149 && RT_C_IS_ALPHA(pszPath[0])) 150 { 151 if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst) 152 return VERR_BUFFER_OVERFLOW; 153 } 154 else 148 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 149 case RTPATH_STR_F_STYLE_HOST: 155 150 #endif 156 { 157 if ((size_t)(pszPathEnd - pszPath) + 1 + cchAppend >= cbPathDst) 158 return VERR_BUFFER_OVERFLOW; 159 *pszPathEnd++ = RTPATH_SLASH; 160 } 161 } 162 else 163 { 164 /* One slash is sufficient at this point. */ 165 while (cchAppend > 1 && RTPATH_IS_SLASH(pszAppend[1])) 166 pszAppend++, cchAppend--; 151 case RTPATH_STR_F_STYLE_DOS: 152 return rtPathAppendExStyleDos(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend); 167 153 168 if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst) 169 return VERR_BUFFER_OVERFLOW; 170 } 154 #if RTPATH_STYLE != RTPATH_STR_F_STYLE_DOS 155 case RTPATH_STR_F_STYLE_HOST: 156 #endif 157 case RTPATH_STR_F_STYLE_UNIX: 158 return rtPathAppendExStyleUnix(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend); 159 160 default: 161 AssertFailedReturn(VERR_INVALID_FLAGS); /* impossible */ 171 162 } 172 else173 {174 /* No slashes needed in the appended bit. */175 while (cchAppend && RTPATH_IS_SLASH(*pszAppend))176 pszAppend++, cchAppend--;177 178 /* In the leading path we can skip unnecessary trailing slashes, but179 be sure to leave one. */180 size_t const cchRoot = rtPathRootSpecLen2(pszPath);181 while ( (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot)182 && RTPATH_IS_SLASH(pszPathEnd[-2]))183 pszPathEnd--;184 185 if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)186 return VERR_BUFFER_OVERFLOW;187 }188 189 /*190 * What remains now is the just the copying.191 */192 memcpy(pszPathEnd, pszAppend, cchAppend);193 pszPathEnd[cchAppend] = '\0';194 return VINF_SUCCESS;195 163 } 196 164 -
trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/VBox-3.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 58652,70973 /branches/VBox-3.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 66309,66318 /branches/VBox-4.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 70873 /branches/VBox-4.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 74233,78414,78691,81841,82127,85941,85944-85947,85949-85950,85953,86701,86728,87009 /branches/VBox-4.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 86229-86230,86234,86529,91503-91504,91506-91508,91510,91514-91515,91521,108112,108114,108127 /branches/VBox-4.3/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 89714,91223,93628-93629,94066,94839,94897,95154,95164,95167,95295,95338,95353-95354,95356,95367,95451,95475,95477,95480,95507,95640,95659,95661,95663,98913-98914 /branches/VBox-4.3/trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 91223 /branches/VBox-5.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 104938,104943,104950,104987-104988,104990,106453 /branches/VBox-5.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 112367,116543,116550,116568,116573 /branches/VBox-5.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 119536,120083,120099,120213,120221,120239,123597-123598,123600-123601,123755,124263,124273,124277-124279,124284-124286,124288-124290,125768,125779-125780,125812,127158-127159,127162-127167,127180 /branches/VBox-6.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 130474-130475,130477,130479,131352 /branches/VBox-6.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 141521,141567-141568,141588-141590,141592-141595,141652,141920 /branches/aeichner/vbox-chromium-cleanup/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 129818-129851,129853-129861,129871-129872,129876,129880,129882,130013-130015,130094-130095 /branches/andy/draganddrop/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 90781-91268 /branches/andy/guestctrl20/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 78916,78930 /branches/andy/pdmaudio/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 94582,94641,94654,94688,94778,94783,94816,95197,95215-95216,95250,95279,95505-95506,95543,95694,96323,96470-96471,96582,96587,96802-96803,96817,96904,96967,96999,97020-97021,97025,97050,97099 /branches/bird/hardenedwindows/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 92692-94610 /branches/dsen/gui/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 79076-79078,79089,79109-79110,79112-79113,79127-79130,79134,79141,79151,79155,79157-79159,79193,79197 /branches/dsen/gui2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 79224,79228,79233,79235,79258,79262-79263,79273,79341,79345,79354,79357,79387-79388,79559-79569,79572-79573,79578,79581-79582,79590-79591,79598-79599,79602-79603,79605-79606,79632,79635,79637,79644 /branches/dsen/gui3/src/VBox/Runtime/common/path/RTPathAppendEx.cpp 79645-79692
r96608 r96609 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTPathAppendEx3 * IPRT - rtPathAppendEx - Code Template. 4 4 */ 5 5 … … 36 36 37 37 38 /*********************************************************************************************************************************39 * Header Files *40 *********************************************************************************************************************************/41 #include "internal/iprt.h"42 #include <iprt/path.h>43 44 #include <iprt/assert.h>45 #include <iprt/ctype.h>46 #include <iprt/errcore.h>47 #include <iprt/string.h>48 49 50 38 /** 51 39 * Figures the length of the root part of the path. … … 60 48 * counts them.) 61 49 */ 62 static size_t rtPathRootSpecLen2(const char *pszPath)50 DECLINLINE(size_t) RTPATH_STYLE_FN(rtPathRootSpecLen2)(const char *pszPath) 63 51 { 64 52 /* fend of wildlife. */ … … 69 57 if (RTPATH_IS_SLASH(pszPath[0])) 70 58 { 71 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)59 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 72 60 /* UNC? */ 73 61 if ( RTPATH_IS_SLASH(pszPath[1]) … … 100 88 } 101 89 102 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)90 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 103 91 /* Drive specifier? */ 104 92 if ( pszPath[0] != '\0' … … 115 103 116 104 117 RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax) 105 /** Internal worker for RTPathAppendEx. */ 106 DECLINLINE(int) RTPATH_STYLE_FN(rtPathAppendEx)(char *pszPath, size_t cbPathDst, char *pszPathEnd, 107 const char *pszAppend, size_t cchAppend) 118 108 { 119 char *pszPathEnd = RTStrEnd(pszPath, cbPathDst);120 AssertReturn(pszPathEnd, VERR_INVALID_PARAMETER);121 122 /*123 * Special cases.124 */125 if (!pszAppend)126 return VINF_SUCCESS;127 size_t cchAppend = RTStrNLen(pszAppend, cchAppendMax);128 if (!cchAppend)129 return VINF_SUCCESS;130 if (pszPathEnd == pszPath)131 {132 if (cchAppend >= cbPathDst)133 return VERR_BUFFER_OVERFLOW;134 memcpy(pszPath, pszAppend, cchAppend);135 pszPath[cchAppend] = '\0';136 return VINF_SUCCESS;137 }138 139 109 /* 140 110 * Balance slashes and check for buffer overflow. … … 144 114 if (!RTPATH_IS_SLASH(pszAppend[0])) 145 115 { 146 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)116 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 147 117 if ( (size_t)(pszPathEnd - pszPath) == 2 148 118 && pszPath[1] == ':' … … 178 148 /* In the leading path we can skip unnecessary trailing slashes, but 179 149 be sure to leave one. */ 180 size_t const cchRoot = rtPathRootSpecLen2(pszPath);150 size_t const cchRoot = RTPATH_STYLE_FN(rtPathRootSpecLen2)(pszPath); 181 151 while ( (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot) 182 152 && RTPATH_IS_SLASH(pszPathEnd[-2])) -
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/VBox/Runtime/common/path/RTPathJoinEx.cpp
r96407 r96609 50 50 RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst, 51 51 const char *pszPathSrc, size_t cchPathSrcMax, 52 const char *pszAppend, size_t cchAppendMax )52 const char *pszAppend, size_t cchAppendMax, uint32_t fFlags) 53 53 { 54 54 AssertPtr(pszPathDst); 55 55 AssertPtr(pszPathSrc); 56 56 AssertPtr(pszAppend); 57 Assert(RTPATH_STR_F_IS_VALID(fFlags, 0)); 57 58 58 59 /* … … 65 66 pszPathDst[cchPathSrc] = '\0'; 66 67 67 return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax );68 return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax, fFlags); 68 69 } 69 70
Note:
See TracChangeset
for help on using the changeset viewer.