diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-07-30 20:34:23 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-07-30 20:34:23 +0000 |
commit | d72782347c2ba802cd030feeb23f7eacc4ae8a23 (patch) | |
tree | a729476323d0d551c2031b3a666193923ceb08a4 /support/win32/mmap.c | |
parent | c297ef7f5928b0407ab67b9a76ccf166d0a1d3e0 (diff) | |
parent | 3b8435d744c504a88493f272068453023585837e (diff) | |
download | navit-svn-wince.tar.gz |
Updated wince branch to current versionwince
git-svn-id: http://svn.code.sf.net/p/navit/code/branches/wince/navit@2430 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'support/win32/mmap.c')
-rw-r--r-- | support/win32/mmap.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/support/win32/mmap.c b/support/win32/mmap.c new file mode 100644 index 00000000..008ffa66 --- /dev/null +++ b/support/win32/mmap.c @@ -0,0 +1,43 @@ +#include <windows.h> +#include "sys/mman.h" + +void * mmap_readonly_win32( const char* name, long* map_handle_ptr, long* map_file_ptr ) +{ + void * mapped_ptr = NULL; +#if defined(__CEGCC__) + + wchar_t filename[MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, strlen(name), 0, 0)]; + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, strlen(name), filename, wcslen(filename)) ; + + HANDLE hFile = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); +#else + HANDLE hFile = CreateFile (name, GENERIC_READ, FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); +#endif + *map_file_ptr = (long)hFile; + *map_handle_ptr = 0; + + if ( hFile != HFILE_ERROR ) + { + HANDLE hMapping = CreateFileMapping( (HANDLE)hFile, NULL, PAGE_READONLY, 0, 0, NULL); + mapped_ptr = MapViewOfFile(hMapping, FILE_MAP_READ, 0 , 0, 0 ); + *map_handle_ptr = (long)hMapping; + } + + return mapped_ptr; +} + +void mmap_unmap_win32( void* mem_ptr, long map_handle, long map_file ) +{ + if ( mem_ptr != NULL ) + { + UnmapViewOfFile( mem_ptr ); + } + if ( map_handle != 0) + { + CloseHandle( (HANDLE)map_handle ); + } + if ( map_file != 0 ) + { + CloseHandle( (HANDLE)map_file ); + } +} |