Namespace

GLib – 2.0

GLib is a general-purpose, portable utility library, which provides many useful data types, macros, type conversions, string utilities, file utilities, a mainloop abstraction, and so on.

Version2.85.0
AuthorsGLib Development Team
LicenseLGPL-2.1-or-later
Websitehttps://www.gtk.org
Sourcehttps://gitlab.gnome.org/GNOME/glib/

Build

C headersglib.h
pkg-config filesglib-2.0
GModule Portable API for dynamically loading modules
Browse documentation
GObject The base type system library
Browse documentation
GIO GObject Interfaces and Objects, Networking, IPC, and I/O
Browse documentation

Structs

Allocator

deprecated: 2.10 

Array

Contains the public fields of a GArray.

AsyncQueue

An opaque data structure which represents an asynchronous queue.

BookmarkFile

GBookmarkFile lets you parse, edit or create files containing bookmarks.

since: 2.12

ByteArray

Contains the public fields of a GByteArray.

Bytes

A simple reference counted data type representing an immutable sequence of zero or more bytes from an unspecified origin.

since: 2.32

Cache

A GCache allows sharing of complex data structures, in order to save system resources.

deprecated: 2.32 

Checksum

GLib provides a generic API for computing checksums (or ‘digests’) for a sequence of arbitrary bytes, using various hashing algorithms like MD5, SHA-1 and SHA-256. Checksums are commonly used in various environments and specifications.

since: 2.16

Completion

GCompletion provides support for automatic completion of a string using any group of target strings. It is typically used for file name completion as is common in many UNIX shells.

deprecated: 2.26 

Cond

The GCond struct is an opaque data structure that represents a condition. Threads can block on a GCond if they find a certain condition to be false. If other threads change the state of this condition they signal the GCond, and that causes the waiting threads to be woken up.

Data

An opaque data structure that represents a keyed data list.

Date

GDate is a struct for calendrical calculations.

DateTime

GDateTime is a structure that combines a Gregorian date and time into a single structure.

since: 2.26

DebugKey

Associates a string with a bit flag. Used in g_parse_debug_string().

Dir

An opaque structure representing an opened directory.

Error

The GError structure contains information about an error that has occurred.

HashTable

The GHashTable struct is an opaque data structure to represent a Hash Table. It should only be accessed via the following functions.

HashTableIter

A GHashTableIter structure represents an iterator that can be used to iterate over the elements of a GHashTable. GHashTableIter structures are typically allocated on the stack and then initialized with g_hash_table_iter_init().

Hmac

HMACs should be used when producing a cookie or hash based on data and a key. Simple mechanisms for using SHA1 and other algorithms to digest a key and data together are vulnerable to various security issues. HMAC uses algorithms like SHA1 in a secure way to produce a digest of a key and data.

since: 2.30

Hook

The GHook struct represents a single hook function in a GHookList.

HookList

The GHookList struct represents a list of hook functions.

IConv

The GIConv struct wraps an iconv() conversion descriptor. It contains private data and should only be accessed using the following functions.

IOChannel

The GIOChannel data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop (see GMainContext). Currently, full support is available on UNIX platforms; support for Windows is only partially complete.

IOFuncs

A table of functions used to handle different types of GIOChannel in a generic way.

KeyFile

GKeyFile parses .ini-like config files.

List

The GList struct is used for each element in a doubly-linked list.

LogField

Structure representing a single field in a structured log entry. See g_log_structured() for details.

since: 2.50

MainContext

The GMainContext struct is an opaque data type representing a set of sources to be handled in a main loop.

MainLoop

The GMainLoop struct is an opaque data type representing the main event loop of a GLib or GTK application.

MappedFile

The GMappedFile represents a file mapping created with g_mapped_file_new(). It has only private members and should not be accessed directly.

MarkupParseContext

A parse context is used to parse a stream of bytes that you expect to contain marked-up text.

MarkupParser

Any of the fields in GMarkupParser can be NULL, in which case they will be ignored. Except for the error function, any of these callbacks can set an error; in particular the G_MARKUP_ERROR_UNKNOWN_ELEMENT, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, and G_MARKUP_ERROR_INVALID_CONTENT errors are intended to be set from these callbacks. If you set an error from a callback, g_markup_parse_context_parse() will report that error back to its caller.

MatchInfo

A GMatchInfo is an opaque struct used to return information about matches.

MemChunk

deprecated: 2.10 

MemVTable

A set of functions used to perform memory allocation. The same GMemVTable must be used for all allocations in the same program; a call to g_mem_set_vtable(), if it exists, should be prior to any use of GLib.

