summaryrefslogtreecommitdiff
path: root/glib/glib/gmappedfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'glib/glib/gmappedfile.c')
-rw-r--r--glib/glib/gmappedfile.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/glib/glib/gmappedfile.c b/glib/glib/gmappedfile.c
index b541870..7d241e7 100644
--- a/glib/glib/gmappedfile.c
+++ b/glib/glib/gmappedfile.c
@@ -38,7 +38,9 @@
#include <windows.h>
#include <io.h>
+#undef fstat
#define fstat(a,b) _fstati64(a,b)
+#undef stat
#define stat _stati64
#ifndef S_ISREG
@@ -400,3 +402,27 @@ g_mapped_file_unref (GMappedFile *file)
if (g_atomic_int_dec_and_test (&file->ref_count))
g_mapped_file_destroy (file);
}
+
+/**
+ * g_mapped_file_get_bytes:
+ * @file: a #GMappedFile
+ *
+ * Creates a new #GBytes which references the data mapped from @file.
+ * The mapped contents of the file must not be modified after creating this
+ * bytes object, because a #GBytes should be immutable.
+ *
+ * Returns: (transfer full): A newly allocated #GBytes referencing data
+ * from @file
+ *
+ * Since: 2.34
+ **/
+GBytes *
+g_mapped_file_get_bytes (GMappedFile *file)
+{
+ g_return_val_if_fail (file != NULL, NULL);
+
+ return g_bytes_new_with_free_func (file->contents,
+ file->length,
+ (GDestroyNotify) g_mapped_file_unref,
+ g_mapped_file_ref (file));
+}