Changeset 3005 for trunk/src/lib/nt/ntdir.c
- Timestamp:
- Nov 6, 2016, 1:07:37 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/ntdir.c
r3004 r3005 115 115 BirdDir_T *birdDirOpenFromHandle(void *pvHandle, const void *pvReserved, unsigned fFlags) 116 116 { 117 if (!pvReserved )117 if (!pvReserved && !(fFlags & BIRDDIR_F_STATIC_ALLOC)) 118 118 { 119 119 /* … … 138 138 } 139 139 else 140 { 141 assert(!(fFlags & BIRDDIR_F_STATIC_ALLOC)); 140 142 assert(pvReserved == NULL); 141 birdSetErrnoToNoMem(); 143 } 144 birdSetErrnoToInvalidArg(); 145 return NULL; 146 } 147 148 149 /** 150 * Special API that takes a preallocated BirdDir_T and can be called again 151 * without involving birdDirClose. 152 * 153 * 154 */ 155 BirdDir_T *birdDirOpenFromHandleWithReuse(BirdDir_T *pDir, void *pvHandle, const void *pvReserved, unsigned fFlags) 156 { 157 if (!pvReserved) 158 { 159 /* 160 * Allocate and initialize the directory enum handle. 161 */ 162 if (pDir) 163 { 164 if (pDir->uMagic == BIRD_DIR_MAGIC) 165 { 166 if ( (pDir->fFlags & BIRDDIR_F_CLOSE_HANDLE) 167 && pDir->pvHandle != INVALID_HANDLE_VALUE) 168 birdCloseFile((HANDLE)pDir->pvHandle); 169 } 170 else 171 { 172 pDir->cbBuf = 0; 173 pDir->pabBuf = NULL; 174 pDir->uMagic = BIRD_DIR_MAGIC; 175 } 176 pDir->pvHandle = pvHandle; 177 pDir->fFlags = fFlags; 178 pDir->uDev = 0; 179 pDir->offPos = 0; 180 pDir->fHaveData = 0; 181 pDir->fFirst = 1; 182 pDir->iInfoClass = fFlags & BIRDDIR_F_EXTRA_INFO ? MyFileIdFullDirectoryInformation : MyFileNamesInformation; 183 pDir->offBuf = 0; 184 return pDir; 185 } 186 } 187 else 188 assert(pvReserved == NULL); 189 birdSetErrnoToInvalidArg(); 142 190 return NULL; 143 191 } … … 174 222 pDir->uDev = 0; 175 223 176 /*177 * Allocate a buffer.178 */179 pDir->cbBuf = 0x20000;180 pDir->pabBuf = birdMemAlloc(pDir->cbBuf);181 224 if (!pDir->pabBuf) 182 return birdSetErrnoToNoMem(); 225 { 226 /* 227 * Allocate a buffer. 228 * 229 * Better not exceed 64KB or CIFS may throw a fit. Also, on win10/64 230 * here there is a noticable speedup when going one byte below 64KB. 231 */ 232 pDir->cbBuf = 0xffe0; 233 pDir->pabBuf = birdMemAlloc(pDir->cbBuf); 234 if (!pDir->pabBuf) 235 return birdSetErrnoToNoMem(); 236 } 183 237 184 238 pDir->fFirst = 0; … … 548 602 * Implements closedir(). 549 603 */ 550 int 604 int birdDirClose(BirdDir_T *pDir) 551 605 { 552 606 if (!pDir || pDir->uMagic != BIRD_DIR_MAGIC) … … 559 613 birdMemFree(pDir->pabBuf); 560 614 pDir->pabBuf = NULL; 561 birdMemFree(pDir); 615 if (!(pDir->fFlags & BIRDDIR_F_STATIC_ALLOC)) 616 birdMemFree(pDir); 562 617 563 618 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.