diff options
Diffstat (limited to 'glib/gmappedfile.c')
-rw-r--r-- | glib/gmappedfile.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c index b54187071..3386d19bd 100644 --- a/glib/gmappedfile.c +++ b/glib/gmappedfile.c @@ -400,3 +400,25 @@ 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. + * It is invalid to use this function if @file is mapped writable, + * 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_if_fail (file != NULL); + + return g_bytes_new_with_free_func (file->contents, + file->length, + (GDestroyNotify) g_mapped_file_unref, + g_mapped_file_ref (file)); +} |