/[zanavi_public1]/navit/navit/support/win32/mmap.c
ZANavi

Contents of /navit/navit/support/win32/mmap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 1264 byte(s)
import files
1 #include <windows.h>
2 #include "sys/mman.h"
3
4 void * mmap_readonly_win32( const char* name, long* map_handle_ptr, long* map_file_ptr )
5 {
6 void * mapped_ptr = NULL;
7 #if defined(__CEGCC__)
8
9 wchar_t filename[MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, strlen(name), 0, 0)];
10 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, strlen(name), filename, wcslen(filename)) ;
11
12 HANDLE hFile = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
13 #else
14 HANDLE hFile = CreateFile (name, GENERIC_READ, FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
15 #endif
16 *map_file_ptr = (long)hFile;
17 *map_handle_ptr = 0;
18
19 if ( hFile != HFILE_ERROR )
20 {
21 HANDLE hMapping = CreateFileMapping( (HANDLE)hFile, NULL, PAGE_READONLY, 0, 0, NULL);
22 mapped_ptr = MapViewOfFile(hMapping, FILE_MAP_READ, 0 , 0, 0 );
23 *map_handle_ptr = (long)hMapping;
24 }
25
26 return mapped_ptr;
27 }
28
29 void mmap_unmap_win32( void* mem_ptr, long map_handle, long map_file )
30 {
31 if ( mem_ptr != NULL )
32 {
33 UnmapViewOfFile( mem_ptr );
34 }
35 if ( map_handle != 0)
36 {
37 CloseHandle( (HANDLE)map_handle );
38 }
39 if ( map_file != 0 )
40 {
41 CloseHandle( (HANDLE)map_file );
42 }
43 }

   
Visit the ZANavi Wiki