- Timestamp:
- Apr 9, 2019 1:30:42 AM (6 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/include/internal/dir.h
r76585 r78050 175 175 * @param pDir The directory to open. The pszPath member contains the 176 176 * path to the directory. 177 * @param pszPathBuf Pointer to a RTPATH_MAX sized buffer containing178 * pszPath. Find-first style systems can use this179 * to setup the wildcard expression.180 177 * @param hRelativeDir The directory @a pvNativeRelative is relative, 181 178 * ~(uintptr_t)0 if absolute. … … 183 180 * we're to use (consume) hRelativeDir. 184 181 */ 185 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf,uintptr_t hRelativeDir, void *pvNativeRelative);182 int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative); 186 183 187 184 /** -
trunk/src/VBox/Runtime/r3/dir.cpp
r76553 r78050 527 527 * As a sideeffect we also validate the path here. 528 528 */ 529 char szRealPath[RTPATH_MAX + 1]; 530 int rc; 529 char *pszAbsPath; 531 530 size_t cbFilter; /* includes '\0' (thus cb and not cch). */ 532 531 size_t cucFilter0; /* includes U+0. */ … … 544 543 545 544 cbFilter = cucFilter0 = 0; 546 rc = RTPathAbs(pszPath, szRealPath, sizeof(szRealPath) - 1);545 pszAbsPath = RTPathAbsDup(pszPath); 547 546 } 548 547 else … … 558 557 return VERR_NO_MEMORY; 559 558 pszTmp[pszFilter - pszPath] = '\0'; 560 rc = RTPathAbs(pszTmp, szRealPath, sizeof(szRealPath) - 1);559 pszAbsPath = RTPathAbsDup(pszTmp); 561 560 RTStrFree(pszTmp); 562 561 } 563 562 else 564 rc = RTPathReal(".", szRealPath, sizeof(szRealPath) - 1);563 pszAbsPath = RTPathAbsDup("."); 565 564 fDirSlash = true; 566 565 } 567 if (RT_FAILURE(rc)) 568 return rc; 569 570 /* add trailing '/' if missing. */ 571 size_t cchRealPath = strlen(szRealPath); 572 if (!RTPATH_IS_SEP(szRealPath[cchRealPath - 1])) 573 { 574 szRealPath[cchRealPath++] = RTPATH_SLASH; 575 szRealPath[cchRealPath] = '\0'; 576 } 566 if (!pszAbsPath) 567 return VERR_NO_MEMORY; 568 569 577 570 578 571 /* … … 582 575 * thus the horrible ugliness here. Solaris uses d_name[1] for instance. 583 576 */ 584 size_t cbDir = rtDirNativeGetStructSize(szRealPath); 585 size_t const cbAllocated = cbDir 586 + cucFilter0 * sizeof(RTUNICP) 587 + cbFilter 588 + cchRealPath + 1 + 4; 577 size_t const cchAbsPath = strlen(pszAbsPath); 578 size_t const cchAbsPathExtra = !RTPATH_IS_SEP(pszAbsPath[cchAbsPath - 1]) ? 1 : 0; /* add trailing '/' if missing */ 579 size_t const cbDir = rtDirNativeGetStructSize(pszAbsPath); 580 size_t const cbAllocated = cbDir 581 + cucFilter0 * sizeof(RTUNICP) 582 + cbFilter 583 + cchAbsPath + cchAbsPathExtra + 1 + 4; 589 584 PRTDIRINTERNAL pDir = (PRTDIRINTERNAL)RTMemAllocZ(cbAllocated); 590 585 if (!pDir) 586 { 587 RTStrFree(pszAbsPath); 591 588 return VERR_NO_MEMORY; 589 } 592 590 uint8_t *pb = (uint8_t *)pDir + cbDir; 593 591 … … 598 596 { 599 597 pDir->puszFilter = (PRTUNICP)pb; 600 rc= RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter);601 AssertRC(rc );598 int rc2 = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter); 599 AssertRC(rc2); 602 600 pb += cucFilter0 * sizeof(RTUNICP); 603 601 pDir->pszFilter = (char *)memcpy(pb, pszFilter, cbFilter); … … 629 627 break; 630 628 } 631 pDir->cchPath = cchRealPath; 632 pDir->pszPath = (char *)memcpy(pb, szRealPath, cchRealPath + 1); 633 Assert(pb - (uint8_t *)pDir + cchRealPath + 1 <= cbAllocated); 629 pDir->cchPath = cchAbsPath + cchAbsPathExtra; 630 pDir->pszPath = (char *)memcpy(pb, pszAbsPath, cchAbsPath); 631 pb[cchAbsPath] = RTPATH_SLASH; 632 pb[cchAbsPath + cchAbsPathExtra] = '\0'; 633 Assert(pb - (uint8_t *)pDir + cchAbsPath + cchAbsPathExtra + 1 <= cbAllocated); 634 634 pDir->pszName = NULL; 635 635 pDir->cchName = 0; … … 641 641 * Hand it over to the native part. 642 642 */ 643 rc = rtDirNativeOpen(pDir, szRealPath, hRelativeDir, pvNativeRelative);643 int rc = rtDirNativeOpen(pDir, hRelativeDir, pvNativeRelative); 644 644 if (RT_SUCCESS(rc)) 645 645 *phDir = pDir; 646 646 else 647 647 RTMemFree(pDir); 648 648 RTStrFree(pszAbsPath); 649 649 return rc; 650 650 } -
trunk/src/VBox/Runtime/r3/nt/direnum-r3-nt.cpp
r76553 r78050 83 83 84 84 85 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf,uintptr_t hRelativeDir, void *pvNativeRelative)85 int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative) 86 86 { 87 87 /* … … 130 130 { 131 131 if (pvNativeRelative == NULL) 132 rc = RTNtPathOpenDir(p szPathBuf,132 rc = RTNtPathOpenDir(pDir->pszPath, 133 133 FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES | FILE_TRAVERSE | SYNCHRONIZE, 134 134 FILE_SHARE_READ | FILE_SHARE_WRITE, -
trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp
r76895 r78050 242 242 243 243 244 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative) 245 { 246 NOREF(pszPathBuf); /* only used on windows */ 244 int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative) 245 { 247 246 NOREF(hRelativeDir); 248 247 NOREF(pvNativeRelative); -
trunk/src/VBox/Runtime/r3/win/direnum-win.cpp
r76553 r78050 51 51 52 52 53 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf,uintptr_t hRelativeDir, void *pvNativeRelative))53 int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative)) 54 54 { 55 55 RT_NOREF(hRelativeDir, pvNativeRelative); … … 62 62 * it when adding the wildcard expression. 63 63 */ 64 /** @todo the pszPathBuf argument was removed in order to support paths longer than RTPATH_MAX. Rewrite this code. */ 64 65 size_t cbExpr; 65 66 const char *pszExpr;
Note:
See TracChangeset
for help on using the changeset viewer.