VirtualBox

Changeset 7418 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Mar 10, 2008 4:01:58 PM (17 years ago)
Author:
vboxsync
Message:

UCS-2 -> UTF-16.

Location:
trunk/src/VBox/Runtime/r3/win
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r6971 r7418  
    5252
    5353    /*
    54      * Convert to UCS2.
    55      */
    56     PRTUCS2 pucszString;
    57     int rc = RTStrUtf8ToUcs2(&pucszString, pszPath);
     54     * Convert to UTF-16.
     55     */
     56    PRTUTF16 pwszString;
     57    int rc = RTStrToUtf16(pszPath, &pwszString);
    5858    AssertRC(rc);
    5959    if (RT_SUCCESS(rc))
     
    6262         * Query and check attributes.
    6363         */
    64         DWORD dwAttr = GetFileAttributesW((LPCWSTR)pucszString);
     64        DWORD dwAttr = GetFileAttributesW((LPCWSTR)pwszString);
    6565        fRc = dwAttr != INVALID_FILE_ATTRIBUTES
    6666            && (dwAttr & FILE_ATTRIBUTE_DIRECTORY);
    6767
    68         RTStrUcs2Free(pucszString);
     68        RTUtf16Free(pwszString);
    6969    }
    7070
     
    8484    {
    8585        /*
    86          * Convert to UCS2.
     86         * Convert to UTF-16.
    8787         */
    88         PRTUCS2 pucszString;
    89         rc = RTStrUtf8ToUcs2(&pucszString, pszPath);
     88        PRTUTF16 pwszString;
     89        rc = RTStrToUtf16(pszPath, &pwszString);
    9090        AssertRC(rc);
    9191        if (RT_SUCCESS(rc))
     
    9494             * Create the directory.
    9595             */
    96             if (CreateDirectoryW((LPCWSTR)pucszString, NULL))
     96            if (CreateDirectoryW((LPCWSTR)pwszString, NULL))
    9797                rc = VINF_SUCCESS;
    9898            else
     
    104104            if (RT_SUCCESS(rc))
    105105            {
    106                 if (SetFileAttributesW((LPCWSTR)pucszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
     106                if (SetFileAttributesW((LPCWSTR)pwszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
    107107                    rc = VINF_SUCCESS;
    108108                else
     
    110110            }
    111111
    112             RTStrUcs2Free(pucszString);
     112            RTUtf16Free(pwszString);
    113113        }
    114114    }
     
    127127{
    128128    /*
    129      * Convert to UCS2.
    130      */
    131     PRTUCS2 pucszString;
    132     int rc = RTStrUtf8ToUcs2(&pucszString, pszPath);
     129     * Convert to UTF-16.
     130     */
     131    PRTUTF16 pwszString;
     132    int rc = RTStrToUtf16(pszPath, &pwszString);
    133133    AssertRC(rc);
    134134    if (RT_SUCCESS(rc))
     
    137137         * Remove the directory.
    138138         */
    139         if (RemoveDirectoryW((LPCWSTR)pucszString))
     139        if (RemoveDirectoryW((LPCWSTR)pwszString))
    140140            rc = VINF_SUCCESS;
    141141        else
    142142            rc = RTErrConvertFromWin32(GetLastError());
    143143
    144         RTStrUcs2Free(pucszString);
     144        RTUtf16Free(pwszString);
    145145    }
    146146
     
    181181    int rc = VINF_SUCCESS;
    182182#ifndef RT_DONT_CONVERT_FILENAMES
    183     PRTUCS2 puszName;
    184     rc = RTStrUtf8ToUcs2(&puszName, pszPathBuf);
     183    PRTUTF16 pwszName;
     184    rc = RTStrToUtf16(pszPathBuf, &pwszName);
    185185    if (RT_SUCCESS(rc))
    186186    {
    187         pDir->hDir    = FindFirstFileW((LPCWSTR)puszName, &pDir->Data);
     187        pDir->hDir    = FindFirstFileW((LPCWSTR)pwszName, &pDir->Data);
    188188#else
    189189        pDir->hDir    = FindFirstFileA(pszPathBuf, &pDir->Data);
     
    197197            rc = RTErrConvertFromWin32(GetLastError());
    198198#ifndef RT_DONT_CONVERT_FILENAMES
    199         RTStrUcs2Free(puszName);
     199        RTUtf16Free(pwszName);
    200200    }
    201201#endif
     
    430430    {
    431431        /* copy and calc length */
    432         PCRTUCS2 pucSrc = (PCRTUCS2)pDir->Data.cAlternateFileName;
    433         PRTUCS2  pucDst = pDirEntry->uszShortName;
    434         while (*pucSrc)
    435             *pucDst++ = *pucSrc++;
    436         pDirEntry->cucShortName = pucDst - &pDirEntry->uszShortName[0];
     432        PCRTUTF16 pwszSrc = (PCRTUTF16)pDir->Data.cAlternateFileName;
     433        PRTUTF16  pwszDst = pDirEntry->wszShortName;
     434        while (*pwszSrc)
     435            *pwszDst++ = *pwszSrc++;
     436        pDirEntry->cwcShortName = pwszDst - &pDirEntry->wszShortName[0];
    437437        /* zero the rest */
    438         const PRTUCS2 pucEnd = &pDirEntry->uszShortName[ELEMENTS(pDirEntry->uszShortName)];
    439         while (pucDst < pucEnd)
    440             *pucDst++ = '\0';
     438        const PRTUTF16 pwszEnd = &pDirEntry->wszShortName[RT_ELEMENTS(pDirEntry->wszShortName)];
     439        while (pwszDst < pwszEnd)
     440            *pwszDst++ = '\0';
    441441    }
    442442    else
    443443#endif
    444444    {
    445         memset(pDirEntry->uszShortName, 0, sizeof(pDirEntry->uszShortName));
    446         pDirEntry->cucShortName = 0;
     445        memset(pDirEntry->wszShortName, 0, sizeof(pDirEntry->wszShortName));
     446        pDirEntry->cwcShortName = 0;
    447447    }
    448448
  • trunk/src/VBox/Runtime/r3/win/fs-win.cpp

    r5999 r7418  
    8787
    8888#ifndef RT_DONT_CONVERT_FILENAMES
     89
    8990/**
    9091 * Finds the root of the specified volume.
     
    9293 * @returns iprt status code.
    9394 * @param   pszFsPath       Path within the filesystem. Verified as one byte or more.
    94  * @param   ppuszFsRoot     Where to store the returned string. Free with rtFsFreeRoot(),
    95  */
    96 static int rtFsGetRoot(const char *pszFsPath, PRTUCS2 *ppuszFsRoot)
     95 * @param   ppwszFsRoot     Where to store the returned string. Free with rtFsFreeRoot(),
     96 */
     97static int rtFsGetRoot(const char *pszFsPath, PRTUTF16 *ppwszFsRoot)
    9798{
    9899    /*
     
    100101     */
    101102    if (rtFsIsRoot(pszFsPath))
    102         return RTStrUtf8ToUcs2(ppuszFsRoot, pszFsPath);
     103        return RTStrToUtf16(pszFsPath, ppwszFsRoot);
    103104
    104105    /*
     
    120121     * Convert the path.
    121122     */
    122     rc = RTStrUtf8ToUcs2(ppuszFsRoot, szFullPath);
     123    rc = RTStrToUtf16(szFullPath, ppwszFsRoot);
    123124    if (RT_FAILURE(rc))
    124125        return rc == VERR_BUFFER_OVERFLOW ? VERR_FILENAME_TOO_LONG : rc;
     
    127128     * Walk the path until our proper API is happy or there is no more path left.
    128129     */
    129     PRTUCS2 puszStart = *ppuszFsRoot;
    130     if (!GetVolumeInformationW(puszStart, NULL, 0, NULL, NULL, 0, NULL, 0))
    131     {
    132         PRTUCS2 puszEnd = puszStart + RTStrUcs2Len(puszStart);
    133         PRTUCS2 puszMin = puszStart + 2;
     130    PRTUTF16 pwszStart = *ppwszFsRoot;
     131    if (!GetVolumeInformationW(pwszStart, NULL, 0, NULL, NULL, 0, NULL, 0))
     132    {
     133        PRTUTF16 pwszEnd = pwszStart + RTUtf16Len(pwszStart);
     134        PRTUTF16 pwszMin = pwszStart + 2;
    134135        do
    135136        {
    136137            /* Strip off the last path component. */
    137             while (puszEnd-- > puszMin)
    138                 if (RTPATH_IS_SLASH(*puszEnd))
     138            while (pwszEnd-- > pwszMin)
     139                if (RTPATH_IS_SLASH(*pwszEnd))
    139140                    break;
    140             AssertReturn(puszEnd >= puszMin, VERR_INTERNAL_ERROR); /* leaks, but that's irrelevant for an internal error. */
    141             puszEnd[1] = '\0';
    142         } while (!GetVolumeInformationW(puszStart, NULL, 0, NULL, NULL, 0, NULL, 0));
     141            AssertReturn(pwszEnd >= pwszMin, VERR_INTERNAL_ERROR); /* leaks, but that's irrelevant for an internal error. */
     142            pwszEnd[1] = '\0';
     143        } while (!GetVolumeInformationW(pwszStart, NULL, 0, NULL, NULL, 0, NULL, 0));
    143144    }
    144145
     
    149150 * Frees string returned by rtFsGetRoot().
    150151 */
    151 static void rtFsFreeRoot(PRTUCS2 puszFsRoot)
    152 {
    153     RTStrUcs2Free(puszFsRoot);
    154 }
    155 
    156 #else
     152static void rtFsFreeRoot(PRTUTF16 pwszFsRoot)
     153{
     154    RTUtf16Free(pwszFsRoot);
     155}
     156
     157#else /* RT_DONT_CONVERT_FILENAMES */
    157158
    158159/**
     
    214215    RTStrFree(pszFsRoot);
    215216}
    216 #endif
     217
     218#endif /* RT_DONT_CONVERT_FILENAMES*/
    217219
    218220
     
    225227    AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
    226228#ifndef RT_DONT_CONVERT_FILENAMES
    227     PRTUCS2 puszFsRoot;
    228     int rc = rtFsGetRoot(pszFsPath, &puszFsRoot);
     229    PRTUTF16 pwszFsRoot;
     230    int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot);
    229231#else
    230232    char pszFsRoot;
     
    242244        ULARGE_INTEGER cbFree;
    243245#ifndef RT_DONT_CONVERT_FILENAMES
    244         if (GetDiskFreeSpaceExW(puszFsRoot, &cbFree, &cbTotal, NULL))
     246        if (GetDiskFreeSpaceExW(pwszFsRoot, &cbFree, &cbTotal, NULL))
    245247#else
    246248        if (GetDiskFreeSpaceExA(pszFsRoot, &cbFree, &cbTotal, NULL))
     
    271273        DWORD cSectorsPerCluster;
    272274#ifndef RT_DONT_CONVERT_FILENAMES
    273         if (GetDiskFreeSpaceW(puszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2))
     275        if (GetDiskFreeSpaceW(pwszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2))
    274276#else
    275277        if (GetDiskFreeSpaceA(pszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2))
     
    291293
    292294#ifndef RT_DONT_CONVERT_FILENAMES
    293     rtFsFreeRoot(puszFsRoot);
     295    rtFsFreeRoot(pwszFsRoot);
    294296#else
    295297    rtFsFreeRoot(pszFsRoot);
     
    314316    AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER);
    315317#ifndef RT_DONT_CONVERT_FILENAMES
    316     PRTUCS2 puszFsRoot;
    317     int rc = rtFsGetRoot(pszFsPath, &puszFsRoot);
     318    PRTUTF16 pwszFsRoot;
     319    int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot);
    318320#else
    319321    char pszFsRoot;
     
    330332    DWORD   dwSerial;
    331333#ifndef RT_DONT_CONVERT_FILENAMES
    332     if (GetVolumeInformationW(puszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
     334    if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
    333335#else
    334336    if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
     
    344346
    345347#ifndef RT_DONT_CONVERT_FILENAMES
    346     RTStrUcs2Free(puszFsRoot);
    347 #else
    348     RTStrUcs2Free(pszFsRoot);
     348    RTUtf16Free(pwszFsRoot);
     349#else
     350    RTStrFree(pszFsRoot);
    349351#endif
    350352    return rc;
     
    367369    AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER);
    368370#ifndef RT_DONT_CONVERT_FILENAMES
    369     PRTUCS2 puszFsRoot;
    370     int rc = rtFsGetRoot(pszFsPath, &puszFsRoot);
     371    PRTUTF16 pwszFsRoot;
     372    int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot);
    371373#else
    372374    char pszFsRoot;
     
    383385    DWORD   dwSerial;
    384386#ifndef RT_DONT_CONVERT_FILENAMES
    385     if (GetVolumeInformationW(puszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
     387    if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
    386388#else
    387389    if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))
     
    406408
    407409#ifndef RT_DONT_CONVERT_FILENAMES
    408     RTStrUcs2Free(puszFsRoot);
    409 #else
    410     RTStrUcs2Free(pszFsRoot);
     410    RTUtf16Free(pwszFsRoot);
     411#else
     412    RTStrFree(pszFsRoot);
    411413#endif
    412414    return rc;
  • trunk/src/VBox/Runtime/r3/win/path-win.cpp

    r7403 r7418  
    193193     * Convert and return.
    194194     */
    195     return RTStrUcs2ToUtf8Ex(&pszPath, cchPath, &wszPath[0]);
     195    return RTUtf16ToUtf8Ex(&wszPath[0], RTSTR_MAX, &pszPath, cchPath, NULL);
    196196}
    197197
     
    225225#ifndef RT_DONT_CONVERT_FILENAMES
    226226    PRTUTF16 pwszPath;
    227     int rc = RTStrUtf8ToUcs2(&pwszPath, pszPath);
     227    int rc = RTStrToUtf16(pszPath, &pwszPath);
    228228    if (RT_FAILURE(rc))
    229229        return rc;
     
    477477#ifndef RT_DONT_CONVERT_FILENAMES
    478478    PRTUTF16 pwszPath;
    479     int rc = RTStrUtf8ToUcs2(&pwszPath, pszPath);
     479    int rc = RTStrToUtf16(pszPath, &pwszPath);
    480480    if (RT_SUCCESS(rc))
    481481    {
  • trunk/src/VBox/Runtime/r3/win/utf8-win.cpp

    r5999 r7418  
    6767     * Convert to wide char first.
    6868     */
    69     PRTUCS2 pucszString = NULL;
    70     int rc = RTStrUtf8ToUcs2(&pucszString, pszString);
     69    PRTUTF16 pwszString = NULL;
     70    int rc = RTStrToUtf16(pszString, &pwszString);
    7171    if (RT_FAILURE(rc))
    7272        return rc;
     
    7575     * First calc result string length.
    7676     */
    77     int cbResult = WideCharToMultiByte(CP_ACP, 0, pucszString, -1, NULL, 0, NULL, NULL);
     77    int cbResult = WideCharToMultiByte(CP_ACP, 0, pwszString, -1, NULL, 0, NULL, NULL);
    7878    if (cbResult > 0)
    7979    {
     
    8787             * Do the translation.
    8888             */
    89             if (WideCharToMultiByte(CP_ACP, 0, pucszString, -1, lpString, cbResult, NULL, NULL) > 0)
     89            if (WideCharToMultiByte(CP_ACP, 0, pwszString, -1, lpString, cbResult, NULL, NULL) > 0)
    9090            {
    9191                /* ok */
    9292                *ppszString = lpString;
    93                 RTMemTmpFree(pucszString);
     93                RTMemTmpFree(pwszString);
    9494                return VINF_SUCCESS;
    9595            }
     
    111111        rc = RTErrConvertFromWin32(iLastErr);
    112112    }
    113     RTMemTmpFree(pucszString);
     113    RTMemTmpFree(pwszString);
    114114    return rc;
    115115}
     
    129129    *ppszString = NULL;
    130130
    131     /** @todo is there a quicker way? Currently: ACP -> UCS-2 -> UTF-8 */
     131    /** @todo is there a quicker way? Currently: ACP -> UTF-16 -> UTF-8 */
    132132
    133133    size_t cch = strlen(pszString);
     
    145145     */
    146146    int rc;
    147     int cuc = MultiByteToWideChar(CP_ACP, 0, pszString, -1, NULL, 0);
    148     if (cuc > 0)
     147    int cwc = MultiByteToWideChar(CP_ACP, 0, pszString, -1, NULL, 0);
     148    if (cwc > 0)
    149149    {
    150150        /*
    151151         * Alloc space for result buffer.
    152152         */
    153         PRTUCS2 pucszString = (PRTUCS2)RTMemTmpAlloc(cuc * sizeof(RTUCS2));
    154         if (pucszString)
     153        PRTUTF16 pwszString = (PRTUTF16)RTMemTmpAlloc(cwc * sizeof(RTUTF16));
     154        if (pwszString)
    155155        {
    156156            /*
    157157             * Do the translation.
    158158             */
    159             if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, pucszString, cuc) > 0)
     159            if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, pwszString, cwc) > 0)
    160160            {
    161161                /*
    162                  * Now we got UCS-2. Convert to UTF-8
     162                 * Now we got UTF-16, convert it to UTF-8
    163163                 */
    164                 rc = RTStrUcs2ToUtf8(ppszString, pucszString);
    165                 RTMemTmpFree(pucszString);
     164                rc = RTUtf16ToUtf8(pwszString, ppszString);
     165                RTMemTmpFree(pwszString);
    166166                return rc;
    167167            }
    168             RTMemTmpFree(pucszString);
     168            RTMemTmpFree(pwszString);
    169169            /* translation error */
    170170            int iLastErr = GetLastError();
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