Changeset 60481 in vbox
- Timestamp:
- Apr 13, 2016 8:14:41 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
-
include/iprt/mangling.h (modified) (3 diffs)
-
include/iprt/utf16.h (modified) (3 diffs)
-
src/VBox/Runtime/common/string/utf-16-case.cpp (modified) (1 diff)
-
src/VBox/Runtime/common/string/utf-16.cpp (modified) (2 diffs)
-
src/VBox/Runtime/nt/RTNtPathExpand8dot3Path.cpp (modified) (1 diff)
-
src/VBox/Runtime/nt/RTNtPathFindPossible8dot3Name.cpp (added)
-
src/VBox/Runtime/r3/nt/pathint-nt.cpp (modified) (4 diffs)
-
src/VBox/Runtime/testcase/Makefile.kmk (modified) (2 diffs)
-
src/VBox/Runtime/testcase/tstRTNtPath-1.cpp (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r60390 r60481 2194 2194 # define RTUriIsSchemeMatch RT_MANGLER(RTUriIsSchemeMatch) 2195 2195 # define RTUtf16AllocTag RT_MANGLER(RTUtf16AllocTag) 2196 # define RTUtf16ReallocTag RT_MANGLER(RTUtf16ReallocTag) 2196 2197 # define RTUtf16CalcLatin1Len RT_MANGLER(RTUtf16CalcLatin1Len) 2197 2198 # define RTUtf16CalcLatin1LenEx RT_MANGLER(RTUtf16CalcLatin1LenEx) … … 2200 2201 # define RTUtf16Cmp RT_MANGLER(RTUtf16Cmp) 2201 2202 # define RTUtf16CmpAscii RT_MANGLER(RTUtf16CmpAscii) 2203 # define RTUtf16CmpUtf8 RT_MANGLER(RTUtf16CmpUtf8) 2202 2204 # define RTUtf16DupExTag RT_MANGLER(RTUtf16DupExTag) 2203 2205 # define RTUtf16DupTag RT_MANGLER(RTUtf16DupTag) … … 2206 2208 # define RTUtf16GetCpInternal RT_MANGLER(RTUtf16GetCpInternal) 2207 2209 # define RTUtf16ICmp RT_MANGLER(RTUtf16ICmp) 2210 # define RTUtf16ICmpUtf8 RT_MANGLER(RTUtf16ICmpUtf8) 2208 2211 # define RTUtf16IsValidEncoding RT_MANGLER(RTUtf16IsValidEncoding) 2209 2212 # define RTUtf16Len RT_MANGLER(RTUtf16Len) -
trunk/include/iprt/utf16.h
r57941 r60481 82 82 RTDECL(PRTUTF16) RTUtf16AllocTag(size_t cb, const char *pszTag); 83 83 84 /** 85 * Reallocates the specified UTF-16 string (default tag). 86 * 87 * You should normally not use this function, except if there is some very 88 * custom string handling you need doing that isn't covered by any of the other 89 * APIs. 90 * 91 * @returns VINF_SUCCESS. 92 * @retval VERR_NO_UTF16_MEMORY if we failed to reallocate the string, @a 93 * *ppwsz remains unchanged. 94 * 95 * @param ppwsz Pointer to the string variable containing the 96 * input and output string. 97 * 98 * When not freeing the string, the result will 99 * always have the last RTUTF16 set to the 100 * terminator character so that when used for 101 * string truncation the result will be a valid 102 * C-style string (your job to keep it a valid 103 * UTF-16 string). 104 * 105 * When the input string is NULL and we're supposed 106 * to reallocate, the returned string will also 107 * have the first RTUTF16 set to the terminator 108 * char so it will be a valid C-style string. 109 * 110 * @param cbNew When @a cbNew is zero, we'll behave like 111 * RTUtf16Free and @a *ppwsz will be set to NULL. 112 * 113 * When not zero, this will be rounded up to a 114 * multiple of two, and used as the new size of the 115 * memory backing the string, i.e. it includes the 116 * terminator (RTUTF16) char. 117 */ 118 #define RTUtf16Realloc(ppwsz, cb) RTUtf16ReallocTag((ppwsz), (cb), RTSTR_TAG) 119 120 /** 121 * Reallocates the specified UTF-16 string (custom tag). 122 * 123 * You should normally not use this function, except if there is some very 124 * custom string handling you need doing that isn't covered by any of the other 125 * APIs. 126 * 127 * @returns VINF_SUCCESS. 128 * @retval VERR_NO_UTF16_MEMORY if we failed to reallocate the string, @a 129 * *ppwsz remains unchanged. 130 * 131 * @param ppwsz Pointer to the string variable containing the 132 * input and output string. 133 * 134 * When not freeing the string, the result will 135 * always have the last RTUTF16 set to the 136 * terminator character so that when used for 137 * string truncation the result will be a valid 138 * C-style string (your job to keep it a valid 139 * UTF-16 string). 140 * 141 * When the input string is NULL and we're supposed 142 * to reallocate, the returned string will also 143 * have the first RTUTF16 set to the terminator 144 * char so it will be a valid C-style string. 145 * 146 * @param cbNew When @a cbNew is zero, we'll behave like 147 * RTUtf16Free and @a *ppwsz will be set to NULL. 148 * 149 * When not zero, this will be rounded up to a 150 * multiple of two, and used as the new size of the 151 * memory backing the string, i.e. it includes the 152 * terminator (RTUTF16) char. 153 * @param pszTag Allocation tag used for statistics and such. 154 */ 155 RTDECL(int) RTUtf16ReallocTag(PRTUTF16 *ppwsz, size_t cbNew, const char *pszTag); 84 156 85 157 /** … … 333 405 334 406 /** 407 * Performs a case sensitive string compare between an UTF-16 string and a UTF-8 408 * string. 409 * 410 * @returns < 0 if the first string less than the second string.s 411 * @returns 0 if the first string identical to the second string. 412 * @returns > 0 if the first string greater than the second string. 413 * @param pwsz1 First UTF-16 string. Null is allowed. 414 * @param psz2 Second string, UTF-8. Null is allowed. 415 * @remarks NULL and empty strings are treated equally. 416 */ 417 RTDECL(int) RTUtf16CmpUtf8(PCRTUTF16 pwsz1, const char *psz2); 418 419 /** 335 420 * Performs a case insensitive string compare between two UTF-16 strings. 336 421 * … … 346 431 */ 347 432 RTDECL(int) RTUtf16ICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2); 433 434 /** 435 * Performs a case insensitive string compare between an UTF-16 string and a 436 * UTF-8 string. 437 * 438 * @returns < 0 if the first string less than the second string.s 439 * @returns 0 if the first string identical to the second string. 440 * @returns > 0 if the first string greater than the second string. 441 * @param pwsz1 First UTF-16 string. Null is allowed. 442 * @param psz2 Second string, UTF-8. Null is allowed. 443 * @remarks NULL and empty strings are treated equally. 444 */ 445 RTDECL(int) RTUtf16ICmpUtf8(PCRTUTF16 pwsz1, const char *psz2); 348 446 349 447 /** -
trunk/src/VBox/Runtime/common/string/utf-16-case.cpp
r57358 r60481 106 106 107 107 108 RTDECL(int) RTUtf16ICmpUtf8(PCRTUTF16 pwsz1, const char *psz2) 109 { 110 /* 111 * NULL and empty strings are all the same. 112 */ 113 if (!pwsz1) 114 return !psz2 || !*psz2 ? 0 : -1; 115 if (!psz2) 116 return !*pwsz1 ? 0 : 1; 117 118 /* 119 * Compare with a UTF-8 string by enumerating them char by char. 120 */ 121 for (;;) 122 { 123 RTUNICP uc1; 124 int rc = RTUtf16GetCpEx(&pwsz1, &uc1); 125 AssertRCReturn(rc, 1); 126 127 RTUNICP uc2; 128 rc = RTStrGetCpEx(&psz2, &uc2); 129 AssertRCReturn(rc, -1); 130 if (uc1 == uc2) 131 { 132 if (uc1) 133 continue; 134 return 0; 135 } 136 137 if (RTUniCpToUpper(uc1) == RTUniCpToUpper(uc2)) 138 continue; 139 if (RTUniCpToLower(uc1) == RTUniCpToLower(uc2)) 140 continue; 141 return uc1 < uc2 ? -1 : 1; 142 } 143 } 144 RT_EXPORT_SYMBOL(RTUtf16CmpIUtf8); 145 146 108 147 RTDECL(PRTUTF16) RTUtf16ToLower(PRTUTF16 pwsz) 109 148 { -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r57358 r60481 114 114 115 115 116 RTDECL(int) RTUtf16ReallocTag(PRTUTF16 *ppwsz, size_t cbNew, const char *pszTag) 117 { 118 PRTUTF16 pwszOld = *ppwsz; 119 cbNew = RT_ALIGN_Z(cbNew, sizeof(RTUTF16)); 120 if (!cbNew) 121 { 122 RTMemFree(pwszOld); 123 *ppwsz = NULL; 124 } 125 else if (pwszOld) 126 { 127 PRTUTF16 pwszNew = (PRTUTF16)RTMemReallocTag(pwszOld, cbNew, pszTag); 128 if (!pwszNew) 129 return VERR_NO_STR_MEMORY; 130 pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0'; 131 *ppwsz = pwszNew; 132 } 133 else 134 { 135 PRTUTF16 pwszNew = (PRTUTF16)RTMemAllocTag(cbNew, pszTag); 136 if (!pwszNew) 137 return VERR_NO_UTF16_MEMORY; 138 pwszNew[0] = '\0'; 139 pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0'; 140 *ppwsz = pwszNew; 141 } 142 return VINF_SUCCESS; 143 } 144 RT_EXPORT_SYMBOL(RTUtf16ReallocTag); 145 146 116 147 RTDECL(void) RTUtf16Free(PRTUTF16 pwszString) 117 148 { … … 183 214 } 184 215 RT_EXPORT_SYMBOL(RTUtf16Cmp); 216 217 218 RTDECL(int) RTUtf16CmpUtf8(PCRTUTF16 pwsz1, const char *psz2) 219 { 220 /* 221 * NULL and empty strings are all the same. 222 */ 223 if (!pwsz1) 224 return !psz2 || !*psz2 ? 0 : -1; 225 if (!psz2) 226 return !*pwsz1 ? 0 : 1; 227 228 /* 229 * Compare with a UTF-8 string by enumerating them char by char. 230 */ 231 for (;;) 232 { 233 RTUNICP uc1; 234 int rc = RTUtf16GetCpEx(&pwsz1, &uc1); 235 AssertRCReturn(rc, 1); 236 237 RTUNICP uc2; 238 rc = RTStrGetCpEx(&psz2, &uc2); 239 AssertRCReturn(rc, -1); 240 if (uc1 == uc2) 241 { 242 if (uc1) 243 continue; 244 return 0; 245 } 246 return uc1 < uc2 ? -1 : 1; 247 } 248 } 249 RT_EXPORT_SYMBOL(RTUtf16CmpUtf8); 185 250 186 251 -
trunk/src/VBox/Runtime/nt/RTNtPathExpand8dot3Path.cpp
r60480 r60481 158 158 pUniStr->Length += (USHORT)(cwcNameNew * sizeof(WCHAR)); 159 159 pwszFixEnd -= cwcNameOld; 160 pwszFixEnd -= cwcNameNew;160 pwszFixEnd += cwcNameNew; 161 161 memcpy(pwszFix, &puBuf->Info.FileName[offName], cwcNameNew * sizeof(WCHAR)); 162 162 } -
trunk/src/VBox/Runtime/r3/nt/pathint-nt.cpp
r58440 r60481 162 162 163 163 /** 164 * Converts a path to NT format and encoding. 165 * 166 * @returns IPRT status code. 167 * @param pNtName Where to return the NT name. 164 * Converts a windows-style path to NT format and encoding. 165 * 166 * @returns IPRT status code. 167 * @param pNtName Where to return the NT name. Free using 168 * rtTNtPathToNative. 168 169 * @param phRootDir Where to return the root handle, if applicable. 169 170 * @param pszPath The UTF-8 path. … … 225 226 memcpy(szPath, pszPrefix, cchPrefix); 226 227 return rtNtPathUtf8ToUniStr(pNtName, phRootDir, szPath); 228 } 229 230 231 /** 232 * Converts a windows-style path to NT format and encoding. 233 * 234 * @returns IPRT status code. 235 * @param pNtName Where to return the NT name. Free using 236 * RTNtPathToNative. 237 * @param phRootDir Where to return the root handle, if applicable. 238 * @param pszPath The UTF-8 path. 239 */ 240 RTDECL(int) RTNtPathFromWinUtf8(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath) 241 { 242 return rtNtPathToNative(pNtName, phRootDir, pszPath); 227 243 } 228 244 … … 341 357 342 358 /** 359 * Ensures that the NT string has sufficient storage to hold @a cwcMin RTUTF16 360 * chars plus a terminator. 361 * 362 * The NT string must have been returned by RTNtPathFromWinUtf8 or 363 * RTNtPathFromWinUtf16Ex. 364 * 365 * @returns IPRT status code. 366 * @param pNtName The NT path string. 367 * @param cwcMin The minimum number of RTUTF16 chars. Max 32767. 368 * @sa RTNtPathFree 369 */ 370 RTDECL(int) RTNtPathEnsureSpace(struct _UNICODE_STRING *pNtName, size_t cwcMin) 371 { 372 if (pNtName->MaximumLength / sizeof(RTUTF16) > cwcMin) 373 return VINF_SUCCESS; 374 375 AssertReturn(cwcMin < _64K / sizeof(RTUTF16), VERR_OUT_OF_RANGE); 376 377 size_t const cbMin = (cwcMin + 1) * sizeof(RTUTF16); 378 int rc = RTUtf16Realloc(&pNtName->Buffer, cbMin); 379 if (RT_SUCCESS(rc)) 380 pNtName->MaximumLength = (uint16_t)cbMin; 381 return rc; 382 } 383 384 385 /** 343 386 * Frees the native path and root handle. 344 387 * 345 388 * @param pNtName The NT path after a successful rtNtPathToNative 346 389 * call. 347 * @param phRootDir The root handle variable after a 348 * rtNtPathToNative. 390 * @param phRootDir The root handle variable from the same call. 349 391 */ 350 392 static void rtNtPathFreeNative(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir) … … 358 400 * Frees the native path and root handle. 359 401 * 360 * @param pNtName The NT path after a successful 361 * RTNtPathFromWinUtf16Ex call. 362 * @param phRootDir The root handle variable after a successfull 363 * RTNtPathFromWinUtf16Ex call. 402 * @param pNtName The NT path from a successful RTNtPathToNative 403 * or RTNtPathFromWinUtf16Ex call. 404 * @param phRootDir The root handle variable from the same call. 364 405 */ 365 406 RTDECL(void) RTNtPathFree(struct _UNICODE_STRING *pNtName, HANDLE *phRootDir) -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r60191 r60481 152 152 tstRTProcWait \ 153 153 tstFileAppendWin-1 \ 154 tstRTNtPath-1 \ 154 155 ntGetTimerResolution 155 156 PROGRAMS.linux += \ … … 526 527 ../common/string/strlen.asm 527 528 529 tstRTNtPath-1_TEMPLATE = VBOXR3TSTEXE 530 tstRTNtPath-1_SOURCES = tstRTNtPath-1.cpp 531 528 532 tstOnce_TEMPLATE = VBOXR3TSTEXE 529 533 tstOnce_SOURCES = tstOnce.cpp
Note:
See TracChangeset
for help on using the changeset viewer.

