#include <assert.h>
#include <stdint.h>
#include <stdio.h>
-#include <iostream>
#include <fstream>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/mman.h>
+#include "cld2_dynamic_compat.h" // for win32/posix compatibility
#include "cld2_dynamic_data.h"
#include "cld2_dynamic_data_loader.h"
#include "integral_types.h"
header->sanityString,
CLD2DynamicData::DATA_FILE_MARKER,
CLD2DynamicData::DATA_FILE_MARKER_LENGTH)) {
- std::cerr << "Malformed header: bad file marker!" << std::endl;
+ fprintf(stderr, "Malformed header: bad file marker!\n");
delete header;
return NULL;
}
// Confirm header size is correct.
int expectedHeaderSize = CLD2DynamicData::calculateHeaderSize(header->numTablesEncoded);
if (expectedHeaderSize != bytesRead) {
- std::cerr << "Header size mismatch! Expected " << expectedHeaderSize << ", but read " << bytesRead << std::endl;
+ fprintf(stderr, "Header size mismatch! Expected %d, but read %d\n", expectedHeaderSize, bytesRead);
delete header;
delete[] tableHeaders;
return NULL;
}
if (actualSize != header->totalFileSizeBytes) {
- std::cerr << "File size mismatch! Expected " << header->totalFileSizeBytes << ", but found " << actualSize << std::endl;
+ fprintf(stderr, "File size mismatch! Expected %d, but found %d\n", header->totalFileSizeBytes, actualSize);
delete header;
delete[] tableHeaders;
return NULL;
void unloadDataFile(CLD2::ScoringTables** scoringTables,
void** mmapAddress, uint32_t* mmapLength) {
+#ifdef _WIN32
+ // See https://code.google.com/p/cld2/issues/detail?id=20
+ fprintf(stderr, "dynamic data unloading from file is not currently supported on win32, use raw mode instead.");
+ return;
+#else // i.e., is POSIX (no support for Mac prior to OSX)
CLD2DynamicDataLoader::unloadDataRaw(scoringTables);
munmap(*mmapAddress, *mmapLength);
*mmapAddress = NULL;
*mmapLength = 0;
+#endif // ifdef _WIN32
}
void unloadDataRaw(CLD2::ScoringTables** scoringTables) {
CLD2::ScoringTables* loadDataFile(const char* fileName,
void** mmapAddressOut, uint32_t* mmapLengthOut) {
+
+#ifdef _WIN32
+ // See https://code.google.com/p/cld2/issues/detail?id=20
+ fprintf(stderr, "dynamic data loading from file is not currently supported on win32, use raw mode instead.");
+ return NULL;
+#else // i.e., is POSIX (no support for Mac prior to OSX)
CLD2DynamicData::FileHeader* header = loadHeaderFromFile(fileName);
if (header == NULL) {
return NULL;
}
// Initialize the memory map
- int inFileHandle = open(fileName, O_RDONLY);
+ int inFileHandle = OPEN(fileName, O_RDONLY);
void* mapped = mmap(NULL, header->totalFileSizeBytes,
PROT_READ, MAP_PRIVATE, inFileHandle, 0);
// Record the map address. This allows callers to unmap
*mmapAddressOut=mapped;
*mmapLengthOut=header->totalFileSizeBytes;
- close(inFileHandle);
+ CLOSE(inFileHandle);
return loadDataInternal(header, mapped, header->totalFileSizeBytes);
+#endif // ifdef _WIN32
}
CLD2::ScoringTables* loadDataRaw(const void* basePointer, const uint32_t length) {