Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / file-mmap-windows.c
index b0fd5d9b8962bbfbcfefa532774b6fdb94adf6dd..59abd6686ffe192285513af90cccac7c23becd7a 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * file-mmap-windows.c: MemoryMappedFile internal calls for Windows
+/**
+ * \file
+ * MemoryMappedFile internal calls for Windows
  *
  * Copyright 2016 Microsoft
  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -13,8 +14,9 @@
  */
 
 #include <config.h>
-
-#ifdef HOST_WIN32
+#include <glib.h>
+#include <mono/utils/mono-compiler.h>
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) && defined(HOST_WIN32)
 
 #include <glib.h>
 
@@ -138,7 +140,7 @@ static void *open_handle (void *handle, MonoString *mapName, int mode, gint64 *c
        HANDLE result = NULL;
 
        if (handle == INVALID_HANDLE_VALUE) {
-               if (*capacity <= 0) {
+               if (*capacity <= 0 && mode != FILE_MODE_OPEN) {
                        *error = CAPACITY_MUST_BE_POSITIVE;
                        return NULL;
                }
@@ -269,6 +271,8 @@ void *mono_mmap_open_file (MonoString *path, int mode, MonoString *mapName, gint
        result = open_handle (hFile, mapName, mode, capacity, access, options, error);
 
 done:
+       if (hFile != INVALID_HANDLE_VALUE)
+               CloseHandle (hFile);
        if (!result && delete_on_error)
                DeleteFileW (w_path);
        if (w_path)
@@ -410,4 +414,8 @@ gboolean mono_mmap_unmap (void *mmap_handle)
        return result;
 }
 
+#else
+
+MONO_EMPTY_SOURCE_FILE (file_mmap_windows);
+
 #endif