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.
Build
glib.h
glib-2.0
Related libraries
Additional documentation
- Building GLib
- Compiling GLib Applications
- Cross-compiling the GLib package
- Running GLib Applications
- Writing GLib Applications
- Support and Bug Reports
- GVariant Format Strings
- GVariant Text Format
- Character Set Conversions
- Internationalization
- String Utilities
- Basic Types
- Macros
- Conversion Macros
- Automatic Cleanup
- Memory Allocation
- Memory Slices
- Error Reporting
- Message Logging
- Warnings and Assertions
- File Utilities
- Hostname Utilities
- Miscellaneous Utilities
- The Main Event Loop
- Reference Counting
- Testing Framework
- Atomic Operations
- Bounds-checking Integer Arithmetic
- Threads
- Spawning Processes
- Random Numbers
- Numerical Definitions
- Simple XML Subset Parser
- Base64 Encoding
- Commandline Option Parser
- Data Structures
- Keyed Data Lists and Datasets
- Shell Utilities
- GUuid
- Unicode
- Version Information
- Deprecated Thread API
- Classes Hierarchy
Structs
deprecated: 2.10
Contains the public fields of a GArray
.
An opaque data structure which represents an asynchronous queue.
Contains the public fields of a GByteArray
.
A simple reference counted data type representing an immutable sequence of zero or more bytes from an unspecified origin.
since: 2.32
A GCache
allows sharing of complex data structures, in order to
save system resources.
deprecated: 2.32
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
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
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.
An opaque data structure that represents a keyed data list.
GDate
is a struct for calendrical calculations.
GDateTime
is a structure that combines a Gregorian date and time
into a single structure.
since: 2.26
Associates a string with a bit flag. Used in g_parse_debug_string().
An opaque structure representing an opened directory.
The GError
structure contains information about
an error that has occurred.
The GHashTable
struct is an opaque data structure to represent a
Hash Table. It should only be accessed via the
following functions.
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().
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
The GHook
struct represents a single hook function in a GHookList
.
The GHookList
struct represents a list of hook functions.
The GIConv struct wraps an iconv()
conversion descriptor. It contains
private data and should only be accessed using the following functions.
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.
A table of functions used to handle different types of GIOChannel
in a generic way.
GKeyFile
parses .ini-like config files.
The GList
struct is used for each element in a doubly-linked list.
Structure representing a single field in a structured log entry. See
g_log_structured()
for details.
since: 2.50
The GMainContext
struct is an opaque data
type representing a set of sources to be handled in a main loop.
The GMainLoop
struct is an opaque data type
representing the main event loop of a GLib or GTK application.
The GMappedFile
represents a file mapping created with
g_mapped_file_new(). It has only private members and should
not be accessed directly.
A parse context is used to parse a stream of bytes that you expect to contain marked-up text.
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.
A GMatchInfo is an opaque struct used to return information about matches.
deprecated: 2.10
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.
The GNode
struct represents one node in a n-ary tree.
A GOnce
struct controls a one-time initialization function. Any
one-time initialization function must have its own unique GOnce
struct.
since: 2.4
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.
G_OPTION_ARG_NONE
: %gbooleanG_OPTION_ARG_STRING
: %gchar*G_OPTION_ARG_INT
: %gintG_OPTION_ARG_FILENAME
: %gchar*G_OPTION_ARG_STRING_ARRAY
: %gchar**G_OPTION_ARG_FILENAME_ARRAY
: %gchar**G_OPTION_ARG_DOUBLE
: %gdouble.
A GOptionGroup
struct defines the options in a single
group. The struct has only private fields and should not be directly accessed.
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
A GPatternSpec
struct is the ‘compiled’ form of a glob-style pattern.
Represents a file descriptor, which events to poll for, and which events occurred.
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.
Contains the public fields of a GPtrArray
.
The GRand struct is an opaque data structure. It should only be accessed through the g_rand_* functions.
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
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
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
GScanner
provides a general-purpose lexical scanner.
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.
The GSequenceIter
struct is an opaque data type representing an
iterator pointing into a GSequence
.
The GSList
struct is used for each element in the singly-linked list.
The GSource
struct is an opaque data type
representing an event source.
The GSourceCallbackFuncs
struct contains
functions for managing callback objects.
The GSourceFuncs
struct contains a table of
functions used to handle event sources in a generic manner.
A type corresponding to the appropriate struct type for the stat()
system call, depending on the platform and/or compiler being used.
A GStaticMutex
works like a GMutex
.
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
.
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
.
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
A GString
is an object that handles the memory management of a C string.
GStringChunk
provides efficient storage of groups of strings.
An opaque structure representing a test case.
An opaque structure representing a test suite.
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().
This function table is no longer used by g_thread_init()
to initialize the thread system.
The GThreadPool
struct represents a thread pool.
GTimer
records a start time, and counts microseconds elapsed since
that time.
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
The GTree struct is an opaque data structure representing a balanced binary tree. It should be accessed only by using the following functions.
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
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
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
GVariant
is a variant datatype; it can contain one or more values
along with information about the type of the values.
since: 2.24
A utility type for constructing container-type GVariant
instances.
GVariantIter
is an opaque data structure and can only be accessed
using the following functions.
Unions
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.
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.
The GMutex
struct is an opaque data structure to represent a mutex
(mutual exclusion). It can be used to protect data against shared access.
A union holding the value of the token.
Aliases
Integer representing a day of the month; between 1 and 31.
Integer type representing a year.
Opaque type. See g_main_context_pusher_new()
for details.
Opaque type. See g_mutex_locker_new()
for details.
A type which is used to hold a process identification.
A GQuark is a non-zero integer which uniquely identifies a particular string.
Opaque type. See g_rec_mutex_locker_new()
for details.
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().
Opaque type. See g_rw_lock_reader_locker_new()
for details.
Opaque type. See g_rw_lock_writer_locker_new()
for details.
A typedef alias for gchar**. This is mostly useful when used together with
g_auto()
.
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
A value representing an interval of time, in microseconds.
Enumerations
The hashing algorithm to be used by GChecksum
when performing the
digest of some data.
since: 2.16
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.
Enumeration representing a month; values are G_DATE_JANUARY
,
G_DATE_FEBRUARY
, etc. G_DATE_BAD_MONTH
is the invalid value.
Enumeration representing a day of the week; G_DATE_MONDAY
,
G_DATE_TUESDAY
, etc. G_DATE_BAD_WEEKDAY
is an invalid weekday.
The possible errors, used in the v_error
field
of GTokenValue
, when the token is a G_TOKEN_ERROR
.
GIOError
is only used by the deprecated functions
g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek().
Statuses returned by most of the GIOFuncs
functions.
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
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.
The possible statuses of a one-time initialization function
controlled by a GOnce
struct.
since: 2.4
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
.
An enumeration specifying the base position for a
g_io_channel_seek_position()
operation.
The type of file to return the filename for, when used with
g_test_build_filename()
.
since: 2.38
Disambiguates a given time in two ways.
The possible types of token returned from each
g_scanner_get_next_token()
call.
Specifies the type of traversal performed by g_tree_traverse(),
g_node_traverse()
and g_node_find().
These are the possible line break classifications.
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
.
These are the possible character classifications from the Unicode specification. See Unicode Character Database.
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
Bitfields
Flags to pass to g_file_set_contents_full()
to affect its safety and performance.
since: 2.66
A test to perform on a file using g_file_test().
Flags to modify the format of the string returned by g_format_size_full().
Flags used internally in the GHook
implementation.
A bitwise combination representing a condition to watch for on an event source.
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().
Flags which influence the parsing.
Flags specifying the level of log messages.
Flags to pass to g_main_context_new_with_flags()
which affect the
behaviour of a GMainContext
.
since: 2.72
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
.
Flags that affect the behaviour of the parser.
Flags which modify individual options.
Flags passed to g_spawn_sync(), g_spawn_async()
and g_spawn_async_with_pipes().
Flags to pass to g_test_trap_subprocess()
to control input and output.
Specifies which nodes are visited during several of the tree
functions, including g_node_traverse()
and g_node_find().
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
Flags modifying the way parameters are handled by g_uri_parse_params()
and
GUriParamsIter
.
since: 2.66
Error Domains
Error codes returned by bookmark file parsing.
Error codes returned by character set conversion routines.
Values corresponding to errno
codes returned from file operations
on UNIX. Unlike errno
codes, GFileError values are available on
all systems, even Windows. The exact meaning of each code depends
on what sort of file operation you were performing; the UNIX
documentation gives more details. The following error code descriptions
come from the GNU C Library manual, and are under the copyright
of that manual.
Error codes returned by GIOChannel
operations.
Error codes returned by key file parsing.
Error codes returned by markup parsing.
Error codes returned by option parsing.
Error codes returned by shell functions.
Error codes returned by spawning processes.
Possible errors of thread related functions.
Error codes returned by parsing text-format GVariants.
Callbacks
Specifies the type of the value_destroy_func
and key_destroy_func
functions passed to g_cache_new(). The functions are passed a
pointer to the GCache
key or GCache
value and should free any
memory and other resources associated with it.
deprecated: 2.32
Specifies the type of the key_dup_func
function passed to
g_cache_new(). The function is passed a key
(not a value as the prototype implies) and
should return a duplicate of the key.
deprecated: 2.32
Specifies the type of the value_new_func
function passed to
g_cache_new(). It is passed a GCache
key and should create the
value corresponding to the key.
deprecated: 2.32
Prototype of a GChildWatchSource
callback, called when a child
process has exited.
Specifies the type of function passed to g_clear_handle_id()
The
implementation is expected to free the resource identified by handle_id
;
for instance, if handle_id
is a GSource
ID,
g_source_remove()
can be used.
since: 2.56
Specifies the type of a comparison function used to compare two values. The function should return a negative integer if the first value comes before the second, 0 if they are equal, or a positive integer if the first value comes after the second.
Specifies the type of a comparison function used to compare two values. The function should return a negative integer if the first value comes before the second, 0 if they are equal, or a positive integer if the first value comes after the second.
Specifies the type of the function passed to g_completion_new(). It
should return the string corresponding to the given target item.
This is used when you use data structures as GCompletion
items.
deprecated: 2.26
Specifies the type of the function passed to
g_completion_set_compare(). This is used when you use strings as
GCompletion
items.
deprecated: 2.26
A function of this signature is used to copy the node data when doing a deep-copy of a tree.
since: 2.4
Specifies the type of function passed to g_dataset_foreach(). It is
called with each GQuark
id and associated data element, together
with the user_data
parameter supplied to g_dataset_foreach().
Specifies the type of function which is called when a data element is destroyed. It is passed the pointer to the data element and should free any memory and resources allocated for it.
The type of functions that are used to ‘duplicate’ an object.
What this means depends on the context, it could just be
incrementing the reference count, if data
is a ref-counted object.
Specifies the type of a function used to test two values for
equality. The function should return TRUE
if both values are equal
and FALSE
otherwise.
Specifies the type of a function used to test two values for
equality. The function should return TRUE
if both values are equal
and FALSE
otherwise.
since: 2.74
Specifies the type of function which is called when an extended error instance is freed. It is passed the error pointer about to be freed, and should free the error’s private data fields.
since: 2.68
Specifies the type of function which is called when an extended
error instance is copied. It is passed the pointer to the
destination error and source error, and should copy only the fields
of the private data from src_error
to dest_error
.
since: 2.68
Specifies the type of function which is called just after an
extended error instance is created and its fields filled. It should
only initialize the fields in the private data, which can be
received with the generated *_get_private()
function.
since: 2.68
Declares a type of function which takes an arbitrary data pointer argument and has no return value. It is not currently used in GLib or GTK.
Specifies the type of functions passed to g_list_foreach()
and g_slist_foreach().
Specifies the type of the hash function which is passed to
g_hash_table_new()
when a GHashTable
is created.
Specifies the type of the function passed to g_hash_table_foreach().
It is called with each key/value pair, together with the user_data
parameter which is passed to g_hash_table_foreach().
Defines the type of a hook function that can be invoked by g_hook_list_invoke_check().
Defines the type of function used by g_hook_list_marshal_check().
Defines the type of function used to compare GHook
elements in g_hook_insert_sorted().
Defines the type of function to be called when a hook in a list of hooks gets finalized.
Defines the type of the function passed to g_hook_find().
Defines the type of a hook function that can be invoked by g_hook_list_invoke().
Defines the type of function used by g_hook_list_marshal().
Specifies the type of the function passed to
g_hash_table_find()
, g_hash_table_foreach_remove()
, and
g_hash_table_foreach_steal()
.
Specifies the type of function passed to g_io_add_watch()
or
g_io_add_watch_full(), which is called when the requested condition
on a GIOChannel
is satisfied.
Specifies the prototype of log handler functions.
Writer function for log entries. A log entry is a collection of one or more
GLogFields
, using the standard field names from journal
specification.
See g_log_structured()
for more information.
since: 2.50
Specifies the type of function passed to g_node_children_foreach(). The function is called with each child node, together with the user data passed to g_node_children_foreach().
Specifies the type of function passed to g_node_traverse(). The
function is called with each of the nodes visited, together with the
user data passed to g_node_traverse(). If the function returns
TRUE
, then the traversal is stopped.
The type of function to be passed as callback for G_OPTION_ARG_CALLBACK
options.
The type of function to be used as callback when a parse error occurs.
The type of function that can be called before and after parsing.
Specifies the type of function passed to g_main_context_set_poll_func().
The semantics of the function should match those of the poll()
system call.
Specifies the type of the print handler functions. These are called with the complete formatted string to output.
Specifies the type of the function passed to g_regex_replace_eval().
It is called for each occurrence of the pattern in the string passed
to g_regex_replace_eval(), and it should append the replacement to
result
.
since: 2.14
Specifies the type of the message handler function.
A GSequenceIterCompareFunc
is a function used to compare iterators.
It must return zero if the iterators compare equal, a negative value
if a
comes before b
, and a positive value if b
comes before a
.
Dispose function for source
. See g_source_set_dispose_function()
for details.
since: 2.64
This is just a placeholder for GClosureMarshal
,
which cannot be used here for dependency reasons.
Specifies the type of function passed to g_timeout_add()
,
g_timeout_add_full()
, g_idle_add()
, and
g_idle_add_full()
.
A source function that is only called once before being removed from the main context automatically.
since: 2.74
Specifies the type of the setup function passed to g_spawn_async(),
g_spawn_sync()
and g_spawn_async_with_pipes(), which can, in very
limited ways, be used to affect the child’s execution.
Specifies the type of the func
functions passed to g_thread_new()
or g_thread_try_new().
The type of functions which are used to translate user-visible strings, for output.
Specifies the type of function passed to g_tree_traverse(). It is
passed the key and value of each node, together with the user_data
parameter passed to g_tree_traverse(). If the function returns
TRUE
, the traversal is stopped.
Specifies the type of function passed to g_tree_foreach_node(). It is
passed each node, together with the user_data
parameter passed to
g_tree_foreach_node(). If the function returns TRUE
, the traversal is stopped.
since: 2.68
Declares a type of function which takes no arguments and has no return value. It is used to specify the type function passed to g_atexit().
Functions
A wrapper for the POSIX access()
function. This function is used to
test a pathname for one or several of read, write or execute
permissions, or just existence.
since: 2.8
This function is similar to g_malloc(), allocating (n_blocks
* n_block_bytes
)
bytes, but care is taken to align the allocated memory to with the given
alignment value. Additionally, it will detect possible overflow during multiplication.
since: 2.72
This function is similar to g_aligned_alloc(), but it will also clear the allocated memory before returning it.
since: 2.72
Frees the memory pointed to by mem
, assuming it is has the given size
and
alignment
.
since: 2.76
Determines the numeric value of a character as a decimal digit. If the
character is not a decimal digit according to g_ascii_isdigit()
,
-1
is returned.
Converts a gdouble
to a string, using the ‘.’ as
decimal point.
Converts a gdouble
to a string, using the ‘.’ as
decimal point. To format the number you pass in
a printf()
-style format string. Allowed conversion
specifiers are ‘e’, ‘E’, ‘f’, ‘F’, ‘g’ and ‘G’.
Compare two strings, ignoring the case of ASCII characters.
Converts all upper case ASCII letters to lower case ASCII letters, with
semantics that exactly match g_ascii_tolower()
.
A convenience function for converting a string to a signed number.
since: 2.54
A convenience function for converting a string to an unsigned number.
since: 2.54
Compare s1
and s2
, ignoring the case of ASCII characters and any
characters after the first n
in each string. If either string is
less than n
bytes long, comparison will stop at the first nul byte encountered.
Converts a string to a floating point value.
Converts all lower case ASCII letters to upper case ASCII letters, with
semantics that exactly match g_ascii_toupper()
.
Convert a character to ASCII lower case. If the character is not an ASCII upper case letter, it is returned unchanged.
Convert a character to ASCII upper case. If the character is not an ASCII lower case letter, it is returned unchanged.
Determines the numeric value of a character as a hexadecimal digit. If the
character is not a hex digit according to g_ascii_isxdigit()
,
-1
is returned.
Internal function used to print messages from the public
g_assert()
and g_assert_not_reached()
macros.
Performs an atomic bitwise ‘and’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Compares atomic
to oldval
and, if equal, sets it to newval
.
If atomic
was not equal to oldval
then no change occurs.
since: 2.4
Compares atomic
to oldval
and, if equal, sets it to newval
.
If atomic
was not equal to oldval
then no change occurs.
In any case the value of atomic
before this operation is stored in preval
.
since: 2.74
This function existed before g_atomic_int_add()
returned the prior
value of the integer (which it now does). It is retained only for
compatibility reasons. Don’t use this function in new code.
deprecated: 2.30 since: 2.4
Performs an atomic bitwise ‘or’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Performs an atomic bitwise ‘xor’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Performs an atomic bitwise ‘and’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Compares atomic
to oldval
and, if equal, sets it to newval
.
If atomic
was not equal to oldval
then no change occurs.
since: 2.4
Compares atomic
to oldval
and, if equal, sets it to newval
.
If atomic
was not equal to oldval
then no change occurs.
In any case the value of atomic
before this operation is stored in preval
.
since: 2.74
Sets the atomic
to newval
and returns the old value from atomic
.
since: 2.74
Performs an atomic bitwise ‘or’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Performs an atomic bitwise ‘xor’ of the value of atomic
and val
,
storing the result back in atomic
.
since: 2.30
Allocates block_size
bytes of memory, and adds atomic
reference counting semantics to it.
since: 2.58
Allocates block_size
bytes of memory, and adds atomic
reference counting semantics to it.
since: 2.58
Allocates a new block of data with atomic reference counting
semantics, and copies block_size
bytes of mem_block
into it.
since: 2.58
Retrieves the size of the reference counted data pointed by mem_block
.
since: 2.58
Atomically releases a reference on the data pointed by mem_block
.
since: 2.58
Decode a sequence of Base-64 encoded text into binary data. Note that the returned binary data is not necessarily zero-terminated, so it should not be used as a character string.
since: 2.12
Decode a sequence of Base-64 encoded text into binary data by overwriting the input data.
since: 2.20
Incrementally decode a sequence of binary data from its Base-64 stringified representation. By calling this function multiple times you can convert data in chunks to avoid having to have the full encoded data in memory.
since: 2.12
Encode a sequence of binary data into its Base-64 stringified representation.
since: 2.12
Flush the status from a sequence of calls to g_base64_encode_step().
since: 2.12
Incrementally encode a sequence of binary data into its Base-64 stringified representation. By calling this function multiple times you can convert data in chunks to avoid having to have the full encoded data in memory.
since: 2.12
Gets the name of the file without any leading directory components. It returns a pointer into the given file name string.
deprecated: 2.2
Sets the indicated lock_bit
in address
. If the bit is already
set, this call will block until g_bit_unlock()
unsets the
corresponding bit.
since: 2.24
Sets the indicated lock_bit
in address
and atomically returns the new value.
unstable since: 2.86
Find the position of the first bit set in mask
, searching
from (but not including) nth_bit
upwards. Bits are numbered
from 0 (least significant) to sizeof(#gulong) * 8 - 1 (31 or 63,
usually). To start searching from the 0th bit, set nth_bit
to -1.
Find the position of the first bit set in mask
, searching
from (but not including) nth_bit
downwards. Bits are numbered
from 0 (least significant) to sizeof(#gulong) * 8 - 1 (31 or 63,
usually). To start searching from the last bit, set nth_bit
to
-1 or GLIB_SIZEOF_LONG * 8.
Gets the number of bits used to hold number
,
e.g. if number
is 4, 3 bits are needed.
Sets the indicated lock_bit
in address
, returning TRUE
if
successful. If the bit is already set, returns FALSE
immediately.
since: 2.24
Clears the indicated lock_bit
in address
. If another thread is
currently blocked in g_bit_lock()
on this same bit then it will be
woken up.
since: 2.24
This is like g_bit_unlock()
but also atomically sets address
to
val
.
unstable since: 2.86
deprecated: 2.10
Creates a filename from a series of elements using the correct separator for the current platform.
Creates a filename from a list of elements using the correct separator for the current platform.
since: 2.56
Creates a filename from a vector of elements using the correct separator for the current platform.
since: 2.8
Creates a path from a series of elements using separator
as the
separator between elements.
Behaves exactly like g_build_path(), but takes the path elements as a string array, instead of variadic arguments.
since: 2.8
Gets the canonical file name from filename
. All triple slashes are turned into
single slashes, and all ..
and .
s resolved against relative_to
.
since: 2.58
A wrapper for the POSIX chdir()
function. The function changes the
current directory of the process to path
.
since: 2.8
Sets a function to be called when the child indicated by pid
exits, at a default priority, G_PRIORITY_DEFAULT
.
since: 2.4
Sets a function to be called when the child indicated by pid
exits, at the priority priority
.
since: 2.4
A wrapper for the POSIX chmod()
function. The chmod()
function is
used to set the permissions of a file system object.
since: 2.8
If err
or *err
is NULL
, does nothing. Otherwise,
calls g_error_free()
on *err
and sets *err
to NULL
.
If fd_ptr
points to a file descriptor, close it and return
whether closing it was successful, like g_close().
If fd_ptr
points to a negative number, return TRUE
without closing
anything.
In both cases, set fd_ptr
to -1
before returning.
since: 2.76
Clears a pointer to a GList
, freeing it and, optionally, freeing its elements using destroy
.
since: 2.64
Clears a pointer to a GSList
, freeing it and, optionally, freeing its elements using destroy
.
since: 2.64
This wraps the close()
call. In case of error, %errno will be
preserved, but the error will also be stored as a GError
in error
.
In case of success, %errno is undefined.
since: 2.36
Computes the checksum for a binary data
. This is a
convenience wrapper for g_checksum_new(), g_checksum_get_string()
and g_checksum_free().
since: 2.34
Computes the checksum for a binary data
of length
. This is a
convenience wrapper for g_checksum_new(), g_checksum_get_string()
and g_checksum_free().
since: 2.16
Computes the HMAC for a binary data
. This is a
convenience wrapper for g_hmac_new(), g_hmac_get_string()
and g_hmac_unref().
since: 2.50
Computes the HMAC for a binary data
of length
. This is a
convenience wrapper for g_hmac_new(), g_hmac_get_string()
and g_hmac_unref().
since: 2.30
Converts a string from one character set to another.
Converts a string from one character set to another, possibly
including fallback sequences for characters not representable
in the output. Note that it is not guaranteed that the specification
for the fallback sequences in fallback
will be honored. Some
systems may do an approximate conversion from from_codeset
to to_codeset
in their iconv()
functions,
in which case GLib will simply return that approximate conversion.
Converts a string from one character set to another.
A wrapper for the POSIX creat()
function. The creat()
function is
used to convert a pathname into a file descriptor, creating a file
if necessary.
since: 2.8
Frees all the data elements of the datalist. The data elements’ destroy functions are called if they have been set.
Calls the given function for each data element of the datalist. The
function is called with each data element’s GQuark
id and data,
together with the given user_data
parameter. Note that this
function is NOT thread-safe. So unless datalist
can be protected
from any modifications during invocation of this function, it should
not be called.
Gets a data element, using its string identifier. This is slower than
g_datalist_id_get_data()
because it compares strings.
Gets flags values packed in together with the datalist. See g_datalist_set_flags().
since: 2.8
This is a variant of g_datalist_id_get_data()
which
returns a ‘duplicate’ of the value. dup_func
defines the
meaning of ‘duplicate’ in this context, it could e.g.
take a reference on a ref-counted object.
since: 2.34
Retrieves the data element corresponding to key_id
.
Removes an element, without calling its destroy notification function.
Compares the member that is associated with key_id
in
datalist
to oldval
, and if they are the same, replace
oldval
with newval
.
since: 2.34
Sets the data corresponding to the given GQuark
id, and the
function to be called when the element is removed from the datalist.
Any previous data with the same key is removed, and its destroy
function is called.
Resets the datalist to NULL
. It does not free any memory or call
any destroy functions.
Turns on flag values for a data list. This function is used
to keep a small number of boolean flags in an object with
a data list without using any additional space. It is
not generally useful except in circumstances where space
is very tight. (It is used in the base GObject
type, for example.).
since: 2.8
Turns off flag values for a data list. See g_datalist_unset_flags().
since: 2.8
Destroys the dataset, freeing all memory allocated, and calling any destroy functions set for data elements.
Calls the given function for each data element which is associated
with the given location. Note that this function is NOT thread-safe.
So unless dataset_location
can be protected from any modifications
during invocation of this function, it should not be called.
Gets the data element corresponding to a GQuark
.
Removes an element, without calling its destroy notification function.
Sets the data element associated with the given GQuark
id, and also
the function to call when the data element is destroyed. Any
previous data with the same key is removed, and its destroy function
is called.
This is a variant of g_dgettext()
that allows specifying a locale
category instead of always using LC_MESSAGES
. See g_dgettext()
for
more information about how this functions differs from calling
dcgettext()
directly.
since: 2.26
This function is a wrapper of dgettext()
which does not translate
the message if the default domain as set with textdomain()
has no
translations for the current locale.
since: 2.18
Compares two #gpointer arguments and returns TRUE
if they are equal.
It can be passed to g_hash_table_new()
as the key_equal_func
parameter, when using opaque pointers compared by pointer value as
keys in a GHashTable
.
Converts a gpointer to a hash value.
It can be passed to g_hash_table_new()
as the hash_func
parameter,
when using opaque pointers compared by pointer value as keys in a
GHashTable
.
This function is a wrapper of dngettext()
which does not translate
the message if the default domain as set with textdomain()
has no
translations for the current locale.
since: 2.18
Compares the two #gdouble values being pointed to and returns
TRUE
if they are equal.
It can be passed to g_hash_table_new()
as the key_equal_func
parameter, when using non-NULL
pointers to doubles as keys in a
GHashTable
.
since: 2.22
Converts a pointer to a #gdouble to a hash value.
It can be passed to g_hash_table_new()
as the hash_func
parameter,
It can be passed to g_hash_table_new()
as the hash_func
parameter,
when using non-NULL
pointers to doubles as keys in a GHashTable
.
since: 2.22
This function is a variant of g_dgettext()
which supports
a disambiguating message context. GNU gettext uses the
‘004円’ character to separate the message context and
message id in msgctxtid
.
If 0 is passed as msgidoffset
, this function will fall back to
trying to use the deprecated convention of using “|” as a separation character.
since: 2.16
This function is a variant of g_dgettext()
which supports
a disambiguating message context. GNU gettext uses the
‘004円’ character to separate the message context and
message id in msgctxtid
.
since: 2.18
Returns the value of the environment variable variable
in the
provided list envp
.
since: 2.32
Sets the environment variable variable
in the provided list
envp
to value
.
since: 2.32
Removes the environment variable variable
from the provided
environment envp
.
since: 2.32
Mark every file descriptor equal to or greater than lowfd
to be closed
at the next execve()
or similar, as if via the FD_CLOEXEC
flag.
since: 2.80
Gets a GFileError
constant based on the passed-in err_no
.
Reads an entire file into allocated memory, with good error checking.
Opens a file for writing in the preferred directory for temporary files (as returned by g_get_tmp_dir()).
Reads the contents of the symbolic link filename
like the POSIX
readlink()
function.
since: 2.4
Writes all of contents
to a file named filename
. This is a convenience
wrapper around calling g_file_set_contents_full()
with flags
set to
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING
and
mode
set to 0666
.
since: 2.8
Writes all of contents
to a file named filename
, with good error checking.
If a file called filename
already exists it will be overwritten.
since: 2.66
Returns TRUE
if any of the tests in the bitfield test
are
TRUE
. For example, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)
will return TRUE
if the file exists; the check whether it’s a
directory doesn’t matter since the existence test is TRUE
. With
the current set of available tests, there’s no point passing in
more than one test at a time.
Returns the display basename for the particular filename, guaranteed to be valid UTF-8. The display name might not be identical to the filename, for instance there might be problems converting it to UTF-8, and some files can be translated in the display.
since: 2.6
Converts a filename into a valid UTF-8 string. The conversion is
not necessarily reversible, so you should keep the original around
and use the return value of this function only for display purposes.
Unlike g_filename_to_utf8(), the result is guaranteed to be non-NULL
even if the filename actually isn’t in the GLib file name encoding.
since: 2.6
Converts an escaped ASCII-encoded URI to a local filename in the encoding used for filenames.
Converts a string from UTF-8 to the encoding GLib uses for filenames. Note that on Windows GLib uses UTF-8 for filenames; on other platforms, this function indirectly depends on the current locale.
Converts an absolute filename to an escaped ASCII-encoded URI, with the path component following Section 3.3. of RFC 2396.
Converts a string which is in the encoding used by GLib for filenames into a UTF-8 string. Note that on Windows GLib uses UTF-8 for filenames; on other platforms, this function indirectly depends on the current locale.
Locates the first executable named program
in the user’s path, in the
same way that execvp()
would locate it. Returns an allocated string
with the absolute path name, or NULL
if the program is not found in
the path. If program
is already an absolute path, returns a copy of
program
if program
exists and is executable, and NULL
otherwise.
On Windows, if program
does not have a file type suffix, tries
with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
the PATHEXT
environment variable.
A wrapper for the stdio fopen()
function. The fopen()
function
opens a file and associates a new stream with it.
since: 2.6
Formats a size (for example the size of a file) into a human readable string. Sizes are rounded to the nearest size prefix (kB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes will be converted into the string “3.2 MB”. The returned string is UTF-8, and may use a non-breaking space to separate the number and units, to ensure they aren’t separated when line wrapped.
since: 2.30
Formats a size (for example the size of a file) into a human readable string. Sizes are rounded to the nearest size prefix (KB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes will be converted into the string “3.1 MB”.
deprecated: 2.30 since: 2.16
An implementation of the standard fprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
Frees the memory pointed to by mem
.
A wrapper for the POSIX freopen()
function. The freopen()
function
opens a file and associates it with an existing stream.
since: 2.6
A wrapper for the POSIX fsync()
function. On Windows, _commit()
will be
used. On macOS, fcntl(F_FULLFSYNC)
will be used.
The fsync()
function is used to synchronize a file’s in-core
state with that of the disk.
since: 2.64
Gets a human-readable name for the application, as set by
g_set_application_name(). This name should be localized if
possible, and is intended for display to the user. Contrast with
g_get_prgname(), which gets a non-localized name. If
g_set_application_name()
has not been called, returns the result of
g_get_prgname()
(which may be NULL
if g_set_prgname()
has also not
been called).
since: 2.2
Obtains the character set for the current locale;
you might use this character set as an argument to g_convert(), to convert
from the current locale’s encoding to some other encoding. (Frequently
g_locale_to_utf8()
and g_locale_from_utf8()
are nice shortcuts, though.).
Gets the character set for the current locale.
Obtains the character set used by the console attached to the process, which is suitable for printing output to the terminal.
since: 2.62
Gets the current directory.
Determines the preferred character sets used for filenames.
The first character set from the charsets
is the filename encoding, the
subsequent character sets are used when trying to generate a displayable
representation of a filename, see g_filename_display_name().
since: 2.6
Gets the current user’s home directory.
Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale “C”.
since: 2.6
Computes a list of applicable locale names with a locale category name, which can be used to construct the fallback locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale “C”.
since: 2.58
Returns a list of derived variants of locale
, which can be used to
e.g. construct locale-dependent filenames or search paths. The returned
list is sorted from most desirable to least desirable.
This function handles territory, charset and extra locale modifiers. See
setlocale(3)
for information about locales and their format.
since: 2.28
Determine the approximate number of threads that the system will
schedule simultaneously for this process. This is intended to be
used as a parameter to g_thread_pool_new()
for CPU bound tasks and
similar cases.
since: 2.36
Gets the name of the program. This name should not be localized, in contrast to g_get_application_name().
Gets the real name of the user. This usually comes from the user’s
entry in the passwd
file. The encoding of the returned string is
system-defined. (On Windows, it is, however, always UTF-8.) If the
real user name cannot be determined, the string “Unknown” is returned.
Returns an ordered list of base directories in which to access system-wide configuration information.
since: 2.6
Returns an ordered list of base directories in which to access system-wide application data.
since: 2.6
Gets the directory to use for temporary files.
Returns a base directory in which to store non-essential, cached data specific to particular user.
since: 2.6
Returns a base directory in which to store user-specific application configuration information such as user preferences and settings.
since: 2.6
Returns a base directory in which to access application data such as icons that is customized for a particular user.
since: 2.6
Gets the user name of the current user. The encoding of the returned string is system-defined. On UNIX, it might be the preferred file name encoding, or something else, and there is no guarantee that it is even consistent on a machine. On Windows, it is always UTF-8.
Returns a directory that is unique to the current user on the local system.
since: 2.28
Returns a base directory in which to store state files specific to particular user.
since: 2.72
Returns the value of an environment variable.
Tests if hostname
contains segments with an ASCII-compatible
encoding of an Internationalized Domain Name. If this returns
TRUE
, you should decode the hostname with g_hostname_to_unicode()
before displaying it to the user.
since: 2.22
Tests if hostname
is the string form of an IPv4 or IPv6 address.
(Eg, “192.168.0.1”.).
since: 2.22
Tests if hostname
contains Unicode characters. If this returns
TRUE
, you need to encode the hostname with g_hostname_to_ascii()
before using it in non-IDN-aware contexts.
since: 2.22
Converts hostname
to its canonical ASCII form; an ASCII-only
string containing no uppercase letters and not ending with a
trailing dot.
since: 2.22
Converts hostname
to its canonical presentation form; a UTF-8
string in Unicode normalization form C, containing no uppercase
letters, no forbidden characters, and no ASCII-encoded segments,
and not ending with a trailing dot.
since: 2.22
Same as the standard UNIX routine iconv(), but may be implemented via libiconv on UNIX flavors that lack a native implementation.
Adds a function to be called whenever there are no higher priority events pending to the default main loop.
Adds a function to be called whenever there are no higher priority events pending.
Adds a function to be called whenever there are no higher priority events pending to the default main loop.
since: 2.74
Removes the idle function with the given data.
Creates a new idle source.
Compares the two #gint64 values being pointed to and returns
TRUE
if they are equal.
It can be passed to g_hash_table_new()
as the key_equal_func
parameter, when using non-NULL
pointers to 64-bit integers as keys in a
GHashTable
.
since: 2.22
Compares the two #gint values being pointed to and returns
TRUE
if they are equal.
It can be passed to g_hash_table_new()
as the key_equal_func
parameter, when using non-NULL
pointers to integers as keys in a
GHashTable
.
Converts a pointer to a #gint to a hash value.
It can be passed to g_hash_table_new()
as the hash_func
parameter,
when using non-NULL
pointers to integer values as keys in a GHashTable
.
Returns a canonical representation for string
. Interned strings
can be compared for equality by comparing the pointers, instead of
using strcmp(). g_intern_static_string()
does not copy the string,
therefore string
must not be freed or modified.
since: 2.10
Returns a canonical representation for string
. Interned strings
can be compared for equality by comparing the pointers, instead of
using strcmp().
since: 2.10
Adds the GIOChannel
into the default main loop context
with the default priority.
Adds the GIOChannel
into the default main loop context
with the given priority.
Creates a GSource
that’s dispatched when condition
is met for the
given channel
. For example, if condition is G_IO_IN
, the source will
be dispatched when there’s data available for reading.
Converts a string from UTF-8 to the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale. On Windows this means the system codepage.
Converts a string which is in the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale into a UTF-8 string.
Logs an error or debugging message.
The default log handler set up by GLib; g_log_set_default_handler()
allows to install an alternate default log handler.
Return whether debug output from the GLib logging system is enabled.
since: 2.72
Removes the log handler.
Sets the message levels which are always fatal, in any log domain.
Enable or disable debug output from the GLib logging system for all domains.
since: 2.72
Installs a default log handler which is used if no log handler has been set for the particular log domain and log level combination.
since: 2.6
Sets the log levels which are fatal in the given domain.
Sets the log handler for a domain and a set of log levels.
Like g_log_set_handler()
, but takes a destroy notify for the user_data
.
since: 2.46
Set a writer function which will be called to format and write out each log message.
since: 2.50
Format a structured log message and output it to the default log destination for the platform.
since: 2.50
Reset the list of domains to be logged, that might be initially set by the
G_MESSAGES_DEBUG
or DEBUG_INVOCATION
environment variables.
since: 2.80
Configure whether the built-in log functions will output all log messages to
stderr
.
since: 2.68
Check whether g_log_writer_default()
and g_log_default_handler()
would
ignore a message with the given domain and level.
since: 2.68
Format a structured log message as a string suitable for outputting to the terminal (or elsewhere).
since: 2.50
Check whether the given output_fd
file descriptor is a connection to the
systemd journal, or something else (like a log file or stdout
or
stderr
).
since: 2.50
Format a structured log message and send it to the systemd journal as a set of key–value pairs.
since: 2.50
Format a structured log message and print it to either stdout
or stderr
,
depending on its log level.
since: 2.50
Check whether the given output_fd
file descriptor supports
ANSI color escape sequences.
since: 2.50
Format a structured log message and send it to the syslog daemon. Only fields which are understood by this function are included in the formatted string which is printed.
since: 2.80
Logs an error or debugging message.
A wrapper for the POSIX lstat()
function. The lstat()
function is
like stat()
except that in the case of symbolic links, it returns
information about the symbolic link itself and not the file that it
refers to. If the system does not support symbolic links g_lstat()
is identical to g_stat().
since: 2.6
Returns the depth of the stack of calls to
g_main_context_dispatch()
on any GMainContext
in the current thread.
Allocates n_bytes
bytes of memory.
If n_bytes
is 0 it returns NULL
.
Allocates n_bytes
bytes of memory, initialized to 0’s.
If n_bytes
is 0 it returns NULL
.
This function is similar to g_malloc0(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
This function is similar to g_malloc(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
Collects the attributes of the element from the data passed to the
GMarkupParser
start_element function, dealing with common error
conditions and supporting boolean values.
since: 2.16
Escapes text so that the markup parser will parse it verbatim. Less than, greater than, ampersand, etc. are replaced with the corresponding entities. This function would typically be used when writing out a file to be parsed with the markup parser.
Formats arguments according to format
, escaping
all string and character arguments in the fashion
of g_markup_escape_text(). This is useful when you
want to insert literal strings into XML-style markup
output, without having to worry that the strings
might themselves contain markup.
since: 2.4
Formats the data in args
according to format
, escaping
all string and character arguments in the fashion
of g_markup_escape_text(). See g_markup_printf_escaped().
since: 2.4
Checks whether the allocator used by g_malloc()
is the system’s
malloc implementation. If it returns TRUE
memory allocated with
malloc()
can be used interchangeably with memory allocated using g_malloc().
This function is useful for avoiding an extra copy of allocated memory returned
by a non-GLib-based API.
deprecated: 2.46
GLib used to support some tools for memory profiling, but this no longer works. There are many other useful tools for memory profiling these days which can be used instead.
deprecated: 2.46
This function used to let you override the memory allocation function. However, its use was incompatible with the use of global constructors in GLib and GIO, because those use the GLib allocators before main is reached. Therefore this function is now deprecated and is just a stub.
deprecated: 2.46
Allocates byte_size
bytes of memory, and copies byte_size
bytes into it
from mem
. If mem
is NULL
it returns NULL
.
deprecated: 2.68
Allocates byte_size
bytes of memory, and copies byte_size
bytes into it
from mem
. If mem
is NULL
it returns NULL
.
since: 2.68
A wrapper for the POSIX mkdir()
function. The mkdir()
function
attempts to create a directory with the given name and permissions.
The mode argument is ignored on Windows.
since: 2.6
Create a directory if it doesn’t already exist. Create intermediate parent directories as needed, too.
since: 2.8
Opens a temporary file in the current directory.
Set the pointer at the specified location to NULL
.
Prompts the user with
[E]xit, [H]alt, show [S]tack trace or [P]roceed
.
This function is intended to be used for debugging use only.
The following example shows how it can be used together with
the g_log()
functions.
Invokes gdb, which attaches to the current process and shows a
stack trace. Called by g_on_error_query()
when the “[S]tack trace”
option is selected. You can get the current process’s program name
with g_get_prgname(), assuming that you have called gtk_init()
or gdk_init().
A wrapper for the POSIX open()
function. The open()
function is
used to convert a pathname into a file descriptor.
since: 2.6
Parses a string containing debugging options into a %guint containing bit flags. This is used within GDK and GTK to parse the debug options passed on the command line or through environment variables.
Gets the last component of the filename.
Gets the directory components of a file name. For example, the directory
component of /usr/bin/test
is /usr/bin
. The directory component of /
is /
.
Returns TRUE
if the given file_name
is an absolute file name.
Note that this is a somewhat vague concept on Windows.
Returns a pointer into file_name
after the root component,
i.e. after the “/” in UNIX or “C:" under Windows. If file_name
is not an absolute path it returns NULL
.
Matches a string against a pattern given as a string.
This is equivalent to g_bit_lock, but working on pointers (or other pointer-sized values).
since: 2.30
This is equivalent to g_bit_lock, but working on pointers (or other pointer-sized values).
since: 2.80
This mangles ptr
as g_pointer_bit_lock()
and g_pointer_bit_unlock()
do.
since: 2.80
This is equivalent to g_bit_trylock(), but working on pointers (or other pointer-sized values).
since: 2.30
This is equivalent to g_bit_unlock, but working on pointers (or other pointer-sized values).
since: 2.30
This is equivalent to g_pointer_bit_unlock()
and atomically setting
the pointer value.
since: 2.80
Polls fds
, as with the poll()
system call, but portably. (On
systems that don’t have poll(), it is emulated using select().)
This is used internally by GMainContext
, but it can be called
directly if you need to block until a file descriptor is ready, but
don’t want to run the full main loop.
since: 2.20
Formats a string according to format
and prefix it to an existing
error message. If err
is NULL
(ie: no error variable) then do nothing.
since: 2.16
Prefixes prefix
to an existing error message. If err
or *err
is
NULL
(i.e.: no error variable) then do nothing.
since: 2.70
Outputs a formatted message via the print handler.
Outputs a formatted message via the error message handler.
An implementation of the standard printf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
Calculates the maximum space needed to store the output
of the sprintf()
function.
If dest
is NULL
, free src
; otherwise, moves src
into *dest
.
The error variable dest
points to must be NULL
.
If dest
is NULL
, free src
; otherwise, moves src
into *dest
.
*dest
must be NULL
. After the move, add a prefix as with g_prefix_error().
since: 2.16
This is just like the standard C qsort()
function, but
the comparison routine accepts a user data argument
(like qsort_r()
).
deprecated: 2.82
Gets the GQuark
identifying the given (static) string. If the
string does not currently have an associated GQuark
, a new GQuark
is created, linked to the given string.
Gets the GQuark
identifying the given string. If the string does
not currently have an associated GQuark
, a new GQuark
is created,
using a copy of the string.
Gets the string associated with the given GQuark
.
Gets the GQuark
associated with the given string, or 0 if string is
NULL
or it has no associated GQuark
.
Returns a random #gdouble equally distributed over the range [0..1).
Returns a random #gdouble equally distributed over the range
[begin
..end
).
Return a random #guint32 equally distributed over the range [0..2^32-1].
Returns a random #gint32 equally distributed over the range
[begin
..end
-1].
Sets the seed for the global random number generator, which is used
by the g_random_* functions, to seed
.
Allocates block_size
bytes of memory, and adds reference
counting semantics to it.
since: 2.58
Allocates block_size
bytes of memory, and adds reference
counting semantics to it.
since: 2.58
Allocates a new block of data with reference counting
semantics, and copies block_size
bytes of mem_block
into it.
since: 2.58
Reallocates the memory pointed to by mem
, so that it now has space for
n_bytes
bytes of memory. It returns the new address of the memory, which may
have been moved. mem
may be NULL
, in which case it’s considered to
have zero-length. n_bytes
may be 0, in which case NULL
will be returned
and mem
will be freed unless it is NULL
.
This function is similar to g_realloc(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
Creates a new reference counted string and copies the contents of str
into it.
since: 2.58
Creates a new reference counted string and copies the content of str
into it.
since: 2.58
Creates a new reference counted string and copies the contents of str
into it, up to len
bytes.
since: 2.58
Releases a reference on a string; if it was the last reference, the resources allocated by the string are freed as well.
since: 2.58
Resets the cache used for g_get_user_special_dir(), so that the latest on-disk version is used. Call this only if you just changed the data on disk yourself.
since: 2.22
A wrapper for the POSIX remove()
function. The remove()
function
deletes a name from the filesystem.
since: 2.6
A wrapper for the POSIX rename()
function. The rename()
function
renames a file, moving it between directories if required.
since: 2.6
Internal function used to print messages from the public g_return_if_fail()
and g_return_val_if_fail()
macros.
A wrapper for the POSIX rmdir()
function. The rmdir()
function
deletes a directory from the filesystem.
since: 2.6
Sets a human-readable name for the application. This name should be
localized if possible, and is intended for display to the user.
Contrast with g_set_prgname(), which sets a non-localized name.
g_set_prgname()
will be called automatically by gtk_init(),
but g_set_application_name()
will not.
since: 2.2
Does nothing if err
is NULL
; if err
is non-NULL
, then *err
must be NULL
. A new GError
is created and assigned to *err
.
Does nothing if err
is NULL
; if err
is non-NULL
, then *err
must be NULL
. A new GError
is created and assigned to *err
.
Unlike g_set_error(), message
is not a printf()-style format string.
Use this function if message
contains text you don’t have control over,
that could include printf()
escape sequences.
since: 2.18
Sets the name of the program. This name should not be localized, in contrast to g_set_application_name().
Sets the print handler to func
, or resets it to the
default GLib handler if NULL
.
Sets the handler for printing error messages to func
,
or resets it to the default GLib handler if NULL
.
Updates a pointer to a string to a copy of new_str
and returns whether the
string was changed.
since: 2.76
Sets an environment variable. On UNIX, both the variable’s name and value can be arbitrary byte strings, except that the variable’s name cannot contain ‘=’. On Windows, they should be in UTF-8.
since: 2.4
Parses a command line into an argument vector, in much the same way the shell would, but without many of the expansions the shell would perform (variable expansion, globs, operators, filename expansion, etc. are not supported).
Quotes a string so that the shell (/bin/sh) will interpret the
quoted string to mean unquoted_string
.
Unquotes a string as the shell (/bin/sh) would.
Allocates a block of memory via g_slice_alloc()
and initializes
the returned memory to 0.
since: 2.10
Allocates a block of memory from the slice allocator
and copies block_size
bytes into it from mem_block
.
since: 2.14
Frees a linked list of memory blocks of structure type type
.
since: 2.10
A safer form of the standard sprintf()
function. The output is guaranteed
to not exceed n
characters (including the terminating nul character), so
it is easy to ensure that a buffer overflow cannot occur.
This is just like the standard C qsort()
function, but
the comparison routine accepts a user data argument
(like qsort_r()
).
since: 2.82
Gets the smallest prime number from a built-in array of primes which
is larger than num
. This is used within GLib to calculate the optimum
size of a GHashTable
.
Executes a child program asynchronously.
Identical to g_spawn_async_with_pipes_and_fds()
but with n_fds
set to zero,
so no FD assignments are used.
Executes a child program asynchronously (your program will not block waiting for the child to exit).
since: 2.68
An old name for g_spawn_check_wait_status(), deprecated because its name is misleading.
deprecated: 2.70 since: 2.34
Set error
if wait_status
indicates the child exited abnormally
(e.g. with a nonzero exit code, or via a fatal signal).
since: 2.70
On some platforms, notably Windows, the GPid
type represents a resource
which must be closed to prevent resource leaking. g_spawn_close_pid()
is provided for this purpose. It should be used on all platforms, even
though it doesn’t do anything under UNIX.
A simple version of g_spawn_async()
that parses a command line with
g_shell_parse_argv()
and passes it to g_spawn_async().
A simple version of g_spawn_sync()
with little-used parameters
removed, taking a command line instead of an argument vector.
Executes a child synchronously (waits for the child to exit before returning).
An implementation of the standard sprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
A wrapper for the POSIX stat()
function. The stat()
function
returns information about a file. On Windows the stat()
function in
the C library checks only the FAT-style READONLY attribute and does
not look at the ACL at all. Thus on Windows the protection bits in
the st_mode
field are a fabrication of little use.
since: 2.6
Copies a nul-terminated string into the destination buffer, including
the trailing nul byte, and returns a pointer to the trailing nul byte
in dest
. The return value is useful for concatenating multiple
strings without having to repeatedly scan for the end.
Compares two strings for byte-by-byte equality and returns TRUE
if they are equal. It can be passed to g_hash_table_new()
as the
key_equal_func
parameter, when using non-NULL
strings as keys in a
GHashTable
.
Converts a string to a hash value.
Determines if a string is pure ASCII. A string is pure ASCII if it contains no bytes with the high bit set.
since: 2.40
Checks if a search conducted for search_term
should match
potential_hit
.
since: 2.40
For each character in string
, if the character is not in valid_chars
,
replaces the character with substitutor
.
A case-insensitive string comparison, corresponding to the standard
strcasecmp()
function on platforms which support it.
deprecated: 2.2
Removes trailing whitespace from a string.
Removes leading whitespace from a string, by moving the rest of the characters forward.
Makes a copy of a string replacing C string-style escape sequences with their one byte equivalent:.
Concatenates all of the given strings into one long string.
Converts any delimiter characters in string
to new_delimiter
.
Duplicates a string. If str
is NULL
it returns NULL
.
Similar to the standard C sprintf()
function but safer, since it
calculates the maximum space required and allocates memory to hold
the result.
Similar to the standard C vsprintf()
function but safer, since it
calculates the maximum space required and allocates memory to hold
the result.
Copies an array of strings. The copy is a deep copy; each string is also copied.
Returns a string corresponding to the given error code, e.g. “no such process”.
It replaces the following special characters in the string source
with their corresponding C escape sequence:.
Frees an array of strings, as well as each string it contains.
Joins a number of strings together to form one long string, with the
optional separator
inserted between each of them.
Joins an array of strings together to form one long string, with the
optional separator
inserted between each of them.
Portability wrapper that calls strlcat()
on systems which have it,
and emulates it otherwise. Appends nul-terminated src
string to dest
,
guaranteeing nul-termination for dest
. The total size of dest
won’t
exceed dest_size
.
Portability wrapper that calls strlcpy()
on systems which have it,
and emulates strlcpy()
otherwise. Copies src
to dest
; dest
is
guaranteed to be nul-terminated; src
must be nul-terminated;
dest_size
is the buffer size, not the number of bytes to copy.
A case-insensitive string comparison, corresponding to the standard
strncasecmp()
function on platforms which support it. It is similar
to g_strcasecmp()
except it only compares the first n
characters of
the strings.
deprecated: 2.2
Duplicates the first n
bytes of a string, returning a newly-allocated
buffer n
+ 1 bytes long which will always be nul-terminated. If str
is less than n
bytes long the buffer is padded with nuls. If str
is
NULL
it returns NULL
.
Creates a new string length
bytes long filled with fill_char
.
Reverses all of the bytes in a string. For example,
g_strreverse ("abcdef")
will result in “fedcba”.
Searches the string haystack
for the last occurrence
of the string needle
.
Searches the string haystack
for the last occurrence
of the string needle
, limiting the length of the search
to haystack_len
.
Returns a string describing the given signal, e.g. “Segmentation fault”. If the signal is unknown, it returns "unknown signal (<signum>)".
Splits a string into a maximum of max_tokens
pieces, using the given
delimiter
. If max_tokens
is reached, the remainder of string
is
appended to the last token.
Splits string
into a number of tokens not containing any of the characters
in delimiters
. A token is the (possibly empty) longest string that does not
contain any of the characters in delimiters
. If max_tokens
is reached, the
remainder is appended to the last token.
since: 2.4
Searches the string haystack
for the first occurrence
of the string needle
, limiting the length of the search
to haystack_len
or a nul terminator byte (whichever is reached first).
Converts a string to a floating point value.
Checks if an array of strings contains the string str
according to
g_str_equal()
. strv
must not be NULL
.
since: 2.44
Checks if two arrays of strings contain exactly the same elements in exactly the same order.
since: 2.60
Indicates that a message with the given log_domain
and log_level
,
with text matching pattern
, is expected to be logged.
since: 2.34
Gets the pathname of the directory containing test files of the type
specified by file_type
.
since: 2.38
Indicates that a test failed because of some incomplete functionality.
since: 2.70
Installs a non-error fatal log handler which can be used to decide whether log messages which are counted as fatal abort the program.
since: 2.22
Enqueues a callback destroy_func
to be executed during the next test case
teardown phase.
since: 2.16
Enqueues a pointer to be released with g_free()
during the next teardown phase.
since: 2.16
Gets a reproducible random floating point number out of a specified range.
since: 2.16
Returns true if the test program is running under g_test_trap_subprocess()
.
since: 2.38
Gets the number of seconds since the last start of the timer with
g_test_timer_start()
.
since: 2.16
Forks the current test program to execute a test case that might not return or that might abort.
deprecated: Unknown since: 2.16
Respawns the test program to run only test_path
in a subprocess with
a given environment.
since: 2.80
Sets a function to be called at regular intervals, with the default
priority, G_PRIORITY_DEFAULT
.
Sets a function to be called at regular intervals, with the given priority.
Sets a function to be called after interval
milliseconds have elapsed,
with the default priority, G_PRIORITY_DEFAULT
.
since: 2.74
Sets a function to be called at regular intervals with the default
priority, G_PRIORITY_DEFAULT
.
since: 2.14
Sets a function to be called at regular intervals, with priority
.
since: 2.14
This function behaves like g_timeout_add_once()
but with a range in seconds.
since: 2.78
Creates a new timeout source.
Attempts to allocate n_bytes
, and returns NULL
on failure.
Contrast with g_malloc(), which aborts the program on failure.
Attempts to allocate n_bytes
, initialized to 0’s, and returns NULL
on
failure. Contrast with g_malloc0(), which aborts the program on failure.
since: 2.8
This function is similar to g_try_malloc0(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
This function is similar to g_try_malloc(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
Attempts to realloc mem
to a new size, n_bytes
, and returns NULL
on failure. Contrast with g_realloc(), which aborts the program
on failure.
This function is similar to g_try_realloc(), allocating (n_blocks
* n_block_bytes
) bytes,
but care is taken to detect possible overflow during multiplication.
since: 2.24
Convert a string from UCS-4 to UTF-16.
Convert a string from a 32-bit fixed width representation as UCS-4. to UTF-8.
Determines the break type of c
. c
should be a Unicode character
(to derive a character from UTF-8 encoded text, use
g_utf8_get_char()). The break type is used to find word and line
breaks (“text boundaries”), Pango implements the Unicode boundary
resolution algorithms and normally you would use a function such
as pango_break()
instead of caring about break types yourself.
Determines the canonical combining class of a Unicode character.
since: 2.14
Performs a single composition step of the Unicode canonical composition algorithm.
since: 2.30
Performs a single decomposition step of the Unicode canonical decomposition algorithm.
since: 2.30
Determines the numeric value of a character as a decimal digit.
Computes the canonical or compatibility decomposition of a
Unicode character. For compatibility decomposition,
pass TRUE
for compat
; for canonical decomposition
pass FALSE
for compat
.
since: 2.30
In Unicode, some characters are “mirrored”. This means that their images are mirrored horizontally in text that is laid out from right to left. For instance, “(” would become its mirror image, “)”, in right-to-left text.
since: 2.4
Looks up the GUnicodeScript
for a particular character (as defined
by Unicode Standard Annex #24). No check is made for ch
being a
valid Unicode character; if you pass in invalid character, the
result is undefined.
since: 2.14
Determines whether a character is alphanumeric. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is alphabetic (i.e. a letter). Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is a control character. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines if a given character is assigned in the Unicode standard.
Determines whether a character is numeric (i.e. a digit). This covers ASCII 0-9 and also digits in other languages/scripts. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is printable and not a space
(returns FALSE
for control characters, format characters, and
spaces). g_unichar_isprint()
is similar, but returns TRUE
for
spaces. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is a lowercase letter. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is a mark (non-spacing mark, combining mark, or enclosing mark in Unicode speak). Given some UTF-8 text, obtain a character value with g_utf8_get_char().
since: 2.14
Determines whether a character is printable.
Unlike g_unichar_isgraph(), returns TRUE
for spaces.
Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is punctuation or a symbol. Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines whether a character is a space, tab, or line separator (newline, carriage return, etc.). Given some UTF-8 text, obtain a character value with g_utf8_get_char().
Determines if a character is titlecase. Some characters in Unicode which are composites, such as the DZ digraph have three case variants instead of just two. The titlecase form is used at the beginning of a word where only the first letter is capitalized. The titlecase form of the DZ digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
Determines if a character is uppercase.
Determines if a character is typically rendered in a double-width cell.
Determines if a character is typically rendered in a double-width cell under legacy East Asian locales. If a character is wide according to g_unichar_iswide(), then it is also reported wide with this function, but the converse is not necessarily true. See the Unicode Standard Annex #11 for details.
since: 2.12
Determines if a character is a hexadecimal digit.
Determines if a given character typically takes zero width when rendered.
The return value is TRUE
for all non-spacing and enclosing marks
(e.g., combining accents), format characters, zero-width
space, but not U+00AD SOFT HYPHEN.
since: 2.14
Converts a single character to UTF-8.
Converts a character to lower case.
Converts a character to the titlecase.
Converts a character to uppercase.
Classifies a Unicode character by type.
Checks whether ch
is a valid Unicode character.
Determines the numeric value of a character as a hexadecimal digit.
Computes the canonical decomposition of a Unicode character.
deprecated: 2.30
Computes the canonical ordering of a string in-place. This rearranges decomposed characters in the string according to their combining classes. See the Unicode manual for more information.
A wrapper for the POSIX unlink()
function. The unlink()
function
deletes a name from the filesystem. If this was the last link to the
file and no processes have it opened, the diskspace occupied by the
file is freed.
since: 2.6
Pauses the current thread for the given number of microseconds.
Convert a string from UTF-16 to UCS-4.
Convert a string from UTF-16 to UTF-8.
Converts a string into a form that is independent of case. The
result will not correspond to any particular case, but can be
compared for equality or ordered with the results of calling
g_utf8_casefold()
on other strings.
Compares two strings for ordering using the linguistically
correct rules for the current locale.
When sorting a large number of strings, it will be significantly
faster to obtain collation keys with g_utf8_collate_key()
and
compare the keys with strcmp()
when sorting instead of sorting
the original strings.
Converts a string into a collation key that can be compared with other collation keys produced by the same function using strcmp().
Converts a string into a collation key that can be compared with other collation keys produced by the same function using strcmp().
since: 2.8
Finds the start of the next UTF-8 character in the string after p
.
Given a position p
with a UTF-8 encoded string str
, find the start
of the previous UTF-8 character starting before p
. Returns NULL
if no
UTF-8 characters are present in str
before p
.
Converts a sequence of bytes encoded as UTF-8 to a Unicode character.
Convert a sequence of bytes encoded as UTF-8 to a Unicode character.
If the provided string is valid UTF-8, return a copy of it. If not, return a copy in which bytes that could not be interpreted as valid Unicode are replaced with the Unicode replacement character (U+FFFD).
since: 2.52
Converts a string into 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. The
string has to be valid UTF-8, otherwise NULL
is
returned. You should generally call g_utf8_normalize()
before comparing two Unicode strings.
Converts from an integer character offset to a pointer to a position within the string.
Converts from a pointer to position within a string to an integer character offset.
Finds the previous UTF-8 character in the string before p
.
Finds the leftmost occurrence of the given Unicode character
in a UTF-8 encoded string, while limiting the search to len
bytes.
Converts all Unicode characters in the string that have a case to lowercase. The exact manner that this is done depends on the current locale, and may result in the number of characters in the string changing.
Computes the length of the string in characters, not including
the terminating nul character. If the max
’th byte falls in the
middle of a character, the last (partial) character is not counted.
Like the standard C strncpy()
function, but copies a given
number of characters instead of a given number of bytes.
Find the rightmost occurrence of the given Unicode character
in a UTF-8 encoded string, while limiting the search to len
bytes.
Converts all Unicode characters in the string that have a case to uppercase. The exact manner that this is done depends on the current locale, and may result in the number of characters in the string increasing. (For instance, the German ess-zet will be changed to SS.).
Copies a substring out of a UTF-8 encoded string.
The substring will contain end_pos
- start_pos
characters.
since: 2.30
Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4.
Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4, assuming valid UTF-8 input.
Convert a string from UTF-8 to UTF-16.
Cuts off the middle of the string, preserving half of truncate_length
characters at the beginning and half at the end.
since: 2.78
Validates UTF-8 encoded text.
A wrapper for the POSIX utime()
function. The utime()
function
sets the access and modification timestamps of a file.
since: 2.18
Generates a random UUID (RFC 4122 version 4) as a string. It has the same
randomness guarantees as GRand
, so must not be used for cryptographic
purposes such as key generation, nonces, salts or one-time pads.
since: 2.52
An implementation of the GNU vasprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
This function is similar to g_vsprintf()
, except that it allocates a
string to hold the output, instead of putting the output in a buffer
you allocate in advance.
since: 2.4
An implementation of the standard fprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
An implementation of the standard vprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
A safer form of the standard vsprintf()
function. The output is guaranteed
to not exceed n
characters (including the terminating nul character), so
it is easy to ensure that a buffer overflow cannot occur.
An implementation of the standard vsprintf()
function which supports
positional parameters, as specified in the Single Unix Specification.
since: 2.2
Internal function used to print messages from the public g_warn_if_reached()
and g_warn_if_fail()
macros.
Function Macros
Return the minimal alignment required by the platform ABI for values of the given
type. The address of a variable or struct member of the given type must always be
a multiple of this alignment. For example, most platforms require int variables
to be aligned at a 4-byte boundary, so G_ALIGNOF (int)
is 4 on most platforms.
since: 2.60
Allocates size
bytes on the stack; these bytes will be freed when the current
stack frame is cleaned up. This macro essentially just wraps the alloca()
function present on most UNIX variants.
Thus it provides the same advantages and pitfalls as alloca():.
Wraps g_alloca()
and initializes allocated memory to zeroes.
If size
is 0
it returns NULL
.
since: 2.72
Evaluates to a truth value if the absolute difference between a
and b
is
smaller than epsilon
, and to a false value otherwise.
since: 2.58
Adds the value on to the end of the array. The array will grow in size automatically if necessary.
Returns the element of a GArray
at the given index. The return
value is cast to the given type. This is the main way to read or write an
element in a GArray
.
Inserts an element into an array at the given index.
Adds the value on to the start of the array. The array will grow in size automatically if necessary.
Determines whether a character is alphanumeric.
Determines whether a character is alphabetic (i.e. a letter).
Determines whether a character is a control character.
Determines whether a character is digit (0-9).
Determines whether a character is a printing character and not a space.
Determines whether a character is an ASCII lower case letter.
Determines whether a character is a printing character.
Determines whether a character is a punctuation character.
Determines whether a character is a white-space character.
Determines whether a character is an ASCII upper case letter.
Determines whether a character is a hexadecimal-digit character.
Debugging macro to terminate the application if the assertion fails.
Debugging macro to compare two floating point numbers within an epsilon.
since: 2.58
Debugging macro to check if two NULL
-terminated string arrays (i.e. 2
GStrv
) are equal.
since: 2.68
Debugging macro to check that an expression has a non-negative return value,
as used by traditional POSIX functions (such as rmdir()
) to indicate success.
since: 2.66
Debugging macro to terminate the application if it is ever reached.
A convenience macro to allocate atomically reference counted
data with the size of the given type
.
since: 2.58
A convenience macro to allocate atomically reference counted
data with the size of the given type
, and set its contents
to zero.
since: 2.58
Inserts a breakpoint instruction into the code.
Macro to check if the current compiler supports a specified version
of the C standard. Such value must be numeric and can be provided both
in the short form for the well-known versions (e.g. 90
, 99
…) or in
the complete form otherwise (e.g. 199000L
, 199901L
, 205503L
…).
since: 2.76
Checks whether the version of the GLib library that is being compiled against is greater than or equal to the given one.
deprecated: 2.10
deprecated: 2.10
deprecated: 2.10
Logs a ‘critical warning’ (G_LOG_LEVEL_CRITICAL
).
Macro to check if the current compiler supports a specified version
of the C++ standard. Such value must be numeric and can be provided both
in the short form for the well-known versions (e.g. 11
, 17
…) or in
the complete form otherwise (e.g. 201103L
, 201703L
, 205503L
…).
since: 2.76
Removes an element, using its GQuark
identifier.
Sets the data corresponding to the given GQuark
id. Any previous
data with the same key is removed, and its destroy function is called.
Removes an element using its string identifier. The data element’s destroy function is called if it has been set.
Removes an element, without calling its destroy notifier.
Sets the data element corresponding to the given string identifier.
Sets the data element corresponding to the given string identifier, and the function to be called when the data element is removed.
Gets the data element corresponding to a string.
Removes a data element from a dataset. The data element’s destroy function is called if it has been set.
Sets the data element associated with the given GQuark
id. Any
previous data with the same key is removed, and its destroy function
is called.
Removes a data element corresponding to a string. Its destroy function is called if it has been set.
Removes an element, without calling its destroy notifier.
Sets the data corresponding to the given string identifier.
Sets the data corresponding to the given string identifier, and the function to call when the data element is destroyed.
A convenience form of g_log_structured(), recommended to be added to
functions when debugging. It prints the current monotonic time and the code
location using G_STRLOC
.
since: 2.50
Defines the appropriate cleanup function for a pointer type.
since: 2.44
A convenience macro which defines two functions. First, returning
the GQuark
for the extended error type ErrorType
; it is called
error_type_quark()
. Second, returning the private data from a
passed GError
; it is called error_type_get_private()
.
since: 2.68
A convenience macro which defines a function returning the
GQuark
for the name QN
. The function will be named
q_n_quark
().
since: 2.34
A convenience function/macro to log an error message.
Expands to the GNU C alloc_size
function attribute if the compiler
is a new enough gcc. This attribute tells the compiler that the
function returns a pointer to memory of a size that is specified
by the xth
function parameter.
since: 2.18
Expands to the GNU C alloc_size
function attribute if the compiler is a
new enough gcc. This attribute tells the compiler that the function returns
a pointer to memory of a size that is specified by the product of two
function parameters.
since: 2.18
Expands to a check for a compiler with GNUC defined and a version greater than or equal to the major and minor numbers provided. For example, the following would only match on compilers such as GCC 4.8 or newer.
since: 2.42
Like G_GNUC_DEPRECATED
, but names the intended replacement for the
deprecated symbol if the version of gcc in use is new enough to support
custom deprecation messages.
since: 2.26
Expands to the GNU C format_arg
function attribute if the compiler
is gcc. This function attribute specifies that a function takes a
format string for a printf()
, scanf()
, strftime()
or strfmon()
style
function and modifies it, so that the result can be passed to a printf()
,
scanf()
, strftime()
or strfmon()
style function (with the remaining
arguments to the format function the same as they would have been
for the unmodified string).
Expands to the GNU C format
function attribute if the compiler is gcc.
This is used for declaring functions which take a variable number of
arguments, with the same syntax as printf()
. It allows the compiler
to type-check the arguments passed to the function.
Expands to the GNU C format
function attribute if the compiler is gcc.
This is used for declaring functions which take a variable number of
arguments, with the same syntax as scanf()
. It allows the compiler
to type-check the arguments passed to the function.
Expands to the GNU C strftime
format function attribute if the compiler
is gcc. This is used for declaring functions which take a format argument
which is passed to strftime()
or an API implementing its formats. It allows
the compiler check the format passed to the function.
since: 2.60
This function is deprecated and will be removed in the next major release of GLib. It does nothing.
This function is deprecated and will be removed in the next major release of GLib. It does nothing.
Returns TRUE
if the GHook
is active, which is normally the case
until the GHook
is destroyed.
Appends a GHook
onto the end of a GHookList
.
Gets the flags of a hook.
Returns TRUE
if the GHook
function is currently executing.
Converts a 32-bit integer value from host to network byte order.
Converts a 16-bit integer value from host to network byte order.
Hints the compiler that the expression is likely to evaluate to a true value. The compiler may use this information for optimizations.
since: 2.2
A convenience macro to get the next element in a GList
.
Note that it is considered perfectly acceptable to access
list
->next directly.
A convenience macro to get the previous element in a GList
.
Note that it is considered perfectly acceptable to access
list
->prev directly.
Works like g_mutex_lock(), but for a lock defined with
G_LOCK_DEFINE
.
The G_LOCK_
macros provide a convenient interface to GMutex
.
G_LOCK_DEFINE
defines a lock. It can appear in any place where
variable definitions may appear in programs, i.e. in the first block
of a function or outside of functions. The name
parameter will be
mangled to get the name of the GMutex
. This means that you
can use names of existing variables as the parameter - e.g. the name
of the variable you intend to protect with the lock. Look at our
give_me_next_number()
example using the G_LOCK
macros:.
This works like G_LOCK_DEFINE
, but it creates a static object.
This declares a lock, that is defined with G_LOCK_DEFINE
in another module.
Checks if any events are pending for the default GMainContext
(i.e. ready to be processed).
deprecated: 2.2
Stops the GMainLoop
.
If g_main_run()
was called to run the GMainLoop
, it will now return.
deprecated: 2.2
Sets the function to use for the handle polling of file descriptors for the default main context.
deprecated: 2.2
deprecated: 2.10
Copies a block of memory len
bytes long, from src
to dest
.
The source and destination areas may overlap.
deprecated: 2.40
A convenience function/macro to log a normal message.
Declare a GMutexLocker
variable with g_autoptr()
and lock the
mutex. The mutex will be unlocked automatically when leaving the scope. The
variable is declared with G_GNUC_UNUSED
to avoid compiler warning if it is
not used in the scope.
since: 2.80.0
Determines the number of elements in an array. The array must be declared so the compiler knows its size at compile-time; this macro will not work on an array allocated on the heap, only static arrays or arrays on the stack.
Allocates n_structs
elements of type struct_type
.
The returned pointer is cast to a pointer to the given type.
If n_structs
is 0 it returns NULL
.
Care is taken to avoid overflow when calculating the size of the allocated block.
Allocates n_structs
elements of type struct_type
, initialized to 0’s.
The returned pointer is cast to a pointer to the given type.
If n_structs
is 0 it returns NULL
.
Care is taken to avoid overflow when calculating the size of the allocated block.
Wraps g_alloca()
in a more typesafe manner.
Inserts a GNode
as the last child of the given parent.
Inserts a new GNode
as the last child of the given parent.
Gets the first child of a GNode
.
Inserts a new GNode
at the given position.
Inserts a new GNode
after the given sibling.
Inserts a new GNode
before the given sibling.
Gets the next sibling of a GNode
.
Inserts a new GNode
as the first child of the given parent.
Gets the previous sibling of a GNode
.
Converts a 32-bit integer value from network to host byte order.
Converts a 16-bit integer value from network to host byte order.
The first call to this routine by a process with a given GOnce
struct calls func
with the given argument. Thereafter, subsequent
calls to g_once()
with the same GOnce
struct do not call func
again, but return the stored result of the first call. On return
from g_once(), the status of once
will be G_ONCE_STATUS_READY
.
since: 2.4
Yields a new preprocessor pasted identifier
identifier1identifier2
from its expanded
arguments identifier1
and identifier2
. For example,
the following code:
#define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller) constgchar*name=GET(traveller,name); constgchar*quest=GET(traveller,quest); GdkColor*favourite=GET(traveller,favourite_colour);
since: 2.20
Returns the pointer at the given index of the pointer array.
Returns a random #gboolean from rand_
.
This corresponds to an unbiased coin toss.
Returns a random #gboolean. This corresponds to an unbiased coin toss.
A convenience macro to allocate reference counted data with
the size of the given type
.
since: 2.58
A convenience macro to allocate reference counted data with
the size of the given type
, and set its contents to zero.
since: 2.58
Declare a GRecMutexLocker
variable with g_autoptr()
and lock the
mutex. The mutex will be unlocked automatically when leaving the scope. The
variable is declared with G_GNUC_UNUSED
to avoid compiler warning if it is
not used in the scope.
since: 2.80.0
Reallocates the memory pointed to by mem
, so that it now has space for
n_structs
elements of type struct_type
. It returns the new address of
the memory, which may have been moved.
Care is taken to avoid overflow when calculating the size of the allocated block.
Declare a GRWLockReaderLocker
variable with g_autoptr()
and lock
for reading. The mutex will be unlocked automatically when leaving the scope.
The variable is declared with G_GNUC_UNUSED
to avoid compiler warning if it
is not used in the scope.
since: 2.80.0
Declare a GRWLockWriterLocker
variable with g_autoptr()
and lock
for writing. The mutex will be unlocked automatically when leaving the scope.
The variable is declared with G_GNUC_UNUSED
to avoid compiler warning if it
is not used in the scope.
since: 2.80.0
There is no reason to use this macro, since it does nothing.
deprecated: 2.2
There is no reason to use this macro, since it does nothing.
deprecated: 2.2
Performs a checked multiplication of a
and b
, storing the result in
dest
.
since: 2.48
Returns the size of member
in the struct definition without having a
declared instance of struct_type
.
since: 2.64
A convenience macro to free a block of memory that has been allocated from the slice allocator.
since: 2.10
A convenience macro to allocate a block of memory from the slice allocator and set the memory to 0.
since: 2.10
A convenience macro to get the next element in a GSList
.
Note that it is considered perfectly acceptable to access
slist
->next directly.
Cast a function pointer to a GSourceFunc
, suppressing
warnings from GCC 8 onwards with -Wextra
or -Wcast-function-type
enabled
about the function types being incompatible.
since: 2.58
The G_STATIC_ASSERT() macro lets the programmer check a condition at compile time, the condition needs to be compile time computable. The macro can be used in any place where a typedef is valid.
since: 2.20
The G_STATIC_ASSERT_EXPR() macro lets the programmer check a condition at compile time. The condition needs to be compile time computable.
since: 2.30
Accepts a macro or a string and converts it into a string after preprocessor argument expansion. For example, the following code:.
Removes leading and trailing whitespace from a string.
Returns a member of a structure at a given offset, using the given type.
Returns an untyped pointer to a given offset of a struct.
Returns the offset, in bytes, of a member of a struct.
Asserts that all messages previously indicated via
g_test_expect_message()
have been seen and suppressed.
since: 2.34
Returns true if tests are run in performance mode.
Enqueue an object to be released with g_object_unref()
during
the next teardown phase.
since: 2.16
Returns true if tests are run in quick mode.
Returns true if tests are run in quiet mode.
Returns true if tests are run in slow mode.
Returns true if tests are run in thorough mode.
Assert that the stderr output of the last test subprocess
matches serrpattern
.
since: 2.16
Assert that the stderr output of the last test subprocess
does not match serrpattern
.
since: 2.16
Assert that the stdout output of the last test subprocess matches
soutpattern
.
since: 2.16
Assert that the stdout output of the last test subprocess
does not match soutpattern
.
since: 2.16
Returns true if tests may provoke assertions and other formally-undefined behaviour, to verify that appropriate warnings are given.
Returns true if tests are run in verbose mode.
This macro returns TRUE
if the thread system is initialized,
and FALSE
if it is not.
Attempts to allocate n_structs
elements of type struct_type
, and returns
NULL
on failure. Contrast with g_new(), which aborts the program on failure.
The returned pointer is cast to a pointer to the given type.
The function returns NULL
when n_structs
is 0 of if an overflow occurs.
since: 2.8
Attempts to allocate n_structs
elements of type struct_type
, initialized
to 0’s, and returns NULL
on failure. Contrast with g_new0(), which aborts
the program on failure.
The returned pointer is cast to a pointer to the given type.
The function returns NULL
when n_structs
is 0 or if an overflow occurs.
since: 2.8
Attempts to reallocate the memory pointed to by mem
, so that it now has
space for n_structs
elements of type struct_type
, and returns NULL
on
failure. Contrast with g_renew(), which aborts the program on failure.
It returns the new address of the memory, which may have been moved.
The function returns NULL
if an overflow occurs.
since: 2.8
Works like g_mutex_trylock(), but for a lock defined with
G_LOCK_DEFINE
.
Performs a checked multiplication of a
and b
, storing the result in
dest
.
since: 2.48
Performs a checked multiplication of a
and b
, storing the result in
dest
.
since: 2.48
Hints the compiler that the expression is unlikely to evaluate to a true value. The compiler may use this information for optimizations.
since: 2.2
Works like g_mutex_unlock(), but for a lock defined with
G_LOCK_DEFINE
.
Skips to the next character in a UTF-8 string.
A stack-allocated GVariantBuilder
must be initialized
if it is used together with
g_auto()
. This macro can
be used as initializer when declaring the builder, but it cannot be
assigned to a variable.
since: 2.50
A stack-allocated GVariantBuilder
must be initialized
if it is used together with
g_auto()
. This macro can
be used as initializer when declaring the builder, but it cannot be
assigned to a variable.
since: 2.84
A stack-allocated GVariantDict
must be initialized if it is used
together with g_auto()
to avoid warnings or crashes if function
returns before g_variant_dict_init()
is called on the builder.
since: 2.50
A convenience function/macro to log a warning message.
On Windows, this macro defines a DllMain() function that stores the actual DLL name that the code being compiled will be included in.
Constants
deprecated: 2.10
deprecated: 2.10
deprecated: 2.10
deprecated: 2.10
deprecated: 2.10
A good size for a buffer to be passed into g_ascii_dtostr()
.
It is guaranteed to be enough for all output of that function
on systems with 64bit IEEE-compatible doubles.
Evaluates to the initial reference count for gatomicrefcount
.
Specifies one of the possible types of byte order.
See G_BYTE_ORDER
.
The C standard version the code is compiling against, it’s normally
defined with the same value of __STDC_VERSION__
for C standard
compatible compilers, while it uses the lowest standard version
in pure MSVC, given that in such compiler the definition depends on
a compilation flag.
The set of uppercase ASCII alphabet characters.
Used for specifying valid identifier characters
in GScannerConfig
.
The set of lowercase ASCII alphabet characters.
Used for specifying valid identifier characters
in GScannerConfig
.
The set of ASCII digits.
Used for specifying valid identifier characters
in GScannerConfig
.
A bitmask that restricts the possible flags passed to g_datalist_set_flags(). Passing a flags value where flags & ~G_DATALIST_FLAGS_MASK != 0 is an error.
Represents an invalid GDateDay
.
Represents an invalid Julian day number.
Represents an invalid year.
The directory separator character.
The directory separator as a string.
The base of natural logarithms.
Expands to “” on all modern compilers, and to FUNCTION on gcc version 2.x. Don’t use it.
deprecated: 2.16
Expands to “” on all modern compilers, and to PRETTY_FUNCTION on gcc version 2.x. Don’t use it.
deprecated: 2.16
Defined to 1 if gcc-style visibility handling is supported.
The position of the first bit which is not reserved for internal
use be the GHook
implementation, i.e.
1 << G_HOOK_FLAG_USER_SHIFT
is the first
bit which can be used for application-defined flags.
The bias by which exponents in double-precision floats are offset.
The bias by which exponents in single-precision floats are offset.
The name of the main group of a desktop entry file, as defined in the Desktop Entry Specification.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string list
giving the available application actions.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a list
of strings giving the categories in which the desktop entry
should be shown in a menu.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a localized
string giving the tooltip for the desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a boolean
set to true if the application is D-Bus activatable.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
giving the command line to execute.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a localized
string giving the generic name of the desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a boolean
stating whether the desktop entry has been deleted by the user.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a localized
string giving the name of the icon to be displayed for the desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a list
of strings giving the MIME types supported by this desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a localized
string giving the specific name of the desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a boolean
stating whether the desktop entry should be shown in menus.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a list of
strings identifying the environments that should not display the
desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a list of
strings identifying the environments that should display the
desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
containing the working directory to run the program in.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a boolean
stating whether the application supports the
Startup Notification Protocol Specification.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is string
identifying the WM class or name hint of a window that the application
will create, which can be used to emulate
Startup Notification
with older applications.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a boolean
stating whether the program should be run in a terminal window.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
giving the file name of a binary on disk used to determine if the
program is actually installed.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
giving the type of the desktop entry.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
giving the URL to access.
A key under G_KEY_FILE_DESKTOP_GROUP
, whose value is a string
giving the version of the Desktop Entry Specification used for
the desktop entry file.
The value of the G_KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop
entries representing applications.
The value of the G_KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop
entries representing directories.
The value of the G_KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop
entries representing links to documents.
Specifies one of the possible types of byte order.
See G_BYTE_ORDER
.
The natural logarithm of 10.
The natural logarithm of 2.
Multiplying the base 2 exponent by this number yields the base 10 exponent.
Defines the log domain. See Log Domains.
GLib log levels that are considered fatal by default.
Log levels below 1<<G_LOG_LEVEL_USER_SHIFT
are used by GLib.
Higher bits can be used for user-defined log levels.
The major version number of the GLib library.
The micro version number of the GLib library.
The minimum value which can be held in a #gint16.
The minimum value which can be held in a #gint32.
The minimum value which can be held in a #gint64.
The minimum value which can be held in a #gint8.
The minor version number of the GLib library.
If a long option in the main group has this name, it is not treated as a
regular option. Instead it collects all non-option arguments which would
otherwise be left in argv
. The option must be of type
G_OPTION_ARG_CALLBACK
, G_OPTION_ARG_STRING_ARRAY
or G_OPTION_ARG_FILENAME_ARRAY
.
Specifies one of the possible types of byte order
(currently unused). See G_BYTE_ORDER
.
The value of pi (ratio of circle’s circumference to its diameter).
Pi divided by 2.
Pi divided by 4.
A format specifier that can be used in printf()-style format strings
when printing a GPid
.
A format specifier that can be used in printf()-style format strings
when printing the fd
member of a GPollFD
.
Use this for default priority event sources.
Use this for default priority idle functions.
Use this for high priority event sources.
Use this for high priority idle functions.
Use this for very low priority background tasks.
Evaluates to the initial reference count for grefcount
.
The search path separator character. This is ‘:’ on UNIX machines and ‘;’ under Windows.
The search path separator as a string. This is “:” on UNIX machines and “;” under Windows.
Use this macro as the return value of a GSourceFunc
to leave
the GSource
in the main loop.
Use this macro as the return value of a GSourceFunc
to remove
the GSource
from the main loop.
The square root of two.
The standard delimiters, used in g_strdelimit()
.
A value that can be passed as an option to g_test_init()
.
A value that can be passed as an option to g_test_init()
.
A value that can be passed as an option to g_test_init()
.
Evaluates to a time span of one day.
Evaluates to a time span of one hour.
Evaluates to a time span of one millisecond.
Evaluates to a time span of one minute.
Evaluates to a time span of one second.
The maximum length (in codepoints) of a compatibility or canonical decomposition of a single Unicode character.
Generic delimiters characters as defined in
RFC 3986. Includes :/?#[]@
.
Subcomponent delimiter characters as defined in
RFC 3986. Includes !$&'()*+,;=
.
Number of microseconds in one second (1 million). This macro is provided for code readability.
A macro that should be defined by the user prior to including
the glib.h header.
The definition should be one of the predefined GLib version
macros: GLIB_VERSION_2_26
, GLIB_VERSION_2_28
,…