VirtualBox

Changeset 60481 in vbox


Ignore:
Timestamp:
Apr 13, 2016 8:14:41 PM (8 years ago)
Author:
vboxsync
Message:

IPRT: Added testcase for RTNtPathExpand8dot3Path and RTNtPathFindPossible8dot3Name, fixing bug in the former. include\ src\VBox\Runtime\

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r60390 r60481  
    21942194# define RTUriIsSchemeMatch                             RT_MANGLER(RTUriIsSchemeMatch)
    21952195# define RTUtf16AllocTag                                RT_MANGLER(RTUtf16AllocTag)
     2196# define RTUtf16ReallocTag                              RT_MANGLER(RTUtf16ReallocTag)
    21962197# define RTUtf16CalcLatin1Len                           RT_MANGLER(RTUtf16CalcLatin1Len)
    21972198# define RTUtf16CalcLatin1LenEx                         RT_MANGLER(RTUtf16CalcLatin1LenEx)
     
    22002201# define RTUtf16Cmp                                     RT_MANGLER(RTUtf16Cmp)
    22012202# define RTUtf16CmpAscii                                RT_MANGLER(RTUtf16CmpAscii)
     2203# define RTUtf16CmpUtf8                                 RT_MANGLER(RTUtf16CmpUtf8)
    22022204# define RTUtf16DupExTag                                RT_MANGLER(RTUtf16DupExTag)
    22032205# define RTUtf16DupTag                                  RT_MANGLER(RTUtf16DupTag)
     
    22062208# define RTUtf16GetCpInternal                           RT_MANGLER(RTUtf16GetCpInternal)
    22072209# define RTUtf16ICmp                                    RT_MANGLER(RTUtf16ICmp)
     2210# define RTUtf16ICmpUtf8                                RT_MANGLER(RTUtf16ICmpUtf8)
    22082211# define RTUtf16IsValidEncoding                         RT_MANGLER(RTUtf16IsValidEncoding)
    22092212# define RTUtf16Len                                     RT_MANGLER(RTUtf16Len)
  • trunk/include/iprt/utf16.h

    r57941 r60481  
    8282RTDECL(PRTUTF16) RTUtf16AllocTag(size_t cb, const char *pszTag);
    8383
     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 */
     155RTDECL(int) RTUtf16ReallocTag(PRTUTF16 *ppwsz, size_t cbNew, const char *pszTag);
    84156
    85157/**
     
    333405
    334406/**
     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 */
     417RTDECL(int) RTUtf16CmpUtf8(PCRTUTF16 pwsz1, const char *psz2);
     418
     419/**
    335420 * Performs a case insensitive string compare between two UTF-16 strings.
    336421 *
     
    346431 */
    347432RTDECL(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 */
     445RTDECL(int) RTUtf16ICmpUtf8(PCRTUTF16 pwsz1, const char *psz2);
    348446
    349447/**
  • trunk/src/VBox/Runtime/common/string/utf-16-case.cpp

    r57358 r60481  
    106106
    107107
     108RTDECL(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}
     144RT_EXPORT_SYMBOL(RTUtf16CmpIUtf8);
     145
     146
    108147RTDECL(PRTUTF16) RTUtf16ToLower(PRTUTF16 pwsz)
    109148{
  • trunk/src/VBox/Runtime/common/string/utf-16.cpp

    r57358 r60481  
    114114
    115115
     116RTDECL(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}
     144RT_EXPORT_SYMBOL(RTUtf16ReallocTag);
     145
     146
    116147RTDECL(void)  RTUtf16Free(PRTUTF16 pwszString)
    117148{
     
    183214}
    184215RT_EXPORT_SYMBOL(RTUtf16Cmp);
     216
     217
     218RTDECL(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}
     249RT_EXPORT_SYMBOL(RTUtf16CmpUtf8);
    185250
    186251
  • trunk/src/VBox/Runtime/nt/RTNtPathExpand8dot3Path.cpp

    r60480 r60481  
    158158                    pUniStr->Length += (USHORT)(cwcNameNew * sizeof(WCHAR));
    159159                    pwszFixEnd      -= cwcNameOld;
    160                     pwszFixEnd      -= cwcNameNew;
     160                    pwszFixEnd      += cwcNameNew;
    161161                    memcpy(pwszFix, &puBuf->Info.FileName[offName], cwcNameNew * sizeof(WCHAR));
    162162                }
  • trunk/src/VBox/Runtime/r3/nt/pathint-nt.cpp

    r58440 r60481  
    162162
    163163/**
    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.
    168169 * @param   phRootDir           Where to return the root handle, if applicable.
    169170 * @param   pszPath             The UTF-8 path.
     
    225226    memcpy(szPath, pszPrefix, cchPrefix);
    226227    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 */
     240RTDECL(int) RTNtPathFromWinUtf8(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
     241{
     242    return rtNtPathToNative(pNtName, phRootDir, pszPath);
    227243}
    228244
     
    341357
    342358/**
     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 */
     370RTDECL(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/**
    343386 * Frees the native path and root handle.
    344387 *
    345388 * @param   pNtName             The NT path after a successful rtNtPathToNative
    346389 *                              call.
    347  * @param   phRootDir           The root handle variable after a
    348  *                              rtNtPathToNative.
     390 * @param   phRootDir           The root handle variable from the same call.
    349391 */
    350392static void rtNtPathFreeNative(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir)
     
    358400 * Frees the native path and root handle.
    359401 *
    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.
    364405 */
    365406RTDECL(void) RTNtPathFree(struct _UNICODE_STRING *pNtName, HANDLE *phRootDir)
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r60191 r60481  
    152152        tstRTProcWait \
    153153        tstFileAppendWin-1 \
     154        tstRTNtPath-1 \
    154155        ntGetTimerResolution
    155156PROGRAMS.linux += \
     
    526527        ../common/string/strlen.asm
    527528
     529tstRTNtPath-1_TEMPLATE = VBOXR3TSTEXE
     530tstRTNtPath-1_SOURCES = tstRTNtPath-1.cpp
     531
    528532tstOnce_TEMPLATE = VBOXR3TSTEXE
    529533tstOnce_SOURCES = tstOnce.cpp
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette