Enable monitor enter/exit wrappers under sgen.
[mono-project/dkf.git] / eglib / src / glib.h
blob3cda065a063dcdef600879aa6010d0840a415946
1 #ifndef __GLIB_H
2 #define __GLIB_H
4 #include <stdarg.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <stddef.h>
9 #include <ctype.h>
10 #include <limits.h>
12 #ifdef _MSC_VER
13 #pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
14 #else
15 #include <stdint.h>
16 #endif
18 #include <eglib-config.h>
19 #ifndef EGLIB_NO_REMAP
20 #include <eglib-remap.h>
21 #endif
23 #ifdef G_HAVE_ALLOCA_H
24 #include <alloca.h>
25 #endif
27 #ifdef WIN32
28 /* For alloca */
29 #include <malloc.h>
30 #endif
32 #ifndef offsetof
33 # define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
34 #endif
36 #define __EGLIB_X11 1
38 #ifdef __cplusplus
39 #define G_BEGIN_DECLS extern "C" {
40 #define G_END_DECLS }
41 #else
42 #define G_BEGIN_DECLS
43 #define G_END_DECLS
44 #endif
46 G_BEGIN_DECLS
49 * Basic data types
51 typedef int gint;
52 typedef unsigned int guint;
53 typedef short gshort;
54 typedef unsigned short gushort;
55 typedef long glong;
56 typedef unsigned long gulong;
57 typedef void * gpointer;
58 typedef const void * gconstpointer;
59 typedef char gchar;
60 typedef unsigned char guchar;
62 #if !G_TYPES_DEFINED
63 #ifdef _MSC_VER
64 typedef __int8 gint8;
65 typedef unsigned __int8 guint8;
66 typedef __int16 gint16;
67 typedef unsigned __int16 guint16;
68 typedef __int32 gint32;
69 typedef unsigned __int32 guint32;
70 typedef __int64 gint64;
71 typedef unsigned __int64 guint64;
72 typedef float gfloat;
73 typedef double gdouble;
74 typedef unsigned __int16 gunichar2;
75 typedef int gboolean;
76 #else
77 /* Types defined in terms of the stdint.h */
78 typedef int8_t gint8;
79 typedef uint8_t guint8;
80 typedef int16_t gint16;
81 typedef uint16_t guint16;
82 typedef int32_t gint32;
83 typedef uint32_t guint32;
84 typedef int64_t gint64;
85 typedef uint64_t guint64;
86 typedef float gfloat;
87 typedef double gdouble;
88 typedef uint16_t gunichar2;
89 typedef int32_t gboolean;
90 #endif
91 #endif
94 * Macros
96 #define G_N_ELEMENTS(s) (sizeof(s) / sizeof ((s) [0]))
98 #define FALSE 0
99 #define TRUE 1
101 #define G_MAXINT INT_MAX
102 #define G_MININT INT_MIN
103 #define G_MAXINT32 INT32_MAX
104 #define G_MININT32 INT32_MIN
105 #define G_MININT64 INT64_MIN
106 #define G_MAXINT64 INT64_MAX
107 #define G_MAXUINT64 UINT64_MAX
109 #define G_LITTLE_ENDIAN 1234
110 #define G_BIG_ENDIAN 4321
111 #define G_STMT_START do
112 #define G_STMT_END while (0)
114 #define G_USEC_PER_SEC 1000000
116 #define ABS(a) ((a) > 0 ? (a) : -(a))
118 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
120 #define EGLIB_STRINGIFY(x) #x
121 #define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
122 #define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
124 #define G_CONST_RETURN const
127 * Allocation
129 void g_free (void *ptr);
130 gpointer g_realloc (gpointer obj, gsize size);
131 gpointer g_malloc (gsize x);
132 gpointer g_malloc0 (gsize x);
133 gpointer g_try_malloc (gsize x);
134 gpointer g_try_realloc (gpointer obj, gsize size);
136 #define g_new(type,size) ((type *) g_malloc (sizeof (type) * (size)))
137 #define g_new0(type,size) ((type *) g_malloc0 (sizeof (type)* (size)))
138 #define g_newa(type,size) ((type *) alloca (sizeof (type) * (size)))
140 #define g_memmove(dest,src,len) memmove (dest, src, len)
141 #define g_renew(struct_type, mem, n_structs) g_realloc (mem, sizeof (struct_type) * n_structs)
142 #define g_alloca(size) alloca (size)
144 gpointer g_memdup (gconstpointer mem, guint byte_size);
145 static inline gchar *g_strdup (const gchar *str) { if (str) {return strdup (str);} return NULL; }
146 gchar **g_strdupv (gchar **str_array);
148 typedef struct {
149 gpointer (*malloc) (gsize n_bytes);
150 gpointer (*realloc) (gpointer mem, gsize n_bytes);
151 void (*free) (gpointer mem);
152 gpointer (*calloc) (gsize n_blocks, gsize n_block_bytes);
153 gpointer (*try_malloc) (gsize n_bytes);
154 gpointer (*try_realloc) (gpointer mem, gsize n_bytes);
155 } GMemVTable;
157 #define g_mem_set_vtable(x)
159 struct _GMemChunk {
160 guint alloc_size;
163 typedef struct _GMemChunk GMemChunk;
165 * Misc.
167 #define g_atexit(func) ((void) atexit (func))
169 const gchar * g_getenv(const gchar *variable);
170 gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
171 void g_unsetenv(const gchar *variable);
173 gchar* g_win32_getlocale(void);
176 * Precondition macros
178 #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
179 #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
182 * Hashtables
184 typedef struct _GHashTable GHashTable;
185 typedef struct _GHashTableIter GHashTableIter;
187 /* Private, but needed for stack allocation */
188 struct _GHashTableIter
190 gpointer dummy [8];
193 typedef void (*GFunc) (gpointer data, gpointer user_data);
194 typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b);
195 typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
196 typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);
197 typedef gboolean (*GHRFunc) (gpointer key, gpointer value, gpointer user_data);
198 typedef void (*GDestroyNotify) (gpointer data);
199 typedef guint (*GHashFunc) (gconstpointer key);
200 typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b);
201 typedef void (*GFreeFunc) (gpointer data);
203 GHashTable *g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
204 GHashTable *g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func,
205 GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
206 void g_hash_table_insert_replace (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
207 guint g_hash_table_size (GHashTable *hash);
208 gpointer g_hash_table_lookup (GHashTable *hash, gconstpointer key);
209 gboolean g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
210 void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data);
211 gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data);
212 gboolean g_hash_table_remove (GHashTable *hash, gconstpointer key);
213 void g_hash_table_remove_all (GHashTable *hash);
214 guint g_hash_table_foreach_remove (GHashTable *hash, GHRFunc func, gpointer user_data);
215 guint g_hash_table_foreach_steal (GHashTable *hash, GHRFunc func, gpointer user_data);
216 void g_hash_table_destroy (GHashTable *hash);
217 void g_hash_table_print_stats (GHashTable *table);
219 void g_hash_table_iter_init (GHashTableIter *iter, GHashTable *hash_table);
220 gboolean g_hash_table_iter_next (GHashTableIter *iter, gpointer *key, gpointer *value);
222 guint g_spaced_primes_closest (guint x);
224 #define g_hash_table_insert(h,k,v) g_hash_table_insert_replace ((h),(k),(v),FALSE)
225 #define g_hash_table_replace(h,k,v) g_hash_table_insert_replace ((h),(k),(v),TRUE)
227 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
228 guint g_direct_hash (gconstpointer v1);
229 gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
230 guint g_int_hash (gconstpointer v1);
231 gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
232 guint g_str_hash (gconstpointer v1);
235 * Errors
237 typedef struct {
238 /* In the real glib, this is a GQuark, but we dont use/need that */
239 gpointer domain;
240 gint code;
241 gchar *message;
242 } GError;
244 void g_clear_error (GError **error);
245 void g_error_free (GError *error);
246 GError *g_error_new (gpointer domain, gint code, const char *format, ...);
247 void g_set_error (GError **err, gpointer domain, gint code, const gchar *format, ...);
248 void g_propagate_error (GError **dest, GError *src);
251 * Strings utility
253 gchar *g_strdup_printf (const gchar *format, ...);
254 gchar *g_strdup_vprintf (const gchar *format, va_list args);
255 gchar *g_strndup (const gchar *str, gsize n);
256 const gchar *g_strerror (gint errnum);
257 gchar *g_strndup (const gchar *str, gsize n);
258 void g_strfreev (gchar **str_array);
259 gchar *g_strconcat (const gchar *first, ...);
260 gchar **g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens);
261 gchar **g_strsplit_set (const gchar *string, const gchar *delimiter, gint max_tokens);
262 gchar *g_strreverse (gchar *str);
263 gboolean g_str_has_prefix (const gchar *str, const gchar *prefix);
264 gboolean g_str_has_suffix (const gchar *str, const gchar *suffix);
265 guint g_strv_length (gchar **str_array);
266 gchar *g_strjoin (const gchar *separator, ...);
267 gchar *g_strjoinv (const gchar *separator, gchar **str_array);
268 gchar *g_strchug (gchar *str);
269 gchar *g_strchomp (gchar *str);
270 void g_strdown (gchar *string);
271 gchar *g_strnfill (gsize length, gchar fill_char);
273 gchar *g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter);
274 gchar *g_strescape (const gchar *source, const gchar *exceptions);
276 gchar *g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error);
277 gchar *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
279 gint g_printf (gchar const *format, ...);
280 gint g_fprintf (FILE *file, gchar const *format, ...);
281 gint g_sprintf (gchar *string, gchar const *format, ...);
282 gint g_snprintf (gchar *string, gulong n, gchar const *format, ...);
283 #define g_vprintf vprintf
284 #define g_vfprintf vfprintf
285 #define g_vsprintf vsprintf
286 #define g_vsnprintf vsnprintf
287 #define g_vasprintf vasprintf
289 gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
291 gchar g_ascii_tolower (gchar c);
292 gchar *g_ascii_strdown (const gchar *str, gssize len);
293 gint g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n);
294 gint g_ascii_xdigit_value (gchar c);
295 #define g_ascii_isspace(c) (isspace (c) != 0)
296 #define g_ascii_isalpha(c) (isalpha (c) != 0)
297 #define g_ascii_isprint(c) (isprint (c) != 0)
298 #define g_ascii_isxdigit(c) (isxdigit (c) != 0)
300 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
301 #ifdef _MSC_VER
302 #define g_strcasecmp stricmp
303 #define g_ascii_strcasecmp stricmp
304 #define g_strncasecmp strnicmp
305 #define g_strstrip(a) g_strchug (g_strchomp (a))
306 #else
307 #define g_strcasecmp strcasecmp
308 #define g_ascii_strcasecmp strcasecmp
309 #define g_ascii_strtoull strtoull
310 #define g_strncasecmp strncasecmp
311 #define g_strstrip(a) g_strchug (g_strchomp (a))
312 #endif
315 #define G_STR_DELIMITERS "_-|> <."
318 * String type
320 typedef struct {
321 char *str;
322 gsize len;
323 gsize allocated_len;
324 } GString;
326 GString *g_string_new (const gchar *init);
327 GString *g_string_new_len (const gchar *init, gssize len);
328 GString *g_string_sized_new (gsize default_size);
329 gchar *g_string_free (GString *string, gboolean free_segment);
330 GString *g_string_append (GString *string, const gchar *val);
331 void g_string_printf (GString *string, const gchar *format, ...);
332 void g_string_append_printf (GString *string, const gchar *format, ...);
333 GString *g_string_append_c (GString *string, gchar c);
334 GString *g_string_append (GString *string, const gchar *val);
335 GString *g_string_append_len (GString *string, const gchar *val, gssize len);
336 GString *g_string_truncate (GString *string, gsize len);
337 GString *g_string_prepend (GString *string, const gchar *val);
339 #define g_string_sprintfa g_string_append_printf
342 * Lists
344 typedef struct _GSList GSList;
345 struct _GSList {
346 gpointer data;
347 GSList *next;
350 GSList *g_slist_alloc (void);
351 GSList *g_slist_append (GSList *list,
352 gpointer data);
353 GSList *g_slist_prepend (GSList *list,
354 gpointer data);
355 void g_slist_free (GSList *list);
356 void g_slist_free_1 (GSList *list);
357 GSList *g_slist_copy (GSList *list);
358 GSList *g_slist_concat (GSList *list1,
359 GSList *list2);
360 void g_slist_foreach (GSList *list,
361 GFunc func,
362 gpointer user_data);
363 GSList *g_slist_last (GSList *list);
364 GSList *g_slist_find (GSList *list,
365 gconstpointer data);
366 GSList *g_slist_find_custom (GSList *list,
367 gconstpointer data,
368 GCompareFunc func);
369 GSList *g_slist_remove (GSList *list,
370 gconstpointer data);
371 GSList *g_slist_remove_all (GSList *list,
372 gconstpointer data);
373 GSList *g_slist_reverse (GSList *list);
374 guint g_slist_length (GSList *list);
375 GSList *g_slist_remove_link (GSList *list,
376 GSList *link);
377 GSList *g_slist_delete_link (GSList *list,
378 GSList *link);
379 GSList *g_slist_insert_sorted (GSList *list,
380 gpointer data,
381 GCompareFunc func);
382 GSList *g_slist_insert_before (GSList *list,
383 GSList *sibling,
384 gpointer data);
385 GSList *g_slist_sort (GSList *list,
386 GCompareFunc func);
387 gint g_slist_index (GSList *list,
388 gconstpointer data);
389 GSList *g_slist_nth (GSList *list,
390 guint n);
391 gpointer g_slist_nth_data (GSList *list,
392 guint n);
394 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
397 typedef struct _GList GList;
398 struct _GList {
399 gpointer data;
400 GList *next;
401 GList *prev;
404 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
405 #define g_list_previous(list) ((list) ? (((GList *) (list))->prev) : NULL)
407 GList *g_list_alloc (void);
408 GList *g_list_append (GList *list,
409 gpointer data);
410 GList *g_list_prepend (GList *list,
411 gpointer data);
412 void g_list_free (GList *list);
413 void g_list_free_1 (GList *list);
414 GList *g_list_copy (GList *list);
415 guint g_list_length (GList *list);
416 gint g_list_index (GList *list,
417 gconstpointer data);
418 GList *g_list_nth (GList *list,
419 guint n);
420 gpointer g_list_nth_data (GList *list,
421 guint n);
422 GList *g_list_last (GList *list);
423 GList *g_list_concat (GList *list1,
424 GList *list2);
425 void g_list_foreach (GList *list,
426 GFunc func,
427 gpointer user_data);
428 GList *g_list_first (GList *list);
429 GList *g_list_find (GList *list,
430 gconstpointer data);
431 GList *g_list_find_custom (GList *list,
432 gconstpointer data,
433 GCompareFunc func);
434 GList *g_list_remove (GList *list,
435 gconstpointer data);
436 GList *g_list_reverse (GList *list);
437 GList *g_list_remove_link (GList *list,
438 GList *link);
439 GList *g_list_delete_link (GList *list,
440 GList *link);
441 GList *g_list_insert_sorted (GList *list,
442 gpointer data,
443 GCompareFunc func);
444 GList *g_list_insert_before (GList *list,
445 GList *sibling,
446 gpointer data);
447 GList *g_list_sort (GList *sort,
448 GCompareFunc func);
451 * ByteArray
454 typedef struct _GByteArray GByteArray;
455 struct _GByteArray {
456 guint8 *data;
457 gint len;
460 GByteArray *g_byte_array_new (void);
461 GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, guint len);
462 guint8* g_byte_array_free (GByteArray *array, gboolean free_segment);
465 * Array
468 typedef struct _GArray GArray;
469 struct _GArray {
470 gchar *data;
471 gint len;
474 GArray *g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
475 gchar* g_array_free (GArray *array, gboolean free_segment);
476 GArray *g_array_append_vals (GArray *array, gconstpointer data, guint len);
477 GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
478 GArray* g_array_remove_index (GArray *array, guint index_);
479 GArray* g_array_remove_index_fast (GArray *array, guint index_);
481 #define g_array_append_val(a,v) (g_array_append_vals((a),&(v),1))
482 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
483 #define g_array_index(a,t,i) *(t*)(((a)->data) + sizeof(t) * (i))
486 * Pointer Array
489 typedef struct _GPtrArray GPtrArray;
490 struct _GPtrArray {
491 gpointer *pdata;
492 guint len;
495 GPtrArray *g_ptr_array_new (void);
496 GPtrArray *g_ptr_array_sized_new (guint reserved_size);
497 void g_ptr_array_add (GPtrArray *array, gpointer data);
498 gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
499 gpointer g_ptr_array_remove_index (GPtrArray *array, guint index);
500 gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
501 gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index);
502 void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
503 void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
504 void g_ptr_array_set_size (GPtrArray *array, gint length);
505 gpointer *g_ptr_array_free (GPtrArray *array, gboolean free_seg);
506 void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data);
507 #define g_ptr_array_index(array,index) (array)->pdata[(index)]
510 * Queues
512 typedef struct {
513 GList *head;
514 GList *tail;
515 guint length;
516 } GQueue;
518 gpointer g_queue_pop_head (GQueue *queue);
519 void g_queue_push_head (GQueue *queue,
520 gpointer data);
521 void g_queue_push_tail (GQueue *queue,
522 gpointer data);
523 gboolean g_queue_is_empty (GQueue *queue);
524 GQueue *g_queue_new (void);
525 void g_queue_free (GQueue *queue);
526 void g_queue_foreach (GQueue *queue, GFunc func, gpointer user_data);
529 * Messages
531 #ifndef G_LOG_DOMAIN
532 #define G_LOG_DOMAIN ((gchar*) 0)
533 #endif
535 typedef enum {
536 G_LOG_FLAG_RECURSION = 1 << 0,
537 G_LOG_FLAG_FATAL = 1 << 1,
539 G_LOG_LEVEL_ERROR = 1 << 2,
540 G_LOG_LEVEL_CRITICAL = 1 << 3,
541 G_LOG_LEVEL_WARNING = 1 << 4,
542 G_LOG_LEVEL_MESSAGE = 1 << 5,
543 G_LOG_LEVEL_INFO = 1 << 6,
544 G_LOG_LEVEL_DEBUG = 1 << 7,
546 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
547 } GLogLevelFlags;
549 void g_print (const gchar *format, ...);
550 void g_printerr (const gchar *format, ...);
551 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
552 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask);
553 void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
554 void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
555 void g_assertion_message (const gchar *format, ...) G_GNUC_NORETURN;
557 #ifdef HAVE_C99_SUPPORT
558 /* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
559 #define g_error(format, ...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
560 #define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
561 #define g_warning(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
562 #define g_message(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
563 #define g_debug(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
564 #else /* HAVE_C99_SUPPORT */
565 #define g_error(...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;); } while (0)
566 #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
567 #define g_warning(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
568 #define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
569 #define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
570 #endif /* ndef HAVE_C99_SUPPORT */
571 #define g_log_set_handler(a,b,c,d)
573 #define G_GNUC_INTERNAL
576 * Conversions
579 gpointer g_convert_error_quark(void);
583 * Unicode Manipulation: most of this is not used by Mono by default, it is
584 * only used if the old collation code is activated, so this is only the
585 * bare minimum to build.
587 typedef guint32 gunichar;
589 typedef enum {
590 G_UNICODE_CONTROL,
591 G_UNICODE_FORMAT,
592 G_UNICODE_UNASSIGNED,
593 G_UNICODE_PRIVATE_USE,
594 G_UNICODE_SURROGATE,
595 G_UNICODE_LOWERCASE_LETTER,
596 G_UNICODE_MODIFIER_LETTER,
597 G_UNICODE_OTHER_LETTER,
598 G_UNICODE_TITLECASE_LETTER,
599 G_UNICODE_UPPERCASE_LETTER,
600 G_UNICODE_COMBINING_MARK,
601 G_UNICODE_ENCLOSING_MARK,
602 G_UNICODE_NON_SPACING_MARK,
603 G_UNICODE_DECIMAL_NUMBER,
604 G_UNICODE_LETTER_NUMBER,
605 G_UNICODE_OTHER_NUMBER,
606 G_UNICODE_CONNECT_PUNCTUATION,
607 G_UNICODE_DASH_PUNCTUATION,
608 G_UNICODE_CLOSE_PUNCTUATION,
609 G_UNICODE_FINAL_PUNCTUATION,
610 G_UNICODE_INITIAL_PUNCTUATION,
611 G_UNICODE_OTHER_PUNCTUATION,
612 G_UNICODE_OPEN_PUNCTUATION,
613 G_UNICODE_CURRENCY_SYMBOL,
614 G_UNICODE_MODIFIER_SYMBOL,
615 G_UNICODE_MATH_SYMBOL,
616 G_UNICODE_OTHER_SYMBOL,
617 G_UNICODE_LINE_SEPARATOR,
618 G_UNICODE_PARAGRAPH_SEPARATOR,
619 G_UNICODE_SPACE_SEPARATOR
620 } GUnicodeType;
622 gunichar g_unichar_toupper (gunichar c);
623 gunichar g_unichar_tolower (gunichar c);
624 gunichar g_unichar_totitle (gunichar c);
625 GUnicodeType g_unichar_type (gunichar c);
626 gboolean g_unichar_isxdigit (gunichar c);
627 gint g_unichar_xdigit_value (gunichar c);
629 #ifndef MAX
630 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
631 #endif
633 #ifndef MIN
634 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
635 #endif
637 #ifndef CLAMP
638 #define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
639 #endif
641 #if defined(__GNUC__) && (__GNUC__ > 2)
642 #define G_LIKELY(expr) (__builtin_expect ((expr) != 0, 1))
643 #define G_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0))
644 #else
645 #define G_LIKELY(x) (x)
646 #define G_UNLIKELY(x) (x)
647 #endif
649 #define g_assert(x) G_STMT_START { if (G_UNLIKELY (!(x))) g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x); } G_STMT_END
650 #define g_assert_not_reached() G_STMT_START { g_assertion_message ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); } G_STMT_END
653 * Unicode conversion
656 #define G_CONVERT_ERROR g_convert_error_quark()
658 typedef enum {
659 G_CONVERT_ERROR_NO_CONVERSION,
660 G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
661 G_CONVERT_ERROR_FAILED,
662 G_CONVERT_ERROR_PARTIAL_INPUT,
663 G_CONVERT_ERROR_BAD_URI,
664 G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
665 } GConvertError;
667 gchar* g_utf8_strup (const gchar *str, gssize len);
668 gchar* g_utf8_strdown (const gchar *str, gssize len);
669 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
670 gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
671 gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
672 gunichar *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
674 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
676 #ifdef G_OS_WIN32
677 #define u16to8(str) g_utf16_to_utf8(str, (glong)wcslen(str), NULL, NULL, NULL)
678 #else
679 #define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
680 #endif
683 * Path
685 gchar *g_build_path (const gchar *separator, const gchar *first_element, ...);
686 #define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
687 gchar *g_path_get_dirname (const gchar *filename);
688 gchar *g_path_get_basename (const char *filename);
689 gchar *g_find_program_in_path (const gchar *program);
690 gchar *g_get_current_dir (void);
691 gboolean g_path_is_absolute (const char *filename);
693 const gchar *g_get_home_dir (void);
694 const gchar *g_get_tmp_dir (void);
695 const gchar *g_get_user_name (void);
696 gchar *g_get_prgname (void);
697 void g_set_prgname (const gchar *prgname);
700 * Shell
703 gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
704 gchar *g_shell_unquote (const gchar *quoted_string, GError **error);
705 gchar *g_shell_quote (const gchar *unquoted_string);
708 * Spawn
710 typedef enum {
711 G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
712 G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
713 G_SPAWN_SEARCH_PATH = 1 << 2,
714 G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
715 G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
716 G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
717 G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
718 } GSpawnFlags;
720 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
722 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
723 gboolean g_spawn_async_with_pipes (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
724 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
728 * Timer
730 typedef struct _GTimer GTimer;
732 GTimer *g_timer_new (void);
733 void g_timer_destroy (GTimer *timer);
734 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
735 void g_timer_stop (GTimer *timer);
736 void g_timer_start (GTimer *timer);
739 * Date and time
741 typedef struct {
742 glong tv_sec;
743 glong tv_usec;
744 } GTimeVal;
746 void g_get_current_time (GTimeVal *result);
747 void g_usleep (gulong microseconds);
750 * File
753 typedef enum {
754 G_FILE_ERROR_EXIST,
755 G_FILE_ERROR_ISDIR,
756 G_FILE_ERROR_ACCES,
757 G_FILE_ERROR_NAMETOOLONG,
758 G_FILE_ERROR_NOENT,
759 G_FILE_ERROR_NOTDIR,
760 G_FILE_ERROR_NXIO,
761 G_FILE_ERROR_NODEV,
762 G_FILE_ERROR_ROFS,
763 G_FILE_ERROR_TXTBSY,
764 G_FILE_ERROR_FAULT,
765 G_FILE_ERROR_LOOP,
766 G_FILE_ERROR_NOSPC,
767 G_FILE_ERROR_NOMEM,
768 G_FILE_ERROR_MFILE,
769 G_FILE_ERROR_NFILE,
770 G_FILE_ERROR_BADF,
771 G_FILE_ERROR_INVAL,
772 G_FILE_ERROR_PIPE,
773 G_FILE_ERROR_AGAIN,
774 G_FILE_ERROR_INTR,
775 G_FILE_ERROR_IO,
776 G_FILE_ERROR_PERM,
777 G_FILE_ERROR_NOSYS,
778 G_FILE_ERROR_FAILED
779 } GFileError;
781 typedef enum {
782 G_FILE_TEST_IS_REGULAR = 1 << 0,
783 G_FILE_TEST_IS_SYMLINK = 1 << 1,
784 G_FILE_TEST_IS_DIR = 1 << 2,
785 G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
786 G_FILE_TEST_EXISTS = 1 << 4
787 } GFileTest;
790 gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
791 GFileError g_file_error_from_errno (gint err_no);
792 gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
793 gboolean g_file_test (const gchar *filename, GFileTest test);
796 * Pattern matching
798 typedef struct _GPatternSpec GPatternSpec;
799 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
800 void g_pattern_spec_free (GPatternSpec *pspec);
801 gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
804 * Directory
806 typedef struct _GDir GDir;
807 GDir *g_dir_open (const gchar *path, guint flags, GError **error);
808 const gchar *g_dir_read_name (GDir *dir);
809 void g_dir_rewind (GDir *dir);
810 void g_dir_close (GDir *dir);
811 #define g_mkdir mkdir
814 * GMarkup
816 typedef struct _GMarkupParseContext GMarkupParseContext;
818 typedef enum
820 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
821 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
822 } GMarkupParseFlags;
824 typedef struct {
825 void (*start_element) (GMarkupParseContext *context,
826 const gchar *element_name,
827 const gchar **attribute_names,
828 const gchar **attribute_values,
829 gpointer user_data,
830 GError **error);
832 void (*end_element) (GMarkupParseContext *context,
833 const gchar *element_name,
834 gpointer user_data,
835 GError **error);
837 void (*text) (GMarkupParseContext *context,
838 const gchar *text,
839 gsize text_len,
840 gpointer user_data,
841 GError **error);
843 void (*passthrough) (GMarkupParseContext *context,
844 const gchar *passthrough_text,
845 gsize text_len,
846 gpointer user_data,
847 GError **error);
848 void (*error) (GMarkupParseContext *context,
849 GError *error,
850 gpointer user_data);
851 } GMarkupParser;
853 GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
854 GMarkupParseFlags flags,
855 gpointer user_data,
856 GDestroyNotify user_data_dnotify);
857 void g_markup_parse_context_free (GMarkupParseContext *context);
858 gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
859 const gchar *text, gssize text_len,
860 GError **error);
861 gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
862 GError **error);
865 * Character set conversion
868 * Index into the table below with the first byte of a UTF-8 sequence to
869 * get the number of trailing bytes that are supposed to follow it.
870 * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
871 * left as-is for anyone who may want to do such conversion, which was
872 * allowed in earlier algorithms.
874 extern const gchar g_trailingBytesForUTF8[256];
876 gboolean g_get_charset (G_CONST_RETURN char **charset);
877 gchar *g_locale_to_utf8 (const gchar *opsysstring, gssize len,
878 gsize *bytes_read, gsize *bytes_written,
879 GError **error);
880 gchar *g_locale_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
881 gsize *bytes_written, GError **error);
882 gchar *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
883 gsize *bytes_written, GError **error);
884 gchar *g_convert (const gchar *str, gssize len,
885 const gchar *to_codeset, const gchar *from_codeset,
886 gsize *bytes_read, gsize *bytes_written, GError **error);
887 gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end);
888 gunichar g_utf8_get_char (const gchar *src);
889 glong g_utf8_strlen (const gchar *str, gssize max);
890 #define g_utf8_next_char(p) p + (g_trailingBytesForUTF8[(guchar)(*p)] + 1)
893 * Empty thread functions, not used by eglib
895 #define g_thread_supported() TRUE
896 #define g_thread_init(x) G_STMT_START { if (x != NULL) { g_error ("No vtable supported in g_thread_init"); } } G_STMT_END
898 #define G_LOCK_DEFINE(name) int name;
899 #define G_LOCK_DEFINE_STATIC(name) static int name;
900 #define G_LOCK_EXTERN(name)
901 #define G_LOCK(name)
902 #define G_TRYLOCK(name)
903 #define G_UNLOCK(name)
905 #define GUINT16_SWAP_LE_BE_CONSTANT(x) ((((guint16) x) >> 8) | ((((guint16) x) << 8)))
907 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
908 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
909 ( (((guint32) (x)) << 24)| \
910 ((((guint32) (x)) & 0xff0000) >> 8) | \
911 ((((guint32) (x)) & 0xff00) << 8) | \
912 (((guint32) (x)) >> 24)) )
914 #define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
915 GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
919 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
920 # define GUINT32_TO_LE(x) (x)
921 # define GUINT64_TO_LE(x) (x)
922 # define GUINT16_TO_LE(x) (x)
923 # define GUINT_TO_LE(x) (x)
924 # define GUINT32_TO_BE(x) GUINT32_SWAP_LE_BE(x)
925 # define GUINT16_FROM_BE(x) GUINT16_SWAP_LE_BE(x)
926 # define GUINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
927 # define GUINT64_FROM_BE(x) GUINT64_SWAP_LE_BE(x)
928 # define GINT16_FROM_BE(x) GUINT16_SWAP_LE_BE(x)
929 # define GINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
930 # define GINT64_FROM_BE(x) GUINT64_SWAP_LE_BE(x)
931 #else
932 # define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
933 # define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
934 # define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
935 # define GUINT_TO_LE(x) GUINT32_SWAP_LE_BE(x)
936 # define GUINT32_TO_BE(x) (x)
937 # define GUINT16_FROM_BE(x) (x)
938 # define GUINT32_FROM_BE(x) (x)
939 # define GUINT64_FROM_BE(x) (x)
940 # define GINT16_FROM_BE(x) (x)
941 # define GINT32_FROM_BE(x) (x)
942 # define GINT64_FROM_BE(x) (x)
943 #endif
945 #define GINT64_FROM_LE(x) (GUINT64_TO_LE (x))
946 #define GINT32_FROM_LE(x) (GUINT32_TO_LE (x))
947 #define GINT16_FROM_LE(x) (GUINT16_TO_LE (x))
949 #define GUINT32_FROM_LE(x) (GUINT32_TO_LE (x))
950 #define GUINT64_FROM_LE(x) (GUINT64_TO_LE (x))
951 #define GUINT16_FROM_LE(x) (GUINT16_TO_LE (x))
952 #define GUINT_FROM_LE(x) (GUINT_TO_LE (x))
954 #define _EGLIB_MAJOR 2
955 #define _EGLIB_MIDDLE 4
956 #define _EGLIB_MINOR 0
958 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
960 G_END_DECLS
962 #endif