- Timestamp:
- Jun 3, 2008 3:32:05 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/include/internal/dir.h
r8245 r9355 101 101 /** What opendir() returned. */ 102 102 DIR *pDir; 103 /** The max size of the d_name member. 104 * This includes the 0 terminator of course.*/ 105 size_t cbMaxName; 103 106 /** Find data buffer. 104 107 * fDataUnread indicates valid data. */ -
trunk/src/VBox/Runtime/r3/dir.cpp
r8245 r9355 34 34 *******************************************************************************/ 35 35 #define LOG_GROUP RTLOGGROUP_DIR 36 #ifdef RT_OS_WINDOWS 36 #ifdef RT_OS_WINDOWS /* PORTME: Assumes everyone else is using dir-posix.cpp */ 37 37 # include <Windows.h> 38 38 #else 39 39 # include <dirent.h> 40 # include <unistd.h> 40 41 #endif 41 42 … … 528 529 char szRealPath[RTPATH_MAX + 1]; 529 530 int rc; 530 size_t c chFilter; /* includes '\0'. */531 size_t cucFilter ;/* includes U+0. */531 size_t cbFilter; /* includes '\0' (thus cb and not cch). */ 532 size_t cucFilter0; /* includes U+0. */ 532 533 if (!pszFilter) 533 534 { 534 c chFilter = cucFilter= 0;535 cbFilter = cucFilter0 = 0; 535 536 rc = RTPathReal(pszPath, szRealPath, sizeof(szRealPath) - 1); 536 537 } 537 538 else 538 539 { 539 c chFilter = strlen(pszFilter) + 1;540 cucFilter = RTStrUniLen(pszFilter) + 1;540 cbFilter = strlen(pszFilter) + 1; 541 cucFilter0 = RTStrUniLen(pszFilter) + 1; 541 542 542 543 if (pszFilter != pszPath) … … 566 567 /* 567 568 * Allocate and initialize the directory handle. 568 */ 569 PRTDIR pDir = (PRTDIR)RTMemAlloc(sizeof(RTDIR) + cchRealPath + 1 + 4 + cchFilter + cucFilter * sizeof(RTUNICP)); 569 * 570 * The posix definition of Data.d_name allows it to be < NAME_MAX + 1, 571 * thus the horrible uglyness here. Solaris uses d_name[1] for instance. 572 */ 573 #ifndef RT_OS_WINDOWS 574 long cbNameMax = pathconf(szRealPath, _PC_NAME_MAX); 575 if (cbNameMax < NAME_MAX) /* This is plain paranoia, but it doesn't hurt. */ 576 cbNameMax = NAME_MAX; 577 size_t cbDir = RT_OFFSETOF(RTDIR, Data.d_name[cbNameMax + 1]); 578 if (cbDir < sizeof(RTDIR)) /* Ditto. */ 579 cbDir = sizeof(RTDIR); 580 cbDir = RT_ALIGN_Z(cbDir, 8); 581 #else 582 size_t cbDir = sizeof(RTDIR); 583 #endif 584 size_t const cbAllocated = cbDir 585 + cucFilter0 * sizeof(RTUNICP) 586 + cbFilter 587 + cchRealPath + 1 + 4; 588 PRTDIR pDir = (PRTDIR)RTMemAlloc(cbAllocated); 570 589 if (!pDir) 571 590 return VERR_NO_MEMORY; 591 uint8_t *pb = (uint8_t *)pDir + cbDir; 572 592 573 593 /* initialize it */ 574 594 pDir->u32Magic = RTDIR_MAGIC; 575 if (c chFilter)576 { 577 pDir->puszFilter = (PRTUNICP) (pDir + 1);578 rc = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter , &pDir->cucFilter);595 if (cbFilter) 596 { 597 pDir->puszFilter = (PRTUNICP)pb; 598 rc = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter); 579 599 AssertRC(rc); 580 pDir->pszFilter = (char *)memcpy(pDir->puszFilter + cucFilter, pszFilter, cchFilter); 581 pDir->cchFilter = cchFilter - 1; 600 pb += cucFilter0 * sizeof(RTUNICP); 601 pDir->pszFilter = (char *)memcpy(pb, pszFilter, cbFilter); 602 pDir->cchFilter = cbFilter - 1; 603 pb += cbFilter; 582 604 } 583 605 else … … 606 628 } 607 629 pDir->cchPath = cchRealPath; 608 pDir->pszPath = (char *)memcpy( (char *)(pDir + 1) + cucFilter * sizeof(RTUNICP) + cchFilter,609 szRealPath, cchRealPath + 1);630 pDir->pszPath = (char *)memcpy(pb, szRealPath, cchRealPath + 1); 631 Assert(pb - (uint8_t *)pDir + cchRealPath + 1 <= cbAllocated); 610 632 pDir->fDataUnread = false; 611 633 #ifndef RT_DONT_CONVERT_FILENAMES 612 634 pDir->pszName = NULL; 613 635 pDir->cchName = 0; 636 #endif 637 #ifndef RT_OS_WINDOWS 638 pDir->cbMaxName = cbDir - RT_OFFSETOF(RTDIR, Data.d_name); 614 639 #endif 615 640 -
trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp
r8245 r9355 143 143 */ 144 144 pDir->fDataUnread = false; 145 memset(&pDir->Data, 0, sizeof(pDir->Data)); /* not strictly necessary */ 145 memset(&pDir->Data, 0, RT_OFFSETOF(RTDIR, Data.d_name)); /* not strictly necessary */ 146 memset(&pDir->Data.d_name[0], 0, pDir->cbMaxName); 146 147 } 147 148 else
Note:
See TracChangeset
for help on using the changeset viewer.