51 # include <sys/wcebase.h>
52 # include <sys/wcetypes.h>
53 # include <sys/wcememory.h>
54 # include <sys/wcefile.h>
55 #elif defined(__SYMBIAN32__)
58 # include <sys/stat.h>
59 # include <sys/mman.h>
65 # include <sys/stat.h>
66 # include <sys/file.h>
67 # 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());
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__)
183 E_FATAL(
"mmio is not implemented on this platform!");
190 E_FATAL(
"mmio is not implemented on this platform!");
196 E_FATAL(
"mmio is not implemented on this platform!");
214 if ((fd = open(filename, O_RDONLY)) == -1) {
218 if (fstat(fd, &buf) == -1) {
223 ptr = mmap(NULL, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
224 if (ptr == (
void *)-1) {
225 E_ERROR_SYSTEM(
"Failed to mmap %lld bytes", (
unsigned long long)buf.st_size);
233 pagesize = getpagesize();
234 mf->mapsize = (buf.st_size + pagesize - 1) / pagesize * pagesize;
244 if (munmap(mf->ptr, mf->mapsize) < 0) {
245 E_ERROR_SYSTEM(
"Failed to unmap %ld bytes at %p", mf->mapsize, mf->ptr);
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
Silvio Moioli: slightly updated.
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.
#define E_FATAL
Exit with non-zero status after error message.
#define E_ERROR
Print error message to standard error stream.
#define E_ERROR_SYSTEM
Print error text; Call perror("");.
SPHINXBASE_EXPORT mmio_file_t * mmio_file_read(const char *filename)
Memory-map a file for reading.
Memory-mapped I/O wrappers for files.