Changeset 7418 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Mar 10, 2008 4:01:58 PM (17 years ago)
- 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 52 52 53 53 /* 54 * Convert to U CS2.55 */ 56 PRTU CS2 pucszString;57 int rc = RTStr Utf8ToUcs2(&pucszString, pszPath);54 * Convert to UTF-16. 55 */ 56 PRTUTF16 pwszString; 57 int rc = RTStrToUtf16(pszPath, &pwszString); 58 58 AssertRC(rc); 59 59 if (RT_SUCCESS(rc)) … … 62 62 * Query and check attributes. 63 63 */ 64 DWORD dwAttr = GetFileAttributesW((LPCWSTR)p ucszString);64 DWORD dwAttr = GetFileAttributesW((LPCWSTR)pwszString); 65 65 fRc = dwAttr != INVALID_FILE_ATTRIBUTES 66 66 && (dwAttr & FILE_ATTRIBUTE_DIRECTORY); 67 67 68 RT StrUcs2Free(pucszString);68 RTUtf16Free(pwszString); 69 69 } 70 70 … … 84 84 { 85 85 /* 86 * Convert to U CS2.86 * Convert to UTF-16. 87 87 */ 88 PRTU CS2 pucszString;89 rc = RTStr Utf8ToUcs2(&pucszString, pszPath);88 PRTUTF16 pwszString; 89 rc = RTStrToUtf16(pszPath, &pwszString); 90 90 AssertRC(rc); 91 91 if (RT_SUCCESS(rc)) … … 94 94 * Create the directory. 95 95 */ 96 if (CreateDirectoryW((LPCWSTR)p ucszString, NULL))96 if (CreateDirectoryW((LPCWSTR)pwszString, NULL)) 97 97 rc = VINF_SUCCESS; 98 98 else … … 104 104 if (RT_SUCCESS(rc)) 105 105 { 106 if (SetFileAttributesW((LPCWSTR)p ucszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))106 if (SetFileAttributesW((LPCWSTR)pwszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) 107 107 rc = VINF_SUCCESS; 108 108 else … … 110 110 } 111 111 112 RT StrUcs2Free(pucszString);112 RTUtf16Free(pwszString); 113 113 } 114 114 } … … 127 127 { 128 128 /* 129 * Convert to U CS2.130 */ 131 PRTU CS2 pucszString;132 int rc = RTStr Utf8ToUcs2(&pucszString, pszPath);129 * Convert to UTF-16. 130 */ 131 PRTUTF16 pwszString; 132 int rc = RTStrToUtf16(pszPath, &pwszString); 133 133 AssertRC(rc); 134 134 if (RT_SUCCESS(rc)) … … 137 137 * Remove the directory. 138 138 */ 139 if (RemoveDirectoryW((LPCWSTR)p ucszString))139 if (RemoveDirectoryW((LPCWSTR)pwszString)) 140 140 rc = VINF_SUCCESS; 141 141 else 142 142 rc = RTErrConvertFromWin32(GetLastError()); 143 143 144 RT StrUcs2Free(pucszString);144 RTUtf16Free(pwszString); 145 145 } 146 146 … … 181 181 int rc = VINF_SUCCESS; 182 182 #ifndef RT_DONT_CONVERT_FILENAMES 183 PRTU CS2 puszName;184 rc = RTStr Utf8ToUcs2(&puszName, pszPathBuf);183 PRTUTF16 pwszName; 184 rc = RTStrToUtf16(pszPathBuf, &pwszName); 185 185 if (RT_SUCCESS(rc)) 186 186 { 187 pDir->hDir = FindFirstFileW((LPCWSTR)p uszName, &pDir->Data);187 pDir->hDir = FindFirstFileW((LPCWSTR)pwszName, &pDir->Data); 188 188 #else 189 189 pDir->hDir = FindFirstFileA(pszPathBuf, &pDir->Data); … … 197 197 rc = RTErrConvertFromWin32(GetLastError()); 198 198 #ifndef RT_DONT_CONVERT_FILENAMES 199 RT StrUcs2Free(puszName);199 RTUtf16Free(pwszName); 200 200 } 201 201 #endif … … 430 430 { 431 431 /* copy and calc length */ 432 PCRTU CS2 pucSrc = (PCRTUCS2)pDir->Data.cAlternateFileName;433 PRTU CS2 pucDst = pDirEntry->uszShortName;434 while (*p ucSrc)435 *p ucDst++ = *pucSrc++;436 pDirEntry->c ucShortName = 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]; 437 437 /* zero the rest */ 438 const PRTU CS2 pucEnd = &pDirEntry->uszShortName[ELEMENTS(pDirEntry->uszShortName)];439 while (p ucDst < pucEnd)440 *p ucDst++ = '\0';438 const PRTUTF16 pwszEnd = &pDirEntry->wszShortName[RT_ELEMENTS(pDirEntry->wszShortName)]; 439 while (pwszDst < pwszEnd) 440 *pwszDst++ = '\0'; 441 441 } 442 442 else 443 443 #endif 444 444 { 445 memset(pDirEntry-> uszShortName, 0, sizeof(pDirEntry->uszShortName));446 pDirEntry->c ucShortName = 0;445 memset(pDirEntry->wszShortName, 0, sizeof(pDirEntry->wszShortName)); 446 pDirEntry->cwcShortName = 0; 447 447 } 448 448 -
trunk/src/VBox/Runtime/r3/win/fs-win.cpp
r5999 r7418 87 87 88 88 #ifndef RT_DONT_CONVERT_FILENAMES 89 89 90 /** 90 91 * Finds the root of the specified volume. … … 92 93 * @returns iprt status code. 93 94 * @param pszFsPath Path within the filesystem. Verified as one byte or more. 94 * @param pp uszFsRoot Where to store the returned string. Free with rtFsFreeRoot(),95 */ 96 static int rtFsGetRoot(const char *pszFsPath, PRTU CS2 *ppuszFsRoot)95 * @param ppwszFsRoot Where to store the returned string. Free with rtFsFreeRoot(), 96 */ 97 static int rtFsGetRoot(const char *pszFsPath, PRTUTF16 *ppwszFsRoot) 97 98 { 98 99 /* … … 100 101 */ 101 102 if (rtFsIsRoot(pszFsPath)) 102 return RTStr Utf8ToUcs2(ppuszFsRoot, pszFsPath);103 return RTStrToUtf16(pszFsPath, ppwszFsRoot); 103 104 104 105 /* … … 120 121 * Convert the path. 121 122 */ 122 rc = RTStr Utf8ToUcs2(ppuszFsRoot, szFullPath);123 rc = RTStrToUtf16(szFullPath, ppwszFsRoot); 123 124 if (RT_FAILURE(rc)) 124 125 return rc == VERR_BUFFER_OVERFLOW ? VERR_FILENAME_TOO_LONG : rc; … … 127 128 * Walk the path until our proper API is happy or there is no more path left. 128 129 */ 129 PRTU CS2 puszStart = *ppuszFsRoot;130 if (!GetVolumeInformationW(p uszStart, NULL, 0, NULL, NULL, 0, NULL, 0))131 { 132 PRTU CS2 puszEnd = puszStart + RTStrUcs2Len(puszStart);133 PRTU CS2 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; 134 135 do 135 136 { 136 137 /* Strip off the last path component. */ 137 while (p uszEnd-- > puszMin)138 if (RTPATH_IS_SLASH(*p uszEnd))138 while (pwszEnd-- > pwszMin) 139 if (RTPATH_IS_SLASH(*pwszEnd)) 139 140 break; 140 AssertReturn(p uszEnd >= puszMin, VERR_INTERNAL_ERROR); /* leaks, but that's irrelevant for an internal error. */141 p uszEnd[1] = '\0';142 } while (!GetVolumeInformationW(p uszStart, 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)); 143 144 } 144 145 … … 149 150 * Frees string returned by rtFsGetRoot(). 150 151 */ 151 static void rtFsFreeRoot(PRTU CS2 puszFsRoot)152 { 153 RT StrUcs2Free(puszFsRoot);154 } 155 156 #else 152 static void rtFsFreeRoot(PRTUTF16 pwszFsRoot) 153 { 154 RTUtf16Free(pwszFsRoot); 155 } 156 157 #else /* RT_DONT_CONVERT_FILENAMES */ 157 158 158 159 /** … … 214 215 RTStrFree(pszFsRoot); 215 216 } 216 #endif 217 218 #endif /* RT_DONT_CONVERT_FILENAMES*/ 217 219 218 220 … … 225 227 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); 226 228 #ifndef RT_DONT_CONVERT_FILENAMES 227 PRTU CS2 puszFsRoot;228 int rc = rtFsGetRoot(pszFsPath, &p uszFsRoot);229 PRTUTF16 pwszFsRoot; 230 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 229 231 #else 230 232 char pszFsRoot; … … 242 244 ULARGE_INTEGER cbFree; 243 245 #ifndef RT_DONT_CONVERT_FILENAMES 244 if (GetDiskFreeSpaceExW(p uszFsRoot, &cbFree, &cbTotal, NULL))246 if (GetDiskFreeSpaceExW(pwszFsRoot, &cbFree, &cbTotal, NULL)) 245 247 #else 246 248 if (GetDiskFreeSpaceExA(pszFsRoot, &cbFree, &cbTotal, NULL)) … … 271 273 DWORD cSectorsPerCluster; 272 274 #ifndef RT_DONT_CONVERT_FILENAMES 273 if (GetDiskFreeSpaceW(p uszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2))275 if (GetDiskFreeSpaceW(pwszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2)) 274 276 #else 275 277 if (GetDiskFreeSpaceA(pszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2)) … … 291 293 292 294 #ifndef RT_DONT_CONVERT_FILENAMES 293 rtFsFreeRoot(p uszFsRoot);295 rtFsFreeRoot(pwszFsRoot); 294 296 #else 295 297 rtFsFreeRoot(pszFsRoot); … … 314 316 AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER); 315 317 #ifndef RT_DONT_CONVERT_FILENAMES 316 PRTU CS2 puszFsRoot;317 int rc = rtFsGetRoot(pszFsPath, &p uszFsRoot);318 PRTUTF16 pwszFsRoot; 319 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 318 320 #else 319 321 char pszFsRoot; … … 330 332 DWORD dwSerial; 331 333 #ifndef RT_DONT_CONVERT_FILENAMES 332 if (GetVolumeInformationW(p uszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))334 if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) 333 335 #else 334 336 if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) … … 344 346 345 347 #ifndef RT_DONT_CONVERT_FILENAMES 346 RT StrUcs2Free(puszFsRoot);347 #else 348 RTStr Ucs2Free(pszFsRoot);348 RTUtf16Free(pwszFsRoot); 349 #else 350 RTStrFree(pszFsRoot); 349 351 #endif 350 352 return rc; … … 367 369 AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER); 368 370 #ifndef RT_DONT_CONVERT_FILENAMES 369 PRTU CS2 puszFsRoot;370 int rc = rtFsGetRoot(pszFsPath, &p uszFsRoot);371 PRTUTF16 pwszFsRoot; 372 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 371 373 #else 372 374 char pszFsRoot; … … 383 385 DWORD dwSerial; 384 386 #ifndef RT_DONT_CONVERT_FILENAMES 385 if (GetVolumeInformationW(p uszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))387 if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) 386 388 #else 387 389 if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) … … 406 408 407 409 #ifndef RT_DONT_CONVERT_FILENAMES 408 RT StrUcs2Free(puszFsRoot);409 #else 410 RTStr Ucs2Free(pszFsRoot);410 RTUtf16Free(pwszFsRoot); 411 #else 412 RTStrFree(pszFsRoot); 411 413 #endif 412 414 return rc; -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r7403 r7418 193 193 * Convert and return. 194 194 */ 195 return RT StrUcs2ToUtf8Ex(&pszPath, cchPath, &wszPath[0]);195 return RTUtf16ToUtf8Ex(&wszPath[0], RTSTR_MAX, &pszPath, cchPath, NULL); 196 196 } 197 197 … … 225 225 #ifndef RT_DONT_CONVERT_FILENAMES 226 226 PRTUTF16 pwszPath; 227 int rc = RTStr Utf8ToUcs2(&pwszPath, pszPath);227 int rc = RTStrToUtf16(pszPath, &pwszPath); 228 228 if (RT_FAILURE(rc)) 229 229 return rc; … … 477 477 #ifndef RT_DONT_CONVERT_FILENAMES 478 478 PRTUTF16 pwszPath; 479 int rc = RTStr Utf8ToUcs2(&pwszPath, pszPath);479 int rc = RTStrToUtf16(pszPath, &pwszPath); 480 480 if (RT_SUCCESS(rc)) 481 481 { -
trunk/src/VBox/Runtime/r3/win/utf8-win.cpp
r5999 r7418 67 67 * Convert to wide char first. 68 68 */ 69 PRTU CS2 pucszString = NULL;70 int rc = RTStr Utf8ToUcs2(&pucszString, pszString);69 PRTUTF16 pwszString = NULL; 70 int rc = RTStrToUtf16(pszString, &pwszString); 71 71 if (RT_FAILURE(rc)) 72 72 return rc; … … 75 75 * First calc result string length. 76 76 */ 77 int cbResult = WideCharToMultiByte(CP_ACP, 0, p ucszString, -1, NULL, 0, NULL, NULL);77 int cbResult = WideCharToMultiByte(CP_ACP, 0, pwszString, -1, NULL, 0, NULL, NULL); 78 78 if (cbResult > 0) 79 79 { … … 87 87 * Do the translation. 88 88 */ 89 if (WideCharToMultiByte(CP_ACP, 0, p ucszString, -1, lpString, cbResult, NULL, NULL) > 0)89 if (WideCharToMultiByte(CP_ACP, 0, pwszString, -1, lpString, cbResult, NULL, NULL) > 0) 90 90 { 91 91 /* ok */ 92 92 *ppszString = lpString; 93 RTMemTmpFree(p ucszString);93 RTMemTmpFree(pwszString); 94 94 return VINF_SUCCESS; 95 95 } … … 111 111 rc = RTErrConvertFromWin32(iLastErr); 112 112 } 113 RTMemTmpFree(p ucszString);113 RTMemTmpFree(pwszString); 114 114 return rc; 115 115 } … … 129 129 *ppszString = NULL; 130 130 131 /** @todo is there a quicker way? Currently: ACP -> U CS-2-> UTF-8 */131 /** @todo is there a quicker way? Currently: ACP -> UTF-16 -> UTF-8 */ 132 132 133 133 size_t cch = strlen(pszString); … … 145 145 */ 146 146 int rc; 147 int c uc = MultiByteToWideChar(CP_ACP, 0, pszString, -1, NULL, 0);148 if (c uc > 0)147 int cwc = MultiByteToWideChar(CP_ACP, 0, pszString, -1, NULL, 0); 148 if (cwc > 0) 149 149 { 150 150 /* 151 151 * Alloc space for result buffer. 152 152 */ 153 PRTU CS2 pucszString = (PRTUCS2)RTMemTmpAlloc(cuc * sizeof(RTUCS2));154 if (p ucszString)153 PRTUTF16 pwszString = (PRTUTF16)RTMemTmpAlloc(cwc * sizeof(RTUTF16)); 154 if (pwszString) 155 155 { 156 156 /* 157 157 * Do the translation. 158 158 */ 159 if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, p ucszString, cuc) > 0)159 if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, pwszString, cwc) > 0) 160 160 { 161 161 /* 162 * Now we got U CS-2. Convert to UTF-8162 * Now we got UTF-16, convert it to UTF-8 163 163 */ 164 rc = RT StrUcs2ToUtf8(ppszString, pucszString);165 RTMemTmpFree(p ucszString);164 rc = RTUtf16ToUtf8(pwszString, ppszString); 165 RTMemTmpFree(pwszString); 166 166 return rc; 167 167 } 168 RTMemTmpFree(p ucszString);168 RTMemTmpFree(pwszString); 169 169 /* translation error */ 170 170 int iLastErr = GetLastError();
Note:
See TracChangeset
for help on using the changeset viewer.