Node

The GNode struct represents one node in a n-ary tree.

Once

A GOnce struct controls a one-time initialization function. Any one-time initialization function must have its own unique GOnce struct.

since: 2.4

OptionContext

A GOptionContext struct defines which options are accepted by the commandline option parser. The struct has only private fields and should not be directly accessed.

OptionEntry
  • G_OPTION_ARG_NONE: %gboolean
    • G_OPTION_ARG_STRING: %gchar*
    • G_OPTION_ARG_INT: %gint
    • G_OPTION_ARG_FILENAME: %gchar*
    • G_OPTION_ARG_STRING_ARRAY: %gchar**
    • G_OPTION_ARG_FILENAME_ARRAY: %gchar**
    • G_OPTION_ARG_DOUBLE: %gdouble.

OptionGroup

A GOptionGroup struct defines the options in a single group. The struct has only private fields and should not be directly accessed.

PathBuf

GPathBuf is a helper type that allows you to easily build paths from individual elements, using the platform specific conventions for path separators.

since: 2.76

PatternSpec

A GPatternSpec struct is the ‘compiled’ form of a glob-style pattern.

PollFD

Represents a file descriptor, which events to poll for, and which events occurred.

Private

The GPrivate struct is an opaque data structure to represent a thread-local data key. It is approximately equivalent to the pthread_setspecific()/pthread_getspecific() APIs on POSIX and to TlsSetValue()/TlsGetValue() on Windows.

PtrArray

Contains the public fields of a pointer array.

Queue

Contains the public fields of a Queue.

Rand

The GRand struct is an opaque data structure. It should only be accessed through the g_rand_* functions.

RecMutex

The GRecMutex struct is an opaque data structure to represent a recursive mutex. It is similar to a GMutex with the difference that it is possible to lock a GRecMutex multiple times in the same thread without deadlock. When doing so, care has to be taken to unlock the recursive mutex as often as it has been locked.

since: 2.32

Regex

A GRegex is a compiled form of a regular expression.

since: 2.14

Relation

A GRelation is a table of data which can be indexed on any number of fields, rather like simple database tables. A GRelation contains a number of records, called tuples. Each record contains a number of fields. Records are not ordered, so it is not possible to find the record at a particular index.

deprecated: 2.26 

RWLock

The GRWLock struct is an opaque data structure to represent a reader-writer lock. It is similar to a GMutex in that it allows multiple threads to coordinate access to a shared resource.

since: 2.32

Scanner

GScanner provides a general-purpose lexical scanner.

ScannerConfig

Specifies the GScanner parser configuration. Most settings can be changed during the parsing phase and will affect the lexical parsing of the next unpeeked token.

Sequence

The GSequence struct is an opaque data type representing a sequence data type.

SequenceIter

The GSequenceIter struct is an opaque data type representing an iterator pointing into a GSequence.

SList

The GSList struct is used for each element in the singly-linked list.

Source

The GSource struct is an opaque data type representing an event source.

SourceCallbackFuncs

The GSourceCallbackFuncs struct contains functions for managing callback objects.

SourceFuncs

The GSourceFuncs struct contains a table of functions used to handle event sources in a generic manner.

StatBuf

A type corresponding to the appropriate struct type for the stat() system call, depending on the platform and/or compiler being used.

StaticMutex

A GStaticMutex works like a GMutex.

StaticPrivate

A GStaticPrivate works almost like a GPrivate, but it has one significant advantage. It doesn’t need to be created at run-time like a GPrivate, but can be defined at compile-time. This is similar to the difference between GMutex and GStaticMutex.

StaticRecMutex

A GStaticRecMutex works like a GStaticMutex, but it can be locked multiple times by one thread. If you enter it n times, you have to unlock it n times again to let other threads lock it. An exception is the function g_static_rec_mutex_unlock_full(): that allows you to unlock a GStaticRecMutex completely returning the depth, (i.e. the number of times this mutex was locked). The depth can later be used to restore the state of the GStaticRecMutex by calling g_static_rec_mutex_lock_full(). In GLib 2.32, GStaticRecMutex has been deprecated in favor of GRecMutex.

StaticRWLock

The GStaticRWLock struct represents a read-write lock. A read-write lock can be used for protecting data that some portions of code only read from, while others also write. In such situations it is desirable that several readers can read at once, whereas of course only one writer may write at a time.

deprecated: 2.32 

String

A GString is an object that handles the memory management of a C string.

StringChunk

GStringChunk provides efficient storage of groups of strings.

StrvBuilder

GStrvBuilder is a helper object to build a NULL-terminated string arrays.

