MappedFile

There is a group of functions which wrap the common POSIX functions dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(), g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these wrappers is to make it possible to handle file names with any Unicode characters in them on Windows without having to use ifdefs and the wide character API in the application code.

The pathname argument should be in the GLib file name encoding. On POSIX this is the actual on-disk encoding which might correspond to the locale settings of the process (or the G_FILENAME_ENCODING environment variable), or not.

On Windows the GLib file name encoding is UTF-8. Note that the Microsoft C library does not use UTF-8, but has separate APIs for current system code page and wide characters (UTF-16). The GLib wrappers call the wide character API if present (on modern Windows systems), otherwise convert to/from the system code page.

Another group of functions allows to open and read directories in the GLib file name encoding. These are g_dir_open(), g_dir_read_name(), g_dir_rewind(), g_dir_close().

Constructors

this
this(GMappedFile* gMappedFile)

Sets our main struct and passes it to the parent class

this
this(string filename, int writable)

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. Since 2.8

this
this(int fd, int writable)

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()). Since 2.32

Members

Functions

doref
MappedFile doref()

Increments the reference count of file by one. It is safe to call this function from any thread. Since 2.22

free
void free()

Warning g_mapped_file_free has been deprecated since version 2.22 and should not be used in newly-written code. Use g_mapped_file_unref() instead. This call existed before GMappedFile had refcounting and is currently exactly the same as g_mapped_file_unref(). Since 2.8

getBytes
Bytes getBytes()

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. Since 2.34

getContents
string getContents()

Returns the contents of a GMappedFile. Note that the contents may not be zero-terminated, even if the GMappedFile is backed by a text file. If the file is empty then NULL is returned. Since 2.8

getLength
gsize getLength()

Returns the length of the contents of a GMappedFile. Since 2.8

getMappedFileStruct
GMappedFile* getMappedFileStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

unref
void unref()

Decrements the reference count of file by one. If the reference count drops to 0, unmaps the buffer of file and frees it. It is safe to call this function from any thread. Since 2.22

Variables

gMappedFile
GMappedFile* gMappedFile;

the main Gtk struct

Meta