Merge pull request #1337 from RyanMelenaNoesis/master
[mono.git] / mono / utils / mono-filemap.c
index fb25eafe2666426ceaf54e9dc3185d0a99c3c6d5..36c7fd6df93abbdec09fb325c2957bad9dbe1e61 100644 (file)
@@ -60,7 +60,7 @@ mono_file_map_close (MonoFileMap *fmap)
        return fclose ((FILE*)fmap);
 }
 
-#if !defined(HAVE_MMAP) && !defined (HOST_WIN32)
+#if !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;
@@ -73,7 +73,7 @@ mono_file_map_set_allocator (mono_file_map_alloc_fn alloc, mono_file_map_release
 }
 
 void *
-mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
+mono_file_map_fileio (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
 {
        guint64 cur_offset;
        size_t bytes_read;
@@ -86,15 +86,30 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand
                return NULL;
        }
        bytes_read = read (fd, ptr, length);
+       if (bytes_read != length)
+               return NULL;
        lseek (fd, cur_offset, SEEK_SET);
        *ret_handle = NULL;
        return ptr;
 }
 
 int
-mono_file_unmap (void *addr, void *handle)
+mono_file_unmap_fileio (void *addr, void *handle)
 {
        (*release_fn) (addr);
        return 0;
 }
+#if !defined(HAVE_MMAP)
+void *
+mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
+{
+       return mono_file_map_fileio (length, flags, fd, offset, ret_handle);
+}
+
+int
+mono_file_unmap (void *addr, void *handle)
+{
+       return mono_file_unmap_fileio(addr, handle);
+}
+#endif
 #endif