2008-10-17 Miguel de Icaza <miguel@novell.com>
[mono-debugger.git] / eglib / src / glib.h
blob2071113cecb318e1cfb539ced5c263885db9ab23
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>
20 #ifndef offsetof
21 # define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
22 #endif
24 #define __EGLIB_X11 1
27 * Basic data types
29 typedef int gboolean;
30 typedef int gint;
31 typedef unsigned int guint;
32 typedef short gshort;
33 typedef unsigned short gushort;
34 typedef long glong;
35 typedef unsigned long gulong;
36 typedef void * gpointer;
37 typedef const void * gconstpointer;
38 typedef char gchar;
39 typedef unsigned char guchar;
41 #if !G_TYPES_DEFINED
42 #ifdef _MSC_VER
43 typedef __int8 gint8;
44 typedef unsigned __int8 guint8;
45 typedef __int16 gint16;
46 typedef unsigned __int16 guint16;
47 typedef __int32 gint32;
48 typedef unsigned __int32 guint32;
49 typedef __int64 gint64;
50 typedef unsigned __int64 guint64;
51 typedef float gfloat;
52 typedef double gdouble;
53 typedef unsigned __int16 gunichar2;
54 #else
55 /* Types defined in terms of the stdint.h */
56 typedef int8_t gint8;
57 typedef uint8_t guint8;
58 typedef int16_t gint16;
59 typedef uint16_t guint16;
60 typedef int32_t gint32;
61 typedef uint32_t guint32;
62 typedef int64_t gint64;
63 typedef uint64_t guint64;
64 typedef float gfloat;
65 typedef double gdouble;
66 typedef uint16_t gunichar2;
67 #endif
68 #endif
72 * Macros
74 #define G_N_ELEMENTS(s) (sizeof(s) / sizeof ((s) [0]))
76 #define FALSE 0
77 #define TRUE 1
79 #define G_MAXINT32 INT32_MAX
80 #define G_MININT32 INT32_MIN
81 #define G_MININT64 INT64_MIN
82 #define G_MAXINT64 INT64_MAX
84 #define G_LITTLE_ENDIAN 1234
85 #define G_BIG_ENDIAN 4321
86 #define G_STMT_START do
87 #define G_STMT_END while (0)
89 #define G_USEC_PER_SEC 1000000
91 #define ABS(a) ((a) > 0 ? (a) : -(a))
93 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
95 #define EGLIB_STRINGIFY(x) #x
96 #define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
97 #define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
99 #ifdef __cplusplus
100 #define G_BEGIN_DECLS extern "C" {
101 #define G_END_DECLS }
102 #else
103 #define G_BEGIN_DECLS
104 #define G_END_DECLS
105 #endif
107 #define G_CONST_RETURN const
110 * Allocation
112 #define g_free free
113 static inline gpointer g_realloc (gpointer obj, gsize size) { if (!size) {g_free (obj); return 0;} return realloc (obj, size);}
114 static inline gpointer g_malloc (gsize x) {if (x) return malloc (x); else return 0;}
115 static inline gpointer g_malloc0 (gsize x) {if (x) return calloc(1,x); else return 0;}
116 #define g_try_malloc(x) g_malloc(x)
117 #define g_try_realloc(obj,size) g_realloc((obj),(size))
119 #define g_new(type,size) ((type *) g_malloc (sizeof (type) * (size)))
120 #define g_new0(type,size) ((type *) g_malloc0 (sizeof (type)* (size)))
121 #define g_newa(type,size) ((type *) alloca (sizeof (type) * (size)))
123 #define g_memmove(dest,src,len) memmove (dest, src, len)
124 #define g_renew(struct_type, mem, n_structs) g_realloc (mem, sizeof (struct_type) * n_structs)
125 #define g_alloca(size) alloca (size)
127 gpointer g_memdup (gconstpointer mem, guint byte_size);
128 static inline gchar *g_strdup (const gchar *str) { if (str) {return strdup (str);} return NULL; }
130 typedef struct {
131 gpointer (*malloc) (gsize n_bytes);
132 gpointer (*realloc) (gpointer mem, gsize n_bytes);
133 void (*free) (gpointer mem);
134 gpointer (*calloc) (gsize n_blocks, gsize n_block_bytes);
135 gpointer (*try_malloc) (gsize n_bytes);
136 gpointer (*try_realloc) (gpointer mem, gsize n_bytes);
137 } GMemVTable;
139 #define g_mem_set_vtable(x)
141 * Misc.
143 #define g_atexit(func) ((void) atexit (func))
145 const gchar * g_getenv(const gchar *variable);
146 gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
147 void g_unsetenv(const gchar *variable);
149 gchar* g_win32_getlocale(void);
152 * Precondition macros
154 #define g_return_if_fail(x) G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END
155 #define g_return_val_if_fail(x,e) G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END
158 * Hashtables
160 typedef struct _GHashTable GHashTable;
161 typedef void (*GFunc) (gpointer data, gpointer user_data);
162 typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b);
163 typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
164 typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);
165 typedef gboolean (*GHRFunc) (gpointer key, gpointer value, gpointer user_data);
166 typedef void (*GDestroyNotify) (gpointer data);
167 typedef guint (*GHashFunc) (gconstpointer key);
168 typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b);
169 typedef void (*GFreeFunc) (gpointer data);
171 GHashTable *g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
172 GHashTable *g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func,
173 GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
174 void g_hash_table_insert_replace (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
175 guint g_hash_table_size (GHashTable *hash);
176 gpointer g_hash_table_lookup (GHashTable *hash, gconstpointer key);
177 gboolean g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
178 void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data);
179 gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data);
180 gboolean g_hash_table_remove (GHashTable *hash, gconstpointer key);
181 guint g_hash_table_foreach_remove (GHashTable *hash, GHRFunc func, gpointer user_data);
182 guint g_hash_table_foreach_steal (GHashTable *hash, GHRFunc func, gpointer user_data);
183 void g_hash_table_destroy (GHashTable *hash);
185 guint g_spaced_primes_closest (guint x);
187 #define g_hash_table_insert(h,k,v) g_hash_table_insert_replace ((h),(k),(v),FALSE)
188 #define g_hash_table_replace(h,k,v) g_hash_table_insert_replace ((h),(k),(v),TRUE)
190 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
191 guint g_direct_hash (gconstpointer v1);
192 gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
193 guint g_int_hash (gconstpointer v1);
194 gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
195 guint g_str_hash (gconstpointer v1);
197 #define g_assert(x) G_STMT_START { if (!(x)) g_error ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x); } G_STMT_END
198 #define g_assert_not_reached() G_STMT_START { g_error ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); } G_STMT_END
201 * Errors
203 typedef struct {
204 /* In the real glib, this is a GQuark, but we dont use/need that */
205 gpointer domain;
206 gint code;
207 gchar *message;
208 } GError;
210 void g_clear_error (GError **error);
211 void g_error_free (GError *error);
212 GError *g_error_new (gpointer domain, gint code, const char *format, ...);
213 void g_set_error (GError **err, gpointer domain, gint code, const gchar *format, ...);
214 void g_propagate_error (GError **dest, GError *src);
217 * Strings utility
219 gchar *g_strdup_printf (const gchar *format, ...);
220 gchar *g_strdup_vprintf (const gchar *format, va_list args);
221 gchar *g_strndup (const gchar *str, gsize n);
222 const gchar *g_strerror (gint errnum);
223 gchar *g_strndup (const gchar *str, gsize n);
224 void g_strfreev (gchar **str_array);
225 gchar *g_strconcat (const gchar *first, ...);
226 gchar **g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens);
227 gchar **g_strsplit_set (const gchar *string, const gchar *delimiter, gint max_tokens);
228 gchar *g_strreverse (gchar *str);
229 gboolean g_str_has_prefix (const gchar *str, const gchar *prefix);
230 gboolean g_str_has_suffix (const gchar *str, const gchar *suffix);
231 guint g_strv_length (gchar **str_array);
232 gchar *g_strjoin (const gchar *separator, ...);
233 gchar *g_strjoinv (const gchar *separator, gchar **str_array);
234 gchar *g_strchug (gchar *str);
235 gchar *g_strchomp (gchar *str);
236 void g_strdown (gchar *string);
238 gchar *g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter);
239 gchar *g_strescape (const gchar *source, const gchar *exceptions);
241 gchar *g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error);
242 gchar *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
244 gint g_printf (gchar const *format, ...);
245 gint g_fprintf (FILE *file, gchar const *format, ...);
246 gint g_sprintf (gchar *string, gchar const *format, ...);
247 gint g_snprintf (gchar *string, gulong n, gchar const *format, ...);
248 #define g_vprintf vprintf
249 #define g_vfprintf vfprintf
250 #define g_vsprintf vsprintf
251 #define g_vsnprintf vsnprintf
252 #define g_vasprintf vasprintf
254 gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
256 gchar g_ascii_tolower (gchar c);
257 gchar *g_ascii_strdown (const gchar *str, gssize len);
258 gint g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n);
259 gint g_ascii_xdigit_value (gchar c);
260 #define g_ascii_isspace(c) (isspace (c) != 0)
261 #define g_ascii_isalpha(c) (isalpha (c) != 0)
262 #define g_ascii_isprint(c) (isprint (c) != 0)
263 #define g_ascii_isxdigit(c) (isxdigit (c) != 0)
265 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
266 #ifdef _MSC_VER
267 #define g_strcasecmp stricmp
268 #define g_ascii_strcasecmp stricmp
269 #define g_strncasecmp strnicmp
270 #define g_strstrip(a) g_strchug (g_strchomp (a))
271 #else
272 #define g_strcasecmp strcasecmp
273 #define g_ascii_strcasecmp strcasecmp
274 #define g_strncasecmp strncasecmp
275 #define g_strstrip(a) g_strchug (g_strchomp (a))
276 #endif
279 #define G_STR_DELIMITERS "_-|> <."
282 * String type
284 typedef struct {
285 char *str;
286 gsize len;
287 gsize allocated_len;
288 } GString;
290 GString *g_string_new (const gchar *init);
291 GString *g_string_new_len (const gchar *init, gssize len);
292 GString *g_string_sized_new (gsize default_size);
293 gchar *g_string_free (GString *string, gboolean free_segment);
294 GString *g_string_append (GString *string, const gchar *val);
295 void g_string_printf (GString *string, const gchar *format, ...);
296 void g_string_append_printf (GString *string, const gchar *format, ...);
297 GString *g_string_append_c (GString *string, gchar c);
298 GString *g_string_append (GString *string, const gchar *val);
299 GString *g_string_append_len (GString *string, const gchar *val, gssize len);
300 GString *g_string_truncate (GString *string, gsize len);
301 GString *g_string_prepend (GString *string, const gchar *val);
303 #define g_string_sprintfa g_string_append_printf
306 * Lists
308 typedef struct _GSList GSList;
309 struct _GSList {
310 gpointer data;
311 GSList *next;
314 GSList *g_slist_alloc (void);
315 GSList *g_slist_append (GSList *list,
316 gpointer data);
317 GSList *g_slist_prepend (GSList *list,
318 gpointer data);
319 void g_slist_free (GSList *list);
320 void g_slist_free_1 (GSList *list);
321 GSList *g_slist_copy (GSList *list);
322 GSList *g_slist_concat (GSList *list1,
323 GSList *list2);
324 void g_slist_foreach (GSList *list,
325 GFunc func,
326 gpointer user_data);
327 GSList *g_slist_last (GSList *list);
328 GSList *g_slist_find (GSList *list,
329 gconstpointer data);
330 GSList *g_slist_find_custom (GSList *list,
331 gconstpointer data,
332 GCompareFunc func);
333 GSList *g_slist_remove (GSList *list,
334 gconstpointer data);
335 GSList *g_slist_remove_all (GSList *list,
336 gconstpointer data);
337 GSList *g_slist_reverse (GSList *list);
338 guint g_slist_length (GSList *list);
339 GSList *g_slist_remove_link (GSList *list,
340 GSList *link);
341 GSList *g_slist_delete_link (GSList *list,
342 GSList *link);
343 GSList *g_slist_insert_sorted (GSList *list,
344 gpointer data,
345 GCompareFunc func);
346 GSList *g_slist_insert_before (GSList *list,
347 GSList *sibling,
348 gpointer data);
349 GSList *g_slist_sort (GSList *list,
350 GCompareFunc func);
351 gint g_slist_index (GSList *list,
352 gconstpointer data);
353 GSList *g_slist_nth (GSList *list,
354 guint n);
355 gpointer g_slist_nth_data (GSList *list,
356 guint n);
358 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
361 typedef struct _GList GList;
362 struct _GList {
363 gpointer data;
364 GList *next;
365 GList *prev;
368 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
370 GList *g_list_alloc (void);
371 GList *g_list_append (GList *list,
372 gpointer data);
373 GList *g_list_prepend (GList *list,
374 gpointer data);
375 void g_list_free (GList *list);
376 void g_list_free_1 (GList *list);
377 GList *g_list_copy (GList *list);
378 guint g_list_length (GList *list);
379 gint g_list_index (GList *list,
380 gconstpointer data);
381 GList *g_list_nth (GList *list,
382 guint n);
383 gpointer g_list_nth_data (GList *list,
384 guint n);
385 GList *g_list_last (GList *list);
386 GList *g_list_concat (GList *list1,
387 GList *list2);
388 void g_list_foreach (GList *list,
389 GFunc func,
390 gpointer user_data);
391 GList *g_list_first (GList *list);
392 GList *g_list_find (GList *list,
393 gconstpointer data);
394 GList *g_list_find_custom (GList *list,
395 gconstpointer data,
396 GCompareFunc func);
397 GList *g_list_remove (GList *list,
398 gconstpointer data);
399 GList *g_list_reverse (GList *list);
400 GList *g_list_remove_link (GList *list,
401 GList *link);
402 GList *g_list_delete_link (GList *list,
403 GList *link);
404 GList *g_list_insert_sorted (GList *list,
405 gpointer data,
406 GCompareFunc func);
407 GList *g_list_insert_before (GList *list,
408 GList *sibling,
409 gpointer data);
410 GList *g_list_sort (GList *sort,
411 GCompareFunc func);
414 * Array
417 typedef struct _GArray GArray;
418 struct _GArray {
419 gchar *data;
420 gint len;
423 GArray *g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
424 gchar* g_array_free (GArray *array, gboolean free_segment);
425 GArray *g_array_append_vals (GArray *array, gconstpointer data, guint len);
426 GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
427 GArray* g_array_remove_index (GArray *array, guint index_);
428 GArray* g_array_remove_index_fast (GArray *array, guint index_);
430 #define g_array_append_val(a,v) (g_array_append_vals((a),&(v),1))
431 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
432 #define g_array_index(a,t,i) *(t*)(((a)->data) + sizeof(t) * (i))
435 * Pointer Array
438 typedef struct _GPtrArray GPtrArray;
439 struct _GPtrArray {
440 gpointer *pdata;
441 guint len;
444 GPtrArray *g_ptr_array_new (void);
445 GPtrArray *g_ptr_array_sized_new (guint reserved_size);
446 void g_ptr_array_add (GPtrArray *array, gpointer data);
447 gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
448 gpointer g_ptr_array_remove_index (GPtrArray *array, guint index);
449 gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
450 gpointer g_ptr_array_remove_index_fast (GPtrArray *array, gpointer data);
451 void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
452 void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
453 void g_ptr_array_set_size (GPtrArray *array, gint length);
454 gpointer *g_ptr_array_free (GPtrArray *array, gboolean free_seg);
455 void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data);
456 #define g_ptr_array_index(array,index) (array)->pdata[(index)]
459 * Queues
461 typedef struct {
462 GList *head;
463 GList *tail;
464 guint length;
465 } GQueue;
467 gpointer g_queue_pop_head (GQueue *queue);
468 void g_queue_push_head (GQueue *queue,
469 gpointer data);
470 gboolean g_queue_is_empty (GQueue *queue);
471 GQueue *g_queue_new (void);
472 void g_queue_free (GQueue *queue);
475 * Messages
477 #ifndef G_LOG_DOMAIN
478 #define G_LOG_DOMAIN ((gchar*) 0)
479 #endif
481 typedef enum {
482 G_LOG_FLAG_RECURSION = 1 << 0,
483 G_LOG_FLAG_FATAL = 1 << 1,
485 G_LOG_LEVEL_ERROR = 1 << 2,
486 G_LOG_LEVEL_CRITICAL = 1 << 3,
487 G_LOG_LEVEL_WARNING = 1 << 4,
488 G_LOG_LEVEL_MESSAGE = 1 << 5,
489 G_LOG_LEVEL_INFO = 1 << 6,
490 G_LOG_LEVEL_DEBUG = 1 << 7,
492 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
493 } GLogLevelFlags;
495 void g_print (const gchar *format, ...);
496 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
497 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask);
498 void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
499 void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
501 #ifdef HAVE_C99_SUPPORT
502 #define g_error(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__)
503 #define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
504 #define g_warning(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
505 #define g_message(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
506 #define g_debug(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
508 #define g_printerr(format, ...) fprintf (stderr, format, __VA_ARGS__)
509 #else
510 #define g_error(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__)
511 #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
512 #define g_warning(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
513 #define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
514 #define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
516 #define g_printerr(...) fprintf (stderr, __VA_ARGS__)
517 #endif
518 #define g_log_set_handler(a,b,c,d)
520 * Conversions
523 gpointer g_convert_error_quark(void);
527 * Unicode Manipulation: most of this is not used by Mono by default, it is
528 * only used if the old collation code is activated, so this is only the
529 * bare minimum to build.
531 typedef guint32 gunichar;
533 typedef enum {
534 G_UNICODE_LOWERCASE_LETTER,
535 } GUnicodeType;
537 gunichar g_unichar_tolower (gunichar c);
538 GUnicodeType g_unichar_type (gunichar c);
539 gboolean g_unichar_isxdigit (gunichar c);
540 gint g_unichar_xdigit_value (gunichar c);
542 #ifndef MAX
543 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
544 #endif
546 #ifndef MIN
547 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
548 #endif
550 #ifndef CLAMP
551 #define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
552 #endif
554 /* FIXME: Implement these two for gcc */
555 #define G_LIKELY(x) (x)
556 #define G_UNLIKELY(x) (x)
559 * Unicode conversion
562 #define G_CONVERT_ERROR g_convert_error_quark()
564 typedef enum {
565 G_CONVERT_ERROR_NO_CONVERSION,
566 G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
567 G_CONVERT_ERROR_FAILED,
568 G_CONVERT_ERROR_PARTIAL_INPUT,
569 G_CONVERT_ERROR_BAD_URI,
570 G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
571 } GConvertError;
573 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
574 gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
575 gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
576 gunichar *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
578 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
580 #ifdef G_OS_WIN32
581 #define u16to8(str) g_utf16_to_utf8(str, (glong)wcslen(str), NULL, NULL, NULL)
582 #else
583 #define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
584 #endif
587 * Path
589 gchar *g_build_path (const gchar *separator, const gchar *first_element, ...);
590 #define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
591 gchar *g_path_get_dirname (const gchar *filename);
592 gchar *g_path_get_basename (const char *filename);
593 gchar *g_find_program_in_path (const gchar *program);
594 gchar *g_get_current_dir (void);
595 gboolean g_path_is_absolute (const char *filename);
597 const gchar *g_get_home_dir (void);
598 const gchar *g_get_tmp_dir (void);
599 const gchar *g_get_user_name (void);
600 gchar *g_get_prgname (void);
601 void g_set_prgname (const gchar *prgname);
604 * Shell
607 gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
608 gchar *g_shell_unquote (const gchar *quoted_string, GError **error);
609 gchar *g_shell_quote (const gchar *unquoted_string);
612 * Spawn
614 typedef enum {
615 G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
616 G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
617 G_SPAWN_SEARCH_PATH = 1 << 2,
618 G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
619 G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
620 G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
621 G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
622 } GSpawnFlags;
624 typedef pid_t GPid;
626 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
628 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
629 gboolean g_spawn_async_with_pipes (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
630 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
634 * Timer
636 typedef struct _GTimer GTimer;
638 GTimer *g_timer_new (void);
639 void g_timer_destroy (GTimer *timer);
640 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
641 void g_timer_stop (GTimer *timer);
642 void g_timer_start (GTimer *timer);
645 * Date and time
647 typedef struct {
648 glong tv_sec;
649 glong tv_usec;
650 } GTimeVal;
652 void g_get_current_time (GTimeVal *result);
655 * File
658 typedef enum {
659 G_FILE_ERROR_EXIST,
660 G_FILE_ERROR_ISDIR,
661 G_FILE_ERROR_ACCES,
662 G_FILE_ERROR_NAMETOOLONG,
663 G_FILE_ERROR_NOENT,
664 G_FILE_ERROR_NOTDIR,
665 G_FILE_ERROR_NXIO,
666 G_FILE_ERROR_NODEV,
667 G_FILE_ERROR_ROFS,
668 G_FILE_ERROR_TXTBSY,
669 G_FILE_ERROR_FAULT,
670 G_FILE_ERROR_LOOP,
671 G_FILE_ERROR_NOSPC,
672 G_FILE_ERROR_NOMEM,
673 G_FILE_ERROR_MFILE,
674 G_FILE_ERROR_NFILE,
675 G_FILE_ERROR_BADF,
676 G_FILE_ERROR_INVAL,
677 G_FILE_ERROR_PIPE,
678 G_FILE_ERROR_AGAIN,
679 G_FILE_ERROR_INTR,
680 G_FILE_ERROR_IO,
681 G_FILE_ERROR_PERM,
682 G_FILE_ERROR_NOSYS,
683 G_FILE_ERROR_FAILED
684 } GFileError;
686 typedef enum {
687 G_FILE_TEST_IS_REGULAR = 1 << 0,
688 G_FILE_TEST_IS_SYMLINK = 1 << 1,
689 G_FILE_TEST_IS_DIR = 1 << 2,
690 G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
691 G_FILE_TEST_EXISTS = 1 << 4
692 } GFileTest;
695 gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
696 GFileError g_file_error_from_errno (gint err_no);
697 gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
698 gboolean g_file_test (const gchar *filename, GFileTest test);
701 * Pattern matching
703 typedef struct _GPatternSpec GPatternSpec;
704 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
705 void g_pattern_spec_free (GPatternSpec *pspec);
706 gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
709 * Directory
711 typedef struct _GDir GDir;
712 GDir *g_dir_open (const gchar *path, guint flags, GError **error);
713 const gchar *g_dir_read_name (GDir *dir);
714 void g_dir_rewind (GDir *dir);
715 void g_dir_close (GDir *dir);
718 * GMarkup
720 typedef struct _GMarkupParseContext GMarkupParseContext;
722 typedef enum
724 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
725 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
726 } GMarkupParseFlags;
728 typedef struct {
729 void (*start_element) (GMarkupParseContext *context,
730 const gchar *element_name,
731 const gchar **attribute_names,
732 const gchar **attribute_values,
733 gpointer user_data,
734 GError **error);
736 void (*end_element) (GMarkupParseContext *context,
737 const gchar *element_name,
738 gpointer user_data,
739 GError **error);
741 void (*text) (GMarkupParseContext *context,
742 const gchar *text,
743 gsize text_len,
744 gpointer user_data,
745 GError **error);
747 void (*passthrough) (GMarkupParseContext *context,
748 const gchar *passthrough_text,
749 gsize text_len,
750 gpointer user_data,
751 GError **error);
752 void (*error) (GMarkupParseContext *context,
753 GError *error,
754 gpointer user_data);
755 } GMarkupParser;
757 GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
758 GMarkupParseFlags flags,
759 gpointer user_data,
760 GDestroyNotify user_data_dnotify);
761 void g_markup_parse_context_free (GMarkupParseContext *context);
762 gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
763 const gchar *text, gssize text_len,
764 GError **error);
765 gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
766 GError **error);
769 * Character set conversion
772 * Index into the table below with the first byte of a UTF-8 sequence to
773 * get the number of trailing bytes that are supposed to follow it.
774 * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
775 * left as-is for anyone who may want to do such conversion, which was
776 * allowed in earlier algorithms.
778 extern const gchar g_trailingBytesForUTF8[256];
780 gboolean g_get_charset (G_CONST_RETURN char **charset);
781 gchar *g_locale_to_utf8 (const gchar *opsysstring, gssize len,
782 gsize *bytes_read, gsize *bytes_written,
783 GError **error);
784 gchar *g_locale_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
785 gsize *bytes_written, GError **error);
786 gchar *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
787 gsize *bytes_written, GError **error);
788 gchar *g_convert (const gchar *str, gssize len,
789 const gchar *to_codeset, const gchar *from_codeset,
790 gsize *bytes_read, gsize *bytes_written, GError **error);
791 gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end);
792 gunichar g_utf8_get_char (const gchar *src);
793 glong g_utf8_strlen (const gchar *str, gssize max);
794 #define g_utf8_next_char(p) p + (g_trailingBytesForUTF8[(guchar)(*p)] + 1)
797 * Empty thread functions, not used by eglib
799 #define g_thread_supported() TRUE
800 #define g_thread_init(x) G_STMT_START { if (x != NULL) { g_error ("No vtable supported in g_thread_init"); } } G_STMT_END
802 #define G_LOCK_DEFINE(name)
803 #define G_LOCK_DEFINE_STATIC(name)
804 #define G_LOCK_EXTERN(name)
805 #define G_LOCK(name)
806 #define G_TRYLOCK(name)
807 #define G_UNLOCK(name)
809 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
810 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
811 ( (((guint32) (x)) << 24)| \
812 ((((guint32) (x)) & 0xff0000) >> 8) | \
813 ((((guint32) (x)) & 0xff00) << 8) | \
814 (((guint32) (x)) >> 24)) )
816 #define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
817 GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
821 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
822 # define GUINT32_TO_LE(x) (x)
823 # define GUINT64_TO_LE(x) (x)
824 # define GUINT16_TO_LE(x) (x)
825 # define GUINT_TO_LE(x) (x)
826 #else
827 # define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
828 # define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
829 # define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
830 # define GUINT_TO_LE(x) GUINT32_SWAP_LE_BE(x)
831 #endif
833 #define GUINT32_FROM_LE(x) (GUINT32_TO_LE (x))
834 #define GUINT64_FROM_LE(x) (GUINT64_TO_LE (x))
835 #define GUINT16_FROM_LE(x) (GUINT16_TO_LE (x))
836 #define GUINT_FROM_LE(x) (GUINT_TO_LE (x))
838 #define _EGLIB_MAJOR 2
839 #define _EGLIB_MIDDLE 4
840 #define _EGLIB_MINOR 0
842 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
844 #endif