Changeset 74460 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Sep 25, 2018 3:42:33 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 125313
- Location:
- trunk/src/VBox/Runtime/r3/win
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/dir-win.cpp
r69111 r74460 58 58 */ 59 59 PRTUTF16 pwszString; 60 rc = RT StrToUtf16(pszPath, &pwszString);60 rc = RTPathWinFromUtf8(&pwszString, pszPath, 0 /*fFlags*/); 61 61 AssertRC(rc); 62 62 if (RT_SUCCESS(rc)) … … 89 89 } 90 90 91 RT Utf16Free(pwszString);91 RTPathWinFree(pwszString); 92 92 } 93 93 } … … 109 109 */ 110 110 PRTUTF16 pwszString; 111 int rc = RT StrToUtf16(pszPath, &pwszString);111 int rc = RTPathWinFromUtf8(&pwszString, pszPath, 0 /*fFlags*/); 112 112 AssertRC(rc); 113 113 if (RT_SUCCESS(rc)) … … 121 121 rc = RTErrConvertFromWin32(GetLastError()); 122 122 123 RT Utf16Free(pwszString);123 RTPathWinFree(pwszString); 124 124 } 125 125 -
trunk/src/VBox/Runtime/r3/win/direnum-win.cpp
r73097 r74460 82 82 * Attempt opening the search. 83 83 */ 84 int rc = VINF_SUCCESS;85 84 PRTUTF16 pwszName; 86 rc = RTStrToUtf16(pszPathBuf, &pwszName);85 int rc = RTPathWinFromUtf8(pwszPathBuf, &pwszName, 0 /*fFlags*/); 87 86 if (RT_SUCCESS(rc)) 88 87 { … … 100 99 rc = RTErrConvertFromWin32(GetLastError()); 101 100 } 102 RT Utf16Free(pwszName);101 RTPathWinFree(pwszName); 103 102 } 104 103 -
trunk/src/VBox/Runtime/r3/win/fileio-win.cpp
r74368 r74460 289 289 /* 290 290 * Open/Create the file. 291 * 292 * When opening files with paths longer than 260 chars, CreateFileW() will fail, unless 293 * you explicitly specify a prefix (see [1], RTPATH_WIN_LONG_PATH_PREFIX). 294 * 295 * Note: Relative paths are not supported, so check for this. 296 * 297 * [1] https://docs.microsoft.com/en-gb/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation 298 */ 299 PRTUTF16 pwszFilename = NULL; 300 #if 0 /** @todo r=bird: This stuff just isn't up to scratch. Sorry. RTStrAPrintf2? WTF?!? When using the long path prefix, 301 * the path is just passed right thru to the NT API, so we need to fix unix slashes, resolve '.' and '..' components, 302 * and probably also get rid of extra slashes. Finally, the 260 limit (there is a \#define for it btw) actually 303 * applies to the converted filename (UTF-16), not the UTF-8 one, so this may break stuff (think asian languages) 304 * that isn't over the 260 limit. */ 305 if (g_enmWinVer >= kRTWinOSType_XP) /* Not sure since when the prefix is available, so play safe by default. */ 306 { 307 #define RTPATH_WIN_LONG_PATH_PREFIX "\\\\?\\" 308 309 if ( strlen(pszFilename) > 260 310 && !RTPathStartsWith(pszFilename, RTPATH_WIN_LONG_PATH_PREFIX) 311 && RTPathStartsWithRoot(pszFilename)) 291 */ 292 PRTUTF16 pwszFilename; 293 rc = RTPathWinFromUtf8(&pwszFilename, pszFilename, 0 /*fFlags*/); 294 if (RT_SUCCESS(rc)) 295 { 296 HANDLE hFile = CreateFileW(pwszFilename, 297 dwDesiredAccess, 298 dwShareMode, 299 pSecurityAttributes, 300 dwCreationDisposition, 301 dwFlagsAndAttributes, 302 NULL); 303 if (hFile != INVALID_HANDLE_VALUE) 312 304 { 313 char *pszFilenameWithPrefix = RTStrAPrintf2("%s%s", RTPATH_WIN_LONG_PATH_PREFIX, pszFilename); 314 if (pszFilenameWithPrefix) 315 { 316 rc = RTStrToUtf16(pszFilenameWithPrefix, &pwszFilename); 317 RTStrFree(pszFilenameWithPrefix); 318 } 319 else 320 rc = VERR_NO_MEMORY; 305 bool fCreated = dwCreationDisposition == CREATE_ALWAYS 306 || dwCreationDisposition == CREATE_NEW 307 || (dwCreationDisposition == OPEN_ALWAYS && GetLastError() == 0); 308 309 /* 310 * Turn off indexing of directory through Windows Indexing Service. 311 */ 312 if ( fCreated 313 && (fOpen & RTFILE_O_NOT_CONTENT_INDEXED)) 314 { 315 if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) 316 rc = RTErrConvertFromWin32(GetLastError()); 317 } 318 /* 319 * Do we need to truncate the file? 320 */ 321 else if ( !fCreated 322 && (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK)) 323 == (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE)) 324 { 325 if (!SetEndOfFile(hFile)) 326 rc = RTErrConvertFromWin32(GetLastError()); 327 } 328 if (RT_SUCCESS(rc)) 329 { 330 *pFile = (RTFILE)hFile; 331 Assert((HANDLE)*pFile == hFile); 332 RTPathWinFree(pwszFilename); 333 return VINF_SUCCESS; 334 } 335 336 CloseHandle(hFile); 321 337 } 322 #undef RTPATH_WIN_LONG_PATH_PREFIX 323 } 324 325 if ( RT_SUCCESS(rc) 326 && !pwszFilename) 327 #endif 328 rc = RTStrToUtf16(pszFilename, &pwszFilename); 329 330 if (RT_FAILURE(rc)) 331 return rc; 332 333 HANDLE hFile = CreateFileW(pwszFilename, 334 dwDesiredAccess, 335 dwShareMode, 336 pSecurityAttributes, 337 dwCreationDisposition, 338 dwFlagsAndAttributes, 339 NULL); 340 if (hFile != INVALID_HANDLE_VALUE) 341 { 342 bool fCreated = dwCreationDisposition == CREATE_ALWAYS 343 || dwCreationDisposition == CREATE_NEW 344 || (dwCreationDisposition == OPEN_ALWAYS && GetLastError() == 0); 345 346 /* 347 * Turn off indexing of directory through Windows Indexing Service. 348 */ 349 if ( fCreated 350 && (fOpen & RTFILE_O_NOT_CONTENT_INDEXED)) 351 { 352 if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) 353 rc = RTErrConvertFromWin32(GetLastError()); 354 } 355 /* 356 * Do we need to truncate the file? 357 */ 358 else if ( !fCreated 359 && (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK)) 360 == (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE)) 361 { 362 if (!SetEndOfFile(hFile)) 363 rc = RTErrConvertFromWin32(GetLastError()); 364 } 365 if (RT_SUCCESS(rc)) 366 { 367 *pFile = (RTFILE)hFile; 368 Assert((HANDLE)*pFile == hFile); 369 RTUtf16Free(pwszFilename); 370 return VINF_SUCCESS; 371 } 372 373 CloseHandle(hFile); 374 } 375 else 376 rc = RTErrConvertFromWin32(GetLastError()); 377 RTUtf16Free(pwszFilename); 338 else 339 rc = RTErrConvertFromWin32(GetLastError()); 340 RTPathWinFree(pwszFilename); 341 } 378 342 return rc; 379 343 } … … 1049 1013 { 1050 1014 PRTUTF16 pwszFilename; 1051 int rc = RT StrToUtf16(pszFilename, &pwszFilename);1015 int rc = RTPathWinFromUtf8(&pwszFilename, pszFilename, 0 /*fFlags*/); 1052 1016 if (RT_SUCCESS(rc)) 1053 1017 { 1054 1018 if (!DeleteFileW(pwszFilename)) 1055 1019 rc = RTErrConvertFromWin32(GetLastError()); 1056 RT Utf16Free(pwszFilename);1020 RTPathWinFree(pwszFilename); 1057 1021 } 1058 1022 -
trunk/src/VBox/Runtime/r3/win/fs-win.cpp
r69111 r74460 281 281 } 282 282 283 RTUtf16Free(pwszFsRoot);283 rtFsFreeRoot(pwszFsRoot); 284 284 return rc; 285 285 } … … 333 333 } 334 334 335 RTUtf16Free(pwszFsRoot);335 rtFsFreeRoot(pwszFsRoot); 336 336 return rc; 337 337 } … … 379 379 */ 380 380 PRTUTF16 pwszFsPath; 381 int rc = RT StrToUtf16(pszFsPath, &pwszFsPath);381 int rc = RTPathWinFromUtf8(&pwszFsPath, pszFsPath, 0 /*fFlags*/); 382 382 if (RT_SUCCESS(rc)) 383 383 { … … 422 422 else 423 423 rc = RTErrConvertFromWin32(GetLastError()); 424 RT Utf16Free(pwszFsPath);424 RTPathWinFree(pwszFsPath); 425 425 } 426 426 return rc; -
trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp
r74458 r74460 69 69 * Convert to UTF-16 and make sure it got a .DLL suffix. 70 70 */ 71 /** @todo Implement long path support for native DLL loading on windows. @bugref{9248} */ 71 72 int rc; 72 73 RTUTF16 *pwszNative = NULL; -
trunk/src/VBox/Runtime/r3/win/localipc-win.cpp
r73097 r74460 366 366 * 367 367 * @returns IPRT status code. 368 * @param pszName The user supplied name. 368 * @param pszName The user supplied name. ASSUMES reasonable length 369 * for now, so no long path prefixing needed. 369 370 * @param pwszFullName The output buffer. 370 371 * @param cwcFullName The output buffer size excluding the terminator. -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r69111 r74460 63 63 */ 64 64 PRTUTF16 pwszPath; 65 int rc = RTStrToUtf16(pszPath, &pwszPath); 66 if (!RT_SUCCESS(rc)) 67 return (rc); 68 69 LPWSTR lpFile; 70 WCHAR wsz[RTPATH_MAX]; 71 rc = GetFullPathNameW((LPCWSTR)pwszPath, RT_ELEMENTS(wsz), &wsz[0], &lpFile); 72 if (rc > 0 && rc < RT_ELEMENTS(wsz)) 73 { 74 /* Check that it exists. (Use RTPathAbs() to just resolve the name.) */ 75 DWORD dwAttr = GetFileAttributesW(wsz); 76 if (dwAttr != INVALID_FILE_ATTRIBUTES) 77 rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL); 65 int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/); 66 if (RT_SUCCESS(rc)) 67 { 68 LPWSTR lpFile; 69 WCHAR wsz[RTPATH_MAX]; 70 rc = GetFullPathNameW((LPCWSTR)pwszPath, RT_ELEMENTS(wsz), &wsz[0], &lpFile); 71 if (rc > 0 && rc < RT_ELEMENTS(wsz)) 72 { 73 /* Check that it exists. (Use RTPathAbs() to just resolve the name.) */ 74 DWORD dwAttr = GetFileAttributesW(wsz); 75 if (dwAttr != INVALID_FILE_ATTRIBUTES) 76 rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL); 77 else 78 rc = RTErrConvertFromWin32(GetLastError()); 79 } 80 else if (rc <= 0) 81 rc = RTErrConvertFromWin32(GetLastError()); 78 82 else 79 rc = RTErrConvertFromWin32(GetLastError()); 80 } 81 else if (rc <= 0) 82 rc = RTErrConvertFromWin32(GetLastError()); 83 else 84 rc = VERR_FILENAME_TOO_LONG; 85 86 RTUtf16Free(pwszPath); 87 83 rc = VERR_FILENAME_TOO_LONG; 84 85 RTPathWinFree(pwszPath); 86 } 88 87 return rc; 89 88 } … … 442 441 */ 443 442 PRTUTF16 pwszPath; 444 int rc = RT StrToUtf16(pszPath, &pwszPath);443 int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/); 445 444 if (RT_SUCCESS(rc)) 446 445 { … … 523 522 } 524 523 525 RT Utf16Free(pwszPath);524 RTPathWinFree(pwszPath); 526 525 } 527 526 … … 553 552 */ 554 553 PRTUTF16 pwszSrc; 555 int rc = RT StrToUtf16(pszSrc, &pwszSrc);554 int rc = RTPathWinFromUtf8(&pwszSrc, pszSrc, 0 /*fFlags*/); 556 555 if (RT_SUCCESS(rc)) 557 556 { 558 557 PRTUTF16 pwszDst; 559 rc = RT StrToUtf16(pszDst, &pwszDst);558 rc = RTPathWinFromUtf8(&pwszDst, pszDst, 0 /*fFlags*/); 560 559 if (RT_SUCCESS(rc)) 561 560 { … … 586 585 } 587 586 } 588 RT Utf16Free(pwszDst);589 } 590 RT Utf16Free(pwszSrc);587 RTPathWinFree(pwszDst); 588 } 589 RTPathWinFree(pwszSrc); 591 590 } 592 591 return rc; … … 642 641 DWORD dwAttr; 643 642 PRTUTF16 pwszPath; 644 int rc = RT StrToUtf16(pszPath, &pwszPath);643 int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/); 645 644 if (RT_SUCCESS(rc)) 646 645 { 647 646 dwAttr = GetFileAttributesW(pwszPath); 648 RT Utf16Free(pwszPath);647 RTPathWinFree(pwszPath); 649 648 } 650 649 else … … 702 701 */ 703 702 PRTUTF16 pwszPath; 704 int rc = RT StrToUtf16(pszPath, &pwszPath);703 int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/); 705 704 if (RT_SUCCESS(rc)) 706 705 { … … 716 715 rc = RTErrConvertFromWin32(GetLastError()); 717 716 718 RT Utf16Free(pwszPath);717 RTPathWinFree(pwszPath); 719 718 } 720 719 return rc; -
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r73097 r74460 2119 2119 * Replace the executable string. 2120 2120 */ 2121 RT Utf16Free(*ppwszExec);2121 RTPathWinFree(*ppwszExec); 2122 2122 *ppwszExec = NULL; 2123 rc = RT StrToUtf16(szRealExec, ppwszExec);2123 rc = RTPathWinFromUtf8(ppwszExec, szRealExec, 0 /*fFlags*/); 2124 2124 } 2125 2125 else if (rc == VERR_END_OF_STRING) … … 2365 2365 { 2366 2366 PRTUTF16 pwszExec; 2367 rc = RT StrToUtf16(pszExec, &pwszExec);2367 rc = RTPathWinFromUtf8(&pwszExec, pszExec, 0 /*fFlags*/); 2368 2368 if (RT_SUCCESS(rc)) 2369 2369 { … … 2449 2449 rc = VINF_SUCCESS; 2450 2450 } 2451 RT Utf16Free(pwszExec);2451 RTPathWinFree(pwszExec); 2452 2452 } 2453 2453 RTUtf16Free(pwszCmdLine); -
trunk/src/VBox/Runtime/r3/win/symlink-win.cpp
r69111 r74460 152 152 */ 153 153 PRTUTF16 pwszNativeSymlink; 154 int rc = RT StrToUtf16(pszSymlink, &pwszNativeSymlink);154 int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/); 155 155 if (RT_SUCCESS(rc)) 156 156 { 157 157 PRTUTF16 pwszNativeTarget; 158 rc = RT StrToUtf16(pszTarget, &pwszNativeTarget);158 rc = RTPathWinFromUtf8(&pwszNativeTarget, pszTarget, 0 /*fFlags*/); 159 159 if (RT_SUCCESS(rc)) 160 160 { … … 219 219 rc = RTErrConvertFromWin32(GetLastError()); 220 220 221 RT Utf16Free(pwszNativeTarget);221 RTPathWinFree(pwszNativeTarget); 222 222 } 223 RT Utf16Free(pwszNativeSymlink);223 RTPathWinFree(pwszNativeSymlink); 224 224 } 225 225 … … 237 237 */ 238 238 PRTUTF16 pwszNativeSymlink; 239 int rc = RT StrToUtf16(pszSymlink, &pwszNativeSymlink);239 int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/); 240 240 if (RT_SUCCESS(rc)) 241 241 { … … 266 266 else 267 267 rc = RTErrConvertFromWin32(GetLastError()); 268 RT Utf16Free(pwszNativeSymlink);268 RTPathWinFree(pwszNativeSymlink); 269 269 } 270 270 … … 294 294 AssertPtr(ppszTarget); 295 295 PRTUTF16 pwszNativeSymlink; 296 int rc = RT StrToUtf16(pszSymlink, &pwszNativeSymlink);296 int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/); 297 297 if (RT_SUCCESS(rc)) 298 298 { … … 345 345 else 346 346 rc = RTErrConvertFromWin32(GetLastError()); 347 RT Utf16Free(pwszNativeSymlink);347 RTPathWinFree(pwszNativeSymlink); 348 348 } 349 349
Note:
See TracChangeset
for help on using the changeset viewer.