52 # include <sys/wcebase.h> 53 # include <sys/wcetypes.h> 54 # include <sys/wcememory.h> 55 # include <sys/wcefile.h> 56 #elif defined(__SYMBIAN32__) 59 # include <sys/stat.h> 60 # include <sys/mman.h> 66 # include <sys/stat.h> 67 # include <sys/file.h> 68 # include <sys/mman.h> 76 #if defined(_WIN32_WCE) || defined(GNUWINCE) 89 len = mbstowcs(NULL, filename, 0) + 1;
90 wfilename = malloc(len *
sizeof(WCHAR));
91 mbstowcs(wfilename, filename, len);
94 CreateFileForMappingW(wfilename, GENERIC_READ, FILE_SHARE_READ,
95 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
96 NULL)) == INVALID_HANDLE_VALUE) {
97 E_ERROR(
"Failed to create mapping for the file '%s': %08x\n", filename,
102 CreateFileMappingW(ffm, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) {
103 E_ERROR(
"Failed to CreateFileMapping: %08x\n", GetLastError());
107 rv = MapViewOfFile(fd, FILE_MAP_READ, 0, 0, 0);
118 if (!UnmapViewOfFile((
void *)mf)) {
119 E_ERROR(
"Failed to UnmapViewOfFile: %08x\n", GetLastError());
129 #elif defined(_WIN32) && !defined(_WIN32_WP) 140 if ((ffm = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ,
141 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
142 NULL)) == INVALID_HANDLE_VALUE) {
143 E_ERROR(
"Failed to create file '%s': %08x\n",
144 filename, GetLastError());
147 if ((fd = CreateFileMapping(ffm, NULL,
148 PAGE_READONLY, 0, 0, NULL)) == NULL) {
149 E_ERROR(
"Failed to CreateFileMapping: %08x\n", GetLastError());
152 rv = MapViewOfFile(fd, FILE_MAP_READ, 0, 0, 0);
162 if (!UnmapViewOfFile((
void *)mf)) {
163 E_ERROR(
"Failed to UnmapViewOfFile: %08x\n", GetLastError());
174 #if defined(__ADSPBLACKFIN__) || defined(_WIN32_WP) 184 E_ERROR(
"mmio is not implemented on this platform!");
191 E_ERROR(
"mmio is not implemented on this platform!");
197 E_ERROR(
"mmio is not implemented on this platform!");
215 if ((fd = open(filename, O_RDONLY)) == -1) {
219 if (fstat(fd, &buf) == -1) {
224 ptr = mmap(NULL, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
225 if (ptr == (
void *)-1) {
226 E_ERROR_SYSTEM(
"Failed to mmap %lld bytes", (
unsigned long long)buf.st_size);
234 pagesize = sysconf(_SC_PAGESIZE);
235 mf->mapsize = (buf.st_size + pagesize - 1) / pagesize * pagesize;
245 if (munmap(mf->ptr, mf->mapsize) < 0) {
246 E_ERROR_SYSTEM(
"Failed to unmap %ld bytes at %p", mf->mapsize, mf->ptr);
#define E_ERROR_SYSTEM(...)
Print error text; Call perror("");.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
#define E_ERROR(...)
Print error message to error log.
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT void mmio_file_unmap(mmio_file_t *mf)
Unmap a file, releasing memory associated with it.
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
SPHINXBASE_EXPORT void * mmio_file_ptr(mmio_file_t *mf)
Get a pointer to the memory mapped for a file.
Implementation of logging routines.
SPHINXBASE_EXPORT mmio_file_t * mmio_file_read(const char *filename)
Memory-map a file for reading.
Memory-mapped I/O wrappers for files.