Function

GLibMappedFilenew

since: 2.8

Declaration

GMappedFile*
g_mapped_file_new (
  const gchar* filename,
  gboolean writable,
  GError** error
)

Description

Maps a file into memory. On UNIX, this is using the mmap() function.

If writable is TRUE, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.

Note that modifications of the underlying file might affect the contents of the GMappedFile. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. using g_file_set_contents()).

If filename is the name of an empty, regular file, the function will successfully return an empty GMappedFile. In other cases of size 0 (e.g. device files such as /dev/null), error will be set to the GFileError value G_FILE_ERROR_INVAL.

Available since: 2.8

Parameters

filename

Type: const gchar*

The path of the file to load, in the GLib filename encoding.

The data is owned by the caller of the function.
The value is a file system path, using the OS encoding.
writable

Type: gboolean

Whether the mapping should be writable.

error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will left initialized to NULL by the function if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: GMappedFile

A newly allocated GMappedFile which must be unref’d with g_mapped_file_unref(), or NULL if the mapping failed.

The caller of the function takes ownership of the data, and is responsible for freeing it.