X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Futils%2Fmono-filemap.c;h=b557ff323315e5600c96ae953d1549d27ac29ce8;hb=185a28af3b48106c0c224d5a518f04d9107ae674;hp=9c1c8ff7b3b9ae1f99835aa451c9b8fb06a27839;hpb=b87c7e29df7d04e3199e224c8b8e9a41292cec1b;p=mono.git diff --git a/mono/utils/mono-filemap.c b/mono/utils/mono-filemap.c index 9c1c8ff7b3b..b557ff32331 100644 --- a/mono/utils/mono-filemap.c +++ b/mono/utils/mono-filemap.c @@ -25,7 +25,18 @@ MonoFileMap * mono_file_map_open (const char* name) { +#ifdef WIN32 + gunichar2 *wname = g_utf8_to_utf16 (name, -1, 0, 0, 0); + MonoFileMap *result; + + if (wname == NULL) + return NULL; + result = (MonoFileMap *) _wfopen ((wchar_t *) wname, L"rb"); + g_free (wname); + return result; +#else return (MonoFileMap *)fopen (name, "rb"); +#endif } guint64 @@ -49,13 +60,24 @@ mono_file_map_close (MonoFileMap *fmap) return fclose ((FILE*)fmap); } -#if !defined(HAVE_MMAP) && !defined (PLATFORM_WIN32) +#if !defined(HAVE_MMAP) && !defined (HOST_WIN32) + +static mono_file_map_alloc_fn alloc_fn = (mono_file_map_alloc_fn) malloc; +static mono_file_map_release_fn release_fn = (mono_file_map_release_fn) free; + +void +mono_file_map_set_allocator (mono_file_map_alloc_fn alloc, mono_file_map_release_fn release) +{ + alloc_fn = alloc == NULL ? (mono_file_map_alloc_fn) malloc : alloc; + release_fn = release == NULL ? (mono_file_map_release_fn) free : release; +} + void * mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle) { guint64 cur_offset; size_t bytes_read; - void *ptr = malloc (length); + void *ptr = (*alloc_fn) (length); if (!ptr) return NULL; cur_offset = lseek (fd, 0, SEEK_CUR); @@ -68,4 +90,11 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand *ret_handle = NULL; return ptr; } + +int +mono_file_unmap (void *addr, void *handle) +{ + (*release_fn) (addr); + return 0; +} #endif