GMappedFile: add g_mapped_file_new_with_fallback() or somesuch
@tpm
Submitted by Tim-Philipp Müller Link to original bug (#622065)
Description
I've seen code like this in quite a few places to read a file:
mapped = g_mapped_file_new (location, FALSE, &err); if (error) { ... try g_file_get_contents(); } else { contents = g_mapped_file_get_contents (mapped); size = g_mapped_file_get_size (mapped); }
... process data ...
if (mapped) g_mapped_file_unref (mapped) else g_free (contents);
It would be nice to either add API to GMappedFile so it uses g_file_get_contents() as backup when writable=FALSE, transparent to the application, or add new API that does mmap where possible, using read() as fallback.