static PLISTFILE_MAP ListMap_InsertName(PLISTFILE_MAP pListMap, const char * szFileName, size_t nLength) { PLISTFILE_ENTRY pListEntry; size_t cbToAllocate; size_t cbEntrySize; // Make sure there is enough space in the list map cbEntrySize = sizeof(LISTFILE_ENTRY) + nLength; cbEntrySize = ALIGN_TO_SIZE(cbEntrySize, 8); if((pListMap->cbBuffer + cbEntrySize) > pListMap->cbBufferMax) { cbToAllocate = sizeof(LISTFILE_MAP) + (pListMap->cbBufferMax * 3) / 2; pListMap = (PLISTFILE_MAP)CASC_REALLOC(BYTE, pListMap, cbToAllocate); if(pListMap == NULL) return NULL; pListMap->cbBufferMax = (pListMap->cbBufferMax * 3) / 2; } // Get the pointer to the first entry pListEntry = (PLISTFILE_ENTRY)((LPBYTE)(pListMap + 1) + pListMap->cbBuffer); pListEntry->FileNameHash = CalcFileNameHash(szFileName); pListEntry->cbEntrySize = (DWORD)cbEntrySize; // Copy the file name to the entry memcpy(pListEntry->szFileName, szFileName, nLength); pListEntry->szFileName[nLength] = 0; // Move the next entry pListMap->cbBuffer += cbEntrySize; pListMap->nEntries++; return pListMap; }
static PLISTFILE_MAP ListMap_InsertName(PLISTFILE_MAP pListMap, const char * szFileName, size_t nLength) { PLISTFILE_ENTRY pListEntry; char szFileName2[MAX_PATH+1]; size_t cbToAllocate; size_t cbEntrySize; uint32_t dwHashHigh = 0; uint32_t dwHashLow = 0; // Make sure there is enough space in the list map cbEntrySize = sizeof(LISTFILE_ENTRY) + nLength; cbEntrySize = ALIGN_TO_SIZE(cbEntrySize, 8); if((pListMap->cbBuffer + cbEntrySize) > pListMap->cbBufferMax) { cbToAllocate = sizeof(LISTFILE_MAP) + (pListMap->cbBufferMax * 3) / 2; pListMap = (PLISTFILE_MAP)CASC_REALLOC(BYTE, pListMap, cbToAllocate); if(pListMap == NULL) return NULL; pListMap->cbBufferMax = (pListMap->cbBufferMax * 3) / 2; } // Get the pointer to the first entry pListEntry = (PLISTFILE_ENTRY)((LPBYTE)(pListMap + 1) + pListMap->cbBuffer); // Get the name hash NormalizeFileName_UpperBkSlash(szFileName, szFileName2); hashlittle2(szFileName2, nLength, &dwHashHigh, &dwHashLow); // Calculate the HASH value of the normalized file name pListEntry->FileNameHash = ((ULONGLONG)dwHashHigh << 0x20) | dwHashLow; pListEntry->cbEntrySize = (DWORD)cbEntrySize; memcpy(pListEntry->szFileName, szFileName, nLength); pListEntry->szFileName[nLength] = 0; // Move the next entry pListMap->cbBuffer += cbEntrySize; pListMap->nEntries++; return pListMap; }