2 * Copyright © 2011 Red Hat, Inc
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Author: Matthias Clasen
23 /* This file collects documentation for macros, typedefs and
24 * the like, which have no good home in any of the 'real' source
28 /* Basic types {{{1 */
33 * @short_description: standard GLib types, defined for ease-of-use
36 * GLib defines a number of commonly used types, which can be divided
37 * into several groups:
38 * - New types which are not part of standard C (but are defined in
39 * various C standard library header files) — #gboolean, #gssize.
40 * - Integer types which are guaranteed to be the same size across
41 * all platforms — #gint8, #guint8, #gint16, #guint16, #gint32,
42 * #guint32, #gint64, #guint64.
43 * - Types which are easier to use than their standard C counterparts -
44 * #gpointer, #gconstpointer, #guchar, #guint, #gushort, #gulong.
45 * - Types which correspond exactly to standard C types, but are
46 * included for completeness — #gchar, #gint, #gshort, #glong,
48 * - Types which correspond exactly to standard C99 types, but are available
49 * to use even if your compiler does not support C99 — #gsize, #goffset,
50 * #gintptr, #guintptr.
52 * GLib also defines macros for the limits of some of the standard
53 * integer and floating point types, as well as macros for suitable
54 * printf() formats for these types.
56 * Note that depending on the platform and build configuration, the format
57 * macros might not be compatible with the system provided printf() function,
58 * because GLib might use a different printf() implementation internally.
59 * The format macros will always work with GLib API (like g_print()), and with
60 * any C99 compatible printf() implementation.
66 * A standard boolean type.
67 * Variables of this type should only contain the value
70 * Never directly compare the contents of a #gboolean variable with the values
71 * %TRUE or %FALSE. Use `if (condition)` to check a #gboolean is "true", instead
72 * of `if (condition == TRUE)`. Likewise use `if (!condition)` to check a
73 * #gboolean is "false".
75 * There is no validation when assigning to a #gboolean variable and so it could
76 * contain any value represented by a #gint. This is why the use of `if
77 * (condition)` is recommended. All non-zero values in C evaluate to "true".
84 * #gpointer looks better and is easier to use than void*.
90 * An untyped pointer to constant data.
91 * The data pointed to should not be changed.
93 * This is typically used in function prototypes to indicate
94 * that the data pointed to will not be altered by the function.
100 * Corresponds to the standard C char type.
106 * Corresponds to the standard C unsigned char type.
112 * Corresponds to the standard C int type.
113 * Values of this type can range from %G_MININT to %G_MAXINT.
119 * The minimum value which can be held in a #gint.
125 * The maximum value which can be held in a #gint.
131 * Corresponds to the standard C unsigned int type.
132 * Values of this type can range from 0 to %G_MAXUINT.
138 * The maximum value which can be held in a #guint.
144 * Corresponds to the standard C short type.
145 * Values of this type can range from %G_MINSHORT to %G_MAXSHORT.
151 * The minimum value which can be held in a #gshort.
157 * The maximum value which can be held in a #gshort.
163 * Corresponds to the standard C unsigned short type.
164 * Values of this type can range from 0 to %G_MAXUSHORT.
170 * The maximum value which can be held in a #gushort.
176 * Corresponds to the standard C long type.
177 * Values of this type can range from %G_MINLONG to %G_MAXLONG.
183 * The minimum value which can be held in a #glong.
189 * The maximum value which can be held in a #glong.
195 * Corresponds to the standard C unsigned long type.
196 * Values of this type can range from 0 to %G_MAXULONG.
202 * The maximum value which can be held in a #gulong.
208 * A signed integer guaranteed to be 8 bits on all platforms.
209 * Values of this type can range from %G_MININT8 (= -128) to
210 * %G_MAXINT8 (= 127).
216 * The maximum value which can be held in a #gint8.
224 * An unsigned integer guaranteed to be 8 bits on all platforms.
225 * Values of this type can range from 0 to %G_MAXUINT8 (= 255).
231 * The maximum value which can be held in a #guint8.
239 * A signed integer guaranteed to be 16 bits on all platforms.
240 * Values of this type can range from %G_MININT16 (= -32,768) to
241 * %G_MAXINT16 (= 32,767).
243 * To print or scan values of this type, use
244 * %G_GINT16_MODIFIER and/or %G_GINT16_FORMAT.
250 * The maximum value which can be held in a #gint16.
258 * The platform dependent length modifier for conversion specifiers
259 * for scanning and printing values of type #gint16 or #guint16. It
260 * is a string literal, but doesn't include the percent-sign, such
261 * that you can add precision and length modifiers between percent-sign
262 * and conversion specifier and append a conversion specifier.
264 * The following example prints "0x7b";
265 * |[<!-- language="C" -->
266 * gint16 value = 123;
267 * g_print ("%#" G_GINT16_MODIFIER "x", value);
276 * This is the platform dependent conversion specifier for scanning and
277 * printing values of type #gint16. It is a string literal, but doesn't
278 * include the percent-sign, such that you can add precision and length
279 * modifiers between percent-sign and conversion specifier.
281 * |[<!-- language="C" -->
284 * sscanf ("42", "%" G_GINT16_FORMAT, &in)
286 * g_print ("%" G_GINT32_FORMAT, out);
293 * An unsigned integer guaranteed to be 16 bits on all platforms.
294 * Values of this type can range from 0 to %G_MAXUINT16 (= 65,535).
296 * To print or scan values of this type, use
297 * %G_GINT16_MODIFIER and/or %G_GUINT16_FORMAT.
303 * The maximum value which can be held in a #guint16.
311 * This is the platform dependent conversion specifier for scanning
312 * and printing values of type #guint16. See also %G_GINT16_FORMAT
318 * A signed integer guaranteed to be 32 bits on all platforms.
319 * Values of this type can range from %G_MININT32 (= -2,147,483,648)
320 * to %G_MAXINT32 (= 2,147,483,647).
322 * To print or scan values of this type, use
323 * %G_GINT32_MODIFIER and/or %G_GINT32_FORMAT.
329 * The maximum value which can be held in a #gint32.
337 * The platform dependent length modifier for conversion specifiers
338 * for scanning and printing values of type #gint32 or #guint32. It
339 * is a string literal. See also %G_GINT16_MODIFIER.
347 * This is the platform dependent conversion specifier for scanning
348 * and printing values of type #gint32. See also %G_GINT16_FORMAT.
354 * An unsigned integer guaranteed to be 32 bits on all platforms.
355 * Values of this type can range from 0 to %G_MAXUINT32 (= 4,294,967,295).
357 * To print or scan values of this type, use
358 * %G_GINT32_MODIFIER and/or %G_GUINT32_FORMAT.
364 * The maximum value which can be held in a #guint32.
372 * This is the platform dependent conversion specifier for scanning
373 * and printing values of type #guint32. See also %G_GINT16_FORMAT.
379 * A signed integer guaranteed to be 64 bits on all platforms.
380 * Values of this type can range from %G_MININT64
381 * (= -9,223,372,036,854,775,808) to %G_MAXINT64
382 * (= 9,223,372,036,854,775,807).
384 * To print or scan values of this type, use
385 * %G_GINT64_MODIFIER and/or %G_GINT64_FORMAT.
391 * The maximum value which can be held in a #gint64.
397 * The platform dependent length modifier for conversion specifiers
398 * for scanning and printing values of type #gint64 or #guint64.
399 * It is a string literal.
401 * Some platforms do not support printing 64-bit integers, even
402 * though the types are supported. On such platforms %G_GINT64_MODIFIER
411 * This is the platform dependent conversion specifier for scanning
412 * and printing values of type #gint64. See also %G_GINT16_FORMAT.
414 * Some platforms do not support scanning and printing 64-bit integers,
415 * even though the types are supported. On such platforms %G_GINT64_FORMAT
416 * is not defined. Note that scanf() may not support 64-bit integers, even
417 * if %G_GINT64_FORMAT is defined. Due to its weak error handling, scanf()
418 * is not recommended for parsing anyway; consider using g_ascii_strtoull()
425 * An unsigned integer guaranteed to be 64-bits on all platforms.
426 * Values of this type can range from 0 to %G_MAXUINT64
427 * (= 18,446,744,073,709,551,615).
429 * To print or scan values of this type, use
430 * %G_GINT64_MODIFIER and/or %G_GUINT64_FORMAT.
436 * The maximum value which can be held in a #guint64.
442 * This is the platform dependent conversion specifier for scanning
443 * and printing values of type #guint64. See also %G_GINT16_FORMAT.
445 * Some platforms do not support scanning and printing 64-bit integers,
446 * even though the types are supported. On such platforms %G_GUINT64_FORMAT
447 * is not defined. Note that scanf() may not support 64-bit integers, even
448 * if %G_GINT64_FORMAT is defined. Due to its weak error handling, scanf()
449 * is not recommended for parsing anyway; consider using g_ascii_strtoull()
455 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7
457 * This macro is used to insert 64-bit integer literals
458 * into the source code.
462 * G_GUINT64_CONSTANT:
463 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7U
465 * This macro is used to insert 64-bit unsigned integer
466 * literals into the source code.
474 * Corresponds to the standard C float type.
475 * Values of this type can range from -%G_MAXFLOAT to %G_MAXFLOAT.
481 * The minimum positive value which can be held in a #gfloat.
483 * If you are interested in the smallest value which can be held
484 * in a #gfloat, use -%G_MAXFLOAT.
490 * The maximum value which can be held in a #gfloat.
496 * Corresponds to the standard C double type.
497 * Values of this type can range from -%G_MAXDOUBLE to %G_MAXDOUBLE.
503 * The minimum positive value which can be held in a #gdouble.
505 * If you are interested in the smallest value which can be held
506 * in a #gdouble, use -%G_MAXDOUBLE.
512 * The maximum value which can be held in a #gdouble.
518 * An unsigned integer type of the result of the sizeof operator,
519 * corresponding to the size_t type defined in C99.
520 * This type is wide enough to hold the numeric value of a pointer,
521 * so it is usually 32 bit wide on a 32-bit platform and 64 bit wide
522 * on a 64-bit platform. Values of this type can range from 0 to
525 * To print or scan values of this type, use
526 * %G_GSIZE_MODIFIER and/or %G_GSIZE_FORMAT.
532 * The maximum value which can be held in a #gsize.
540 * The platform dependent length modifier for conversion specifiers
541 * for scanning and printing values of type #gsize. It
542 * is a string literal.
550 * This is the platform dependent conversion specifier for scanning
551 * and printing values of type #gsize. See also %G_GINT16_FORMAT.
559 * A signed variant of #gsize, corresponding to the
560 * ssize_t defined on most platforms.
561 * Values of this type can range from %G_MINSSIZE
564 * To print or scan values of this type, use
565 * %G_GSSIZE_MODIFIER and/or %G_GSSIZE_FORMAT.
571 * The minimum value which can be held in a #gssize.
579 * The maximum value which can be held in a #gssize.
587 * This is the platform dependent conversion specifier for scanning
588 * and printing values of type #gssize. See also %G_GINT16_FORMAT.
596 * The platform dependent length modifier for conversion specifiers
597 * for scanning and printing values of type #gssize. It
598 * is a string literal.
606 * A signed integer type that is used for file offsets,
607 * corresponding to the POSIX type `off_t` as if compiling with
608 * `_FILE_OFFSET_BITS` set to 64. #goffset is always 64 bits wide, even on
609 * 32-bit architectures.
610 * Values of this type can range from %G_MINOFFSET to
613 * To print or scan values of this type, use
614 * %G_GOFFSET_MODIFIER and/or %G_GOFFSET_FORMAT.
622 * The minimum value which can be held in a #goffset.
628 * The maximum value which can be held in a #goffset.
632 * G_GOFFSET_MODIFIER:
634 * The platform dependent length modifier for conversion specifiers
635 * for scanning and printing values of type #goffset. It is a string
636 * literal. See also %G_GINT64_MODIFIER.
644 * This is the platform dependent conversion specifier for scanning
645 * and printing values of type #goffset. See also %G_GINT64_FORMAT.
651 * G_GOFFSET_CONSTANT:
652 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7
654 * This macro is used to insert #goffset 64-bit integer literals
655 * into the source code.
657 * See also G_GINT64_CONSTANT().
665 * Corresponds to the C99 type intptr_t,
666 * a signed integer type that can hold any pointer.
668 * To print or scan values of this type, use
669 * %G_GINTPTR_MODIFIER and/or %G_GINTPTR_FORMAT.
675 * G_GINTPTR_MODIFIER:
677 * The platform dependent length modifier for conversion specifiers
678 * for scanning and printing values of type #gintptr or #guintptr.
679 * It is a string literal.
687 * This is the platform dependent conversion specifier for scanning
688 * and printing values of type #gintptr.
696 * Corresponds to the C99 type uintptr_t,
697 * an unsigned integer type that can hold any pointer.
699 * To print or scan values of this type, use
700 * %G_GINTPTR_MODIFIER and/or %G_GUINTPTR_FORMAT.
708 * This is the platform dependent conversion specifier
709 * for scanning and printing values of type #guintptr.
714 /* Type conversion {{{1 */
717 * SECTION:type_conversion
718 * @title: Type Conversion Macros
719 * @short_description: portably storing integers in pointer variables
721 * Many times GLib, GTK+, and other libraries allow you to pass "user
722 * data" to a callback, in the form of a void pointer. From time to time
723 * you want to pass an integer instead of a pointer. You could allocate
724 * an integer, with something like:
725 * |[<!-- language="C" -->
726 * int *ip = g_new (int, 1);
729 * But this is inconvenient, and it's annoying to have to free the
730 * memory at some later time.
732 * Pointers are always at least 32 bits in size (on all platforms GLib
733 * intends to support). Thus you can store at least 32-bit integer values
734 * in a pointer value. Naively, you might try this, but it's incorrect:
735 * |[<!-- language="C" -->
741 * Again, that example was not correct, don't copy it.
742 * The problem is that on some systems you need to do this:
743 * |[<!-- language="C" -->
746 * p = (void*) (long) 42;
747 * i = (int) (long) p;
749 * The GLib macros GPOINTER_TO_INT(), GINT_TO_POINTER(), etc. take care
750 * to do the right thing on every platform.
752 * Warning: You may not store pointers in integers. This is not
753 * portable in any way, shape or form. These macros only allow storing
754 * integers in pointers, and only preserve 32 bits of the integer; values
755 * outside the range of a 32-bit integer will be mangled.
760 * @i: integer to stuff into a pointer
762 * Stuffs an integer into a pointer type.
764 * Remember, you may not store pointers in integers. This is not portable
765 * in any way, shape or form. These macros only allow storing integers in
766 * pointers, and only preserve 32 bits of the integer; values outside the
767 * range of a 32-bit integer will be mangled.
772 * @p: pointer containing an integer
774 * Extracts an integer from a pointer. The integer must have
775 * been stored in the pointer with GINT_TO_POINTER().
777 * Remember, you may not store pointers in integers. This is not portable
778 * in any way, shape or form. These macros only allow storing integers in
779 * pointers, and only preserve 32 bits of the integer; values outside the
780 * range of a 32-bit integer will be mangled.
785 * @u: unsigned integer to stuff into the pointer
787 * Stuffs an unsigned integer into a pointer type.
792 * @p: pointer to extract an unsigned integer from
794 * Extracts an unsigned integer from a pointer. The integer must have
795 * been stored in the pointer with GUINT_TO_POINTER().
800 * @s: #gsize to stuff into the pointer
802 * Stuffs a #gsize into a pointer type.
807 * @p: pointer to extract a #gsize from
809 * Extracts a #gsize from a pointer. The #gsize must have
810 * been stored in the pointer with GSIZE_TO_POINTER().
813 /* Byte order {{{1 */
817 * @title: Byte Order Macros
818 * @short_description: a portable way to convert between different byte orders
820 * These macros provide a portable way to determine the host byte order
821 * and to convert values between different byte orders.
823 * The byte order is the order in which bytes are stored to create larger
824 * data types such as the #gint and #glong values.
825 * The host byte order is the byte order used on the current machine.
827 * Some processors store the most significant bytes (i.e. the bytes that
828 * hold the largest part of the value) first. These are known as big-endian
829 * processors. Other processors (notably the x86 family) store the most
830 * significant byte last. These are known as little-endian processors.
832 * Finally, to complicate matters, some other processors store the bytes in
833 * a rather curious order known as PDP-endian. For a 4-byte word, the 3rd
834 * most significant byte is stored first, then the 4th, then the 1st and
837 * Obviously there is a problem when these different processors communicate
838 * with each other, for example over networks or by using binary file formats.
839 * This is where these macros come in. They are typically used to convert
840 * values into a byte order which has been agreed on for use when
841 * communicating between different processors. The Internet uses what is
842 * known as 'network byte order' as the standard byte order (which is in
843 * fact the big-endian byte order).
845 * Note that the byte order conversion macros may evaluate their arguments
846 * multiple times, thus you should not use them with arguments which have
853 * The host byte order.
854 * This can be either %G_LITTLE_ENDIAN or %G_BIG_ENDIAN (support for
855 * %G_PDP_ENDIAN may be added in future.)
861 * Specifies one of the possible types of byte order.
868 * Specifies one of the possible types of byte order.
875 * Specifies one of the possible types of byte order
876 * (currently unused). See %G_BYTE_ORDER.
881 * @val: a 32-bit integer value in host byte order
883 * Converts a 32-bit integer value from host to network byte order.
885 * Returns: @val converted to network byte order
890 * @val: a 16-bit integer value in host byte order
892 * Converts a 16-bit integer value from host to network byte order.
894 * Returns: @val converted to network byte order
899 * @val: a 32-bit integer value in network byte order
901 * Converts a 32-bit integer value from network to host byte order.
903 * Returns: @val converted to host byte order.
908 * @val: a 16-bit integer value in network byte order
910 * Converts a 16-bit integer value from network to host byte order.
912 * Returns: @val converted to host byte order
917 * @val: a #gint value in big-endian byte order
919 * Converts a #gint value from big-endian to host byte order.
921 * Returns: @val converted to host byte order
926 * @val: a #gint value in little-endian byte order
928 * Converts a #gint value from little-endian to host byte order.
930 * Returns: @val converted to host byte order
935 * @val: a #gint value in host byte order
937 * Converts a #gint value from host byte order to big-endian.
939 * Returns: @val converted to big-endian byte order
944 * @val: a #gint value in host byte order
946 * Converts a #gint value from host byte order to little-endian.
948 * Returns: @val converted to little-endian byte order
953 * @val: a #guint value in big-endian byte order
955 * Converts a #guint value from big-endian to host byte order.
957 * Returns: @val converted to host byte order
962 * @val: a #guint value in little-endian byte order
964 * Converts a #guint value from little-endian to host byte order.
966 * Returns: @val converted to host byte order
971 * @val: a #guint value in host byte order
973 * Converts a #guint value from host byte order to big-endian.
975 * Returns: @val converted to big-endian byte order
980 * @val: a #guint value in host byte order
982 * Converts a #guint value from host byte order to little-endian.
984 * Returns: @val converted to little-endian byte order.
989 * @val: a #glong value in big-endian byte order
991 * Converts a #glong value from big-endian to the host byte order.
993 * Returns: @val converted to host byte order
998 * @val: a #glong value in little-endian byte order
1000 * Converts a #glong value from little-endian to host byte order.
1002 * Returns: @val converted to host byte order
1007 * @val: a #glong value in host byte order
1009 * Converts a #glong value from host byte order to big-endian.
1011 * Returns: @val converted to big-endian byte order
1016 * @val: a #glong value in host byte order
1018 * Converts a #glong value from host byte order to little-endian.
1020 * Returns: @val converted to little-endian
1025 * @val: a #gulong value in big-endian byte order
1027 * Converts a #gulong value from big-endian to host byte order.
1029 * Returns: @val converted to host byte order
1034 * @val: a #gulong value in little-endian byte order
1036 * Converts a #gulong value from little-endian to host byte order.
1038 * Returns: @val converted to host byte order
1043 * @val: a #gulong value in host byte order
1045 * Converts a #gulong value from host byte order to big-endian.
1047 * Returns: @val converted to big-endian
1052 * @val: a #gulong value in host byte order
1054 * Converts a #gulong value from host byte order to little-endian.
1056 * Returns: @val converted to little-endian
1061 * @val: a #gsize value in big-endian byte order
1063 * Converts a #gsize value from big-endian to the host byte order.
1065 * Returns: @val converted to host byte order
1070 * @val: a #gsize value in little-endian byte order
1072 * Converts a #gsize value from little-endian to host byte order.
1074 * Returns: @val converted to host byte order
1079 * @val: a #gsize value in host byte order
1081 * Converts a #gsize value from host byte order to big-endian.
1083 * Returns: @val converted to big-endian byte order
1088 * @val: a #gsize value in host byte order
1090 * Converts a #gsize value from host byte order to little-endian.
1092 * Returns: @val converted to little-endian
1097 * @val: a #gssize value in big-endian byte order
1099 * Converts a #gssize value from big-endian to host byte order.
1101 * Returns: @val converted to host byte order
1106 * @val: a #gssize value in little-endian byte order
1108 * Converts a #gssize value from little-endian to host byte order.
1110 * Returns: @val converted to host byte order
1115 * @val: a #gssize value in host byte order
1117 * Converts a #gssize value from host byte order to big-endian.
1119 * Returns: @val converted to big-endian
1124 * @val: a #gssize value in host byte order
1126 * Converts a #gssize value from host byte order to little-endian.
1128 * Returns: @val converted to little-endian
1133 * @val: a #gint16 value in big-endian byte order
1135 * Converts a #gint16 value from big-endian to host byte order.
1137 * Returns: @val converted to host byte order
1142 * @val: a #gint16 value in little-endian byte order
1144 * Converts a #gint16 value from little-endian to host byte order.
1146 * Returns: @val converted to host byte order
1151 * @val: a #gint16 value in host byte order
1153 * Converts a #gint16 value from host byte order to big-endian.
1155 * Returns: @val converted to big-endian
1160 * @val: a #gint16 value in host byte order
1162 * Converts a #gint16 value from host byte order to little-endian.
1164 * Returns: @val converted to little-endian
1169 * @val: a #guint16 value in big-endian byte order
1171 * Converts a #guint16 value from big-endian to host byte order.
1173 * Returns: @val converted to host byte order
1178 * @val: a #guint16 value in little-endian byte order
1180 * Converts a #guint16 value from little-endian to host byte order.
1182 * Returns: @val converted to host byte order
1187 * @val: a #guint16 value in host byte order
1189 * Converts a #guint16 value from host byte order to big-endian.
1191 * Returns: @val converted to big-endian
1196 * @val: a #guint16 value in host byte order
1198 * Converts a #guint16 value from host byte order to little-endian.
1200 * Returns: @val converted to little-endian
1205 * @val: a #gint32 value in big-endian byte order
1207 * Converts a #gint32 value from big-endian to host byte order.
1209 * Returns: @val converted to host byte order
1214 * @val: a #gint32 value in little-endian byte order
1216 * Converts a #gint32 value from little-endian to host byte order.
1218 * Returns: @val converted to host byte order
1223 * @val: a #gint32 value in host byte order
1225 * Converts a #gint32 value from host byte order to big-endian.
1227 * Returns: @val converted to big-endian
1232 * @val: a #gint32 value in host byte order
1234 * Converts a #gint32 value from host byte order to little-endian.
1236 * Returns: @val converted to little-endian
1241 * @val: a #guint32 value in big-endian byte order
1243 * Converts a #guint32 value from big-endian to host byte order.
1245 * Returns: @val converted to host byte order
1250 * @val: a #guint32 value in little-endian byte order
1252 * Converts a #guint32 value from little-endian to host byte order.
1254 * Returns: @val converted to host byte order
1259 * @val: a #guint32 value in host byte order
1261 * Converts a #guint32 value from host byte order to big-endian.
1263 * Returns: @val converted to big-endian
1268 * @val: a #guint32 value in host byte order
1270 * Converts a #guint32 value from host byte order to little-endian.
1272 * Returns: @val converted to little-endian
1277 * @val: a #gint64 value in big-endian byte order
1279 * Converts a #gint64 value from big-endian to host byte order.
1281 * Returns: @val converted to host byte order
1286 * @val: a #gint64 value in little-endian byte order
1288 * Converts a #gint64 value from little-endian to host byte order.
1290 * Returns: @val converted to host byte order
1295 * @val: a #gint64 value in host byte order
1297 * Converts a #gint64 value from host byte order to big-endian.
1299 * Returns: @val converted to big-endian
1304 * @val: a #gint64 value in host byte order
1306 * Converts a #gint64 value from host byte order to little-endian.
1308 * Returns: @val converted to little-endian
1313 * @val: a #guint64 value in big-endian byte order
1315 * Converts a #guint64 value from big-endian to host byte order.
1317 * Returns: @val converted to host byte order
1322 * @val: a #guint64 value in little-endian byte order
1324 * Converts a #guint64 value from little-endian to host byte order.
1326 * Returns: @val converted to host byte order
1331 * @val: a #guint64 value in host byte order
1333 * Converts a #guint64 value from host byte order to big-endian.
1335 * Returns: @val converted to big-endian
1340 * @val: a #guint64 value in host byte order
1342 * Converts a #guint64 value from host byte order to little-endian.
1344 * Returns: @val converted to little-endian
1348 * GUINT16_SWAP_BE_PDP:
1349 * @val: a #guint16 value in big-endian or pdp-endian byte order
1351 * Converts a #guint16 value between big-endian and pdp-endian byte order.
1352 * The conversion is symmetric so it can be used both ways.
1354 * Returns: @val converted to the opposite byte order
1358 * GUINT16_SWAP_LE_BE:
1359 * @val: a #guint16 value in little-endian or big-endian byte order
1361 * Converts a #guint16 value between little-endian and big-endian byte order.
1362 * The conversion is symmetric so it can be used both ways.
1364 * Returns: @val converted to the opposite byte order
1368 * GUINT16_SWAP_LE_PDP:
1369 * @val: a #guint16 value in little-endian or pdp-endian byte order
1371 * Converts a #guint16 value between little-endian and pdp-endian byte order.
1372 * The conversion is symmetric so it can be used both ways.
1374 * Returns: @val converted to the opposite byte order
1378 * GUINT32_SWAP_BE_PDP:
1379 * @val: a #guint32 value in big-endian or pdp-endian byte order
1381 * Converts a #guint32 value between big-endian and pdp-endian byte order.
1382 * The conversion is symmetric so it can be used both ways.
1384 * Returns: @val converted to the opposite byte order
1388 * GUINT32_SWAP_LE_BE:
1389 * @val: a #guint32 value in little-endian or big-endian byte order
1391 * Converts a #guint32 value between little-endian and big-endian byte order.
1392 * The conversion is symmetric so it can be used both ways.
1394 * Returns: @val converted to the opposite byte order
1398 * GUINT32_SWAP_LE_PDP:
1399 * @val: a #guint32 value in little-endian or pdp-endian byte order
1401 * Converts a #guint32 value between little-endian and pdp-endian byte order.
1402 * The conversion is symmetric so it can be used both ways.
1404 * Returns: @val converted to the opposite byte order
1408 * GUINT64_SWAP_LE_BE:
1409 * @val: a #guint64 value in little-endian or big-endian byte order
1411 * Converts a #guint64 value between little-endian and big-endian byte order.
1412 * The conversion is symmetric so it can be used both ways.
1414 * Returns: @val converted to the opposite byte order
1417 /* Bounds-checked integer arithmetic {{{1 */
1419 * SECTION:checkedmath
1420 * @title: Bounds-checking integer arithmetic
1421 * @short_description: a set of helpers for performing checked integer arithmetic
1423 * GLib offers a set of macros for doing additions and multiplications
1424 * of unsigned integers, with checks for overflows.
1426 * The helpers all have three arguments. A pointer to the destination
1427 * is always the first argument and the operands to the operation are
1430 * Following standard GLib convention, the helpers return %TRUE in case
1431 * of success (ie: no overflow).
1433 * The helpers may be macros, normal functions or inlines. They may be
1434 * implemented with inline assembly or compiler intrinsics where
1441 * g_uint_checked_add
1442 * @dest: a pointer to the #guint destination
1443 * @a: the #guint left operand
1444 * @b: the #guint right operand
1446 * Performs a checked addition of @a and @b, storing the result in
1449 * If the operation is successful, %TRUE is returned. If the operation
1450 * overflows then the state of @dest is undefined and %FALSE is
1453 * Returns: %TRUE if there was no overflow
1458 * g_uint_checked_mul
1459 * @dest: a pointer to the #guint destination
1460 * @a: the #guint left operand
1461 * @b: the #guint right operand
1463 * Performs a checked multiplication of @a and @b, storing the result in
1466 * If the operation is successful, %TRUE is returned. If the operation
1467 * overflows then the state of @dest is undefined and %FALSE is
1470 * Returns: %TRUE if there was no overflow
1475 * g_uint64_checked_add
1476 * @dest: a pointer to the #guint64 destination
1477 * @a: the #guint64 left operand
1478 * @b: the #guint64 right operand
1480 * Performs a checked addition of @a and @b, storing the result in
1483 * If the operation is successful, %TRUE is returned. If the operation
1484 * overflows then the state of @dest is undefined and %FALSE is
1487 * Returns: %TRUE if there was no overflow
1492 * g_uint64_checked_mul
1493 * @dest: a pointer to the #guint64 destination
1494 * @a: the #guint64 left operand
1495 * @b: the #guint64 right operand
1497 * Performs a checked multiplication of @a and @b, storing the result in
1500 * If the operation is successful, %TRUE is returned. If the operation
1501 * overflows then the state of @dest is undefined and %FALSE is
1504 * Returns: %TRUE if there was no overflow
1509 * g_size_checked_add
1510 * @dest: a pointer to the #gsize destination
1511 * @a: the #gsize left operand
1512 * @b: the #gsize right operand
1514 * Performs a checked addition of @a and @b, storing the result in
1517 * If the operation is successful, %TRUE is returned. If the operation
1518 * overflows then the state of @dest is undefined and %FALSE is
1521 * Returns: %TRUE if there was no overflow
1526 * g_size_checked_mul
1527 * @dest: a pointer to the #gsize destination
1528 * @a: the #gsize left operand
1529 * @b: the #gsize right operand
1531 * Performs a checked multiplication of @a and @b, storing the result in
1534 * If the operation is successful, %TRUE is returned. If the operation
1535 * overflows then the state of @dest is undefined and %FALSE is
1538 * Returns: %TRUE if there was no overflow
1541 /* Numerical Definitions {{{1 */
1545 * @title: Numerical Definitions
1546 * @short_description: mathematical constants, and floating point decomposition
1548 * GLib offers mathematical constants such as %G_PI for the value of pi;
1549 * many platforms have these in the C library, but some don't, the GLib
1550 * versions always exist.
1552 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the
1553 * sign, mantissa and exponent of IEEE floats and doubles. These unions are
1554 * defined as appropriate for a given platform. IEEE floats and doubles are
1555 * supported (used for storage) by at least Intel, PPC and Sparc. See
1556 * [IEEE 754-2008](http://en.wikipedia.org/wiki/IEEE_float)
1557 * for more information about IEEE number formats.
1561 * G_IEEE754_FLOAT_BIAS:
1563 * The bias by which exponents in single-precision floats are offset.
1567 * G_IEEE754_DOUBLE_BIAS:
1569 * The bias by which exponents in double-precision floats are offset.
1574 * @v_float: the double value
1576 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the sign,
1577 * mantissa and exponent of IEEE floats and doubles. These unions are defined
1578 * as appropriate for a given platform. IEEE floats and doubles are supported
1579 * (used for storage) by at least Intel, PPC and Sparc.
1584 * @v_double: the double value
1586 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the sign,
1587 * mantissa and exponent of IEEE floats and doubles. These unions are defined
1588 * as appropriate for a given platform. IEEE floats and doubles are supported
1589 * (used for storage) by at least Intel, PPC and Sparc.
1595 * The base of natural logarithms.
1601 * The natural logarithm of 2.
1607 * The natural logarithm of 10.
1613 * The value of pi (ratio of circle's circumference to its diameter).
1631 * The square root of two.
1637 * Multiplying the base 2 exponent by this number yields the base 10 exponent.
1644 * @title: Standard Macros
1645 * @short_description: commonly-used macros
1647 * These macros provide a few commonly-used features.
1653 * This macro is defined only on Windows. So you can bracket
1654 * Windows-specific code in "\#ifdef G_OS_WIN32".
1660 * This macro is defined only on UNIX. So you can bracket
1661 * UNIX-specific code in "\#ifdef G_OS_UNIX".
1667 * The directory separator character.
1668 * This is '/' on UNIX machines and '\' under Windows.
1672 * G_DIR_SEPARATOR_S:
1674 * The directory separator as a string.
1675 * This is "/" on UNIX machines and "\" under Windows.
1679 * G_IS_DIR_SEPARATOR:
1682 * Checks whether a character is a directory
1683 * separator. It returns %TRUE for '/' on UNIX
1684 * machines and for '\' or '/' under Windows.
1690 * G_SEARCHPATH_SEPARATOR:
1692 * The search path separator character.
1693 * This is ':' on UNIX machines and ';' under Windows.
1697 * G_SEARCHPATH_SEPARATOR_S:
1699 * The search path separator as a string.
1700 * This is ":" on UNIX machines and ";" under Windows.
1706 * Defines the %TRUE value for the #gboolean type.
1712 * Defines the %FALSE value for the #gboolean type.
1718 * Defines the standard %NULL pointer.
1723 * @a: a numeric value
1724 * @b: a numeric value
1726 * Calculates the minimum of @a and @b.
1728 * Returns: the minimum of @a and @b.
1733 * @a: a numeric value
1734 * @b: a numeric value
1736 * Calculates the maximum of @a and @b.
1738 * Returns: the maximum of @a and @b.
1743 * @a: a numeric value
1745 * Calculates the absolute value of @a.
1746 * The absolute value is simply the number with any negative sign taken away.
1750 * - ABS(10) is also 10.
1752 * Returns: the absolute value of @a.
1757 * @x: the value to clamp
1758 * @low: the minimum value allowed
1759 * @high: the maximum value allowed
1761 * Ensures that @x is between the limits set by @low and @high. If @low is
1762 * greater than @high the result is undefined.
1765 * - CLAMP(5, 10, 15) is 10.
1766 * - CLAMP(15, 5, 10) is 10.
1767 * - CLAMP(20, 15, 25) is 20.
1769 * Returns: the value of @x clamped to the range between @low and @high
1774 * @a: a numeric value
1775 * @b: a numeric value
1776 * @epsilon: a numeric value that expresses the tolerance between @a and @b
1778 * Evaluates to a truth value if the absolute difference between @a and @b is
1779 * smaller than @epsilon, and to a false value otherwise.
1782 * - `G_APPROX_VALUE (5, 6, 2)` evaluates to true
1783 * - `G_APPROX_VALUE (3.14, 3.15, 0.001)` evaluates to false
1784 * - `G_APPROX_VALUE (n, 0.f, FLT_EPSILON)` evaluates to true if `n` is within
1785 * the single precision floating point epsilon from zero
1787 * Returns: %TRUE if the two values are within the desired range
1794 * @member_type: the type of the struct field
1795 * @struct_p: a pointer to a struct
1796 * @struct_offset: the offset of the field from the start of the struct,
1799 * Returns a member of a structure at a given offset, using the given type.
1801 * Returns: the struct member
1805 * G_STRUCT_MEMBER_P:
1806 * @struct_p: a pointer to a struct
1807 * @struct_offset: the offset from the start of the struct, in bytes
1809 * Returns an untyped pointer to a given offset of a struct.
1811 * Returns: an untyped pointer to @struct_p plus @struct_offset bytes
1816 * @struct_type: a structure type, e.g. #GtkWidget
1817 * @member: a field in the structure, e.g. @window
1819 * Returns the offset, in bytes, of a member of a struct.
1821 * Returns: the offset of @member from the start of @struct_type
1828 * Determines the number of elements in an array. The array must be
1829 * declared so the compiler knows its size at compile-time; this
1830 * macro will not work on an array allocated on the heap, only static
1831 * arrays or arrays on the stack.
1834 /* Miscellaneous Macros {{{1 */
1837 * SECTION:macros_misc
1838 * @title: Miscellaneous Macros
1839 * @short_description: specialized macros which are not used often
1841 * These macros provide more specialized features which are not
1842 * needed so often by application programmers.
1848 * Used within multi-statement macros so that they can be used in places
1849 * where only one statement is expected by the compiler.
1855 * Used within multi-statement macros so that they can be used in places
1856 * where only one statement is expected by the compiler.
1862 * Used (along with %G_END_DECLS) to bracket header files. If the
1863 * compiler in use is a C++ compiler, adds extern "C"
1864 * around the header.
1870 * Used (along with %G_BEGIN_DECLS) to bracket header files. If the
1871 * compiler in use is a C++ compiler, adds extern "C"
1872 * around the header.
1877 * @ap1: the va_list variable to place a copy of @ap2 in
1880 * Portable way to copy va_list variables.
1882 * In order to use this function, you must include string.h yourself,
1883 * because this macro may use memmove() and GLib does not include
1886 * Each invocation of `G_VA_COPY (ap1, ap2)` must be matched with a
1887 * corresponding `va_end (ap1)` call in the same function.
1892 * @macro_or_string: a macro or a string
1894 * Accepts a macro or a string and converts it into a string after
1895 * preprocessor argument expansion. For example, the following code:
1897 * |[<!-- language="C" -->
1899 * const gchar *greeting = G_STRINGIFY (AGE) " today!";
1902 * is transformed by the preprocessor into (code equivalent to):
1904 * |[<!-- language="C" -->
1905 * const gchar *greeting = "27 today!";
1911 * @identifier1: an identifier
1912 * @identifier2: an identifier
1914 * Yields a new preprocessor pasted identifier
1915 * @identifier1identifier2 from its expanded
1916 * arguments @identifier1 and @identifier2. For example,
1917 * the following code:
1918 * |[<!-- language="C" -->
1919 * #define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
1920 * const gchar *name = GET (traveller, name);
1921 * const gchar *quest = GET (traveller, quest);
1922 * GdkColor *favourite = GET (traveller, favourite_colour);
1925 * is transformed by the preprocessor into:
1926 * |[<!-- language="C" -->
1927 * const gchar *name = traveller_get_name (traveller);
1928 * const gchar *quest = traveller_get_quest (traveller);
1929 * GdkColor *favourite = traveller_get_favourite_colour (traveller);
1937 * @expr: a constant expression
1939 * The G_STATIC_ASSERT() macro lets the programmer check
1940 * a condition at compile time, the condition needs to
1941 * be compile time computable. The macro can be used in
1942 * any place where a typedef is valid.
1944 * A typedef is generally allowed in exactly the same places that
1945 * a variable declaration is allowed. For this reason, you should
1946 * not use G_STATIC_ASSERT() in the middle of blocks of code.
1948 * The macro should only be used once per source code line.
1954 * G_STATIC_ASSERT_EXPR:
1955 * @expr: a constant expression
1957 * The G_STATIC_ASSERT_EXPR() macro lets the programmer check
1958 * a condition at compile time. The condition needs to be
1959 * compile time computable.
1961 * Unlike G_STATIC_ASSERT(), this macro evaluates to an expression
1962 * and, as such, can be used in the middle of other expressions.
1963 * Its value should be ignored. This can be accomplished by placing
1964 * it as the first argument of a comma expression.
1966 * |[<!-- language="C" -->
1967 * #define ADD_ONE_TO_INT(x) \
1968 * (G_STATIC_ASSERT_EXPR(sizeof (x) == sizeof (int)), ((x) + 1))
1977 * Expands to __extension__ when gcc is used as the compiler. This simply
1978 * tells gcc not to warn about the following non-standard code when compiling
1979 * with the `-pedantic` option.
1983 * G_GNUC_CHECK_VERSION:
1984 * @major: major version to check against
1985 * @minor: minor version to check against
1987 * Expands to a check for a compiler with __GNUC__ defined and a version
1988 * greater than or equal to the major and minor numbers provided. For example,
1989 * the following would only match on compilers such as GCC 4.8 or newer.
1991 * |[<!-- language="C" -->
1992 * #if G_GNUC_CHECK_VERSION(4, 8)
2000 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS:
2002 * Tells gcc (if it is a new enough version) to temporarily stop emitting
2003 * warnings when functions marked with %G_GNUC_DEPRECATED or
2004 * %G_GNUC_DEPRECATED_FOR are called. This is useful for when you have
2005 * one deprecated function calling another one, or when you still have
2006 * regression tests for deprecated functions.
2008 * Use %G_GNUC_END_IGNORE_DEPRECATIONS to begin warning again. (If you
2009 * are not compiling with `-Wdeprecated-declarations` then neither macro
2012 * This macro can be used either inside or outside of a function body,
2013 * but must appear on a line by itself. Both this macro and the corresponding
2014 * %G_GNUC_END_IGNORE_DEPRECATIONS are considered statements, so they
2015 * should not be used around branching or loop conditions; for instance,
2016 * this use is invalid:
2018 * |[<!-- language="C" -->
2019 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2020 * if (check == some_deprecated_function ())
2021 * G_GNUC_END_IGNORE_DEPRECATIONS
2027 * and you should move the deprecated section outside the condition
2029 * |[<!-- language="C" -->
2034 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2035 * res = some_deprecated_function ();
2036 * G_GNUC_END_IGNORE_DEPRECATIONS
2044 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2045 * if (check == some_deprecated_function ())
2049 * G_GNUC_END_IGNORE_DEPRECATIONS
2052 * |[<!-- language="C" -->
2054 * test_deprecated_function (void)
2056 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2057 * g_assert_cmpint (my_mistake (), ==, 42);
2058 * G_GNUC_END_IGNORE_DEPRECATIONS
2066 * G_GNUC_END_IGNORE_DEPRECATIONS:
2068 * Undoes the effect of %G_GNUC_BEGIN_IGNORE_DEPRECATIONS, telling
2069 * gcc to begin outputting warnings again (assuming those warnings
2070 * had been enabled to begin with).
2072 * This macro can be used either inside or outside of a function body,
2073 * but must appear on a line by itself.
2081 * This macro is similar to %G_GNUC_DEPRECATED, and can be used to mark
2082 * functions declarations as deprecated. Unlike %G_GNUC_DEPRECATED, it is
2083 * meant to be portable across different compilers and must be placed
2084 * before the function declaration.
2086 * |[<!-- language="C" -->
2088 * int my_mistake (void);
2096 * @f: the name of the function that this function was deprecated for
2098 * This macro is similar to %G_GNUC_DEPRECATED_FOR, and can be used to mark
2099 * functions declarations as deprecated. Unlike %G_GNUC_DEPRECATED_FOR, it
2100 * is meant to be portable across different compilers and must be placed
2101 * before the function declaration.
2103 * |[<!-- language="C" -->
2104 * G_DEPRECATED_FOR(my_replacement)
2105 * int my_mistake (void);
2113 * @maj: the major version that introduced the symbol
2114 * @min: the minor version that introduced the symbol
2116 * This macro can be used to mark a function declaration as unavailable.
2117 * It must be placed before the function declaration. Use of a function
2118 * that has been annotated with this macros will produce a compiler warning.
2124 * GLIB_DISABLE_DEPRECATION_WARNINGS:
2126 * A macro that should be defined before including the glib.h header.
2127 * If it is defined, no compiler warnings will be produced for uses
2128 * of deprecated GLib APIs.
2134 * This attribute can be used for marking library functions as being used
2135 * internally to the library only, which may allow the compiler to handle
2136 * function calls more efficiently. Note that static functions do not need
2137 * to be marked as internal in this way. See the GNU C documentation for
2140 * When using a compiler that supports the GNU C hidden visibility attribute,
2141 * this macro expands to __attribute__((visibility("hidden"))).
2142 * When using the Sun Studio compiler, it expands to __hidden.
2144 * Note that for portability, the attribute should be placed before the
2145 * function declaration. While GCC allows the macro after the declaration,
2146 * Sun Studio does not.
2148 * |[<!-- language="C" -->
2150 * void _g_log_fallback_handler (const gchar *log_domain,
2151 * GLogLevelFlags log_level,
2152 * const gchar *message,
2153 * gpointer unused_data);
2161 * @expr: the expression
2163 * Hints the compiler that the expression is likely to evaluate to
2164 * a true value. The compiler may use this information for optimizations.
2166 * |[<!-- language="C" -->
2167 * if (G_LIKELY (random () != 1))
2168 * g_print ("not one");
2171 * Returns: the value of @expr
2178 * @expr: the expression
2180 * Hints the compiler that the expression is unlikely to evaluate to
2181 * a true value. The compiler may use this information for optimizations.
2183 * |[<!-- language="C" -->
2184 * if (G_UNLIKELY (random () == 1))
2185 * g_print ("a random one");
2188 * Returns: the value of @expr
2196 * Expands to a string identifying the current code position.
2202 * Expands to a string identifying the current function.
2208 * G_HAVE_GNUC_VISIBILITY:
2210 * Defined to 1 if gcc-style visibility handling is supported.
2213 /* g_auto(), g_autoptr() and helpers {{{1 */
2217 * @TypeName: a supported variable type
2219 * Helper to declare a variable with automatic cleanup.
2221 * The variable is cleaned up in a way appropriate to its type when the
2222 * variable goes out of scope. The type must support this.
2223 * The way to clean up the type must have been defined using one of the macros
2224 * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC() or G_DEFINE_AUTO_CLEANUP_FREE_FUNC().
2226 * This feature is only supported on GCC and clang. This macro is not
2227 * defined on other compilers and should not be used in programs that
2228 * are intended to be portable to those compilers.
2230 * This is meant to be used with stack-allocated structures and
2231 * non-pointer types. For the (more commonly used) pointer version, see
2234 * This macro can be used to avoid having to do explicit cleanups of
2235 * local variables when exiting functions. It often vastly simplifies
2236 * handling of error conditions, removing the need for various tricks
2237 * such as `goto out` or repeating of cleanup code. It is also helpful
2238 * for non-error cases.
2240 * Consider the following example:
2246 * g_auto(GQueue) queue = G_QUEUE_INIT;
2247 * g_auto(GVariantBuilder) builder;
2248 * g_auto(GStrv) strv;
2250 * g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
2251 * strv = g_strsplit("a:b:c", ":", -1);
2255 * if (error_condition)
2260 * return g_variant_builder_end (&builder);
2264 * You must initialize the variable in some way — either by use of an
2265 * initialiser or by ensuring that an `_init` function will be called on
2266 * it unconditionally before it goes out of scope.
2273 * @TypeName: a supported variable type
2275 * Helper to declare a pointer variable with automatic cleanup.
2277 * The variable is cleaned up in a way appropriate to its type when the
2278 * variable goes out of scope. The type must support this.
2279 * The way to clean up the type must have been defined using the macro
2280 * G_DEFINE_AUTOPTR_CLEANUP_FUNC().
2282 * This feature is only supported on GCC and clang. This macro is not
2283 * defined on other compilers and should not be used in programs that
2284 * are intended to be portable to those compilers.
2286 * This is meant to be used to declare pointers to types with cleanup
2287 * functions. The type of the variable is a pointer to @TypeName. You
2288 * must not add your own `*`.
2290 * This macro can be used to avoid having to do explicit cleanups of
2291 * local variables when exiting functions. It often vastly simplifies
2292 * handling of error conditions, removing the need for various tricks
2293 * such as `goto out` or repeating of cleanup code. It is also helpful
2294 * for non-error cases.
2296 * Consider the following example:
2300 * check_exists(GVariant *dict)
2302 * g_autoptr(GVariant) dirname, basename = NULL;
2303 * g_autofree gchar *path = NULL;
2305 * dirname = g_variant_lookup_value (dict, "dirname", G_VARIANT_TYPE_STRING);
2307 * if (dirname == NULL)
2310 * basename = g_variant_lookup_value (dict, "basename", G_VARIANT_TYPE_STRING);
2312 * if (basename == NULL)
2315 * path = g_build_filename (g_variant_get_string (dirname, NULL),
2316 * g_variant_get_string (basename, NULL),
2319 * return g_access (path, R_OK) == 0;
2323 * You must initialise the variable in some way — either by use of an
2324 * initialiser or by ensuring that it is assigned to unconditionally
2325 * before it goes out of scope.
2327 * See also g_auto(), g_autofree() and g_steal_pointer().
2335 * Macro to add an attribute to pointer variable to ensure automatic
2336 * cleanup using g_free().
2338 * This macro differs from g_autoptr() in that it is an attribute supplied
2339 * before the type name, rather than wrapping the type definition. Instead
2340 * of using a type-specific lookup, this macro always calls g_free() directly.
2342 * This means it's useful for any type that is returned from
2345 * Otherwise, this macro has similar constraints as g_autoptr(): only
2346 * supported on GCC and clang, the variable must be initialized, etc.
2350 * operate_on_malloc_buf (void)
2352 * g_autofree guint8* membuf = NULL;
2354 * membuf = g_malloc (8192);
2356 * // Some computation on membuf
2358 * // membuf will be automatically freed here
2368 * @TypeName: a supported variable type
2370 * Helper to declare a list variable with automatic deep cleanup.
2372 * The list is deeply freed, in a way appropriate to the specified type, when the
2373 * variable goes out of scope. The type must support this.
2375 * This feature is only supported on GCC and clang. This macro is not
2376 * defined on other compilers and should not be used in programs that
2377 * are intended to be portable to those compilers.
2379 * This is meant to be used to declare lists of a type with a cleanup
2380 * function. The type of the variable is a `GList *`. You
2381 * must not add your own `*`.
2383 * This macro can be used to avoid having to do explicit cleanups of
2384 * local variables when exiting functions. It often vastly simplifies
2385 * handling of error conditions, removing the need for various tricks
2386 * such as `goto out` or repeating of cleanup code. It is also helpful
2387 * for non-error cases.
2389 * See also g_autoslist(), g_autoptr() and g_steal_pointer().
2396 * @TypeName: a supported variable type
2398 * Helper to declare a singly linked list variable with automatic deep cleanup.
2400 * The list is deeply freed, in a way appropriate to the specified type, when the
2401 * variable goes out of scope. The type must support this.
2403 * This feature is only supported on GCC and clang. This macro is not
2404 * defined on other compilers and should not be used in programs that
2405 * are intended to be portable to those compilers.
2407 * This is meant to be used to declare lists of a type with a cleanup
2408 * function. The type of the variable is a `GSList *`. You
2409 * must not add your own `*`.
2411 * This macro can be used to avoid having to do explicit cleanups of
2412 * local variables when exiting functions. It often vastly simplifies
2413 * handling of error conditions, removing the need for various tricks
2414 * such as `goto out` or repeating of cleanup code. It is also helpful
2415 * for non-error cases.
2417 * See also g_autolist(), g_autoptr() and g_steal_pointer().
2424 * @TypeName: a supported variable type
2426 * Helper to declare a double-ended queue variable with automatic deep cleanup.
2428 * The queue is deeply freed, in a way appropriate to the specified type, when the
2429 * variable goes out of scope. The type must support this.
2431 * This feature is only supported on GCC and clang. This macro is not
2432 * defined on other compilers and should not be used in programs that
2433 * are intended to be portable to those compilers.
2435 * This is meant to be used to declare queues of a type with a cleanup
2436 * function. The type of the variable is a `GQueue *`. You
2437 * must not add your own `*`.
2439 * This macro can be used to avoid having to do explicit cleanups of
2440 * local variables when exiting functions. It often vastly simplifies
2441 * handling of error conditions, removing the need for various tricks
2442 * such as `goto out` or repeating of cleanup code. It is also helpful
2443 * for non-error cases.
2445 * See also g_autolist(), g_autoptr() and g_steal_pointer().
2452 * G_DEFINE_AUTOPTR_CLEANUP_FUNC:
2453 * @TypeName: a type name to define a g_autoptr() cleanup function for
2454 * @func: the cleanup function
2456 * Defines the appropriate cleanup function for a pointer type.
2458 * The function will not be called if the variable to be cleaned up
2461 * This will typically be the `_free()` or `_unref()` function for the given
2464 * With this definition, it will be possible to use g_autoptr() with
2468 * G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref)
2471 * This macro should be used unconditionally; it is a no-op on compilers
2472 * where cleanup is not supported.
2478 * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC:
2479 * @TypeName: a type name to define a g_auto() cleanup function for
2480 * @func: the clear function
2482 * Defines the appropriate cleanup function for a type.
2484 * This will typically be the `_clear()` function for the given type.
2486 * With this definition, it will be possible to use g_auto() with
2490 * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
2493 * This macro should be used unconditionally; it is a no-op on compilers
2494 * where cleanup is not supported.
2500 * G_DEFINE_AUTO_CLEANUP_FREE_FUNC:
2501 * @TypeName: a type name to define a g_auto() cleanup function for
2502 * @func: the free function
2503 * @none: the "none" value for the type
2505 * Defines the appropriate cleanup function for a type.
2507 * With this definition, it will be possible to use g_auto() with
2510 * This function will be rarely used. It is used with pointer-based
2511 * typedefs and non-pointer types where the value of the variable
2512 * represents a resource that must be freed. Two examples are #GStrv
2513 * and file descriptors.
2515 * @none specifies the "none" value for the type in question. It is
2516 * probably something like %NULL or `-1`. If the variable is found to
2517 * contain this value then the free function will not be called.
2520 * G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
2523 * This macro should be used unconditionally; it is a no-op on compilers
2524 * where cleanup is not supported.
2529 /* Warnings and Assertions {{{1 */
2533 * @title: Warnings and Assertions
2534 * @short_description: warnings and assertions to use in runtime code
2536 * GLib defines several warning functions and assertions which can be used to
2537 * warn of programmer errors when calling functions, and print error messages
2538 * from command line programs.
2540 * The g_return_if_fail(), g_return_val_if_fail(), g_return_if_reached() and
2541 * g_return_val_if_reached() macros are intended as pre-condition assertions, to
2542 * be used at the top of a public function to check that the function’s
2543 * arguments are acceptable. Any failure of such a pre-condition assertion is
2544 * considered a programming error on the part of the caller of the public API,
2545 * and the program is considered to be in an undefined state afterwards. They
2546 * are similar to the libc assert() function, but provide more context on
2550 * |[<!-- language="C" -->
2552 * g_dtls_connection_shutdown (GDtlsConnection *conn,
2553 * gboolean shutdown_read,
2554 * gboolean shutdown_write,
2555 * GCancellable *cancellable,
2558 * // local variable declarations
2560 * g_return_val_if_fail (G_IS_DTLS_CONNECTION (conn), FALSE);
2561 * g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
2562 * g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
2566 * return return_val;
2570 * g_print(), g_printerr() and g_set_print_handler() are intended to be used for
2571 * output from command line applications, since they output to standard output
2572 * and standard error by default — whereas functions like g_message() and
2573 * g_log() may be redirected to special purpose message windows, files, or the
2577 /* Windows Compatibility Functions {{{1 */
2581 * @title: Windows Compatibility Functions
2582 * @short_description: UNIX emulation on Windows
2584 * These functions provide some level of UNIX emulation on the
2585 * Windows platform. If your application really needs the POSIX
2586 * APIs, we suggest you try the Cygwin project.
2592 * Provided for UNIX emulation on Windows; equivalent to UNIX
2593 * macro %MAXPATHLEN, which is the maximum length of a filename
2594 * (including full path).
2598 * G_WIN32_DLLMAIN_FOR_DLL_NAME:
2599 * @static: empty or "static"
2600 * @dll_name: the name of the (pointer to the) char array where
2601 * the DLL name will be stored. If this is used, you must also
2602 * include `windows.h`. If you need a more complex DLL entry
2603 * point function, you cannot use this
2605 * On Windows, this macro defines a DllMain() function that stores
2606 * the actual DLL name that the code being compiled will be included in.
2608 * On non-Windows platforms, expands to nothing.
2612 * G_WIN32_HAVE_WIDECHAR_API:
2614 * On Windows, this macro defines an expression which evaluates to
2615 * %TRUE if the code is running on a version of Windows where the wide
2616 * character versions of the Win32 API functions, and the wide character
2617 * versions of the C library functions work. (They are always present in
2618 * the DLLs, but don't work on Windows 9x and Me.)
2620 * On non-Windows platforms, it is not defined.
2627 * G_WIN32_IS_NT_BASED:
2629 * On Windows, this macro defines an expression which evaluates to
2630 * %TRUE if the code is running on an NT-based Windows operating system.
2632 * On non-Windows platforms, it is not defined.
2638 /* vim: set foldmethod=marker: */