since: 2.68

TestCase

An opaque structure representing a test case.

TestConfig

TestLogBuffer

TestLogMsg

TestSuite

An opaque structure representing a test suite.

Thread

The GThread struct represents a running thread. This struct is returned by g_thread_new() or g_thread_try_new(). You can obtain the GThread struct representing the current thread by calling g_thread_self().

ThreadFunctions

This function table is no longer used by g_thread_init() to initialize the thread system.

ThreadPool

The GThreadPool struct represents a thread pool.

Timer

GTimer records a start time, and counts microseconds elapsed since that time.

TimeVal

Represents a precise time, with seconds and microseconds.

deprecated: 2.62 

TimeZone

A GTimeZone represents a time zone, at no particular point in time.

since: 2.26

TrashStack

A GTrashStack is an efficient way to keep a stack of unused allocated memory chunks. Each memory chunk is required to be large enough to hold a gpointer. This allows the stack to be maintained without any space overhead, since the stack pointers can be stored inside the memory chunks.

deprecated: 2.48 

Tree

The GTree struct is an opaque data structure representing a balanced binary tree. It should be accessed only by using the following functions.

TreeNode

An opaque type which identifies a specific node in a GTree.

since: 2.68

Tuples

The GTuples struct is used to return records (or tuples) from the GRelation by g_relation_select(). It only contains one public member - the number of records that matched. To access the matched records, you must use g_tuples_index().

deprecated: 2.26 

Uri

The GUri type and related functions can be used to parse URIs into their components, and build valid URIs from individual components.

since: 2.66

UriParamsIter

Many URI schemes include one or more attribute/value pairs as part of the URI value. For example scheme://server/path?query=string&is=there has two attributes – query=string and is=there – in its query part.

since: 2.66

Variant

GVariant is a variant datatype; it can contain one or more values along with information about the type of the values.

since: 2.24

VariantBuilder

A utility type for constructing container-type GVariant instances.

VariantDict

GVariantDict is a mutable interface to GVariant dictionaries.

since: 2.40

VariantIter

GVariantIter is an opaque data structure and can only be accessed using the following functions.

VariantType

A type in the GVariant type system.

since: 2.24

Unions

DoubleIEEE754

The GFloatIEEE754 and GDoubleIEEE754 unions are used to access the sign, mantissa and exponent of IEEE floats and doubles. These unions are defined as appropriate for a given platform. IEEE floats and doubles are supported (used for storage) by at least Intel, PPC and Sparc.

FloatIEEE754

The GFloatIEEE754 and GDoubleIEEE754 unions are used to access the sign, mantissa and exponent of IEEE floats and doubles. These unions are defined as appropriate for a given platform. IEEE floats and doubles are supported (used for storage) by at least Intel, PPC and Sparc.

Mutex

The GMutex struct is an opaque data structure to represent a mutex (mutual exclusion). It can be used to protect data against shared access.

TokenValue

A union holding the value of the token.

Aliases

DateDay

Integer representing a day of the month; between 1 and 31.

DateYear

Integer type representing a year.

MainContextPusher

Opaque type. See g_main_context_pusher_new() for details.

MutexLocker

Opaque type. See g_mutex_locker_new() for details.

Pid

A type which is used to hold a process identification.

Quark

A GQuark is a non-zero integer which uniquely identifies a particular string.

RecMutexLocker

Opaque type. See g_rec_mutex_locker_new() for details.

RefString

A typedef for a reference-counted string. A pointer to a GRefString can be treated like a standard char* array by all code, but can additionally have g_ref_string_*() methods called on it. g_ref_string_*() methods cannot be called on char* arrays not allocated using g_ref_string_new().

RWLockReaderLocker

Opaque type. See g_rw_lock_reader_locker_new() for details.

RWLockWriterLocker

Opaque type. See g_rw_lock_writer_locker_new() for details.

Strv

A typedef alias for gchar**. This is mostly useful when used together with g_auto().

Time

Simply a replacement for time_t. It has been deprecated since it is not equivalent to time_t on 64-bit platforms with a 64-bit time_t.

deprecated: 2.62 

TimeSpan

A value representing an interval of time, in microseconds.

Enumerations

ChecksumType

The hashing algorithm to be used by GChecksum when performing the digest of some data.

since: 2.16

DateDMY

This enumeration isn’t used in the API, but may be useful if you need to mark a number as a day, month, or year.

DateMonth

Enumeration representing a month; values are G_DATE_JANUARY, G_DATE_FEBRUARY, etc. G_DATE_BAD_MONTH is the invalid value.

