2 * mono-filemap.c: Unix/Windows implementation for filemap.
5 * Paolo Molaro (lupus@ximian.com)
7 * Copyright 2008-2008 Novell, Inc.
23 #include "mono-mmap.h"
26 mono_file_map_open (const char* name)
28 return (MonoFileMap *)fopen (name, "rb");
32 mono_file_map_size (MonoFileMap *fmap)
35 if (fstat (fileno ((FILE*)fmap), &stat_buf) < 0)
37 return stat_buf.st_size;
41 mono_file_map_fd (MonoFileMap *fmap)
43 return fileno ((FILE*)fmap);
47 mono_file_map_close (MonoFileMap *fmap)
49 return fclose ((FILE*)fmap);
52 #if !defined(HAVE_MMAP) && !defined (HOST_WIN32)
54 static mono_file_map_alloc_fn alloc_fn = (mono_file_map_alloc_fn) malloc;
55 static mono_file_map_release_fn release_fn = (mono_file_map_release_fn) free;
58 mono_file_map_set_allocator (mono_file_map_alloc_fn alloc, mono_file_map_release_fn release)
60 alloc_fn = alloc == NULL ? (mono_file_map_alloc_fn) malloc : alloc;
61 release_fn = release == NULL ? (mono_file_map_release_fn) free : release;
65 mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
69 void *ptr = (*alloc_fn) (length);
72 cur_offset = lseek (fd, 0, SEEK_CUR);
73 if (lseek (fd, offset, SEEK_SET) != offset) {
77 bytes_read = read (fd, ptr, length);
78 lseek (fd, cur_offset, SEEK_SET);
84 mono_file_unmap (void *addr, void *handle)