- Timestamp:
- Apr 18, 2019 1:40:11 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/nt/pathint-nt.cpp
r76553 r78200 276 276 * Straighten out all .. and uncessary . references and convert slashes. 277 277 */ 278 char szPath[RTPATH_MAX]; 279 int rc = RTPathAbs(pszPath, &szPath[cchPrefix - cchSkip], sizeof(szPath) - (cchPrefix - cchSkip)); 280 if (RT_FAILURE(rc)) 278 char szAbsPathBuf[RTPATH_MAX]; 279 size_t cbAbsPath = sizeof(szAbsPathBuf) - (cchPrefix - cchSkip); 280 char *pszAbsPath = szAbsPathBuf; 281 char *pszAbsPathFree = NULL; 282 int rc = RTPathAbsEx(NULL, pszPath, RTPATH_STR_F_STYLE_DOS, &pszAbsPath[cchPrefix - cchSkip], &cbAbsPath); 283 if (RT_SUCCESS(rc)) 284 { /* likely */ } 285 else if (rc == VERR_BUFFER_OVERFLOW) 286 { 287 unsigned cTries = 8; 288 size_t cbAbsPathBuf = RTPATH_MAX; 289 for (;;) 290 { 291 cbAbsPathBuf = RT_MAX(RT_ALIGN_Z((cchPrefix - cchSkip) + cbAbsPath + 32, 64), cbAbsPathBuf + 256); 292 if (cTries == 1) 293 cbAbsPathBuf = RT_MAX(cbAbsPathBuf, RTPATH_BIG_MAX * 2); 294 pszAbsPathFree = pszAbsPath = (char *)RTMemTmpAlloc(cbAbsPathBuf); 295 if (!pszAbsPath) 296 return VERR_NO_TMP_MEMORY; 297 298 cbAbsPath = cbAbsPathBuf - (cchPrefix - cchSkip); 299 rc = RTPathAbsEx(NULL, pszPath, RTPATH_STR_F_STYLE_DOS, &pszAbsPath[cchPrefix - cchSkip], &cbAbsPath); 300 if (RT_SUCCESS(rc)) 301 break; 302 RTMemTmpFree(pszAbsPathFree); 303 pszAbsPathFree = NULL; 304 if (rc != VERR_BUFFER_OVERFLOW) 305 return rc; 306 if (--cTries == 0) 307 return VERR_FILENAME_TOO_LONG; 308 } 309 } 310 else 281 311 return rc; 282 312 … … 284 314 * Add prefix and convert it to UTF16. 285 315 */ 286 memcpy(szPath, pszPrefix, cchPrefix); 287 return rtNtPathUtf8ToUniStr(pNtName, phRootDir, szPath); 316 memcpy(pszAbsPath, pszPrefix, cchPrefix); 317 rc = rtNtPathUtf8ToUniStr(pNtName, phRootDir, pszAbsPath); 318 319 if (pszAbsPathFree) 320 RTMemTmpFree(pszAbsPathFree); 321 return rc; 288 322 } 289 323 … … 406 440 * Straighten out all .. and unnecessary . references and convert slashes. 407 441 */ 408 char szAbsPath[RTPATH_MAX];442 /* UTF-16 -> UTF-8 (relative path) */ 409 443 char szRelPath[RTPATH_MAX]; 444 char *pszRelPathFree = NULL; 410 445 char *pszRelPath = szRelPath; 411 446 size_t cchRelPath; 412 447 rc = RTUtf16ToUtf8Ex(pwszWinPath, cwcWinPath, &pszRelPath, sizeof(szRelPath), &cchRelPath); 413 448 if (RT_SUCCESS(rc)) 414 rc = RTPathAbs(szRelPath, &szAbsPath[cchPrefix - cchSkip], sizeof(szAbsPath) - (cchPrefix - cchSkip)); 449 { /* likely */ } 450 else if (rc == VERR_BUFFER_OVERFLOW) 451 { 452 pszRelPath = NULL; 453 rc = RTUtf16ToUtf8Ex(pwszWinPath, cwcWinPath, &pszRelPath, 0, &cchRelPath); 454 if (RT_SUCCESS(rc)) 455 pszRelPathFree = pszRelPath; 456 } 415 457 if (RT_SUCCESS(rc)) 416 458 { 417 /* 418 * Add prefix 419 */ 420 memcpy(szAbsPath, pszPrefix, cchPrefix); 421 422 /* 423 * Remove trailing '.' that is used to specify no extension in the Win32/DOS world. 424 */ 425 size_t cchAbsPath = strlen(szAbsPath); 426 if ( cchAbsPath > 2 427 && szAbsPath[cchAbsPath - 1] == '.') 428 { 429 char const ch = szAbsPath[cchAbsPath - 2]; 430 if ( ch != '/' 431 && ch != '\\' 432 && ch != ':' 433 && ch != '.') 434 szAbsPath[--cchAbsPath] = '\0'; 435 } 436 437 /* 438 * Finally convert to UNICODE_STRING. 439 */ 440 return rtNtPathUtf8ToUniStr(pNtName, phRootDir, szAbsPath); 459 /* Relative -> Absolute. */ 460 char szAbsPathBuf[RTPATH_MAX]; 461 char *pszAbsPathFree = NULL; 462 char *pszAbsPath = szAbsPathBuf; 463 size_t cbAbsPath = sizeof(szAbsPathBuf) - (cchPrefix - cchSkip); 464 rc = RTPathAbsEx(NULL, szRelPath, RTPATH_STR_F_STYLE_DOS, &pszAbsPath[cchPrefix - cchSkip], &cbAbsPath); 465 if (RT_SUCCESS(rc)) 466 { /* likely */ } 467 else if (rc == VERR_BUFFER_OVERFLOW) 468 { 469 unsigned cTries = 8; 470 size_t cbAbsPathBuf = RTPATH_MAX; 471 for (;;) 472 { 473 cbAbsPathBuf = RT_MAX(RT_ALIGN_Z((cchPrefix - cchSkip) + cbAbsPath + 32, 64), cbAbsPathBuf + 256); 474 if (cTries == 1) 475 cbAbsPathBuf = RT_MAX(cbAbsPathBuf, RTPATH_BIG_MAX * 2); 476 pszAbsPathFree = pszAbsPath = (char *)RTMemTmpAlloc(cbAbsPathBuf); 477 if (!pszAbsPath) 478 { 479 rc = VERR_NO_TMP_MEMORY; 480 break; 481 } 482 483 cbAbsPath = cbAbsPathBuf - (cchPrefix - cchSkip); 484 rc = RTPathAbsEx(NULL, szRelPath, RTPATH_STR_F_STYLE_DOS, &pszAbsPath[cchPrefix - cchSkip], &cbAbsPath); 485 if (RT_SUCCESS(rc)) 486 break; 487 488 RTMemTmpFree(pszAbsPathFree); 489 pszAbsPathFree = NULL; 490 if (rc != VERR_BUFFER_OVERFLOW) 491 break; 492 if (--cTries == 0) 493 { 494 rc = VERR_FILENAME_TOO_LONG; 495 break; 496 } 497 } 498 499 } 500 if (pszRelPathFree) 501 RTStrFree(pszRelPathFree); 502 503 if (RT_SUCCESS(rc)) 504 { 505 /* 506 * Add prefix 507 */ 508 memcpy(pszAbsPath, pszPrefix, cchPrefix); 509 510 /* 511 * Remove trailing '.' that is used to specify no extension in the Win32/DOS world. 512 */ 513 size_t cchAbsPath = strlen(pszAbsPath); 514 if ( cchAbsPath > 2 515 && pszAbsPath[cchAbsPath - 1] == '.') 516 { 517 char const ch = pszAbsPath[cchAbsPath - 2]; 518 if ( ch != '/' 519 && ch != '\\' 520 && ch != ':' 521 && ch != '.') 522 pszAbsPath[--cchAbsPath] = '\0'; 523 } 524 525 /* 526 * Finally convert to UNICODE_STRING. 527 */ 528 rc = rtNtPathUtf8ToUniStr(pNtName, phRootDir, pszAbsPath); 529 530 if (pszAbsPathFree) 531 RTMemTmpFree(pszAbsPathFree); 532 } 441 533 } 442 534 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.