DateWeekday

Enumeration representing a day of the week; G_DATE_MONDAY, G_DATE_TUESDAY, etc. G_DATE_BAD_WEEKDAY is an invalid weekday.

ErrorType

The possible errors, used in the v_error field of GTokenValue, when the token is a G_TOKEN_ERROR.

IOError

GIOError is only used by the deprecated functions g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek().

IOStatus

Statuses returned by most of the GIOFuncs functions.

LogWriterOutput

Return values from GLogWriterFuncs to indicate whether the given log entry was successfully handled by the writer, or whether there was an error in handling it (and hence a fallback writer should be used).

since: 2.50

NormalizeMode

Defines how a Unicode string is transformed in a canonical form, standardizing such issues as whether a character with an accent is represented as a base character and combining accent or as a single precomposed character. Unicode strings should generally be normalized before comparing them.

OnceStatus

The possible statuses of a one-time initialization function controlled by a GOnce struct.

since: 2.4

OptionArg

The GOptionArg enum values determine which type of extra argument the options expect to find. If an option expects an extra argument, it can be specified in several ways; with a short option: -x arg, with a long option: --name arg or combined in a single argument: --name=arg.

SeekType

An enumeration specifying the base position for a g_io_channel_seek_position() operation.

SliceConfig

TestFileType

The type of file to return the filename for, when used with g_test_build_filename().

since: 2.38

TestLogType

TestResult

ThreadPriority

Thread priorities.

deprecated: 2.32 

TimeType

Disambiguates a given time in two ways.

TokenType

The possible types of token returned from each g_scanner_get_next_token() call.

TraverseType

Specifies the type of traversal performed by g_tree_traverse(), g_node_traverse() and g_node_find().

UnicodeBreakType

These are the possible line break classifications.

UnicodeScript

The GUnicodeScript enumeration identifies different writing systems. The values correspond to the names as defined in the Unicode standard. The enumeration has been added in GLib 2.14, and is interchangeable with PangoScript.

UnicodeType

These are the possible character classifications from the Unicode specification. See Unicode Character Database.

UserDirectory

These are logical ids for special directories which are defined depending on the platform used. You should use g_get_user_special_dir() to retrieve the full path associated to the logical id.

since: 2.14

VariantClass

The range of possible top-level types of GVariant instances.

since: 2.24

Bitfields

AsciiType

FileSetContentsFlags

Flags to pass to g_file_set_contents_full() to affect its safety and performance.

since: 2.66

FileTest

A test to perform on a file using g_file_test().

FormatSizeFlags

Flags to modify the format of the string returned by g_format_size_full().

HookFlagMask

Flags used internally in the GHook implementation.

IOCondition

A bitwise combination representing a condition to watch for on an event source.

IOFlags

Specifies properties of a GIOChannel. Some of the flags can only be read with g_io_channel_get_flags(), but not changed with g_io_channel_set_flags().

KeyFileFlags

Flags which influence the parsing.

LogLevelFlags

Flags specifying the level of log messages.

MainContextFlags

Flags to pass to g_main_context_new_with_flags() which affect the behaviour of a GMainContext.

since: 2.72

MarkupCollectType

A mixed enumerated type and flags field. You must specify one type (string, strdup, boolean, tristate). Additionally, you may optionally bitwise OR the type with the flag G_MARKUP_COLLECT_OPTIONAL.

MarkupParseFlags

Flags that affect the behaviour of the parser.

OptionFlags

Flags which modify individual options.

RegexCompileFlags

Flags specifying compile-time options.

since: 2.14

RegexMatchFlags

Flags specifying match-time options.

since: 2.14

SpawnFlags

Flags passed to g_spawn_sync(), g_spawn_async() and g_spawn_async_with_pipes().

TestSubprocessFlags

Flags to pass to g_test_trap_subprocess() to control input and output.

TestTrapFlags

Flags to pass to g_test_trap_fork() to control input and output.

deprecated: 2.38 

TraverseFlags

Specifies which nodes are visited during several of the tree functions, including g_node_traverse() and g_node_find().

UriFlags

Flags that describe a URI.

since: 2.66

UriHideFlags

Flags describing what parts of the URI to hide in g_uri_to_string_partial(). Note that G_URI_HIDE_PASSWORD and G_URI_HIDE_AUTH_PARAMS will only work if the GUri was parsed with the corresponding flags.

since: 2.66

UriParamsFlags

Flags modifying the way parameters are handled by g_uri_parse_params() and GUriParamsIter.

since: 2.66

Error Domains

BookmarkFileError

Error codes returned by bookmark file parsing.