[runtime] Switch getenv to use heap memory
[mono.git] / eglib / src / glib.h
1 #ifndef __GLIB_H
2 #define __GLIB_H
3 #include <stdarg.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stddef.h>
8 #include <ctype.h>
9 #include <limits.h>
10
11
12 #ifdef _MSC_VER
13 #pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
14 #endif
15
16 #include <stdint.h>
17
18 #include <eglib-config.h>
19 #ifndef EGLIB_NO_REMAP
20 #include <eglib-remap.h>
21 #endif
22
23 #ifdef G_HAVE_ALLOCA_H
24 #include <alloca.h>
25 #endif
26
27 #ifdef WIN32
28 /* For alloca */
29 #include <malloc.h>
30 #endif
31
32 #ifndef offsetof
33 #   define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
34 #endif
35
36 #define __EGLIB_X11 1
37
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
45
46 G_BEGIN_DECLS
47
48 /*
49  * Basic data types
50  */
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;
61
62 /* Types defined in terms of the stdint.h */
63 typedef int8_t         gint8;
64 typedef uint8_t        guint8;
65 typedef int16_t        gint16;
66 typedef uint16_t       guint16;
67 typedef int32_t        gint32;
68 typedef uint32_t       guint32;
69 typedef int64_t        gint64;
70 typedef uint64_t       guint64;
71 typedef float          gfloat;
72 typedef double         gdouble;
73 typedef int32_t        gboolean;
74
75 typedef guint16 gunichar2;
76 typedef guint32 gunichar;
77
78 /*
79  * Macros
80  */
81 #define G_N_ELEMENTS(s)      (sizeof(s) / sizeof ((s) [0]))
82
83 #define FALSE                0
84 #define TRUE                 1
85
86 #define G_MINSHORT           SHRT_MIN
87 #define G_MAXSHORT           SHRT_MAX
88 #define G_MAXUSHORT          USHRT_MAX
89 #define G_MAXINT             INT_MAX
90 #define G_MININT             INT_MIN
91 #define G_MAXINT32           INT32_MAX
92 #define G_MAXUINT32          UINT32_MAX
93 #define G_MININT32           INT32_MIN
94 #define G_MININT64           INT64_MIN
95 #define G_MAXINT64           INT64_MAX
96 #define G_MAXUINT64          UINT64_MAX
97
98 #define G_LITTLE_ENDIAN 1234
99 #define G_BIG_ENDIAN    4321
100 #define G_STMT_START    do 
101 #define G_STMT_END      while (0)
102
103 #define G_USEC_PER_SEC  1000000
104
105 #ifndef ABS
106 #define ABS(a)         ((a) > 0 ? (a) : -(a))
107 #endif
108
109 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
110
111 #define EGLIB_STRINGIFY(x) #x
112 #define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
113 #define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
114
115 #define G_CONST_RETURN const
116
117 #define G_GUINT64_FORMAT PRIu64
118 #define G_GINT64_FORMAT PRIi64
119 #define G_GUINT32_FORMAT PRIu32
120 #define G_GINT32_FORMAT PRIi32
121
122 /*
123  * Allocation
124  */
125 void g_free (void *ptr);
126 gpointer g_realloc (gpointer obj, gsize size);
127 gpointer g_malloc (gsize x);
128 gpointer g_malloc0 (gsize x);
129 gpointer g_calloc (gsize n, gsize x);
130 gpointer g_try_malloc (gsize x);
131 gpointer g_try_realloc (gpointer obj, gsize size);
132
133 #define g_new(type,size)        ((type *) g_malloc (sizeof (type) * (size)))
134 #define g_new0(type,size)       ((type *) g_malloc0 (sizeof (type)* (size)))
135 #define g_newa(type,size)       ((type *) alloca (sizeof (type) * (size)))
136
137 #define g_memmove(dest,src,len) memmove (dest, src, len)
138 #define g_renew(struct_type, mem, n_structs) g_realloc (mem, sizeof (struct_type) * n_structs)
139 #define g_alloca(size)          alloca (size)
140
141 gpointer g_memdup (gconstpointer mem, guint byte_size);
142 static inline gchar   *g_strdup (const gchar *str) { if (str) { return (gchar*) g_memdup (str, (guint)strlen (str) + 1); } return NULL; }
143 gchar **g_strdupv (gchar **str_array);
144
145 typedef struct {
146         gpointer (*malloc)      (gsize    n_bytes);
147         gpointer (*realloc)     (gpointer mem, gsize n_bytes);
148         void     (*free)        (gpointer mem);
149         gpointer (*calloc)      (gsize    n_blocks, gsize n_block_bytes);
150 } GMemVTable;
151
152 void g_mem_set_vtable (GMemVTable* vtable);
153
154 struct _GMemChunk {
155         guint alloc_size;
156 };
157
158 typedef struct _GMemChunk GMemChunk;
159 /*
160  * Misc.
161  */
162
163 gboolean         g_hasenv(const gchar *variable);
164 gchar *          g_getenv(const gchar *variable);
165 gboolean         g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
166 void             g_unsetenv(const gchar *variable);
167
168 gchar*           g_win32_getlocale(void);
169
170 /*
171  * Precondition macros
172  */
173 #define g_warn_if_fail(x)  G_STMT_START { if (!(x)) { g_warning ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); } } G_STMT_END
174 #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
175 #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
176
177 /*
178  * Errors
179  */
180 typedef struct {
181         /* In the real glib, this is a GQuark, but we dont use/need that */
182         gpointer domain;
183         gint     code;
184         gchar   *message;
185 } GError;
186
187 void    g_clear_error (GError **error);
188 void    g_error_free (GError *error);
189 GError *g_error_new  (gpointer domain, gint code, const char *format, ...);
190 void    g_set_error  (GError **err, gpointer domain, gint code, const gchar *format, ...);
191 void    g_propagate_error (GError **dest, GError *src);
192
193 /*
194  * Strings utility
195  */
196 gchar       *g_strdup_printf  (const gchar *format, ...);
197 gchar       *g_strdup_vprintf (const gchar *format, va_list args);
198 gchar       *g_strndup        (const gchar *str, gsize n);
199 const gchar *g_strerror       (gint errnum);
200 gchar       *g_strndup        (const gchar *str, gsize n);
201 void         g_strfreev       (gchar **str_array);
202 gchar       *g_strconcat      (const gchar *first, ...);
203 gchar      **g_strsplit       (const gchar *string, const gchar *delimiter, gint max_tokens);
204 gchar      **g_strsplit_set   (const gchar *string, const gchar *delimiter, gint max_tokens);
205 gchar       *g_strreverse     (gchar *str);
206 gboolean     g_str_has_prefix (const gchar *str, const gchar *prefix);
207 gboolean     g_str_has_suffix (const gchar *str, const gchar *suffix);
208 guint        g_strv_length    (gchar **str_array);
209 gchar       *g_strjoin        (const gchar *separator, ...);
210 gchar       *g_strjoinv       (const gchar *separator, gchar **str_array);
211 gchar       *g_strchug        (gchar *str);
212 gchar       *g_strchomp       (gchar *str);
213 void         g_strdown        (gchar *string);
214 gchar       *g_strnfill       (gsize length, gchar fill_char);
215
216 gchar       *g_strdelimit     (gchar *string, const gchar *delimiters, gchar new_delimiter);
217 gchar       *g_strescape      (const gchar *source, const gchar *exceptions);
218
219 gchar       *g_filename_to_uri   (const gchar *filename, const gchar *hostname, GError **error);
220 gchar       *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
221
222 gint         g_printf          (gchar const *format, ...);
223 gint         g_fprintf         (FILE *file, gchar const *format, ...);
224 gint         g_sprintf         (gchar *string, gchar const *format, ...);
225 gint         g_snprintf        (gchar *string, gulong n, gchar const *format, ...);
226 gint         g_vasprintf       (gchar **ret, const gchar *fmt, va_list ap);
227 #define g_vprintf vprintf
228 #define g_vfprintf vfprintf
229 #define g_vsprintf vsprintf
230 #define g_vsnprintf vsnprintf
231
232 gsize   g_strlcpy            (gchar *dest, const gchar *src, gsize dest_size);
233 gchar  *g_stpcpy             (gchar *dest, const char *src);
234
235
236 gchar   g_ascii_tolower      (gchar c);
237 gchar   g_ascii_toupper      (gchar c);
238 gchar  *g_ascii_strdown      (const gchar *str, gssize len);
239 gchar  *g_ascii_strup        (const gchar *str, gssize len);
240 gint    g_ascii_strncasecmp  (const gchar *s1, const gchar *s2, gsize n);
241 gint    g_ascii_strcasecmp   (const gchar *s1, const gchar *s2);
242 gint    g_ascii_xdigit_value (gchar c);
243 #define g_ascii_isspace(c)   (isspace (c) != 0)
244 #define g_ascii_isalpha(c)   (isalpha (c) != 0)
245 #define g_ascii_isprint(c)   (isprint (c) != 0)
246 #define g_ascii_isxdigit(c)  (isxdigit (c) != 0)
247
248 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
249 #ifdef _MSC_VER
250 #define g_strcasecmp stricmp
251 #define g_strncasecmp strnicmp
252 #define g_strstrip(a) g_strchug (g_strchomp (a))
253 #else
254 #define g_strcasecmp strcasecmp
255 #define g_ascii_strtoull strtoull
256 #define g_strncasecmp strncasecmp
257 #define g_strstrip(a) g_strchug (g_strchomp (a))
258 #endif
259 #define g_ascii_strdup strdup
260
261
262 #define G_STR_DELIMITERS "_-|> <."
263
264 /*
265  * String type
266  */
267 typedef struct {
268         char *str;
269         gsize len;
270         gsize allocated_len;
271 } GString;
272
273 GString     *g_string_new           (const gchar *init);
274 GString     *g_string_new_len       (const gchar *init, gssize len);
275 GString     *g_string_sized_new     (gsize default_size);
276 gchar       *g_string_free          (GString *string, gboolean free_segment);
277 GString     *g_string_append        (GString *string, const gchar *val);
278 void         g_string_printf        (GString *string, const gchar *format, ...);
279 void         g_string_append_printf (GString *string, const gchar *format, ...);
280 void         g_string_append_vprintf (GString *string, const gchar *format, va_list args);
281 GString     *g_string_append_unichar (GString *string, gunichar c);
282 GString     *g_string_append_c      (GString *string, gchar c);
283 GString     *g_string_append        (GString *string, const gchar *val);
284 GString     *g_string_append_len    (GString *string, const gchar *val, gssize len);
285 GString     *g_string_truncate      (GString *string, gsize len);
286 GString     *g_string_prepend       (GString *string, const gchar *val);
287 GString     *g_string_insert        (GString *string, gssize pos, const gchar *val);
288 GString     *g_string_set_size      (GString *string, gsize len);
289 GString     *g_string_erase         (GString *string, gssize pos, gssize len);
290
291 #define g_string_sprintfa g_string_append_printf
292
293 typedef void     (*GFunc)          (gpointer data, gpointer user_data);
294 typedef gint     (*GCompareFunc)   (gconstpointer a, gconstpointer b);
295 typedef gint     (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
296 typedef void     (*GHFunc)         (gpointer key, gpointer value, gpointer user_data);
297 typedef gboolean (*GHRFunc)        (gpointer key, gpointer value, gpointer user_data);
298 typedef void     (*GDestroyNotify) (gpointer data);
299 typedef guint    (*GHashFunc)      (gconstpointer key);
300 typedef gboolean (*GEqualFunc)     (gconstpointer a, gconstpointer b);
301 typedef void     (*GFreeFunc)      (gpointer       data);
302
303 /*
304  * Lists
305  */
306 typedef struct _GSList GSList;
307 struct _GSList {
308         gpointer data;
309         GSList *next;
310 };
311
312 GSList *g_slist_alloc         (void);
313 GSList *g_slist_append        (GSList        *list,
314                                gpointer       data);
315 GSList *g_slist_prepend       (GSList        *list,
316                                gpointer       data);
317 void    g_slist_free          (GSList        *list);
318 void    g_slist_free_1        (GSList        *list);
319 GSList *g_slist_copy          (GSList        *list);
320 GSList *g_slist_concat        (GSList        *list1,
321                                GSList        *list2);
322 void    g_slist_foreach       (GSList        *list,
323                                GFunc          func,
324                                gpointer       user_data);
325 GSList *g_slist_last          (GSList        *list);
326 GSList *g_slist_find          (GSList        *list,
327                                gconstpointer  data);
328 GSList *g_slist_find_custom   (GSList        *list,
329                                gconstpointer  data,
330                                GCompareFunc   func);
331 GSList *g_slist_remove        (GSList        *list,
332                                gconstpointer  data);
333 GSList *g_slist_remove_all    (GSList        *list,
334                                gconstpointer  data);
335 GSList *g_slist_reverse       (GSList        *list);
336 guint   g_slist_length        (GSList        *list);
337 GSList *g_slist_remove_link   (GSList        *list,
338                                GSList        *link);
339 GSList *g_slist_delete_link   (GSList        *list,
340                                GSList        *link);
341 GSList *g_slist_insert_sorted (GSList        *list,
342                                gpointer       data,
343                                GCompareFunc   func);
344 GSList *g_slist_insert_before (GSList        *list,
345                                GSList        *sibling,
346                                gpointer       data);
347 GSList *g_slist_sort          (GSList        *list,
348                                GCompareFunc   func);
349 gint    g_slist_index         (GSList        *list,
350                                gconstpointer  data);
351 GSList *g_slist_nth           (GSList        *list,
352                                guint          n);
353 gpointer g_slist_nth_data     (GSList        *list,
354                                guint          n);
355
356 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
357
358
359 typedef struct _GList GList;
360 struct _GList {
361   gpointer data;
362   GList *next;
363   GList *prev;
364 };
365
366 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
367 #define g_list_previous(list) ((list) ? (((GList *) (list))->prev) : NULL)
368
369 GList *g_list_alloc         (void);
370 GList *g_list_append        (GList         *list,
371                              gpointer       data);
372 GList *g_list_prepend       (GList         *list,
373                              gpointer       data);
374 void   g_list_free          (GList         *list);
375 void   g_list_free_1        (GList         *list);
376 GList *g_list_copy          (GList         *list);
377 guint  g_list_length        (GList         *list);
378 gint   g_list_index         (GList         *list,
379                              gconstpointer  data);
380 GList *g_list_nth           (GList         *list,
381                              guint          n);
382 gpointer g_list_nth_data      (GList         *list,
383                              guint          n);
384 GList *g_list_last          (GList         *list);
385 GList *g_list_concat        (GList         *list1,
386                              GList         *list2);
387 void   g_list_foreach       (GList         *list,
388                              GFunc          func,
389                              gpointer       user_data);
390 GList *g_list_first         (GList         *list);
391 GList *g_list_find          (GList         *list,
392                              gconstpointer  data);
393 GList *g_list_find_custom   (GList         *list,
394                              gconstpointer  data,
395                              GCompareFunc   func);
396 GList *g_list_remove        (GList         *list,
397                              gconstpointer  data);
398 GList *g_list_remove_all    (GList         *list,
399                              gconstpointer  data);
400 GList *g_list_reverse       (GList         *list);
401 GList *g_list_remove_link   (GList         *list,
402                              GList         *link);
403 GList *g_list_delete_link   (GList         *list,
404                              GList         *link);
405 GList *g_list_insert_sorted (GList         *list,
406                              gpointer       data,
407                              GCompareFunc   func);
408 GList *g_list_insert_before (GList         *list,
409                              GList         *sibling,
410                              gpointer       data);
411 GList *g_list_sort          (GList         *sort,
412                              GCompareFunc   func);
413
414 /*
415  * Hashtables
416  */
417 typedef struct _GHashTable GHashTable;
418 typedef struct _GHashTableIter GHashTableIter;
419
420 /* Private, but needed for stack allocation */
421 struct _GHashTableIter
422 {
423         gpointer dummy [8];
424 };
425
426 GHashTable     *g_hash_table_new             (GHashFunc hash_func, GEqualFunc key_equal_func);
427 GHashTable     *g_hash_table_new_full        (GHashFunc hash_func, GEqualFunc key_equal_func,
428                                               GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
429 void            g_hash_table_insert_replace  (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
430 guint           g_hash_table_size            (GHashTable *hash);
431 GList          *g_hash_table_get_keys        (GHashTable *hash);
432 GList          *g_hash_table_get_values      (GHashTable *hash);
433 gpointer        g_hash_table_lookup          (GHashTable *hash, gconstpointer key);
434 gboolean        g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
435 void            g_hash_table_foreach         (GHashTable *hash, GHFunc func, gpointer user_data);
436 gpointer        g_hash_table_find            (GHashTable *hash, GHRFunc predicate, gpointer user_data);
437 gboolean        g_hash_table_remove          (GHashTable *hash, gconstpointer key);
438 gboolean        g_hash_table_steal           (GHashTable *hash, gconstpointer key);
439 void            g_hash_table_remove_all      (GHashTable *hash);
440 guint           g_hash_table_foreach_remove  (GHashTable *hash, GHRFunc func, gpointer user_data);
441 guint           g_hash_table_foreach_steal   (GHashTable *hash, GHRFunc func, gpointer user_data);
442 void            g_hash_table_destroy         (GHashTable *hash);
443 void            g_hash_table_print_stats     (GHashTable *table);
444
445 void            g_hash_table_iter_init       (GHashTableIter *iter, GHashTable *hash_table);
446 gboolean        g_hash_table_iter_next       (GHashTableIter *iter, gpointer *key, gpointer *value);
447
448 guint           g_spaced_primes_closest      (guint x);
449
450 #define g_hash_table_insert(h,k,v)    g_hash_table_insert_replace ((h),(k),(v),FALSE)
451 #define g_hash_table_replace(h,k,v)   g_hash_table_insert_replace ((h),(k),(v),TRUE)
452
453 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
454 guint    g_direct_hash  (gconstpointer v1);
455 gboolean g_int_equal    (gconstpointer v1, gconstpointer v2);
456 guint    g_int_hash     (gconstpointer v1);
457 gboolean g_str_equal    (gconstpointer v1, gconstpointer v2);
458 guint    g_str_hash     (gconstpointer v1);
459
460 /*
461  * ByteArray
462  */
463
464 typedef struct _GByteArray GByteArray;
465 struct _GByteArray {
466         guint8 *data;
467         gint len;
468 };
469
470 GByteArray *g_byte_array_new    (void);
471 GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, guint len);
472 guint8*  g_byte_array_free      (GByteArray *array, gboolean free_segment);
473 void     g_byte_array_set_size  (GByteArray *array, gint length);
474
475 /*
476  * Array
477  */
478
479 typedef struct _GArray GArray;
480 struct _GArray {
481         gchar *data;
482         gint len;
483 };
484
485 GArray *g_array_new               (gboolean zero_terminated, gboolean clear_, guint element_size);
486 GArray *g_array_sized_new         (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
487 gchar*  g_array_free              (GArray *array, gboolean free_segment);
488 GArray *g_array_append_vals       (GArray *array, gconstpointer data, guint len);
489 GArray* g_array_insert_vals       (GArray *array, guint index_, gconstpointer data, guint len);
490 GArray* g_array_remove_index      (GArray *array, guint index_);
491 GArray* g_array_remove_index_fast (GArray *array, guint index_);
492 void    g_array_set_size          (GArray *array, gint length);
493
494 #define g_array_append_val(a,v)   (g_array_append_vals((a),&(v),1))
495 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
496 #define g_array_index(a,t,i)      *(t*)(((a)->data) + sizeof(t) * (i))
497
498 /*
499  * QSort
500 */
501
502 void g_qsort_with_data (gpointer base, size_t nmemb, size_t size, GCompareDataFunc compare, gpointer user_data);
503
504 /*
505  * Pointer Array
506  */
507
508 typedef struct _GPtrArray GPtrArray;
509 struct _GPtrArray {
510         gpointer *pdata;
511         guint len;
512 };
513
514 GPtrArray *g_ptr_array_new                (void);
515 GPtrArray *g_ptr_array_sized_new          (guint reserved_size);
516 void       g_ptr_array_add                (GPtrArray *array, gpointer data);
517 gboolean   g_ptr_array_remove             (GPtrArray *array, gpointer data);
518 gpointer   g_ptr_array_remove_index       (GPtrArray *array, guint index);
519 gboolean   g_ptr_array_remove_fast        (GPtrArray *array, gpointer data);
520 gpointer   g_ptr_array_remove_index_fast  (GPtrArray *array, guint index);
521 void       g_ptr_array_sort               (GPtrArray *array, GCompareFunc compare_func);
522 void       g_ptr_array_sort_with_data     (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
523 void       g_ptr_array_set_size           (GPtrArray *array, gint length);
524 gpointer  *g_ptr_array_free               (GPtrArray *array, gboolean free_seg);
525 void       g_ptr_array_foreach            (GPtrArray *array, GFunc func, gpointer user_data);
526 #define    g_ptr_array_index(array,index) (array)->pdata[(index)]
527
528 /*
529  * Queues
530  */
531 typedef struct {
532         GList *head;
533         GList *tail;
534         guint length;
535 } GQueue;
536
537 gpointer g_queue_pop_head  (GQueue   *queue);
538 void     g_queue_push_head (GQueue   *queue,
539                             gpointer  data);
540 void     g_queue_push_tail (GQueue   *queue,
541                             gpointer  data);
542 gboolean g_queue_is_empty  (GQueue   *queue);
543 GQueue  *g_queue_new       (void);
544 void     g_queue_free      (GQueue   *queue);
545 void     g_queue_foreach   (GQueue   *queue, GFunc func, gpointer user_data);
546
547 /*
548  * Messages
549  */
550 #ifndef G_LOG_DOMAIN
551 #define G_LOG_DOMAIN ((gchar*) 0)
552 #endif
553
554 typedef enum {
555         G_LOG_FLAG_RECURSION          = 1 << 0,
556         G_LOG_FLAG_FATAL              = 1 << 1,
557         
558         G_LOG_LEVEL_ERROR             = 1 << 2,
559         G_LOG_LEVEL_CRITICAL          = 1 << 3,
560         G_LOG_LEVEL_WARNING           = 1 << 4,
561         G_LOG_LEVEL_MESSAGE           = 1 << 5,
562         G_LOG_LEVEL_INFO              = 1 << 6,
563         G_LOG_LEVEL_DEBUG             = 1 << 7,
564         
565         G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
566 } GLogLevelFlags;
567
568 void           g_print                (const gchar *format, ...);
569 void           g_printerr             (const gchar *format, ...);
570 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
571 GLogLevelFlags g_log_set_fatal_mask   (const gchar *log_domain, GLogLevelFlags fatal_mask);
572 void           g_logv                 (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
573 void           g_log                  (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
574 void           g_assertion_message    (const gchar *format, ...) G_GNUC_NORETURN;
575
576 #ifdef HAVE_C99_SUPPORT
577 /* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
578 #define g_error(format, ...)    do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
579 #define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
580 #define g_warning(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
581 #define g_message(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
582 #define g_debug(format, ...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
583 #else   /* HAVE_C99_SUPPORT */
584 #define g_error(...)    do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;); } while (0)
585 #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
586 #define g_warning(...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
587 #define g_message(...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
588 #define g_debug(...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
589 #endif  /* ndef HAVE_C99_SUPPORT */
590
591 typedef void (*GLogFunc) (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
592 typedef void (*GPrintFunc) (const gchar *string);
593
594 void       g_log_default_handler     (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data);
595 GLogFunc   g_log_set_default_handler (GLogFunc log_func, gpointer user_data);
596 GPrintFunc g_set_print_handler       (GPrintFunc func);
597 GPrintFunc g_set_printerr_handler    (GPrintFunc func);
598 /*
599  * Conversions
600  */
601
602 gpointer g_convert_error_quark(void);
603
604
605 /*
606  * Unicode Manipulation: most of this is not used by Mono by default, it is
607  * only used if the old collation code is activated, so this is only the
608  * bare minimum to build.
609  */
610
611 typedef enum {
612         G_UNICODE_CONTROL,
613         G_UNICODE_FORMAT,
614         G_UNICODE_UNASSIGNED,
615         G_UNICODE_PRIVATE_USE,
616         G_UNICODE_SURROGATE,
617         G_UNICODE_LOWERCASE_LETTER,
618         G_UNICODE_MODIFIER_LETTER,
619         G_UNICODE_OTHER_LETTER,
620         G_UNICODE_TITLECASE_LETTER,
621         G_UNICODE_UPPERCASE_LETTER,
622         G_UNICODE_COMBINING_MARK,
623         G_UNICODE_ENCLOSING_MARK,
624         G_UNICODE_NON_SPACING_MARK,
625         G_UNICODE_DECIMAL_NUMBER,
626         G_UNICODE_LETTER_NUMBER,
627         G_UNICODE_OTHER_NUMBER,
628         G_UNICODE_CONNECT_PUNCTUATION,
629         G_UNICODE_DASH_PUNCTUATION,
630         G_UNICODE_CLOSE_PUNCTUATION,
631         G_UNICODE_FINAL_PUNCTUATION,
632         G_UNICODE_INITIAL_PUNCTUATION,
633         G_UNICODE_OTHER_PUNCTUATION,
634         G_UNICODE_OPEN_PUNCTUATION,
635         G_UNICODE_CURRENCY_SYMBOL,
636         G_UNICODE_MODIFIER_SYMBOL,
637         G_UNICODE_MATH_SYMBOL,
638         G_UNICODE_OTHER_SYMBOL,
639         G_UNICODE_LINE_SEPARATOR,
640         G_UNICODE_PARAGRAPH_SEPARATOR,
641         G_UNICODE_SPACE_SEPARATOR
642 } GUnicodeType;
643
644 typedef enum {
645         G_UNICODE_BREAK_MANDATORY,
646         G_UNICODE_BREAK_CARRIAGE_RETURN,
647         G_UNICODE_BREAK_LINE_FEED,
648         G_UNICODE_BREAK_COMBINING_MARK,
649         G_UNICODE_BREAK_SURROGATE,
650         G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
651         G_UNICODE_BREAK_INSEPARABLE,
652         G_UNICODE_BREAK_NON_BREAKING_GLUE,
653         G_UNICODE_BREAK_CONTINGENT,
654         G_UNICODE_BREAK_SPACE,
655         G_UNICODE_BREAK_AFTER,
656         G_UNICODE_BREAK_BEFORE,
657         G_UNICODE_BREAK_BEFORE_AND_AFTER,
658         G_UNICODE_BREAK_HYPHEN,
659         G_UNICODE_BREAK_NON_STARTER,
660         G_UNICODE_BREAK_OPEN_PUNCTUATION,
661         G_UNICODE_BREAK_CLOSE_PUNCTUATION,
662         G_UNICODE_BREAK_QUOTATION,
663         G_UNICODE_BREAK_EXCLAMATION,
664         G_UNICODE_BREAK_IDEOGRAPHIC,
665         G_UNICODE_BREAK_NUMERIC,
666         G_UNICODE_BREAK_INFIX_SEPARATOR,
667         G_UNICODE_BREAK_SYMBOL,
668         G_UNICODE_BREAK_ALPHABETIC,
669         G_UNICODE_BREAK_PREFIX,
670         G_UNICODE_BREAK_POSTFIX,
671         G_UNICODE_BREAK_COMPLEX_CONTEXT,
672         G_UNICODE_BREAK_AMBIGUOUS,
673         G_UNICODE_BREAK_UNKNOWN,
674         G_UNICODE_BREAK_NEXT_LINE,
675         G_UNICODE_BREAK_WORD_JOINER,
676         G_UNICODE_BREAK_HANGUL_L_JAMO,
677         G_UNICODE_BREAK_HANGUL_V_JAMO,
678         G_UNICODE_BREAK_HANGUL_T_JAMO,
679         G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
680         G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE
681 } GUnicodeBreakType;
682
683 gunichar       g_unichar_toupper (gunichar c);
684 gunichar       g_unichar_tolower (gunichar c);
685 gunichar       g_unichar_totitle (gunichar c);
686 GUnicodeType   g_unichar_type    (gunichar c);
687 gboolean       g_unichar_isspace (gunichar c);
688 gboolean       g_unichar_isxdigit (gunichar c);
689 gint           g_unichar_xdigit_value (gunichar c);
690 GUnicodeBreakType   g_unichar_break_type (gunichar c);
691
692 #ifndef MAX
693 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
694 #endif
695
696 #ifndef MIN
697 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
698 #endif
699
700 #ifndef CLAMP
701 #define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
702 #endif
703
704 #if defined(__GNUC__) && (__GNUC__ > 2)
705 #define G_LIKELY(expr) (__builtin_expect ((expr) != 0, 1))
706 #define G_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0))
707 #else
708 #define G_LIKELY(x) (x)
709 #define G_UNLIKELY(x) (x)
710 #endif
711
712 #if defined(_MSC_VER)
713 #define  eg_unreachable() __assume(0)
714 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 5)))
715 #define  eg_unreachable() __builtin_unreachable()
716 #else
717 #define  eg_unreachable()
718 #endif
719
720 #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
721 #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
722
723 /*
724  * Unicode conversion
725  */
726
727 #define G_CONVERT_ERROR g_convert_error_quark()
728
729 typedef enum {
730         G_CONVERT_ERROR_NO_CONVERSION,
731         G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
732         G_CONVERT_ERROR_FAILED,
733         G_CONVERT_ERROR_PARTIAL_INPUT,
734         G_CONVERT_ERROR_BAD_URI,
735         G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
736 } GConvertError;
737
738 gchar     *g_utf8_strup (const gchar *str, gssize len);
739 gchar     *g_utf8_strdown (const gchar *str, gssize len);
740 gint       g_unichar_to_utf8 (gunichar c, gchar *outbuf);
741 gunichar  *g_utf8_to_ucs4_fast (const gchar *str, glong len, glong *items_written);
742 gunichar  *g_utf8_to_ucs4 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
743 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
744 gunichar2 *eg_utf8_to_utf16_with_nuls (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
745 gchar     *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
746 gunichar  *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
747 gchar     *g_ucs4_to_utf8  (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **err);
748 gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **err);
749
750 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
751
752 #ifdef G_OS_WIN32
753 #define u16to8(str) g_utf16_to_utf8((gunichar2 *) (str), (glong)wcslen((wchar_t *) (str)), NULL, NULL, NULL)
754 #else
755 #define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
756 #endif
757
758 /*
759  * Path
760  */
761 gchar  *g_build_path           (const gchar *separator, const gchar *first_element, ...);
762 #define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
763 gchar  *g_path_get_dirname     (const gchar *filename);
764 gchar  *g_path_get_basename    (const char *filename);
765 gchar  *g_find_program_in_path (const gchar *program);
766 gchar  *g_get_current_dir      (void);
767 gboolean g_path_is_absolute    (const char *filename);
768
769 const gchar *g_get_home_dir    (void);
770 const gchar *g_get_tmp_dir     (void);
771 const gchar *g_get_user_name   (void);
772 gchar *g_get_prgname           (void);
773 void  g_set_prgname            (const gchar *prgname);
774
775 gboolean g_ensure_directory_exists (const gchar *filename);
776
777 /*
778  * Shell
779  */
780
781 gboolean  g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
782 gchar    *g_shell_unquote    (const gchar *quoted_string, GError **error);
783 gchar    *g_shell_quote      (const gchar *unquoted_string);
784
785 /*
786  * Spawn
787  */
788 typedef enum {
789         G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
790         G_SPAWN_DO_NOT_REAP_CHILD      = 1 << 1,
791         G_SPAWN_SEARCH_PATH            = 1 << 2,
792         G_SPAWN_STDOUT_TO_DEV_NULL     = 1 << 3,
793         G_SPAWN_STDERR_TO_DEV_NULL     = 1 << 4,
794         G_SPAWN_CHILD_INHERITS_STDIN   = 1 << 5,
795         G_SPAWN_FILE_AND_ARGV_ZERO     = 1 << 6
796 } GSpawnFlags;
797
798 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
799
800 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
801 gboolean g_spawn_async_with_pipes  (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
802                                 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
803
804 int eg_getdtablesize (void);
805
806 /*
807  * Timer
808  */
809 typedef struct _GTimer GTimer;
810
811 GTimer *g_timer_new (void);
812 void g_timer_destroy (GTimer *timer);
813 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
814 void g_timer_stop (GTimer *timer);
815 void g_timer_start (GTimer *timer);
816
817 /*
818  * Date and time
819  */
820 typedef struct {
821         glong tv_sec;
822         glong tv_usec;
823 } GTimeVal;
824
825 void g_get_current_time (GTimeVal *result);
826 void g_usleep (gulong microseconds);
827
828 /*
829  * File
830  */
831
832 gpointer g_file_error_quark (void);
833
834 #define G_FILE_ERROR g_file_error_quark ()
835
836 typedef enum {
837         G_FILE_ERROR_EXIST,
838         G_FILE_ERROR_ISDIR,
839         G_FILE_ERROR_ACCES,
840         G_FILE_ERROR_NAMETOOLONG,
841         G_FILE_ERROR_NOENT,
842         G_FILE_ERROR_NOTDIR,
843         G_FILE_ERROR_NXIO,
844         G_FILE_ERROR_NODEV,
845         G_FILE_ERROR_ROFS,
846         G_FILE_ERROR_TXTBSY,
847         G_FILE_ERROR_FAULT,
848         G_FILE_ERROR_LOOP,
849         G_FILE_ERROR_NOSPC,
850         G_FILE_ERROR_NOMEM,
851         G_FILE_ERROR_MFILE,
852         G_FILE_ERROR_NFILE,
853         G_FILE_ERROR_BADF,
854         G_FILE_ERROR_INVAL,
855         G_FILE_ERROR_PIPE,
856         G_FILE_ERROR_AGAIN,
857         G_FILE_ERROR_INTR,
858         G_FILE_ERROR_IO,
859         G_FILE_ERROR_PERM,
860         G_FILE_ERROR_NOSYS,
861         G_FILE_ERROR_FAILED
862 } GFileError;
863
864 typedef enum {
865         G_FILE_TEST_IS_REGULAR = 1 << 0,
866         G_FILE_TEST_IS_SYMLINK = 1 << 1,
867         G_FILE_TEST_IS_DIR = 1 << 2,
868         G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
869         G_FILE_TEST_EXISTS = 1 << 4
870 } GFileTest;
871
872
873 gboolean   g_file_set_contents (const gchar *filename, const gchar *contents, gssize length, GError **error);
874 gboolean   g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
875 GFileError g_file_error_from_errno (gint err_no);
876 gint       g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
877 gboolean   g_file_test (const gchar *filename, GFileTest test);
878
879 #define g_open open
880 #define g_rename rename
881 #define g_stat stat
882 #define g_unlink unlink
883 #define g_fopen fopen
884 #define g_lstat lstat
885 #define g_rmdir rmdir
886 #define g_mkstemp mkstemp
887 #define g_ascii_isdigit isdigit
888 #define g_ascii_strtod strtod
889 #define g_ascii_isalnum isalnum
890
891 gchar *g_mkdtemp (gchar *tmpl);
892
893 /*
894  * Pattern matching
895  */
896 typedef struct _GPatternSpec GPatternSpec;
897 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
898 void           g_pattern_spec_free (GPatternSpec *pspec);
899 gboolean       g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
900
901 /*
902  * Directory
903  */
904 typedef struct _GDir GDir;
905 GDir        *g_dir_open (const gchar *path, guint flags, GError **error);
906 const gchar *g_dir_read_name (GDir *dir);
907 void         g_dir_rewind (GDir *dir);
908 void         g_dir_close (GDir *dir);
909
910 int          g_mkdir_with_parents (const gchar *pathname, int mode);
911 #define g_mkdir mkdir
912
913 /*
914  * GMarkup
915  */
916 typedef struct _GMarkupParseContext GMarkupParseContext;
917
918 typedef enum
919 {
920         G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
921         G_MARKUP_TREAT_CDATA_AS_TEXT              = 1 << 1
922 } GMarkupParseFlags;
923
924 typedef struct {
925         void (*start_element)  (GMarkupParseContext *context,
926                                 const gchar *element_name,
927                                 const gchar **attribute_names,
928                                 const gchar **attribute_values,
929                                 gpointer user_data,
930                                 GError **error);
931
932         void (*end_element)    (GMarkupParseContext *context,
933                                 const gchar         *element_name,
934                                 gpointer             user_data,
935                                 GError             **error);
936         
937         void (*text)           (GMarkupParseContext *context,
938                                 const gchar         *text,
939                                 gsize                text_len,  
940                                 gpointer             user_data,
941                                 GError             **error);
942         
943         void (*passthrough)    (GMarkupParseContext *context,
944                                 const gchar         *passthrough_text,
945                                 gsize                text_len,  
946                                 gpointer             user_data,
947                                 GError             **error);
948         void (*error)          (GMarkupParseContext *context,
949                                 GError              *error,
950                                 gpointer             user_data);
951 } GMarkupParser;
952
953 GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
954                                                    GMarkupParseFlags flags,
955                                                    gpointer user_data,
956                                                    GDestroyNotify user_data_dnotify);
957 void                 g_markup_parse_context_free  (GMarkupParseContext *context);
958 gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
959                                                    const gchar *text, gssize text_len,
960                                                    GError **error);
961 gboolean         g_markup_parse_context_end_parse (GMarkupParseContext *context,
962                                                    GError **error);
963
964 /*
965  * Character set conversion
966  */
967 typedef struct _GIConv *GIConv;
968
969 gsize g_iconv (GIConv cd, gchar **inbytes, gsize *inbytesleft, gchar **outbytes, gsize *outbytesleft);
970 GIConv g_iconv_open (const gchar *to_charset, const gchar *from_charset);
971 int g_iconv_close (GIConv cd);
972
973 gboolean  g_get_charset        (G_CONST_RETURN char **charset);
974 gchar    *g_locale_to_utf8     (const gchar *opsysstring, gssize len,
975                                 gsize *bytes_read, gsize *bytes_written,
976                                 GError **error);
977 gchar    *g_locale_from_utf8   (const gchar *utf8string, gssize len, gsize *bytes_read,
978                                 gsize *bytes_written, GError **error);
979 gchar    *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
980                                 gsize *bytes_written, GError **error);
981 gchar    *g_convert            (const gchar *str, gssize len,
982                                 const gchar *to_codeset, const gchar *from_codeset,
983                                 gsize *bytes_read, gsize *bytes_written, GError **error);
984
985 /*
986  * Unicode manipulation
987  */
988 extern const guchar g_utf8_jump_table[256];
989
990 gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **end);
991 gunichar  g_utf8_get_char_validated (const gchar *str, gssize max_len);
992 gchar    *g_utf8_find_prev_char (const char *str, const char *p);
993 gchar    *g_utf8_prev_char     (const char *str);
994 #define   g_utf8_next_char(p)  ((p) + g_utf8_jump_table[(guchar)(*p)])
995 gunichar  g_utf8_get_char      (const gchar *src);
996 glong     g_utf8_strlen        (const gchar *str, gssize max);
997 gchar    *g_utf8_offset_to_pointer (const gchar *str, glong offset);
998 glong     g_utf8_pointer_to_offset (const gchar *str, const gchar *pos);
999
1000 /*
1001  * priorities
1002  */
1003 #define G_PRIORITY_DEFAULT 0
1004 #define G_PRIORITY_DEFAULT_IDLE 200
1005
1006 #define GUINT16_SWAP_LE_BE_CONSTANT(x) ((((guint16) x) >> 8) | ((((guint16) x) << 8)))
1007
1008 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
1009 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
1010                                ( (((guint32) (x)) << 24)| \
1011                                  ((((guint32) (x)) & 0xff0000) >> 8) | \
1012                                  ((((guint32) (x)) & 0xff00) << 8) | \
1013                                  (((guint32) (x)) >> 24)) )
1014  
1015 #define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
1016                                GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
1017
1018                                   
1019  
1020 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1021 #   define GUINT64_FROM_BE(x) GUINT64_SWAP_LE_BE(x)
1022 #   define GUINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
1023 #   define GUINT16_FROM_BE(x) GUINT16_SWAP_LE_BE(x)
1024 #   define GUINT_FROM_BE(x)   GUINT32_SWAP_LE_BE(x)
1025 #   define GUINT64_FROM_LE(x) (x)
1026 #   define GUINT32_FROM_LE(x) (x)
1027 #   define GUINT16_FROM_LE(x) (x)
1028 #   define GUINT_FROM_LE(x)   (x)
1029 #   define GUINT64_TO_BE(x)   GUINT64_SWAP_LE_BE(x)
1030 #   define GUINT32_TO_BE(x)   GUINT32_SWAP_LE_BE(x)
1031 #   define GUINT16_TO_BE(x)   GUINT16_SWAP_LE_BE(x)
1032 #   define GUINT_TO_BE(x)     GUINT32_SWAP_LE_BE(x)
1033 #   define GUINT64_TO_LE(x)   (x)
1034 #   define GUINT32_TO_LE(x)   (x)
1035 #   define GUINT16_TO_LE(x)   (x)
1036 #   define GUINT_TO_LE(x)     (x)
1037 #else
1038 #   define GUINT64_FROM_BE(x) (x)
1039 #   define GUINT32_FROM_BE(x) (x)
1040 #   define GUINT16_FROM_BE(x) (x)
1041 #   define GUINT_FROM_BE(x)   (x)
1042 #   define GUINT64_FROM_LE(x) GUINT64_SWAP_LE_BE(x)
1043 #   define GUINT32_FROM_LE(x) GUINT32_SWAP_LE_BE(x)
1044 #   define GUINT16_FROM_LE(x) GUINT16_SWAP_LE_BE(x)
1045 #   define GUINT_FROM_LE(x)   GUINT32_SWAP_LE_BE(x)
1046 #   define GUINT64_TO_BE(x)   (x)
1047 #   define GUINT32_TO_BE(x)   (x)
1048 #   define GUINT16_TO_BE(x)   (x)
1049 #   define GUINT_TO_BE(x)     (x)
1050 #   define GUINT64_TO_LE(x)   GUINT64_SWAP_LE_BE(x)
1051 #   define GUINT32_TO_LE(x)   GUINT32_SWAP_LE_BE(x)
1052 #   define GUINT16_TO_LE(x)   GUINT16_SWAP_LE_BE(x)
1053 #   define GUINT_TO_LE(x)     GUINT32_SWAP_LE_BE(x)
1054 #endif
1055
1056 #define GINT64_FROM_BE(x)   (GUINT64_TO_BE (x))
1057 #define GINT32_FROM_BE(x)   (GUINT32_TO_BE (x))
1058 #define GINT16_FROM_BE(x)   (GUINT16_TO_BE (x))
1059 #define GINT64_FROM_LE(x)   (GUINT64_TO_LE (x))
1060 #define GINT32_FROM_LE(x)   (GUINT32_TO_LE (x))
1061 #define GINT16_FROM_LE(x)   (GUINT16_TO_LE (x))
1062
1063 #define _EGLIB_MAJOR  2
1064 #define _EGLIB_MIDDLE 4
1065 #define _EGLIB_MINOR  0
1066  
1067 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
1068
1069 #define G_HAVE_API_SUPPORT(x) (x)
1070 #define G_UNSUPPORTED_API "%s:%d: '%s' not supported.", __FILE__, __LINE__
1071 #define g_unsupported_api(name) G_STMT_START { g_warning (G_UNSUPPORTED_API, name); } G_STMT_END
1072  
1073 G_END_DECLS
1074
1075 #endif
1076
1077
1078