[runtime] Define DEFFILEMODE to 0666 if not defined.
[mono.git] / mono / metadata / file-mmap-posix.c
index 7e3195e0d433714099cfe18b8ec07ea403e36ec8..ce7643f2e82fa2c9e718770ad59af509f2825349 100644 (file)
@@ -97,6 +97,9 @@ enum {
        MMAP_FILE_ACCESS_READ_WRITE_EXECUTE = 5,
 };
 
+#ifndef DEFFILEMODE
+#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
+#endif
 
 static int mmap_init_state;
 static mono_mutex_t named_regions_mutex;
@@ -272,16 +275,10 @@ open_file_map (MonoString *path, int input_fd, int mode, gint64 *capacity, int a
                }
        }
 
-#ifndef PLATFORM_ANDROID
        if (path) //FIXME use io portability?
                fd = open (c_path, file_mode_to_unix (mode) | access_mode_to_unix (access), DEFFILEMODE);
        else
                fd = dup (input_fd);
-#else
-       // FIXME: No DEFFILEMODE
-       fd = -1;
-       g_assert_not_reached ();
-#endif
 
        if (fd == -1) { //XXX translate errno?
                *error = COULD_NOT_OPEN;
@@ -290,8 +287,9 @@ open_file_map (MonoString *path, int input_fd, int mode, gint64 *capacity, int a
 
        *capacity = align_up_to_page_size ((size_t)*capacity);
 
-       if (*capacity > buf.st_size)
-               ftruncate (fd, (off_t)*capacity);
+       if (*capacity > buf.st_size) {
+               int unused G_GNUC_UNUSED = ftruncate (fd, (off_t)*capacity);
+       }
 
        handle = g_new0 (FileHandle, 1);
        handle->handle.kind = MMAP_KIND_FILE;
@@ -487,9 +485,9 @@ mono_mmap_map (void *handle, gint64 offset, gint64 *size, int access, void **mma
 
                if (!eff_size)
                        eff_size = *size = mh->length;
-               mmap_offset = (size_t)mmap_offset;
+               mmap_offset = (size_t)offset;
                res.address = (char*)mh->address + offset;
-               res.length = (size_t)size;
+               res.length = (size_t)*size;
                res.kind = MMAP_KIND_MEMORY;
        }