Introduce g_static_assert. (#14651)
[mono-project.git] / mono / eglib / glib.h
blobd7911b708e7ef88984bf1f21926fa9dcee97db09
1 #ifndef __GLIB_H
2 #define __GLIB_H
4 // Ask stdint.h and inttypes.h for the full C99 features for CentOS 6 g++ 4.4, Android, etc.
5 // See for example:
6 // $HOME/android-toolchain/toolchains/armeabi-v7a-clang/sysroot/usr/include/inttypes.h
7 // $HOME/android-toolchain/toolchains/armeabi-v7a-clang/sysroot/usr/include/stdint.h
8 #ifdef __cplusplus
9 #ifndef __STDC_LIMIT_MACROS
10 #define __STDC_LIMIT_MACROS
11 #endif
12 #ifndef __STDC_CONSTANT_MACROS
13 #define __STDC_CONSTANT_MACROS
14 #endif
15 #ifndef __STDC_FORMAT_MACROS
16 #define __STDC_FORMAT_MACROS
17 #endif
18 #endif // __cplusplus
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include <stddef.h>
25 #include <ctype.h>
26 #include <limits.h>
27 #include <stdint.h>
28 #include <inttypes.h>
29 #ifdef _MSC_VER
30 #include <eglib-config.hw>
31 #else
32 #include <eglib-config.h>
33 #endif
35 // - Pointers should only be converted to or from pointer-sized integers.
36 // - Any size integer can be converted to any other size integer.
37 // - Therefore a pointer-sized integer is the intermediary between
38 // a pointer and any integer type.
39 #define GPOINTER_TO_INT(ptr) ((gint)(gssize)(ptr))
40 #define GPOINTER_TO_UINT(ptr) ((guint)(gsize)(ptr))
41 #define GINT_TO_POINTER(v) ((gpointer)(gssize)(v))
42 #define GUINT_TO_POINTER(v) ((gpointer)(gsize)(v))
44 #ifndef EGLIB_NO_REMAP
45 #include <eglib-remap.h>
46 #endif
48 #ifdef G_HAVE_ALLOCA_H
49 #include <alloca.h>
50 #endif
52 #ifdef WIN32
53 /* For alloca */
54 #include <malloc.h>
55 #endif
57 #ifdef G_HAVE_UNISTD_H
58 #include <unistd.h>
59 #endif
61 #ifndef offsetof
62 # define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
63 #endif
65 #ifdef __cplusplus
66 #define G_BEGIN_DECLS extern "C" {
67 #define G_END_DECLS }
68 #define G_EXTERN_C extern "C"
69 #else
70 #define G_BEGIN_DECLS /* nothing */
71 #define G_END_DECLS /* nothing */
72 #define G_EXTERN_C /* nothing */
73 #endif
75 #ifdef __cplusplus
77 #define g_cast monoeg_g_cast // in case not inlined (see eglib-remap.h)
79 // g_cast converts void* to T*.
80 // e.g. #define malloc(x) (g_cast (malloc (x)))
81 // FIXME It used to do more. Rename?
82 struct g_cast
84 private:
85 void * const x;
86 public:
87 explicit g_cast (void volatile *y) : x((void*)y) { }
88 // Lack of rvalue constructor inhibits ternary operator.
89 // Either don't use ternary, or cast each side.
90 // sa = (salen <= 128) ? g_alloca (salen) : g_malloc (salen);
91 // w32socket.c:1045:24: error: call to deleted constructor of 'monoeg_g_cast'
92 //g_cast (g_cast&& y) : x(y.x) { }
93 g_cast (g_cast&&) = delete;
94 g_cast () = delete;
95 g_cast (const g_cast&) = delete;
97 template <typename TTo>
98 operator TTo* () const
100 return (TTo*)x;
104 #else
106 // FIXME? Parens are omitted to preserve prior meaning.
107 #define g_cast(x) x
109 #endif
111 // G++4.4 breaks opeq below without this.
112 #if defined (__GNUC__) || defined (__clang__)
113 #define G_MAY_ALIAS __attribute__((__may_alias__))
114 #else
115 #define G_MAY_ALIAS /* nothing */
116 #endif
118 #ifdef __cplusplus
120 // Provide for bit operations on enums, but not all integer operations.
121 // This alleviates a fair number of casts in porting C to C++.
123 // Forward declare template with no generic implementation.
124 template <size_t> struct g_size_to_int;
126 // Template specializations.
127 template <> struct g_size_to_int<1> { typedef int8_t type; };
128 template <> struct g_size_to_int<2> { typedef int16_t type; };
129 template <> struct g_size_to_int<4> { typedef int32_t type; };
130 template <> struct g_size_to_int<8> { typedef int64_t type; };
132 // g++4.4 does not accept:
133 //template <typename T>
134 //using g_size_to_int_t = typename g_size_to_int <sizeof (T)>::type;
135 #define g_size_to_int_t(x) g_size_to_int <sizeof (x)>::type
137 #define G_ENUM_BINOP(Enum, op, opeq) \
138 inline Enum \
139 operator op (Enum a, Enum b) \
141 typedef g_size_to_int_t (Enum) type; \
142 return static_cast<Enum>(static_cast<type>(a) op b); \
145 inline Enum& \
146 operator opeq (Enum& a, Enum b) \
148 typedef g_size_to_int_t (Enum) G_MAY_ALIAS type; \
149 return (Enum&)((type&)a opeq b); \
152 #define G_ENUM_FUNCTIONS(Enum) \
153 extern "C++" { /* in case within extern "C" */ \
154 inline Enum \
155 operator~ (Enum a) \
157 typedef g_size_to_int_t (Enum) type; \
158 return static_cast<Enum>(~static_cast<type>(a)); \
161 G_ENUM_BINOP (Enum, |, |=) \
162 G_ENUM_BINOP (Enum, &, &=) \
163 G_ENUM_BINOP (Enum, ^, ^=) \
165 } /* extern "C++" */
167 #else
168 #define G_ENUM_FUNCTIONS(Enum) /* nothing */
169 #endif
171 G_BEGIN_DECLS
174 * Basic data types
176 typedef int gint;
177 typedef unsigned int guint;
178 typedef short gshort;
179 typedef unsigned short gushort;
180 typedef long glong;
181 typedef unsigned long gulong;
182 typedef void * gpointer;
183 typedef const void * gconstpointer;
184 typedef char gchar;
185 typedef unsigned char guchar;
187 /* Types defined in terms of the stdint.h */
188 typedef int8_t gint8;
189 typedef uint8_t guint8;
190 typedef int16_t gint16;
191 typedef uint16_t guint16;
192 typedef int32_t gint32;
193 typedef uint32_t guint32;
194 typedef int64_t gint64;
195 typedef uint64_t guint64;
196 typedef float gfloat;
197 typedef double gdouble;
198 typedef int32_t gboolean;
200 #if defined (HOST_WIN32) || defined (_WIN32)
201 G_END_DECLS
202 #include <wchar.h>
203 typedef wchar_t gunichar2;
204 G_BEGIN_DECLS
205 #else
206 typedef guint16 gunichar2;
207 #endif
208 typedef guint32 gunichar;
211 * Macros
213 #define G_N_ELEMENTS(s) (sizeof(s) / sizeof ((s) [0]))
215 #define FALSE 0
216 #define TRUE 1
218 #define G_MINSHORT SHRT_MIN
219 #define G_MAXSHORT SHRT_MAX
220 #define G_MAXUSHORT USHRT_MAX
221 #define G_MAXINT INT_MAX
222 #define G_MININT INT_MIN
223 #define G_MAXINT8 INT8_MAX
224 #define G_MAXUINT8 UINT8_MAX
225 #define G_MININT8 INT8_MIN
226 #define G_MAXINT16 INT16_MAX
227 #define G_MAXUINT16 UINT16_MAX
228 #define G_MININT16 INT16_MIN
229 #define G_MAXINT32 INT32_MAX
230 #define G_MAXUINT32 UINT32_MAX
231 #define G_MININT32 INT32_MIN
232 #define G_MININT64 INT64_MIN
233 #define G_MAXINT64 INT64_MAX
234 #define G_MAXUINT64 UINT64_MAX
236 #define G_LITTLE_ENDIAN 1234
237 #define G_BIG_ENDIAN 4321
238 #define G_STMT_START do
239 #define G_STMT_END while (0)
241 #define G_USEC_PER_SEC 1000000
243 #ifndef ABS
244 #define ABS(a) ((a) > 0 ? (a) : -(a))
245 #endif
247 #ifndef ALIGN_TO
248 #define ALIGN_TO(val,align) ((((gssize)val) + ((align) - 1)) & ~((align) - 1))
249 #endif
251 #ifndef ALIGN_PTR_TO
252 #define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
253 #endif
255 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
257 #define EGLIB_STRINGIFY(x) #x
258 #define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
259 #define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
261 #define G_CONST_RETURN const
263 #define G_GUINT64_FORMAT PRIu64
264 #define G_GINT64_FORMAT PRIi64
265 #define G_GUINT32_FORMAT PRIu32
266 #define G_GINT32_FORMAT PRIi32
268 #ifdef __GNUC__
269 #define G_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__((__format__(__printf__,fmt_pos,arg_pos)))
270 #else
271 #define G_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
272 #endif
275 * Allocation
277 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
278 void g_free (void *ptr);
279 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
280 gpointer g_realloc (gpointer obj, gsize size);
281 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
282 gpointer g_malloc (gsize x);
283 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
284 gpointer g_malloc0 (gsize x);
285 G_EXTERN_C // Used by profilers, at least.
286 gpointer g_calloc (gsize n, gsize x);
287 gpointer g_try_malloc (gsize x);
288 gpointer g_try_realloc (gpointer obj, gsize size);
290 #define g_new(type,size) ((type *) g_malloc (sizeof (type) * (size)))
291 #define g_new0(type,size) ((type *) g_malloc0 (sizeof (type)* (size)))
292 #define g_newa(type,size) ((type *) alloca (sizeof (type) * (size)))
294 #define g_memmove(dest,src,len) memmove (dest, src, len)
295 #define g_renew(struct_type, mem, n_structs) ((struct_type*)g_realloc (mem, sizeof (struct_type) * n_structs))
296 #define g_alloca(size) (g_cast (alloca (size)))
298 G_EXTERN_C // Used by libtest, at least.
299 gpointer g_memdup (gconstpointer mem, guint byte_size);
300 static inline gchar *g_strdup (const gchar *str) { if (str) { return (gchar*) g_memdup (str, (guint)strlen (str) + 1); } return NULL; }
301 gchar **g_strdupv (gchar **str_array);
303 typedef struct {
304 gpointer (*malloc) (gsize n_bytes);
305 gpointer (*realloc) (gpointer mem, gsize n_bytes);
306 void (*free) (gpointer mem);
307 gpointer (*calloc) (gsize n_blocks, gsize n_block_bytes);
308 } GMemVTable;
310 void g_mem_set_vtable (GMemVTable* vtable);
311 void g_mem_get_vtable (GMemVTable* vtable);
313 struct _GMemChunk {
314 guint alloc_size;
317 typedef struct _GMemChunk GMemChunk;
319 * Misc.
322 gboolean g_hasenv(const gchar *variable);
323 gchar * g_getenv(const gchar *variable);
325 G_EXTERN_C // sdks/wasm/driver.c is C and uses this
326 gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
328 void g_unsetenv(const gchar *variable);
330 gchar* g_win32_getlocale(void);
333 * Precondition macros
335 #define g_warn_if_fail(x) G_STMT_START { if (!(x)) { g_warning ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); } } G_STMT_END
336 #define g_return_if_fail(x) G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END
337 #define g_return_val_if_fail(x,e) G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END
340 * Errors
342 typedef struct {
343 /* In the real glib, this is a GQuark, but we dont use/need that */
344 gpointer domain;
345 gint code;
346 gchar *message;
347 } GError;
349 void g_clear_error (GError **gerror);
350 void g_error_free (GError *gerror);
351 GError *g_error_new (gpointer domain, gint code, const char *format, ...);
352 void g_set_error (GError **err, gpointer domain, gint code, const gchar *format, ...);
353 void g_propagate_error (GError **dest, GError *src);
356 * Strings utility
358 G_EXTERN_C // Used by libtest, at least.
359 gchar *g_strdup_printf (const gchar *format, ...) G_ATTR_FORMAT_PRINTF(1, 2);
360 gchar *g_strdup_vprintf (const gchar *format, va_list args);
361 gchar *g_strndup (const gchar *str, gsize n);
362 const gchar *g_strerror (gint errnum);
363 gchar *g_strndup (const gchar *str, gsize n);
364 void g_strfreev (gchar **str_array);
365 gchar *g_strconcat (const gchar *first, ...);
366 gchar **g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens);
367 gchar **g_strsplit_set (const gchar *string, const gchar *delimiter, gint max_tokens);
368 gchar *g_strreverse (gchar *str);
369 gboolean g_str_has_prefix (const gchar *str, const gchar *prefix);
370 gboolean g_str_has_suffix (const gchar *str, const gchar *suffix);
371 guint g_strv_length (gchar **str_array);
372 gchar *g_strjoin (const gchar *separator, ...);
373 gchar *g_strjoinv (const gchar *separator, gchar **str_array);
374 gchar *g_strchug (gchar *str);
375 gchar *g_strchomp (gchar *str);
376 void g_strdown (gchar *string);
377 gchar *g_strnfill (gsize length, gchar fill_char);
379 void g_strdelimit (char *string, char delimiter, char new_delimiter);
380 gchar *g_strescape (const gchar *source, const gchar *exceptions);
382 gchar *g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **gerror);
383 gchar *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **gerror);
385 gint g_printf (gchar const *format, ...) G_ATTR_FORMAT_PRINTF(1, 2);
386 gint g_fprintf (FILE *file, gchar const *format, ...) G_ATTR_FORMAT_PRINTF(2, 3);
387 gint g_sprintf (gchar *string, gchar const *format, ...) G_ATTR_FORMAT_PRINTF(2, 3);
388 gint g_snprintf (gchar *string, gulong n, gchar const *format, ...) G_ATTR_FORMAT_PRINTF(3, 4);
389 gint g_vasprintf (gchar **ret, const gchar *fmt, va_list ap);
390 #define g_vprintf vprintf
391 #define g_vfprintf vfprintf
392 #define g_vsprintf vsprintf
393 #define g_vsnprintf vsnprintf
395 gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
396 gchar *g_stpcpy (gchar *dest, const char *src);
399 gchar g_ascii_tolower (gchar c);
400 gchar g_ascii_toupper (gchar c);
401 gchar *g_ascii_strdown (const gchar *str, gssize len);
402 gchar *g_ascii_strup (const gchar *str, gssize len);
403 gint g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n);
404 gint g_ascii_strcasecmp (const gchar *s1, const gchar *s2);
405 gint g_ascii_xdigit_value (gchar c);
406 #define g_ascii_isspace(c) (isspace (c) != 0)
407 #define g_ascii_isalpha(c) (isalpha (c) != 0)
408 #define g_ascii_isprint(c) (isprint (c) != 0)
409 #define g_ascii_isxdigit(c) (isxdigit (c) != 0)
410 gboolean g_utf16_ascii_equal (const gunichar2 *utf16, size_t ulen, const char *ascii, size_t alen);
411 gboolean g_utf16_asciiz_equal (const gunichar2 *utf16, const char *ascii);
413 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
414 #ifdef _MSC_VER
415 #define g_strcasecmp _stricmp
416 #define g_strncasecmp _strnicmp
417 #define g_strstrip(a) g_strchug (g_strchomp (a))
418 #else
419 #define g_strcasecmp strcasecmp
420 #define g_ascii_strtoull strtoull
421 #define g_strncasecmp strncasecmp
422 #define g_strstrip(a) g_strchug (g_strchomp (a))
423 #endif
424 #define g_ascii_strdup strdup
427 * String type
429 typedef struct {
430 char *str;
431 gsize len;
432 gsize allocated_len;
433 } GString;
435 GString *g_string_new (const gchar *init);
436 GString *g_string_new_len (const gchar *init, gssize len);
437 GString *g_string_sized_new (gsize default_size);
438 gchar *g_string_free (GString *string, gboolean free_segment);
439 GString *g_string_append (GString *string, const gchar *val);
441 void g_string_printf (GString *string, const gchar *format, ...) G_ATTR_FORMAT_PRINTF(2, 3);
442 void g_string_append_printf (GString *string, const gchar *format, ...) G_ATTR_FORMAT_PRINTF(2, 3);
443 void g_string_append_vprintf (GString *string, const gchar *format, va_list args);
444 GString *g_string_append_unichar (GString *string, gunichar c);
445 GString *g_string_append_c (GString *string, gchar c);
446 GString *g_string_append (GString *string, const gchar *val);
447 GString *g_string_append_len (GString *string, const gchar *val, gssize len);
448 GString *g_string_truncate (GString *string, gsize len);
449 GString *g_string_set_size (GString *string, gsize len);
451 #define g_string_sprintfa g_string_append_printf
453 typedef void (*GFunc) (gpointer data, gpointer user_data);
454 typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b);
455 typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
456 typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);
457 typedef gboolean (*GHRFunc) (gpointer key, gpointer value, gpointer user_data);
458 typedef void (*GDestroyNotify) (gpointer data);
459 typedef guint (*GHashFunc) (gconstpointer key);
460 typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b);
461 typedef void (*GFreeFunc) (gpointer data);
464 * Lists
466 typedef struct _GSList GSList;
467 struct _GSList {
468 gpointer data;
469 GSList *next;
472 GSList *g_slist_alloc (void);
473 GSList *g_slist_append (GSList *list,
474 gpointer data);
475 GSList *g_slist_prepend (GSList *list,
476 gpointer data);
477 void g_slist_free (GSList *list);
478 void g_slist_free_1 (GSList *list);
479 GSList *g_slist_copy (GSList *list);
480 GSList *g_slist_concat (GSList *list1,
481 GSList *list2);
482 void g_slist_foreach (GSList *list,
483 GFunc func,
484 gpointer user_data);
485 GSList *g_slist_last (GSList *list);
486 GSList *g_slist_find (GSList *list,
487 gconstpointer data);
488 GSList *g_slist_find_custom (GSList *list,
489 gconstpointer data,
490 GCompareFunc func);
491 GSList *g_slist_remove (GSList *list,
492 gconstpointer data);
493 GSList *g_slist_remove_all (GSList *list,
494 gconstpointer data);
495 GSList *g_slist_reverse (GSList *list);
496 guint g_slist_length (GSList *list);
497 GSList *g_slist_remove_link (GSList *list,
498 GSList *link);
499 GSList *g_slist_delete_link (GSList *list,
500 GSList *link);
501 GSList *g_slist_insert_sorted (GSList *list,
502 gpointer data,
503 GCompareFunc func);
504 GSList *g_slist_insert_before (GSList *list,
505 GSList *sibling,
506 gpointer data);
507 GSList *g_slist_sort (GSList *list,
508 GCompareFunc func);
509 gint g_slist_index (GSList *list,
510 gconstpointer data);
511 GSList *g_slist_nth (GSList *list,
512 guint n);
513 gpointer g_slist_nth_data (GSList *list,
514 guint n);
516 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
519 typedef struct _GList GList;
520 struct _GList {
521 gpointer data;
522 GList *next;
523 GList *prev;
526 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
527 #define g_list_previous(list) ((list) ? (((GList *) (list))->prev) : NULL)
529 GList *g_list_alloc (void);
530 GList *g_list_append (GList *list,
531 gpointer data);
532 GList *g_list_prepend (GList *list,
533 gpointer data);
534 void g_list_free (GList *list);
535 void g_list_free_1 (GList *list);
536 GList *g_list_copy (GList *list);
537 guint g_list_length (GList *list);
538 gint g_list_index (GList *list,
539 gconstpointer data);
540 GList *g_list_nth (GList *list,
541 guint n);
542 gpointer g_list_nth_data (GList *list,
543 guint n);
544 GList *g_list_last (GList *list);
545 GList *g_list_concat (GList *list1,
546 GList *list2);
547 void g_list_foreach (GList *list,
548 GFunc func,
549 gpointer user_data);
550 GList *g_list_first (GList *list);
551 GList *g_list_find (GList *list,
552 gconstpointer data);
553 GList *g_list_find_custom (GList *list,
554 gconstpointer data,
555 GCompareFunc func);
556 GList *g_list_remove (GList *list,
557 gconstpointer data);
558 GList *g_list_remove_all (GList *list,
559 gconstpointer data);
560 GList *g_list_reverse (GList *list);
561 GList *g_list_remove_link (GList *list,
562 GList *link);
563 GList *g_list_delete_link (GList *list,
564 GList *link);
565 GList *g_list_insert_sorted (GList *list,
566 gpointer data,
567 GCompareFunc func);
568 GList *g_list_insert_before (GList *list,
569 GList *sibling,
570 gpointer data);
571 GList *g_list_sort (GList *sort,
572 GCompareFunc func);
575 * Hashtables
577 typedef struct _GHashTable GHashTable;
578 typedef struct _GHashTableIter GHashTableIter;
580 /* Private, but needed for stack allocation */
581 struct _GHashTableIter
583 gpointer dummy [8];
586 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
587 GHashTable *g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
588 GHashTable *g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func,
589 GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
590 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
591 void g_hash_table_insert_replace (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
592 guint g_hash_table_size (GHashTable *hash);
593 GList *g_hash_table_get_keys (GHashTable *hash);
594 GList *g_hash_table_get_values (GHashTable *hash);
595 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
596 gpointer g_hash_table_lookup (GHashTable *hash, gconstpointer key);
597 gboolean g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
598 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
599 void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data);
600 gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data);
601 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
602 gboolean g_hash_table_remove (GHashTable *hash, gconstpointer key);
603 gboolean g_hash_table_steal (GHashTable *hash, gconstpointer key);
604 void g_hash_table_remove_all (GHashTable *hash);
605 guint g_hash_table_foreach_remove (GHashTable *hash, GHRFunc func, gpointer user_data);
606 guint g_hash_table_foreach_steal (GHashTable *hash, GHRFunc func, gpointer user_data);
607 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
608 void g_hash_table_destroy (GHashTable *hash);
609 void g_hash_table_print_stats (GHashTable *table);
611 void g_hash_table_iter_init (GHashTableIter *iter, GHashTable *hash_table);
612 gboolean g_hash_table_iter_next (GHashTableIter *iter, gpointer *key, gpointer *value);
614 guint g_spaced_primes_closest (guint x);
616 #define g_hash_table_insert(h,k,v) g_hash_table_insert_replace ((h),(k),(v),FALSE)
617 #define g_hash_table_replace(h,k,v) g_hash_table_insert_replace ((h),(k),(v),TRUE)
619 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
620 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
621 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
622 guint g_direct_hash (gconstpointer v1);
623 gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
624 guint g_int_hash (gconstpointer v1);
625 gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
626 guint g_str_hash (gconstpointer v1);
629 * ByteArray
632 typedef struct _GByteArray GByteArray;
633 struct _GByteArray {
634 guint8 *data;
635 gint len;
638 GByteArray *g_byte_array_new (void);
639 GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, guint len);
640 guint8* g_byte_array_free (GByteArray *array, gboolean free_segment);
641 void g_byte_array_set_size (GByteArray *array, gint length);
644 * Array
647 typedef struct _GArray GArray;
648 struct _GArray {
649 gchar *data;
650 gint len;
653 GArray *g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
654 GArray *g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
655 gchar* g_array_free (GArray *array, gboolean free_segment);
656 GArray *g_array_append_vals (GArray *array, gconstpointer data, guint len);
657 GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
658 GArray* g_array_remove_index (GArray *array, guint index_);
659 GArray* g_array_remove_index_fast (GArray *array, guint index_);
660 void g_array_set_size (GArray *array, gint length);
662 #define g_array_append_val(a,v) (g_array_append_vals((a),&(v),1))
663 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
664 #define g_array_index(a,t,i) *(t*)(((a)->data) + sizeof(t) * (i))
665 //FIXME previous missing parens
668 * QSort
671 void g_qsort_with_data (gpointer base, size_t nmemb, size_t size, GCompareDataFunc compare, gpointer user_data);
674 * Pointer Array
677 typedef struct _GPtrArray GPtrArray;
678 struct _GPtrArray {
679 gpointer *pdata;
680 guint len;
683 GPtrArray *g_ptr_array_new (void);
684 GPtrArray *g_ptr_array_sized_new (guint reserved_size);
685 void g_ptr_array_add (GPtrArray *array, gpointer data);
686 gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
687 gpointer g_ptr_array_remove_index (GPtrArray *array, guint index);
688 gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
689 gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index);
690 void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
691 void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
692 void g_ptr_array_set_size (GPtrArray *array, gint length);
693 gpointer *g_ptr_array_free (GPtrArray *array, gboolean free_seg);
694 void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data);
695 guint g_ptr_array_capacity (GPtrArray *array);
696 #define g_ptr_array_index(array,index) (array)->pdata[(index)]
697 //FIXME previous missing parens
700 * Queues
702 typedef struct {
703 GList *head;
704 GList *tail;
705 guint length;
706 } GQueue;
708 gpointer g_queue_pop_head (GQueue *queue);
709 void g_queue_push_head (GQueue *queue,
710 gpointer data);
711 void g_queue_push_tail (GQueue *queue,
712 gpointer data);
713 gboolean g_queue_is_empty (GQueue *queue);
714 GQueue *g_queue_new (void);
715 void g_queue_free (GQueue *queue);
716 void g_queue_foreach (GQueue *queue, GFunc func, gpointer user_data);
719 * Messages
721 #ifndef G_LOG_DOMAIN
722 #define G_LOG_DOMAIN ((gchar*) 0)
723 #endif
725 typedef enum {
726 G_LOG_FLAG_RECURSION = 1 << 0,
727 G_LOG_FLAG_FATAL = 1 << 1,
729 G_LOG_LEVEL_ERROR = 1 << 2,
730 G_LOG_LEVEL_CRITICAL = 1 << 3,
731 G_LOG_LEVEL_WARNING = 1 << 4,
732 G_LOG_LEVEL_MESSAGE = 1 << 5,
733 G_LOG_LEVEL_INFO = 1 << 6,
734 G_LOG_LEVEL_DEBUG = 1 << 7,
736 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
737 } GLogLevelFlags;
739 G_ENUM_FUNCTIONS (GLogLevelFlags)
741 void g_printv (const gchar *format, va_list args);
742 void g_print (const gchar *format, ...);
743 void g_printerr (const gchar *format, ...);
744 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
745 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask);
746 void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
747 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
748 void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
749 G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
750 void g_assertion_message (const gchar *format, ...) G_GNUC_NORETURN;
751 const char * g_get_assertion_message (void);
753 #ifdef HAVE_C99_SUPPORT
754 /* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
755 #define g_error(format, ...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
756 #define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
757 #define g_warning(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
758 #define g_message(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
759 #define g_debug(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
760 #else /* HAVE_C99_SUPPORT */
761 #define g_error(...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;); } while (0)
762 #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
763 #define g_warning(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
764 #define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
765 #define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
766 #endif /* ndef HAVE_C99_SUPPORT */
768 typedef void (*GLogFunc) (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
769 typedef void (*GPrintFunc) (const gchar *string);
770 typedef void (*GAbortFunc) (void);
772 void g_assertion_disable_global (GAbortFunc func);
773 void g_assert_abort (void);
774 void g_log_default_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data);
775 GLogFunc g_log_set_default_handler (GLogFunc log_func, gpointer user_data);
776 GPrintFunc g_set_print_handler (GPrintFunc func);
777 GPrintFunc g_set_printerr_handler (GPrintFunc func);
779 * Conversions
782 gpointer g_convert_error_quark(void);
786 * Unicode Manipulation: most of this is not used by Mono by default, it is
787 * only used if the old collation code is activated, so this is only the
788 * bare minimum to build.
791 typedef enum {
792 G_UNICODE_CONTROL,
793 G_UNICODE_FORMAT,
794 G_UNICODE_UNASSIGNED,
795 G_UNICODE_PRIVATE_USE,
796 G_UNICODE_SURROGATE,
797 G_UNICODE_LOWERCASE_LETTER,
798 G_UNICODE_MODIFIER_LETTER,
799 G_UNICODE_OTHER_LETTER,
800 G_UNICODE_TITLECASE_LETTER,
801 G_UNICODE_UPPERCASE_LETTER,
802 G_UNICODE_COMBINING_MARK,
803 G_UNICODE_ENCLOSING_MARK,
804 G_UNICODE_NON_SPACING_MARK,
805 G_UNICODE_DECIMAL_NUMBER,
806 G_UNICODE_LETTER_NUMBER,
807 G_UNICODE_OTHER_NUMBER,
808 G_UNICODE_CONNECT_PUNCTUATION,
809 G_UNICODE_DASH_PUNCTUATION,
810 G_UNICODE_CLOSE_PUNCTUATION,
811 G_UNICODE_FINAL_PUNCTUATION,
812 G_UNICODE_INITIAL_PUNCTUATION,
813 G_UNICODE_OTHER_PUNCTUATION,
814 G_UNICODE_OPEN_PUNCTUATION,
815 G_UNICODE_CURRENCY_SYMBOL,
816 G_UNICODE_MODIFIER_SYMBOL,
817 G_UNICODE_MATH_SYMBOL,
818 G_UNICODE_OTHER_SYMBOL,
819 G_UNICODE_LINE_SEPARATOR,
820 G_UNICODE_PARAGRAPH_SEPARATOR,
821 G_UNICODE_SPACE_SEPARATOR
822 } GUnicodeType;
824 typedef enum {
825 G_UNICODE_BREAK_MANDATORY,
826 G_UNICODE_BREAK_CARRIAGE_RETURN,
827 G_UNICODE_BREAK_LINE_FEED,
828 G_UNICODE_BREAK_COMBINING_MARK,
829 G_UNICODE_BREAK_SURROGATE,
830 G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
831 G_UNICODE_BREAK_INSEPARABLE,
832 G_UNICODE_BREAK_NON_BREAKING_GLUE,
833 G_UNICODE_BREAK_CONTINGENT,
834 G_UNICODE_BREAK_SPACE,
835 G_UNICODE_BREAK_AFTER,
836 G_UNICODE_BREAK_BEFORE,
837 G_UNICODE_BREAK_BEFORE_AND_AFTER,
838 G_UNICODE_BREAK_HYPHEN,
839 G_UNICODE_BREAK_NON_STARTER,
840 G_UNICODE_BREAK_OPEN_PUNCTUATION,
841 G_UNICODE_BREAK_CLOSE_PUNCTUATION,
842 G_UNICODE_BREAK_QUOTATION,
843 G_UNICODE_BREAK_EXCLAMATION,
844 G_UNICODE_BREAK_IDEOGRAPHIC,
845 G_UNICODE_BREAK_NUMERIC,
846 G_UNICODE_BREAK_INFIX_SEPARATOR,
847 G_UNICODE_BREAK_SYMBOL,
848 G_UNICODE_BREAK_ALPHABETIC,
849 G_UNICODE_BREAK_PREFIX,
850 G_UNICODE_BREAK_POSTFIX,
851 G_UNICODE_BREAK_COMPLEX_CONTEXT,
852 G_UNICODE_BREAK_AMBIGUOUS,
853 G_UNICODE_BREAK_UNKNOWN,
854 G_UNICODE_BREAK_NEXT_LINE,
855 G_UNICODE_BREAK_WORD_JOINER,
856 G_UNICODE_BREAK_HANGUL_L_JAMO,
857 G_UNICODE_BREAK_HANGUL_V_JAMO,
858 G_UNICODE_BREAK_HANGUL_T_JAMO,
859 G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
860 G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE
861 } GUnicodeBreakType;
863 gunichar g_unichar_toupper (gunichar c);
864 gunichar g_unichar_tolower (gunichar c);
865 gunichar g_unichar_totitle (gunichar c);
866 GUnicodeType g_unichar_type (gunichar c);
867 gboolean g_unichar_isspace (gunichar c);
868 gboolean g_unichar_isxdigit (gunichar c);
869 gint g_unichar_xdigit_value (gunichar c);
870 GUnicodeBreakType g_unichar_break_type (gunichar c);
872 #ifndef MAX
873 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
874 #endif
876 #ifndef MIN
877 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
878 #endif
880 #ifndef CLAMP
881 #define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
882 #endif
884 #if defined(__GNUC__) && (__GNUC__ > 2)
885 #define G_LIKELY(expr) (__builtin_expect ((expr) != 0, 1))
886 #define G_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0))
887 #else
888 #define G_LIKELY(x) (x)
889 #define G_UNLIKELY(x) (x)
890 #endif
892 #if defined(_MSC_VER)
893 #define eg_unreachable() __assume(0)
894 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 5)))
895 #define eg_unreachable() __builtin_unreachable()
896 #else
897 #define eg_unreachable()
898 #endif
900 /* g_assert is a boolean expression; the precise value is not preserved, just true or false. */
901 #ifdef DISABLE_ASSERT_MESSAGES
902 #define g_assert(x) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, "<disabled>"), 0))
903 #else
904 #define g_assert(x) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x), 0))
905 #endif
907 #ifdef __cplusplus
908 #define g_static_assert(x) static_assert (x, "")
909 #else
910 #define g_static_assert(x) g_assert (x)
911 #endif
913 #define g_assert_not_reached() G_STMT_START { g_assertion_message ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); eg_unreachable(); } G_STMT_END
915 /* f is format -- like printf and scanf
916 * Where you might have said:
917 * if (!(expr))
918 * g_error("%s invalid bar:%d", __func__, bar)
920 * You can say:
921 * g_assertf(expr, "bar:%d", bar);
923 * The usual assertion text of file/line/expr/newline are builtin, and __func__.
925 * g_assertf is a boolean expression -- the precise value is not preserved, just true or false.
927 * Other than expr, the parameters are not evaluated unless expr is false.
929 * format must be a string literal, in order to be concatenated.
930 * If this is too restrictive, g_error remains.
932 #if defined(_MSC_VER) && (_MSC_VER < 1910)
933 #define g_assertf(x, format, ...) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met, function:%s, " format "\n", __FILE__, __LINE__, #x, __func__, __VA_ARGS__), 0))
934 #else
935 #define g_assertf(x, format, ...) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met, function:%s, " format "\n", __FILE__, __LINE__, #x, __func__, ##__VA_ARGS__), 0))
936 #endif
939 * Unicode conversion
942 #define G_CONVERT_ERROR g_convert_error_quark()
944 typedef enum {
945 G_CONVERT_ERROR_NO_CONVERSION,
946 G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
947 G_CONVERT_ERROR_FAILED,
948 G_CONVERT_ERROR_PARTIAL_INPUT,
949 G_CONVERT_ERROR_BAD_URI,
950 G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
951 } GConvertError;
953 gchar *g_utf8_strup (const gchar *str, gssize len);
954 gchar *g_utf8_strdown (const gchar *str, gssize len);
955 gint g_unichar_to_utf8 (gunichar c, gchar *outbuf);
956 gunichar *g_utf8_to_ucs4_fast (const gchar *str, glong len, glong *items_written);
957 gunichar *g_utf8_to_ucs4 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
958 G_EXTERN_C // Used by libtest, at least.
959 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
960 gunichar2 *eg_utf8_to_utf16_with_nuls (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
961 gunichar2 *eg_wtf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
962 G_EXTERN_C // Used by libtest, at least.
963 gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
964 gunichar *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
965 gchar *g_ucs4_to_utf8 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **err);
966 gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **err);
967 size_t g_utf16_len (const gunichar2 *);
969 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
971 #ifdef G_OS_WIN32
972 #define u16to8(str) g_utf16_to_utf8((gunichar2 *) (str), (glong)wcslen((wchar_t *) (str)), NULL, NULL, NULL)
973 #else
974 #define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
975 #endif
978 * Path
980 gchar *g_build_path (const gchar *separator, const gchar *first_element, ...);
981 #define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
982 gchar *g_path_get_dirname (const gchar *filename);
983 gchar *g_path_get_basename (const char *filename);
984 gchar *g_find_program_in_path (const gchar *program);
985 gchar *g_get_current_dir (void);
986 gboolean g_path_is_absolute (const char *filename);
988 const gchar *g_get_home_dir (void);
989 const gchar *g_get_tmp_dir (void);
990 const gchar *g_get_user_name (void);
991 gchar *g_get_prgname (void);
992 void g_set_prgname (const gchar *prgname);
994 gboolean g_ensure_directory_exists (const gchar *filename);
997 * Shell
1000 gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **gerror);
1001 gchar *g_shell_unquote (const gchar *quoted_string, GError **gerror);
1002 gchar *g_shell_quote (const gchar *unquoted_string);
1005 * Spawn
1007 typedef enum {
1008 G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
1009 G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
1010 G_SPAWN_SEARCH_PATH = 1 << 2,
1011 G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
1012 G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
1013 G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
1014 G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
1015 } GSpawnFlags;
1017 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
1019 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **gerror);
1020 gboolean g_spawn_async_with_pipes (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
1021 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **gerror);
1023 int eg_getdtablesize (void);
1026 * Timer
1028 typedef struct _GTimer GTimer;
1030 GTimer *g_timer_new (void);
1031 void g_timer_destroy (GTimer *timer);
1032 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
1033 void g_timer_stop (GTimer *timer);
1034 void g_timer_start (GTimer *timer);
1037 * Date and time
1039 typedef struct {
1040 glong tv_sec;
1041 glong tv_usec;
1042 } GTimeVal;
1044 void g_get_current_time (GTimeVal *result);
1045 void g_usleep (gulong microseconds);
1048 * File
1051 gpointer g_file_error_quark (void);
1053 #define G_FILE_ERROR g_file_error_quark ()
1055 typedef enum {
1056 G_FILE_ERROR_EXIST,
1057 G_FILE_ERROR_ISDIR,
1058 G_FILE_ERROR_ACCES,
1059 G_FILE_ERROR_NAMETOOLONG,
1060 G_FILE_ERROR_NOENT,
1061 G_FILE_ERROR_NOTDIR,
1062 G_FILE_ERROR_NXIO,
1063 G_FILE_ERROR_NODEV,
1064 G_FILE_ERROR_ROFS,
1065 G_FILE_ERROR_TXTBSY,
1066 G_FILE_ERROR_FAULT,
1067 G_FILE_ERROR_LOOP,
1068 G_FILE_ERROR_NOSPC,
1069 G_FILE_ERROR_NOMEM,
1070 G_FILE_ERROR_MFILE,
1071 G_FILE_ERROR_NFILE,
1072 G_FILE_ERROR_BADF,
1073 G_FILE_ERROR_INVAL,
1074 G_FILE_ERROR_PIPE,
1075 G_FILE_ERROR_AGAIN,
1076 G_FILE_ERROR_INTR,
1077 G_FILE_ERROR_IO,
1078 G_FILE_ERROR_PERM,
1079 G_FILE_ERROR_NOSYS,
1080 G_FILE_ERROR_FAILED
1081 } GFileError;
1083 typedef enum {
1084 G_FILE_TEST_IS_REGULAR = 1 << 0,
1085 G_FILE_TEST_IS_SYMLINK = 1 << 1,
1086 G_FILE_TEST_IS_DIR = 1 << 2,
1087 G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
1088 G_FILE_TEST_EXISTS = 1 << 4
1089 } GFileTest;
1091 G_ENUM_FUNCTIONS (GFileTest)
1093 gboolean g_file_set_contents (const gchar *filename, const gchar *contents, gssize length, GError **gerror);
1094 gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **gerror);
1095 GFileError g_file_error_from_errno (gint err_no);
1096 gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **gerror);
1097 gboolean g_file_test (const gchar *filename, GFileTest test);
1099 #ifdef G_OS_WIN32
1100 #define g_open _open
1101 #else
1102 #define g_open open
1103 #endif
1104 #define g_rename rename
1105 #define g_stat stat
1106 #ifdef G_OS_WIN32
1107 #define g_access _access
1108 #else
1109 #define g_access access
1110 #endif
1111 #ifdef G_OS_WIN32
1112 #define g_mktemp _mktemp
1113 #else
1114 #define g_mktemp mktemp
1115 #endif
1116 #ifdef G_OS_WIN32
1117 #define g_unlink _unlink
1118 #else
1119 #define g_unlink unlink
1120 #endif
1121 #ifdef G_OS_WIN32
1122 #define g_write _write
1123 #else
1124 #define g_write write
1125 #endif
1126 #define g_fopen fopen
1127 #define g_lstat lstat
1128 #define g_rmdir rmdir
1129 #define g_mkstemp mkstemp
1130 #define g_ascii_isdigit isdigit
1131 #define g_ascii_strtod strtod
1132 #define g_ascii_isalnum isalnum
1134 gchar *g_mkdtemp (gchar *tmpl);
1138 * Low-level write-based printing functions
1140 static inline gint
1141 g_async_safe_vfprintf (int handle, gchar const *format, va_list args)
1143 char print_buff [1024];
1144 print_buff [0] = '\0';
1145 g_vsnprintf (print_buff, sizeof(print_buff), format, args);
1146 int ret = g_write (handle, print_buff, (guint32) strlen (print_buff));
1148 return ret;
1151 static inline gint
1152 g_async_safe_fprintf (int handle, gchar const *format, ...)
1154 va_list args;
1155 va_start (args, format);
1156 int ret = g_async_safe_vfprintf (handle, format, args);
1157 va_end (args);
1158 return ret;
1161 static inline gint
1162 g_async_safe_vprintf (gchar const *format, va_list args)
1164 return g_async_safe_vfprintf (1, format, args);
1167 static inline gint
1168 g_async_safe_printf (gchar const *format, ...)
1170 va_list args;
1171 va_start (args, format);
1172 int ret = g_async_safe_vfprintf (1, format, args);
1173 va_end (args);
1175 return ret;
1180 * Pattern matching
1182 typedef struct _GPatternSpec GPatternSpec;
1183 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
1184 void g_pattern_spec_free (GPatternSpec *pspec);
1185 gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
1188 * Directory
1190 typedef struct _GDir GDir;
1191 GDir *g_dir_open (const gchar *path, guint flags, GError **gerror);
1192 const gchar *g_dir_read_name (GDir *dir);
1193 void g_dir_rewind (GDir *dir);
1194 void g_dir_close (GDir *dir);
1196 int g_mkdir_with_parents (const gchar *pathname, int mode);
1197 #define g_mkdir mkdir
1200 * GMarkup
1202 typedef struct _GMarkupParseContext GMarkupParseContext;
1204 typedef enum
1206 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
1207 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
1208 } GMarkupParseFlags;
1210 typedef struct {
1211 void (*start_element) (GMarkupParseContext *context,
1212 const gchar *element_name,
1213 const gchar **attribute_names,
1214 const gchar **attribute_values,
1215 gpointer user_data,
1216 GError **gerror);
1218 void (*end_element) (GMarkupParseContext *context,
1219 const gchar *element_name,
1220 gpointer user_data,
1221 GError **gerror);
1223 void (*text) (GMarkupParseContext *context,
1224 const gchar *text,
1225 gsize text_len,
1226 gpointer user_data,
1227 GError **gerror);
1229 void (*passthrough) (GMarkupParseContext *context,
1230 const gchar *passthrough_text,
1231 gsize text_len,
1232 gpointer user_data,
1233 GError **gerror);
1234 void (*error) (GMarkupParseContext *context,
1235 GError *gerror,
1236 gpointer user_data);
1237 } GMarkupParser;
1239 GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
1240 GMarkupParseFlags flags,
1241 gpointer user_data,
1242 GDestroyNotify user_data_dnotify);
1243 void g_markup_parse_context_free (GMarkupParseContext *context);
1244 gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
1245 const gchar *text, gssize text_len,
1246 GError **gerror);
1247 gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
1248 GError **gerror);
1251 * Character set conversion
1253 typedef struct _GIConv *GIConv;
1255 gsize g_iconv (GIConv cd, gchar **inbytes, gsize *inbytesleft, gchar **outbytes, gsize *outbytesleft);
1256 GIConv g_iconv_open (const gchar *to_charset, const gchar *from_charset);
1257 int g_iconv_close (GIConv cd);
1259 gboolean g_get_charset (G_CONST_RETURN char **charset);
1260 gchar *g_locale_to_utf8 (const gchar *opsysstring, gssize len,
1261 gsize *bytes_read, gsize *bytes_written,
1262 GError **gerror);
1263 gchar *g_locale_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
1264 gsize *bytes_written, GError **gerror);
1265 gchar *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
1266 gsize *bytes_written, GError **gerror);
1267 gchar *g_convert (const gchar *str, gssize len,
1268 const gchar *to_codeset, const gchar *from_codeset,
1269 gsize *bytes_read, gsize *bytes_written, GError **gerror);
1272 * Unicode manipulation
1274 extern const guchar g_utf8_jump_table[256];
1276 gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end);
1277 gunichar g_utf8_get_char_validated (const gchar *str, gssize max_len);
1278 #define g_utf8_next_char(p) ((p) + g_utf8_jump_table[(guchar)(*p)])
1279 gunichar g_utf8_get_char (const gchar *src);
1280 glong g_utf8_strlen (const gchar *str, gssize max);
1281 gchar *g_utf8_offset_to_pointer (const gchar *str, glong offset);
1282 glong g_utf8_pointer_to_offset (const gchar *str, const gchar *pos);
1285 * priorities
1287 #define G_PRIORITY_DEFAULT 0
1288 #define G_PRIORITY_DEFAULT_IDLE 200
1290 #define GUINT16_SWAP_LE_BE_CONSTANT(x) ((((guint16) x) >> 8) | ((((guint16) x) << 8)))
1292 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
1293 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
1294 ( (((guint32) (x)) << 24)| \
1295 ((((guint32) (x)) & 0xff0000) >> 8) | \
1296 ((((guint32) (x)) & 0xff00) << 8) | \
1297 (((guint32) (x)) >> 24)) )
1299 #define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
1300 GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
1304 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1305 # define GUINT64_FROM_BE(x) GUINT64_SWAP_LE_BE(x)
1306 # define GUINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
1307 # define GUINT16_FROM_BE(x) GUINT16_SWAP_LE_BE(x)
1308 # define GUINT_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
1309 # define GUINT64_FROM_LE(x) (x)
1310 # define GUINT32_FROM_LE(x) (x)
1311 # define GUINT16_FROM_LE(x) (x)
1312 # define GUINT_FROM_LE(x) (x)
1313 # define GUINT64_TO_BE(x) GUINT64_SWAP_LE_BE(x)
1314 # define GUINT32_TO_BE(x) GUINT32_SWAP_LE_BE(x)
1315 # define GUINT16_TO_BE(x) GUINT16_SWAP_LE_BE(x)
1316 # define GUINT_TO_BE(x) GUINT32_SWAP_LE_BE(x)
1317 # define GUINT64_TO_LE(x) (x)
1318 # define GUINT32_TO_LE(x) (x)
1319 # define GUINT16_TO_LE(x) (x)
1320 # define GUINT_TO_LE(x) (x)
1321 #else
1322 # define GUINT64_FROM_BE(x) (x)
1323 # define GUINT32_FROM_BE(x) (x)
1324 # define GUINT16_FROM_BE(x) (x)
1325 # define GUINT_FROM_BE(x) (x)
1326 # define GUINT64_FROM_LE(x) GUINT64_SWAP_LE_BE(x)
1327 # define GUINT32_FROM_LE(x) GUINT32_SWAP_LE_BE(x)
1328 # define GUINT16_FROM_LE(x) GUINT16_SWAP_LE_BE(x)
1329 # define GUINT_FROM_LE(x) GUINT32_SWAP_LE_BE(x)
1330 # define GUINT64_TO_BE(x) (x)
1331 # define GUINT32_TO_BE(x) (x)
1332 # define GUINT16_TO_BE(x) (x)
1333 # define GUINT_TO_BE(x) (x)
1334 # define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
1335 # define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
1336 # define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
1337 # define GUINT_TO_LE(x) GUINT32_SWAP_LE_BE(x)
1338 #endif
1340 #define GINT64_FROM_BE(x) (GUINT64_TO_BE (x))
1341 #define GINT32_FROM_BE(x) (GUINT32_TO_BE (x))
1342 #define GINT16_FROM_BE(x) (GUINT16_TO_BE (x))
1343 #define GINT64_FROM_LE(x) (GUINT64_TO_LE (x))
1344 #define GINT32_FROM_LE(x) (GUINT32_TO_LE (x))
1345 #define GINT16_FROM_LE(x) (GUINT16_TO_LE (x))
1347 #define _EGLIB_MAJOR 2
1348 #define _EGLIB_MIDDLE 4
1349 #define _EGLIB_MINOR 0
1351 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
1353 #define G_HAVE_API_SUPPORT(x) (x)
1354 #define G_UNSUPPORTED_API "%s:%d: '%s' not supported.", __FILE__, __LINE__
1355 #define g_unsupported_api(name) G_STMT_START { g_warning (G_UNSUPPORTED_API, name); } G_STMT_END
1357 G_END_DECLS
1359 // For each allocator; i.e. returning gpointer that needs to be cast.
1360 // Macros do not recurse, so naming function and macro the same is ok.
1361 // However these are also already macros.
1362 #undef g_malloc
1363 #undef g_realloc
1364 #undef g_malloc0
1365 #undef g_calloc
1366 #undef g_try_malloc
1367 #undef g_try_realloc
1368 #undef g_memdup
1369 #define g_malloc(x) (g_cast (monoeg_malloc (x)))
1370 #define g_realloc(obj, size) (g_cast (monoeg_realloc ((obj), (size))))
1371 #define g_malloc0(x) (g_cast (monoeg_malloc0 (x)))
1372 #define g_calloc(x, y) (g_cast (monoeg_g_calloc ((x), (y))))
1373 #define g_try_malloc(x) (g_cast (monoeg_try_malloc (x)))
1374 #define g_try_realloc(obj, size) (g_cast (monoeg_try_realloc ((obj), (size))))
1375 #define g_memdup(mem, size) (g_cast (monoeg_g_memdup ((mem), (size))))
1377 #endif // __GLIB_H