added GLIB_CHECK_VERSION() macro similar to GTK_CHECK_VERSION().
[platform/upstream/glib.git] / glib.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_LIB_H__
28 #define __G_LIB_H__
29
30 /* system specific config file glibconfig.h provides definitions for
31  * the extrema of many of the standard types. These are:
32  *
33  *  G_MINSHORT, G_MAXSHORT
34  *  G_MININT, G_MAXINT
35  *  G_MINLONG, G_MAXLONG
36  *  G_MINFLOAT, G_MAXFLOAT
37  *  G_MINDOUBLE, G_MAXDOUBLE
38  *
39  * It also provides the following typedefs:
40  *
41  *  gint8, guint8
42  *  gint16, guint16
43  *  gint32, guint32
44  *  gint64, guint64
45  *
46  * It defines the G_BYTE_ORDER symbol to one of G_*_ENDIAN (see later in
47  * this file). 
48  *
49  * And it provides a way to store and retrieve a `gint' in/from a `gpointer'.
50  * This is useful to pass an integer instead of a pointer to a callback.
51  *
52  *  GINT_TO_POINTER(i), GUINT_TO_POINTER(i)
53  *  GPOINTER_TO_INT(p), GPOINTER_TO_UINT(p)
54  *
55  * Finally, it provide the following wrappers to STDC functions:
56  *
57  *  g_ATEXIT
58  *    To register hooks which are executed on exit().
59  *    Usually a wrapper for STDC atexit.
60  *
61  *  void *g_memmove(void *dest, const void *src, guint count);
62  *    A wrapper for STDC memmove, or an implementation, if memmove doesn't
63  *    exist.  The prototype looks like the above, give or take a const,
64  *    or size_t.
65  */
66 #include <glibconfig.h>
67
68 /* include varargs functions for assertment macros
69  */
70 #include <stdarg.h>
71
72 /* optionally feature DMALLOC memory allocation debugger
73  */
74 #ifdef USE_DMALLOC
75 #include "dmalloc.h"
76 #endif
77
78
79 #ifdef NATIVE_WIN32
80
81 /* On native Win32, directory separator is the backslash, and search path
82  * separator is the semicolon.
83  */
84 #define G_DIR_SEPARATOR '\\'
85 #define G_DIR_SEPARATOR_S "\\"
86 #define G_SEARCHPATH_SEPARATOR ';'
87 #define G_SEARCHPATH_SEPARATOR_S ";"
88
89 #else  /* !NATIVE_WIN32 */
90
91 /* Unix */
92
93 #define G_DIR_SEPARATOR '/'
94 #define G_DIR_SEPARATOR_S "/"
95 #define G_SEARCHPATH_SEPARATOR ':'
96 #define G_SEARCHPATH_SEPARATOR_S ":"
97
98 #endif /* !NATIVE_WIN32 */
99
100 #ifdef __cplusplus
101 extern "C" {
102 #endif /* __cplusplus */
103
104
105 /* Provide definitions for some commonly used macros.
106  *  Some of them are only provided if they haven't already
107  *  been defined. It is assumed that if they are already
108  *  defined then the current definition is correct.
109  */
110 #ifndef NULL
111 #define NULL    ((void*) 0)
112 #endif
113
114 #ifndef FALSE
115 #define FALSE   (0)
116 #endif
117
118 #ifndef TRUE
119 #define TRUE    (!FALSE)
120 #endif
121
122 #undef  MAX
123 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
124
125 #undef  MIN
126 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
127
128 #undef  ABS
129 #define ABS(a)     (((a) < 0) ? -(a) : (a))
130
131 #undef  CLAMP
132 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
133
134
135 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
136  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
137  */
138 #if !defined (G_VA_COPY)
139 #  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
140 #  define G_VA_COPY(ap1, ap2)     (*(ap1) = *(ap2))
141 #  elif defined (G_VA_COPY_AS_ARRAY)
142 #  define G_VA_COPY(ap1, ap2)     g_memmove ((ap1), (ap2), sizeof (va_list))
143 #  else /* va_list is a pointer */
144 #  define G_VA_COPY(ap1, ap2)     ((ap1) = (ap2))
145 #  endif /* va_list is a pointer */
146 #endif /* !G_VA_COPY */
147
148
149 /* Provide convenience macros for handling structure
150  * fields through their offsets.
151  */
152 #define G_STRUCT_OFFSET(struct_type, member)    \
153     ((gulong) ((gchar*) &((struct_type*) 0)->member))
154 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
155     ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset)))
156 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
157     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
158
159
160 /* inlining hassle. for compilers that don't allow the `inline' keyword,
161  * mostly because of strict ANSI C compliance or dumbness, we try to fall
162  * back to either `__inline__' or `__inline'.
163  * we define G_CAN_INLINE, if the compiler seems to be actually
164  * *capable* to do function inlining, in which case inline function bodys
165  * do make sense. we also define G_INLINE_FUNC to properly export the
166  * function prototypes if no inlining can be performed.
167  * we special case most of the stuff, so inline functions can have a normal
168  * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
169  */
170 #ifndef G_INLINE_FUNC
171 #  define G_CAN_INLINE 1
172 #endif
173 #ifdef G_HAVE_INLINE
174 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
175 #    undef inline
176 #    define inline __inline__
177 #  endif
178 #else /* !G_HAVE_INLINE */
179 #  undef inline
180 #  if defined (G_HAVE___INLINE__)
181 #    define inline __inline__
182 #  else /* !inline && !__inline__ */
183 #    if defined (G_HAVE___INLINE)
184 #      define inline __inline
185 #    else /* !inline && !__inline__ && !__inline */
186 #      define inline /* don't inline, then */
187 #      ifndef G_INLINE_FUNC
188 #        undef G_CAN_INLINE
189 #      endif
190 #    endif
191 #  endif
192 #endif
193 #ifndef G_INLINE_FUNC
194 #  ifdef __GNUC__
195 #    ifdef __OPTIMIZE__
196 #      define G_INLINE_FUNC extern inline
197 #    else
198 #      undef G_CAN_INLINE
199 #      define G_INLINE_FUNC extern
200 #    endif
201 #  else /* !__GNUC__ */
202 #    ifdef G_CAN_INLINE
203 #      define G_INLINE_FUNC static inline
204 #    else
205 #      define G_INLINE_FUNC extern
206 #    endif
207 #  endif /* !__GNUC__ */
208 #endif /* !G_INLINE_FUNC */
209
210
211 /* Provide simple macro statement wrappers (adapted from Perl):
212  *  G_STMT_START { statements; } G_STMT_END;
213  *  can be used as a single statement, as in
214  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
215  *
216  *  For gcc we will wrap the statements within `({' and `})' braces.
217  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
218  *  and otherwise within `do' and `while (0)'.
219  */
220 #if !(defined (G_STMT_START) && defined (G_STMT_END))
221 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
222 #    define G_STMT_START        (void)(
223 #    define G_STMT_END          )
224 #  else
225 #    if (defined (sun) || defined (__sun__))
226 #      define G_STMT_START      if (1)
227 #      define G_STMT_END        else (void)0
228 #    else
229 #      define G_STMT_START      do
230 #      define G_STMT_END        while (0)
231 #    endif
232 #  endif
233 #endif
234
235
236 /* Provide macros to feature the GCC function attribute.
237  */
238 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
239 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
240   __attribute__((format (printf, format_idx, arg_idx)))
241 #define G_GNUC_SCANF( format_idx, arg_idx )     \
242   __attribute__((format (scanf, format_idx, arg_idx)))
243 #define G_GNUC_FORMAT( arg_idx )                \
244   __attribute__((format_arg (arg_idx)))
245 #define G_GNUC_NORETURN                         \
246   __attribute__((noreturn))
247 #define G_GNUC_CONST                            \
248   __attribute__((const))
249 #define G_GNUC_UNUSED                           \
250   __attribute__((unused))
251 #else   /* !__GNUC__ */
252 #define G_GNUC_PRINTF( format_idx, arg_idx )
253 #define G_GNUC_SCANF( format_idx, arg_idx )
254 #define G_GNUC_FORMAT( arg_idx )
255 #define G_GNUC_NORETURN
256 #define G_GNUC_CONST
257 #define G_GNUC_UNUSED
258 #endif  /* !__GNUC__ */
259
260
261 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
262  * macros, so we can refer to them as strings unconditionally.
263  */
264 #ifdef  __GNUC__
265 #define G_GNUC_FUNCTION         (__FUNCTION__)
266 #define G_GNUC_PRETTY_FUNCTION  (__PRETTY_FUNCTION__)
267 #else   /* !__GNUC__ */
268 #define G_GNUC_FUNCTION         ("")
269 #define G_GNUC_PRETTY_FUNCTION  ("")
270 #endif  /* !__GNUC__ */
271
272 /* we try to provide a usefull equivalent for ATEXIT if it is
273  * not defined, but use is actually abandoned. people should
274  * use g_atexit() instead.
275  */
276 #ifndef ATEXIT
277 # define ATEXIT(proc)   g_ATEXIT(proc)
278 #else
279 # define G_NATIVE_ATEXIT
280 #endif /* ATEXIT */
281
282 /* Hacker macro to place breakpoints for elected machines.
283  * Actual use is strongly deprecated of course ;)
284  */
285 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
286 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
287 #elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2
288 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
289 #else   /* !__i386__ && !__alpha__ */
290 #define G_BREAKPOINT()
291 #endif  /* __i386__ */
292
293
294 /* Provide macros for easily allocating memory. The macros
295  *  will cast the allocated memory to the specified type
296  *  in order to avoid compiler warnings. (Makes the code neater).
297  */
298
299 #ifdef __DMALLOC_H__
300 #  define g_new(type, count)            (ALLOC (type, count))
301 #  define g_new0(type, count)           (CALLOC (type, count))
302 #  define g_renew(type, mem, count)     (REALLOC (mem, type, count))
303 #else /* __DMALLOC_H__ */
304 #  define g_new(type, count)      \
305       ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
306 #  define g_new0(type, count)     \
307       ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
308 #  define g_renew(type, mem, count)       \
309       ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
310 #endif /* __DMALLOC_H__ */
311
312 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
313   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
314                    sizeof (type), \
315                    sizeof (type) * (pre_alloc), \
316                    (alloc_type)) \
317 )
318 #define g_chunk_new(type, chunk)        ( \
319   (type *) g_mem_chunk_alloc (chunk) \
320 )
321 #define g_chunk_new0(type, chunk)       ( \
322   (type *) g_mem_chunk_alloc0 (chunk) \
323 )
324 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
325   g_mem_chunk_free ((mem_chunk), (mem)); \
326 } G_STMT_END
327
328
329 #define g_string(x) #x
330
331
332 /* Provide macros for error handling. The "assert" macros will
333  *  exit on failure. The "return" macros will exit the current
334  *  function. Two different definitions are given for the macros
335  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
336  *  __PRETTY_FUNCTION__ capability.
337  */
338
339 #ifdef G_DISABLE_ASSERT
340
341 #define g_assert(expr)
342 #define g_assert_not_reached()
343
344 #else /* !G_DISABLE_ASSERT */
345
346 #ifdef __GNUC__
347
348 #define g_assert(expr)                  G_STMT_START{           \
349      if (!(expr))                                               \
350        g_log (G_LOG_DOMAIN,                                     \
351               G_LOG_LEVEL_ERROR,                                \
352               "file %s: line %d (%s): assertion failed: (%s)",  \
353               __FILE__,                                         \
354               __LINE__,                                         \
355               __PRETTY_FUNCTION__,                              \
356               #expr);                   }G_STMT_END
357
358 #define g_assert_not_reached()          G_STMT_START{           \
359      g_log (G_LOG_DOMAIN,                                       \
360             G_LOG_LEVEL_ERROR,                                  \
361             "file %s: line %d (%s): should not be reached",     \
362             __FILE__,                                           \
363             __LINE__,                                           \
364             __PRETTY_FUNCTION__);       }G_STMT_END
365
366 #else /* !__GNUC__ */
367
368 #define g_assert(expr)                  G_STMT_START{           \
369      if (!(expr))                                               \
370        g_log (G_LOG_DOMAIN,                                     \
371               G_LOG_LEVEL_ERROR,                                \
372               "file %s: line %d: assertion failed: (%s)",       \
373               __FILE__,                                         \
374               __LINE__,                                         \
375               #expr);                   }G_STMT_END
376
377 #define g_assert_not_reached()          G_STMT_START{   \
378      g_log (G_LOG_DOMAIN,                               \
379             G_LOG_LEVEL_ERROR,                          \
380             "file %s: line %d: should not be reached",  \
381             __FILE__,                                   \
382             __LINE__);          }G_STMT_END
383
384 #endif /* __GNUC__ */
385
386 #endif /* !G_DISABLE_ASSERT */
387
388
389 #ifdef G_DISABLE_CHECKS
390
391 #define g_return_if_fail(expr)
392 #define g_return_val_if_fail(expr,val)
393
394 #else /* !G_DISABLE_CHECKS */
395
396 #ifdef __GNUC__
397
398 #define g_return_if_fail(expr)          G_STMT_START{                   \
399      if (!(expr))                                                       \
400        {                                                                \
401          g_log (G_LOG_DOMAIN,                                           \
402                 G_LOG_LEVEL_CRITICAL,                                   \
403                 "file %s: line %d (%s): assertion `%s' failed.",        \
404                 __FILE__,                                               \
405                 __LINE__,                                               \
406                 __PRETTY_FUNCTION__,                                    \
407                 #expr);                                                 \
408          return;                                                        \
409        };                               }G_STMT_END
410
411 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
412      if (!(expr))                                                       \
413        {                                                                \
414          g_log (G_LOG_DOMAIN,                                           \
415                 G_LOG_LEVEL_CRITICAL,                                   \
416                 "file %s: line %d (%s): assertion `%s' failed.",        \
417                 __FILE__,                                               \
418                 __LINE__,                                               \
419                 __PRETTY_FUNCTION__,                                    \
420                 #expr);                                                 \
421          return val;                                                    \
422        };                               }G_STMT_END
423
424 #else /* !__GNUC__ */
425
426 #define g_return_if_fail(expr)          G_STMT_START{           \
427      if (!(expr))                                               \
428        {                                                        \
429          g_log (G_LOG_DOMAIN,                                   \
430                 G_LOG_LEVEL_CRITICAL,                           \
431                 "file %s: line %d: assertion `%s' failed.",     \
432                 __FILE__,                                       \
433                 __LINE__,                                       \
434                 #expr);                                         \
435          return;                                                \
436        };                               }G_STMT_END
437
438 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
439      if (!(expr))                                               \
440        {                                                        \
441          g_log (G_LOG_DOMAIN,                                   \
442                 G_LOG_LEVEL_CRITICAL,                           \
443                 "file %s: line %d: assertion `%s' failed.",     \
444                 __FILE__,                                       \
445                 __LINE__,                                       \
446                 #expr);                                         \
447          return val;                                            \
448        };                               }G_STMT_END
449
450 #endif /* !__GNUC__ */
451
452 #endif /* !G_DISABLE_CHECKS */
453
454
455 /* Provide type definitions for commonly used types.
456  *  These are useful because a "gint8" can be adjusted
457  *  to be 1 byte (8 bits) on all platforms. Similarly and
458  *  more importantly, "gint32" can be adjusted to be
459  *  4 bytes (32 bits) on all platforms.
460  */
461
462 typedef char   gchar;
463 typedef short  gshort;
464 typedef long   glong;
465 typedef int    gint;
466 typedef gint   gboolean;
467
468 typedef unsigned char   guchar;
469 typedef unsigned short  gushort;
470 typedef unsigned long   gulong;
471 typedef unsigned int    guint;
472
473 #define G_GSHORT_FORMAT  "hi"
474 #define G_GUSHORT_FORMAT "hu"
475 #define G_GINT_FORMAT    "i"
476 #define G_GUINT_FORMAT   "u"
477 #define G_GLONG_FORMAT   "li"
478 #define G_GULONG_FORMAT  "lu"
479
480 typedef float   gfloat;
481 typedef double  gdouble;
482
483 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
484  * Since gldouble isn't used anywhere, just disable it for now */
485
486 #if 0
487 #ifdef HAVE_LONG_DOUBLE
488 typedef long double gldouble;
489 #else /* HAVE_LONG_DOUBLE */
490 typedef double gldouble;
491 #endif /* HAVE_LONG_DOUBLE */
492 #endif /* 0 */
493
494 typedef void* gpointer;
495 typedef const void *gconstpointer;
496
497
498 typedef gint32  gssize;
499 typedef guint32 gsize;
500 typedef guint32 GQuark;
501 typedef gint32  GTime;
502
503
504 /* Portable endian checks and conversions
505  *
506  * glibconfig.h defines G_BYTE_ORDER which expands to one of
507  * the below macros.
508  */
509 #define G_LITTLE_ENDIAN 1234
510 #define G_BIG_ENDIAN    4321
511 #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
512
513
514 /* Basic bit swapping functions
515  */
516 #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
517     (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
518     (((guint16) (val) & (guint16) 0xff00U) >> 8)))
519 #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
520     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
521     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
522     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
523     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
524
525 /* Intel specific stuff for speed
526  */
527 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
528 #  define GUINT16_SWAP_LE_BE_X86(val) \
529      (__extension__                                     \
530       ({ register guint16 __v;                          \
531          if (__builtin_constant_p (val))                \
532            __v = GUINT16_SWAP_LE_BE_CONSTANT (val);     \
533          else                                           \
534            __asm__ __const__ ("rorw $8, %w0"            \
535                               : "=r" (__v)              \
536                               : "0" ((guint16) (val))); \
537         __v; }))
538 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val))
539 #  if !defined(__i486__) && !defined(__i586__) \
540       && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__)
541 #     define GUINT32_SWAP_LE_BE_X86(val) \
542         (__extension__                                          \
543          ({ register guint32 __v;                               \
544             if (__builtin_constant_p (val))                     \
545               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
546           else                                                  \
547             __asm__ __const__ ("rorw $8, %w0\n\t"               \
548                                "rorl $16, %0\n\t"               \
549                                "rorw $8, %w0"                   \
550                                : "=r" (__v)                     \
551                                : "0" ((guint32) (val)));        \
552         __v; }))
553 #  else /* 486 and higher has bswap */
554 #     define GUINT32_SWAP_LE_BE_X86(val) \
555         (__extension__                                          \
556          ({ register guint32 __v;                               \
557             if (__builtin_constant_p (val))                     \
558               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
559           else                                                  \
560             __asm__ __const__ ("bswap %0"                       \
561                                : "=r" (__v)                     \
562                                : "0" ((guint32) (val)));        \
563         __v; }))
564 #  endif /* processor specific 32-bit stuff */
565 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val))
566 #else /* !__i386__ */
567 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
568 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
569 #endif /* __i386__ */
570
571 #ifdef G_HAVE_GINT64
572 #  define GUINT64_SWAP_LE_BE_CONSTANT(val)      ((guint64) ( \
573       (((guint64) (val) &                                               \
574         (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) |      \
575       (((guint64) (val) &                                               \
576         (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) |      \
577       (((guint64) (val) &                                               \
578         (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) |      \
579       (((guint64) (val) &                                               \
580         (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) <<  8) |      \
581       (((guint64) (val) &                                               \
582         (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >>  8) |      \
583       (((guint64) (val) &                                               \
584         (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) |      \
585       (((guint64) (val) &                                               \
586         (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) |      \
587       (((guint64) (val) &                                               \
588         (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56)))
589 #  if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
590 #    define GUINT64_SWAP_LE_BE_X86(val) \
591         (__extension__                                          \
592          ({ union { guint64 __ll;                               \
593                     guint32 __l[2]; } __r;                      \
594             if (__builtin_constant_p (val))                     \
595               __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val);     \
596             else                                                \
597               {                                                 \
598                 union { guint64 __ll;                           \
599                         guint32 __l[2]; } __w;                  \
600                 __w.__ll = ((guint64) val);                     \
601                 __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]);   \
602                 __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]);   \
603               }                                                 \
604           __r.__ll; }))
605 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val))
606 #  else /* !__i386__ */
607 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val))
608 #  endif
609 #endif
610
611 #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
612 #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
613 #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
614     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
615     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
616 #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
617     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
618     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
619
620 /* The G*_TO_?E() macros are defined in glibconfig.h.
621  * The transformation is symmetric, so the FROM just maps to the TO.
622  */
623 #define GINT16_FROM_LE(val)     (GINT16_TO_LE (val))
624 #define GUINT16_FROM_LE(val)    (GUINT16_TO_LE (val))
625 #define GINT16_FROM_BE(val)     (GINT16_TO_BE (val))
626 #define GUINT16_FROM_BE(val)    (GUINT16_TO_BE (val))
627 #define GINT32_FROM_LE(val)     (GINT32_TO_LE (val))
628 #define GUINT32_FROM_LE(val)    (GUINT32_TO_LE (val))
629 #define GINT32_FROM_BE(val)     (GINT32_TO_BE (val))
630 #define GUINT32_FROM_BE(val)    (GUINT32_TO_BE (val))
631
632 #ifdef G_HAVE_GINT64
633 #define GINT64_FROM_LE(val)     (GINT64_TO_LE (val))
634 #define GUINT64_FROM_LE(val)    (GUINT64_TO_LE (val))
635 #define GINT64_FROM_BE(val)     (GINT64_TO_BE (val))
636 #define GUINT64_FROM_BE(val)    (GUINT64_TO_BE (val))
637 #endif
638
639 #define GLONG_FROM_LE(val)      (GLONG_TO_LE (val))
640 #define GULONG_FROM_LE(val)     (GULONG_TO_LE (val))
641 #define GLONG_FROM_BE(val)      (GLONG_TO_BE (val))
642 #define GULONG_FROM_BE(val)     (GULONG_TO_BE (val))
643
644 #define GINT_FROM_LE(val)       (GINT_TO_LE (val))
645 #define GUINT_FROM_LE(val)      (GUINT_TO_LE (val))
646 #define GINT_FROM_BE(val)       (GINT_TO_BE (val))
647 #define GUINT_FROM_BE(val)      (GUINT_TO_BE (val))
648
649
650 /* Portable versions of host-network order stuff
651  */
652 #define g_ntohl(val) (GUINT32_FROM_BE (val))
653 #define g_ntohs(val) (GUINT16_FROM_BE (val))
654 #define g_htonl(val) (GUINT32_TO_BE (val))
655 #define g_htons(val) (GUINT16_TO_BE (val))
656
657
658 /* Glib version.
659  * we prefix variable declarations so they can
660  * properly get exported in windows dlls.
661  */
662 #ifdef NATIVE_WIN32
663 #  ifdef GLIB_COMPILATION
664 #    define GUTILS_C_VAR __declspec(dllexport)
665 #  else /* !GLIB_COMPILATION */
666 #    define GUTILS_C_VAR extern __declspec(dllimport)
667 #  endif /* !GLIB_COMPILATION */
668 #else /* !NATIVE_WIN32 */
669 #  define GUTILS_C_VAR extern
670 #endif /* !NATIVE_WIN32 */
671
672 GUTILS_C_VAR const guint glib_major_version;
673 GUTILS_C_VAR const guint glib_minor_version;
674 GUTILS_C_VAR const guint glib_micro_version;
675 GUTILS_C_VAR const guint glib_interface_age;
676 GUTILS_C_VAR const guint glib_binary_age;
677
678 #define GLIB_CHECK_VERSION(major,minor,micro)    \
679     (GLIB_MAJOR_VERSION > (major) || \
680      (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
681      (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
682       GLIB_MICRO_VERSION >= (micro)))
683
684 /* Forward declarations of glib types.
685  */
686 typedef struct _GAllocator      GAllocator;
687 typedef struct _GArray          GArray;
688 typedef struct _GByteArray      GByteArray;
689 typedef struct _GCache          GCache;
690 typedef struct _GCompletion     GCompletion;
691 typedef struct _GData           GData;
692 typedef struct _GDebugKey       GDebugKey;
693 typedef struct _GHashTable      GHashTable;
694 typedef struct _GHook           GHook;
695 typedef struct _GHookList       GHookList;
696 typedef struct _GList           GList;
697 typedef struct _GMemChunk       GMemChunk;
698 typedef struct _GNode           GNode;
699 typedef struct _GPtrArray       GPtrArray;
700 typedef struct _GQueue          GQueue;
701 typedef struct _GRelation       GRelation;
702 typedef struct _GScanner        GScanner;
703 typedef struct _GScannerConfig  GScannerConfig;
704 typedef struct _GSList          GSList;
705 typedef struct _GStack          GStack;
706 typedef struct _GString         GString;
707 typedef struct _GStringChunk    GStringChunk;
708 typedef struct _GTimer          GTimer;
709 typedef struct _GTree           GTree;
710 typedef struct _GTuples         GTuples;
711 typedef union  _GTokenValue     GTokenValue;
712 typedef struct _GIOChannel      GIOChannel;
713
714 typedef enum
715 {
716   G_TRAVERSE_LEAFS      = 1 << 0,
717   G_TRAVERSE_NON_LEAFS  = 1 << 1,
718   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
719   G_TRAVERSE_MASK       = 0x03
720 } GTraverseFlags;
721
722 typedef enum
723 {
724   G_IN_ORDER,
725   G_PRE_ORDER,
726   G_POST_ORDER,
727   G_LEVEL_ORDER
728 } GTraverseType;
729
730 /* Log level shift offset for user defined
731  * log levels (0-7 are used by GLib).
732  */
733 #define G_LOG_LEVEL_USER_SHIFT  (8)
734
735 /* Glib log levels and flags.
736  */
737 typedef enum
738 {
739   /* log flags */
740   G_LOG_FLAG_RECURSION          = 1 << 0,
741   G_LOG_FLAG_FATAL              = 1 << 1,
742   
743   /* GLib log levels */
744   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
745   G_LOG_LEVEL_CRITICAL          = 1 << 3,
746   G_LOG_LEVEL_WARNING           = 1 << 4,
747   G_LOG_LEVEL_MESSAGE           = 1 << 5,
748   G_LOG_LEVEL_INFO              = 1 << 6,
749   G_LOG_LEVEL_DEBUG             = 1 << 7,
750   
751   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
752 } GLogLevelFlags;
753
754 /* GLib log levels that are considered fatal by default */
755 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
756
757
758 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
759 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
760 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
761 typedef gint            (*GCompareFunc)         (gconstpointer  a,
762                                                  gconstpointer  b);
763 typedef gchar*          (*GCompletionFunc)      (gpointer);
764 typedef void            (*GDestroyNotify)       (gpointer       data);
765 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
766                                                  gpointer       data,
767                                                  gpointer       user_data);
768 typedef void            (*GFunc)                (gpointer       data,
769                                                  gpointer       user_data);
770 typedef guint           (*GHashFunc)            (gconstpointer  key);
771 typedef void            (*GFreeFunc)            (gpointer       data);
772 typedef void            (*GHFunc)               (gpointer       key,
773                                                  gpointer       value,
774                                                  gpointer       user_data);
775 typedef gboolean        (*GHRFunc)              (gpointer       key,
776                                                  gpointer       value,
777                                                  gpointer       user_data);
778 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
779                                                  GHook          *sibling);
780 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
781                                                  gpointer        data);
782 typedef void            (*GHookMarshaller)      (GHook          *hook,
783                                                  gpointer        data);
784 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
785                                                  gpointer        data);
786 typedef void            (*GHookFunc)            (gpointer        data);
787 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
788 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
789                                                  GHook          *hook);
790 typedef void            (*GLogFunc)             (const gchar   *log_domain,
791                                                  GLogLevelFlags log_level,
792                                                  const gchar   *message,
793                                                  gpointer       user_data);
794 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
795                                                  gpointer       data);
796 typedef void            (*GNodeForeachFunc)     (GNode         *node,
797                                                  gpointer       data);
798 typedef gint            (*GSearchFunc)          (gpointer       key,
799                                                  gpointer       data);
800 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
801                                                  gchar         *message,
802                                                  gint           error);
803 typedef gint            (*GTraverseFunc)        (gpointer       key,
804                                                  gpointer       value,
805                                                  gpointer       data);
806 typedef void            (*GVoidFunc)            (void);
807
808
809 struct _GList
810 {
811   gpointer data;
812   GList *next;
813   GList *prev;
814 };
815
816 struct _GSList
817 {
818   gpointer data;
819   GSList *next;
820 };
821
822 struct _GStack
823 {
824   GList *list;
825 };
826
827 struct _GQueue
828 {
829   GList *list;
830   GList *list_end;
831   guint list_size;
832 };
833
834 struct _GString
835 {
836   gchar *str;
837   gint len;
838 };
839
840 struct _GArray
841 {
842   gchar *data;
843   guint len;
844 };
845
846 struct _GByteArray
847 {
848   guint8 *data;
849   guint   len;
850 };
851
852 struct _GPtrArray
853 {
854   gpointer *pdata;
855   guint     len;
856 };
857
858 struct _GTuples
859 {
860   guint len;
861 };
862
863 struct _GDebugKey
864 {
865   gchar *key;
866   guint  value;
867 };
868
869
870 /* Doubly linked lists
871  */
872 void   g_list_push_allocator    (GAllocator     *allocator);
873 void   g_list_pop_allocator     (void);
874 GList* g_list_alloc             (void);
875 void   g_list_free              (GList          *list);
876 void   g_list_free_1            (GList          *list);
877 GList* g_list_append            (GList          *list,
878                                  gpointer        data);
879 GList* g_list_prepend           (GList          *list,
880                                  gpointer        data);
881 GList* g_list_insert            (GList          *list,
882                                  gpointer        data,
883                                  gint            position);
884 GList* g_list_insert_sorted     (GList          *list,
885                                  gpointer        data,
886                                  GCompareFunc    func);
887 GList* g_list_concat            (GList          *list1,
888                                  GList          *list2);
889 GList* g_list_delete            (GList          *list,
890                                  GList          *link);
891 GList* g_list_remove            (GList          *list,
892                                  gpointer        data);
893 GList* g_list_remove_link       (GList          *list,
894                                  GList          *llink);
895 GList* g_list_reverse           (GList          *list);
896 GList* g_list_copy              (GList          *list);
897 GList* g_list_nth               (GList          *list,
898                                  guint           n);
899 GList* g_list_find              (GList          *list,
900                                  gpointer        data);
901 GList* g_list_find_custom       (GList          *list,
902                                  gpointer        data,
903                                  GCompareFunc    func);
904 gint   g_list_position          (GList          *list,
905                                  GList          *llink);
906 gint   g_list_index             (GList          *list,
907                                  gpointer        data);
908 GList* g_list_last              (GList          *list);
909 GList* g_list_first             (GList          *list);
910 guint  g_list_length            (GList          *list);
911 void   g_list_foreach           (GList          *list,
912                                  GFunc           func,
913                                  gpointer        user_data);
914 GList* g_list_sort              (GList          *list,
915                                  GCompareFunc    compare_func);
916 gpointer g_list_nth_data        (GList          *list,
917                                  guint           n);
918 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
919 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
920
921
922 /* Singly linked lists
923  */
924 void    g_slist_push_allocator  (GAllocator     *allocator);
925 void    g_slist_pop_allocator   (void);
926 GSList* g_slist_alloc           (void);
927 void    g_slist_free            (GSList         *list);
928 void    g_slist_free_1          (GSList         *list);
929 GSList* g_slist_append          (GSList         *list,
930                                  gpointer        data);
931 GSList* g_slist_prepend         (GSList         *list,
932                                  gpointer        data);
933 GSList* g_slist_insert          (GSList         *list,
934                                  gpointer        data,
935                                  gint            position);
936 GSList* g_slist_insert_sorted   (GSList         *list,
937                                  gpointer        data,
938                                  GCompareFunc    func);
939 GSList* g_slist_concat          (GSList         *list1,
940                                  GSList         *list2);
941 GSList* g_slist_remove          (GSList         *list,
942                                  gpointer        data);
943 GSList* g_slist_remove_link     (GSList         *list,
944                                  GSList         *llink);
945 GSList* g_slist_reverse         (GSList         *list);
946 GSList* g_slist_copy            (GSList         *list);
947 GSList* g_slist_nth             (GSList         *list,
948                                  guint           n);
949 GSList* g_slist_find            (GSList         *list,
950                                  gpointer        data);
951 GSList* g_slist_find_custom     (GSList         *list,
952                                  gpointer        data,
953                                  GCompareFunc    func);
954 gint    g_slist_position        (GSList         *list,
955                                  GSList         *llink);
956 gint    g_slist_index           (GSList         *list,
957                                  gpointer        data);
958 GSList* g_slist_last            (GSList         *list);
959 guint   g_slist_length          (GSList         *list);
960 void    g_slist_foreach         (GSList         *list,
961                                  GFunc           func,
962                                  gpointer        user_data);
963 GSList*  g_slist_sort           (GSList          *list,
964                                  GCompareFunc    compare_func);
965 gpointer g_slist_nth_data       (GSList         *list,
966                                  guint           n);
967 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
968
969
970 /* Stacks
971  */
972
973 GStack * g_stack_new    (void);
974 void     g_stack_free   (GStack *stack);
975 gpointer g_stack_pop    (GStack *stack);
976
977 #define g_stack_empty(stack) \
978         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? FALSE : TRUE)
979
980 #define g_stack_peek(stack) \
981         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
982                 ((GStack *)(stack))->list->data : NULL)
983
984 #define g_stack_index(stack,ptr) \
985         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
986                 g_list_index (((GStack *)(stack))->list, (ptr)) : -1)
987
988 #define g_stack_push(stack,data) G_STMT_START {                         \
989             if ((GStack *)(stack))                                      \
990               ((GStack *)(stack))->list =                               \
991                   g_list_prepend (((GStack *)(stack))->list, (data));   \
992           } G_STMT_END
993
994
995
996 /* Queues
997  */
998
999 GQueue *        g_queue_new             (void);
1000 void            g_queue_free            (GQueue *q);
1001 guint           g_queue_get_size        (GQueue *q);
1002 void            g_queue_push_front      (GQueue *q, gpointer data);
1003 void            g_queue_push_back       (GQueue *q, gpointer data);
1004 gpointer        g_queue_pop_front       (GQueue *q);
1005 gpointer        g_queue_pop_back        (GQueue *q);
1006
1007 #define g_queue_empty(queue) \
1008         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? FALSE : TRUE)
1009
1010 #define g_queue_peek_front(queue) \
1011         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1012                 ((GQueue *)(queue))->list->data : NULL)
1013
1014 #define g_queue_peek_back(queue) \
1015         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list_end) ? \
1016                 ((GQueue *)(queue))->list_end->data : NULL)
1017
1018 #define g_queue_index(queue,ptr) \
1019         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1020                 g_list_index (((GQueue *)(queue))->list, (ptr)) : -1)
1021
1022 #define         g_queue_push            g_queue_push_back
1023 #define         g_queue_pop             g_queue_pop_front
1024 #define         g_queue_peek            g_queue_peek_front
1025
1026
1027
1028
1029
1030 /* Hash tables
1031  */
1032 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
1033                                          GCompareFunc    key_compare_func);
1034 void        g_hash_table_destroy        (GHashTable     *hash_table);
1035 void        g_hash_table_insert         (GHashTable     *hash_table,
1036                                          gpointer        key,
1037                                          gpointer        value);
1038 void        g_hash_table_remove         (GHashTable     *hash_table,
1039                                          gconstpointer   key);
1040 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
1041                                          gconstpointer   key);
1042 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
1043                                          gconstpointer   lookup_key,
1044                                          gpointer       *orig_key,
1045                                          gpointer       *value);
1046 void        g_hash_table_freeze         (GHashTable     *hash_table);
1047 void        g_hash_table_thaw           (GHashTable     *hash_table);
1048 void        g_hash_table_foreach        (GHashTable     *hash_table,
1049                                          GHFunc          func,
1050                                          gpointer        user_data);
1051 guint       g_hash_table_foreach_remove (GHashTable     *hash_table,
1052                                          GHRFunc         func,
1053                                          gpointer        user_data);
1054 guint       g_hash_table_size           (GHashTable     *hash_table);
1055
1056
1057 /* Caches
1058  */
1059 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
1060                                 GCacheDestroyFunc  value_destroy_func,
1061                                 GCacheDupFunc      key_dup_func,
1062                                 GCacheDestroyFunc  key_destroy_func,
1063                                 GHashFunc          hash_key_func,
1064                                 GHashFunc          hash_value_func,
1065                                 GCompareFunc       key_compare_func);
1066 void     g_cache_destroy       (GCache            *cache);
1067 gpointer g_cache_insert        (GCache            *cache,
1068                                 gpointer           key);
1069 void     g_cache_remove        (GCache            *cache,
1070                                 gpointer           value);
1071 void     g_cache_key_foreach   (GCache            *cache,
1072                                 GHFunc             func,
1073                                 gpointer           user_data);
1074 void     g_cache_value_foreach (GCache            *cache,
1075                                 GHFunc             func,
1076                                 gpointer           user_data);
1077
1078
1079 /* Balanced binary trees
1080  */
1081 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
1082 void     g_tree_destroy  (GTree         *tree);
1083 void     g_tree_insert   (GTree         *tree,
1084                           gpointer       key,
1085                           gpointer       value);
1086 void     g_tree_remove   (GTree         *tree,
1087                           gpointer       key);
1088 gpointer g_tree_lookup   (GTree         *tree,
1089                           gpointer       key);
1090 void     g_tree_traverse (GTree         *tree,
1091                           GTraverseFunc  traverse_func,
1092                           GTraverseType  traverse_type,
1093                           gpointer       data);
1094 gpointer g_tree_search   (GTree         *tree,
1095                           GSearchFunc    search_func,
1096                           gpointer       data);
1097 gint     g_tree_height   (GTree         *tree);
1098 gint     g_tree_nnodes   (GTree         *tree);
1099
1100
1101
1102 /* N-way tree implementation
1103  */
1104 struct _GNode
1105 {
1106   gpointer data;
1107   GNode   *next;
1108   GNode   *prev;
1109   GNode   *parent;
1110   GNode   *children;
1111 };
1112
1113 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
1114                                  ((GNode*) (node))->prev == NULL && \
1115                                  ((GNode*) (node))->next == NULL)
1116 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
1117
1118 void     g_node_push_allocator  (GAllocator       *allocator);
1119 void     g_node_pop_allocator   (void);
1120 GNode*   g_node_new             (gpointer          data);
1121 void     g_node_destroy         (GNode            *root);
1122 void     g_node_unlink          (GNode            *node);
1123 GNode*   g_node_insert          (GNode            *parent,
1124                                  gint              position,
1125                                  GNode            *node);
1126 GNode*   g_node_insert_before   (GNode            *parent,
1127                                  GNode            *sibling,
1128                                  GNode            *node);
1129 GNode*   g_node_prepend         (GNode            *parent,
1130                                  GNode            *node);
1131 guint    g_node_n_nodes         (GNode            *root,
1132                                  GTraverseFlags    flags);
1133 GNode*   g_node_get_root        (GNode            *node);
1134 gboolean g_node_is_ancestor     (GNode            *node,
1135                                  GNode            *descendant);
1136 guint    g_node_depth           (GNode            *node);
1137 GNode*   g_node_find            (GNode            *root,
1138                                  GTraverseType     order,
1139                                  GTraverseFlags    flags,
1140                                  gpointer          data);
1141
1142 /* convenience macros */
1143 #define g_node_append(parent, node)                             \
1144      g_node_insert_before ((parent), NULL, (node))
1145 #define g_node_insert_data(parent, position, data)              \
1146      g_node_insert ((parent), (position), g_node_new (data))
1147 #define g_node_insert_data_before(parent, sibling, data)        \
1148      g_node_insert_before ((parent), (sibling), g_node_new (data))
1149 #define g_node_prepend_data(parent, data)                       \
1150      g_node_prepend ((parent), g_node_new (data))
1151 #define g_node_append_data(parent, data)                        \
1152      g_node_insert_before ((parent), NULL, g_node_new (data))
1153
1154 /* traversal function, assumes that `node' is root
1155  * (only traverses `node' and its subtree).
1156  * this function is just a high level interface to
1157  * low level traversal functions, optimized for speed.
1158  */
1159 void     g_node_traverse        (GNode            *root,
1160                                  GTraverseType     order,
1161                                  GTraverseFlags    flags,
1162                                  gint              max_depth,
1163                                  GNodeTraverseFunc func,
1164                                  gpointer          data);
1165
1166 /* return the maximum tree height starting with `node', this is an expensive
1167  * operation, since we need to visit all nodes. this could be shortened by
1168  * adding `guint height' to struct _GNode, but then again, this is not very
1169  * often needed, and would make g_node_insert() more time consuming.
1170  */
1171 guint    g_node_max_height       (GNode *root);
1172
1173 void     g_node_children_foreach (GNode           *node,
1174                                   GTraverseFlags   flags,
1175                                   GNodeForeachFunc func,
1176                                   gpointer         data);
1177 void     g_node_reverse_children (GNode           *node);
1178 guint    g_node_n_children       (GNode           *node);
1179 GNode*   g_node_nth_child        (GNode           *node,
1180                                   guint            n);
1181 GNode*   g_node_last_child       (GNode           *node);
1182 GNode*   g_node_find_child       (GNode           *node,
1183                                   GTraverseFlags   flags,
1184                                   gpointer         data);
1185 gint     g_node_child_position   (GNode           *node,
1186                                   GNode           *child);
1187 gint     g_node_child_index      (GNode           *node,
1188                                   gpointer         data);
1189
1190 GNode*   g_node_first_sibling    (GNode           *node);
1191 GNode*   g_node_last_sibling     (GNode           *node);
1192
1193 #define  g_node_prev_sibling(node)      ((node) ? \
1194                                          ((GNode*) (node))->prev : NULL)
1195 #define  g_node_next_sibling(node)      ((node) ? \
1196                                          ((GNode*) (node))->next : NULL)
1197 #define  g_node_first_child(node)       ((node) ? \
1198                                          ((GNode*) (node))->children : NULL)
1199
1200
1201 /* Callback maintenance functions
1202  */
1203 #define G_HOOK_FLAG_USER_SHIFT  (4)
1204 typedef enum
1205 {
1206   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1207   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1208   G_HOOK_FLAG_MASK      = 0x0f
1209 } GHookFlagMask;
1210
1211 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
1212
1213 struct _GHookList
1214 {
1215   guint          seq_id;
1216   guint          hook_size;
1217   guint          is_setup : 1;
1218   GHook         *hooks;
1219   GMemChunk     *hook_memchunk;
1220   GHookFreeFunc  hook_free; /* virtual function */
1221   GHookFreeFunc  hook_destroy; /* virtual function */
1222 };
1223
1224 struct _GHook
1225 {
1226   gpointer       data;
1227   GHook         *next;
1228   GHook         *prev;
1229   guint          ref_count;
1230   guint          hook_id;
1231   guint          flags;
1232   gpointer       func;
1233   GDestroyNotify destroy;
1234 };
1235
1236 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
1237                                           G_HOOK_FLAG_ACTIVE) != 0)
1238 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
1239                                           G_HOOK_FLAG_IN_CALL) != 0)
1240 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
1241                                          G_HOOK_ACTIVE (hook))
1242 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
1243                                          ((GHook*) hook)->prev == NULL && \
1244                                          ((GHook*) hook)->hook_id == 0 && \
1245                                          ((GHook*) hook)->ref_count == 0)
1246
1247 void     g_hook_list_init               (GHookList              *hook_list,
1248                                          guint                   hook_size);
1249 void     g_hook_list_clear              (GHookList              *hook_list);
1250 GHook*   g_hook_alloc                   (GHookList              *hook_list);
1251 void     g_hook_free                    (GHookList              *hook_list,
1252                                          GHook                  *hook);
1253 void     g_hook_ref                     (GHookList              *hook_list,
1254                                          GHook                  *hook);
1255 void     g_hook_unref                   (GHookList              *hook_list,
1256                                          GHook                  *hook);
1257 gboolean g_hook_destroy                 (GHookList              *hook_list,
1258                                          guint                   hook_id);
1259 void     g_hook_destroy_link            (GHookList              *hook_list,
1260                                          GHook                  *hook);
1261 void     g_hook_prepend                 (GHookList              *hook_list,
1262                                          GHook                  *hook);
1263 void     g_hook_insert_before           (GHookList              *hook_list,
1264                                          GHook                  *sibling,
1265                                          GHook                  *hook);
1266 void     g_hook_insert_sorted           (GHookList              *hook_list,
1267                                          GHook                  *hook,
1268                                          GHookCompareFunc        func);
1269 GHook*   g_hook_get                     (GHookList              *hook_list,
1270                                          guint                   hook_id);
1271 GHook*   g_hook_find                    (GHookList              *hook_list,
1272                                          gboolean                need_valids,
1273                                          GHookFindFunc           func,
1274                                          gpointer                data);
1275 GHook*   g_hook_find_data               (GHookList              *hook_list,
1276                                          gboolean                need_valids,
1277                                          gpointer                data);
1278 GHook*   g_hook_find_func               (GHookList              *hook_list,
1279                                          gboolean                need_valids,
1280                                          gpointer                func);
1281 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1282                                          gboolean                need_valids,
1283                                          gpointer                func,
1284                                          gpointer                data);
1285 /* return the first valid hook, and increment its reference count */
1286 GHook*   g_hook_first_valid             (GHookList              *hook_list,
1287                                          gboolean                may_be_in_call);
1288 /* return the next valid hook with incremented reference count, and
1289  * decrement the reference count of the original hook
1290  */
1291 GHook*   g_hook_next_valid              (GHookList              *hook_list,
1292                                          GHook                  *hook,
1293                                          gboolean                may_be_in_call);
1294
1295 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1296 gint     g_hook_compare_ids             (GHook                  *new_hook,
1297                                          GHook                  *sibling);
1298
1299 /* convenience macros */
1300 #define  g_hook_append( hook_list, hook )  \
1301      g_hook_insert_before ((hook_list), NULL, (hook))
1302
1303 /* invoke all valid hooks with the (*GHookFunc) signature.
1304  */
1305 void     g_hook_list_invoke             (GHookList              *hook_list,
1306                                          gboolean                may_recurse);
1307 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1308  * and destroy the hook if FALSE is returned.
1309  */
1310 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1311                                          gboolean                may_recurse);
1312 /* invoke a marshaller on all valid hooks.
1313  */
1314 void     g_hook_list_marshal            (GHookList              *hook_list,
1315                                          gboolean                may_recurse,
1316                                          GHookMarshaller         marshaller,
1317                                          gpointer                data);
1318 void     g_hook_list_marshal_check      (GHookList              *hook_list,
1319                                          gboolean                may_recurse,
1320                                          GHookCheckMarshaller    marshaller,
1321                                          gpointer                data);
1322
1323
1324 /* Fatal error handlers.
1325  * g_on_error_query() will prompt the user to either
1326  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1327  * g_on_error_stack_trace() invokes gdb, which attaches to the current
1328  * process and shows a stack trace.
1329  * These function may cause different actions on non-unix platforms.
1330  * The prg_name arg is required by gdb to find the executable, if it is
1331  * passed as NULL, g_on_error_query() will try g_get_prgname().
1332  */
1333 void g_on_error_query (const gchar *prg_name);
1334 void g_on_error_stack_trace (const gchar *prg_name);
1335
1336
1337 /* Logging mechanism
1338  */
1339 extern          const gchar             *g_log_domain_glib;
1340 guint           g_log_set_handler       (const gchar    *log_domain,
1341                                          GLogLevelFlags  log_levels,
1342                                          GLogFunc        log_func,
1343                                          gpointer        user_data);
1344 void            g_log_remove_handler    (const gchar    *log_domain,
1345                                          guint           handler_id);
1346 void            g_log_default_handler   (const gchar    *log_domain,
1347                                          GLogLevelFlags  log_level,
1348                                          const gchar    *message,
1349                                          gpointer        unused_data);
1350 void            g_log                   (const gchar    *log_domain,
1351                                          GLogLevelFlags  log_level,
1352                                          const gchar    *format,
1353                                          ...) G_GNUC_PRINTF (3, 4);
1354 void            g_logv                  (const gchar    *log_domain,
1355                                          GLogLevelFlags  log_level,
1356                                          const gchar    *format,
1357                                          va_list         args);
1358 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1359                                          GLogLevelFlags  fatal_mask);
1360 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1361 #ifndef G_LOG_DOMAIN
1362 #define G_LOG_DOMAIN    ((gchar*) 0)
1363 #endif  /* G_LOG_DOMAIN */
1364 #ifdef  __GNUC__
1365 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1366                                                G_LOG_LEVEL_ERROR, \
1367                                                format, ##args)
1368 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1369                                                G_LOG_LEVEL_MESSAGE, \
1370                                                format, ##args)
1371 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1372                                                G_LOG_LEVEL_WARNING, \
1373                                                format, ##args)
1374 #else   /* !__GNUC__ */
1375 static void
1376 g_error (const gchar *format,
1377          ...)
1378 {
1379   va_list args;
1380   va_start (args, format);
1381   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1382   va_end (args);
1383 }
1384 static void
1385 g_message (const gchar *format,
1386            ...)
1387 {
1388   va_list args;
1389   va_start (args, format);
1390   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1391   va_end (args);
1392 }
1393 static void
1394 g_warning (const gchar *format,
1395            ...)
1396 {
1397   va_list args;
1398   va_start (args, format);
1399   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1400   va_end (args);
1401 }
1402 #endif  /* !__GNUC__ */
1403
1404 typedef void    (*GPrintFunc)           (const gchar    *string);
1405 void            g_print                 (const gchar    *format,
1406                                          ...) G_GNUC_PRINTF (1, 2);
1407 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1408 void            g_printerr              (const gchar    *format,
1409                                          ...) G_GNUC_PRINTF (1, 2);
1410 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1411
1412 /* deprecated compatibility functions, use g_log_set_handler() instead */
1413 typedef void            (*GErrorFunc)           (const gchar *str);
1414 typedef void            (*GWarningFunc)         (const gchar *str);
1415 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1416 GWarningFunc g_set_warning_handler (GWarningFunc func);
1417 GPrintFunc   g_set_message_handler (GPrintFunc func);
1418
1419
1420 /* Memory allocation and debugging
1421  */
1422 #ifdef USE_DMALLOC
1423
1424 #define g_malloc(size)       ((gpointer) MALLOC (size))
1425 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1426 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1427 #define g_free(mem)          FREE (mem)
1428
1429 #else /* !USE_DMALLOC */
1430
1431 gpointer g_malloc      (gulong    size);
1432 gpointer g_malloc0     (gulong    size);
1433 gpointer g_realloc     (gpointer  mem,
1434                         gulong    size);
1435 void     g_free        (gpointer  mem);
1436
1437 #endif /* !USE_DMALLOC */
1438
1439 void     g_mem_profile (void);
1440 void     g_mem_check   (gpointer  mem);
1441
1442 /* Generic allocators
1443  */
1444 GAllocator* g_allocator_new   (const gchar  *name,
1445                                guint         n_preallocs);
1446 void        g_allocator_free  (GAllocator   *allocator);
1447
1448 #define G_ALLOCATOR_LIST        (1)
1449 #define G_ALLOCATOR_SLIST       (2)
1450 #define G_ALLOCATOR_NODE        (3)
1451
1452
1453 /* "g_mem_chunk_new" creates a new memory chunk.
1454  * Memory chunks are used to allocate pieces of memory which are
1455  *  always the same size. Lists are a good example of such a data type.
1456  * The memory chunk allocates and frees blocks of memory as needed.
1457  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1458  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1459  *  fault...somewhere).
1460  *
1461  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1462  *  want to know what's going on inside do you?)
1463  */
1464
1465 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1466  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1467  *  atom. (They are also useful for lists which use MemChunk to allocate
1468  *  memory but are also part of the MemChunk implementation).
1469  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1470  */
1471
1472 #define G_ALLOC_ONLY      1
1473 #define G_ALLOC_AND_FREE  2
1474
1475 GMemChunk* g_mem_chunk_new     (gchar     *name,
1476                                 gint       atom_size,
1477                                 gulong     area_size,
1478                                 gint       type);
1479 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1480 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1481 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1482 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1483                                 gpointer   mem);
1484 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1485 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1486 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1487 void       g_mem_chunk_info    (void);
1488
1489 /* Ah yes...we have a "g_blow_chunks" function.
1490  * "g_blow_chunks" simply compresses all the chunks. This operation
1491  *  consists of freeing every memory area that should be freed (but
1492  *  which we haven't gotten around to doing yet). And, no,
1493  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1494  *  much better name than "g_mem_chunk_clean_all" or something
1495  *  similar.
1496  */
1497 void g_blow_chunks (void);
1498
1499
1500 /* Timer
1501  */
1502 GTimer* g_timer_new     (void);
1503 void    g_timer_destroy (GTimer  *timer);
1504 void    g_timer_start   (GTimer  *timer);
1505 void    g_timer_stop    (GTimer  *timer);
1506 void    g_timer_reset   (GTimer  *timer);
1507 gdouble g_timer_elapsed (GTimer  *timer,
1508                          gulong  *microseconds);
1509
1510
1511 /* String utility functions that modify a string argument or
1512  * return a constant string that must not be freed.
1513  */
1514 #define  G_STR_DELIMITERS       "_-|> <."
1515 gchar*   g_strdelimit           (gchar       *string,
1516                                  const gchar *delimiters,
1517                                  gchar        new_delimiter);
1518 gdouble  g_strtod               (const gchar *nptr,
1519                                  gchar      **endptr);
1520 gchar*   g_strerror             (gint         errnum);
1521 gchar*   g_strsignal            (gint         signum);
1522 gint     g_strcasecmp           (const gchar *s1,
1523                                  const gchar *s2);
1524 gint     g_strncasecmp          (const gchar *s1,
1525                                  const gchar *s2,
1526                                  guint        n);
1527 void     g_strdown              (gchar       *string);
1528 void     g_strup                (gchar       *string);
1529 void     g_strreverse           (gchar       *string);
1530 /* removes leading spaces */
1531 gchar*   g_strchug              (gchar        *string);
1532 /* removes trailing spaces */
1533 gchar*  g_strchomp              (gchar        *string);
1534 /* removes leading & trailing spaces */
1535 #define g_strstrip( string )    g_strchomp (g_strchug (string))
1536
1537 /* String utility functions that return a newly allocated string which
1538  * ought to be freed from the caller at some point.
1539  */
1540 gchar*   g_strdup               (const gchar *str);
1541 gchar*   g_strdup_printf        (const gchar *format,
1542                                  ...) G_GNUC_PRINTF (1, 2);
1543 gchar*   g_strdup_vprintf       (const gchar *format,
1544                                  va_list      args);
1545 gchar*   g_strndup              (const gchar *str,
1546                                  guint        n);
1547 gchar*   g_strnfill             (guint        length,
1548                                  gchar        fill_char);
1549 gchar*   g_strconcat            (const gchar *string1,
1550                                  ...); /* NULL terminated */
1551 gchar*   g_strjoin              (const gchar  *separator,
1552                                  ...); /* NULL terminated */
1553 gchar*   g_strescape            (gchar        *string);
1554 gpointer g_memdup               (gconstpointer mem,
1555                                  guint         byte_size);
1556
1557 /* NULL terminated string arrays.
1558  * g_strsplit() splits up string into max_tokens tokens at delim and
1559  * returns a newly allocated string array.
1560  * g_strjoinv() concatenates all of str_array's strings, sliding in an
1561  * optional separator, the returned string is newly allocated.
1562  * g_strfreev() frees the array itself and all of its strings.
1563  */
1564 gchar**  g_strsplit             (const gchar  *string,
1565                                  const gchar  *delimiter,
1566                                  gint          max_tokens);
1567 gchar*   g_strjoinv             (const gchar  *separator,
1568                                  gchar       **str_array);
1569 void     g_strfreev             (gchar       **str_array);
1570
1571
1572
1573 /* calculate a string size, guarranteed to fit format + args.
1574  */
1575 guint   g_printf_string_upper_bound (const gchar* format,
1576                                      va_list      args);
1577
1578
1579 /* Retrive static string info
1580  */
1581 gchar*  g_get_user_name         (void);
1582 gchar*  g_get_real_name         (void);
1583 gchar*  g_get_home_dir          (void);
1584 gchar*  g_get_tmp_dir           (void);
1585 gchar*  g_get_prgname           (void);
1586 void    g_set_prgname           (const gchar *prgname);
1587
1588
1589 /* Miscellaneous utility functions
1590  */
1591 guint   g_parse_debug_string    (const gchar *string,
1592                                  GDebugKey   *keys,
1593                                  guint        nkeys);
1594 gint    g_snprintf              (gchar       *string,
1595                                  gulong       n,
1596                                  gchar const *format,
1597                                  ...) G_GNUC_PRINTF (3, 4);
1598 gint    g_vsnprintf             (gchar       *string,
1599                                  gulong       n,
1600                                  gchar const *format,
1601                                  va_list      args);
1602 gchar*  g_basename              (const gchar *file_name);
1603 /* Check if a file name is an absolute path */
1604 gboolean g_path_is_absolute     (const gchar *file_name);
1605 /* In case of absolute paths, skip the root part */
1606 gchar*  g_path_skip_root        (gchar       *file_name);
1607
1608 /* strings are newly allocated with g_malloc() */
1609 gchar*  g_dirname               (const gchar *file_name);
1610 gchar*  g_get_current_dir       (void);
1611 gchar*  g_getenv                (const gchar *variable);
1612
1613
1614 /* we use a GLib function as a replacement for ATEXIT, so
1615  * the programmer is not required to check the return value
1616  * (if there is any in the implementation) and doesn't encounter
1617  * missing include files.
1618  */
1619 void    g_atexit                (GVoidFunc    func);
1620
1621
1622 /* Bit tests
1623  */
1624 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1625                                        gint    nth_bit);
1626 #ifdef  G_CAN_INLINE
1627 G_INLINE_FUNC gint
1628 g_bit_nth_lsf (guint32 mask,
1629                gint    nth_bit)
1630 {
1631   do
1632     {
1633       nth_bit++;
1634       if (mask & (1 << (guint) nth_bit))
1635         return nth_bit;
1636     }
1637   while (nth_bit < 32);
1638   return -1;
1639 }
1640 #endif  /* G_CAN_INLINE */
1641
1642 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1643                                        gint    nth_bit);
1644 #ifdef G_CAN_INLINE
1645 G_INLINE_FUNC gint
1646 g_bit_nth_msf (guint32 mask,
1647                gint    nth_bit)
1648 {
1649   if (nth_bit < 0)
1650     nth_bit = 32;
1651   do
1652     {
1653       nth_bit--;
1654       if (mask & (1 << (guint) nth_bit))
1655         return nth_bit;
1656     }
1657   while (nth_bit > 0);
1658   return -1;
1659 }
1660 #endif  /* G_CAN_INLINE */
1661
1662 G_INLINE_FUNC guint     g_bit_storage (guint number);
1663 #ifdef G_CAN_INLINE
1664 G_INLINE_FUNC guint
1665 g_bit_storage (guint number)
1666 {
1667   register guint n_bits = 0;
1668   
1669   do
1670     {
1671       n_bits++;
1672       number >>= 1;
1673     }
1674   while (number);
1675   return n_bits;
1676 }
1677 #endif  /* G_CAN_INLINE */
1678
1679 /* String Chunks
1680  */
1681 GStringChunk* g_string_chunk_new           (gint size);
1682 void          g_string_chunk_free          (GStringChunk *chunk);
1683 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1684                                             const gchar  *string);
1685 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1686                                             const gchar  *string);
1687
1688
1689 /* Strings
1690  */
1691 GString* g_string_new       (const gchar *init);
1692 GString* g_string_sized_new (guint        dfl_size);
1693 void     g_string_free      (GString     *string,
1694                              gint         free_segment);
1695 GString* g_string_assign    (GString     *lval,
1696                              const gchar *rval);
1697 GString* g_string_truncate  (GString     *string,
1698                              gint         len);
1699 GString* g_string_append    (GString     *string,
1700                              const gchar *val);
1701 GString* g_string_append_c  (GString     *string,
1702                              gchar        c);
1703 GString* g_string_prepend   (GString     *string,
1704                              const gchar *val);
1705 GString* g_string_prepend_c (GString     *string,
1706                              gchar        c);
1707 GString* g_string_insert    (GString     *string,
1708                              gint         pos,
1709                              const gchar *val);
1710 GString* g_string_insert_c  (GString     *string,
1711                              gint         pos,
1712                              gchar        c);
1713 GString* g_string_erase     (GString     *string,
1714                              gint         pos,
1715                              gint         len);
1716 GString* g_string_down      (GString     *string);
1717 GString* g_string_up        (GString     *string);
1718 void     g_string_sprintf   (GString     *string,
1719                              const gchar *format,
1720                              ...) G_GNUC_PRINTF (2, 3);
1721 void     g_string_sprintfa  (GString     *string,
1722                              const gchar *format,
1723                              ...) G_GNUC_PRINTF (2, 3);
1724
1725
1726 /* Resizable arrays, remove fills any cleared spot and shortens the
1727  * array, while preserving the order. remove_fast will distort the
1728  * order by moving the last element to the position of the removed 
1729  */
1730
1731 #define g_array_append_val(a,v)   g_array_append_vals (a, &v, 1)
1732 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &v, 1)
1733 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1)
1734 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
1735
1736 GArray* g_array_new               (gboolean         zero_terminated,
1737                                    gboolean         clear,
1738                                    guint            element_size);
1739 void    g_array_free              (GArray          *array,
1740                                    gboolean         free_segment);
1741 GArray* g_array_append_vals       (GArray          *array,
1742                                    gconstpointer    data,
1743                                    guint            len);
1744 GArray* g_array_prepend_vals      (GArray          *array,
1745                                    gconstpointer    data,
1746                                    guint            len);
1747 GArray* g_array_insert_vals       (GArray          *array,
1748                                    guint            index,
1749                                    gconstpointer    data,
1750                                    guint            len);
1751 GArray* g_array_set_size          (GArray          *array,
1752                                    guint            length);
1753 GArray* g_array_remove_index      (GArray          *array,
1754                                    guint            index);
1755 GArray* g_array_remove_index_fast (GArray          *array,
1756                                    guint            index);
1757
1758 /* Resizable pointer array.  This interface is much less complicated
1759  * than the above.  Add appends appends a pointer.  Remove fills any
1760  * cleared spot and shortens the array. remove_fast will again distort
1761  * order.  
1762  */
1763 #define     g_ptr_array_index(array,index) (array->pdata)[index]
1764 GPtrArray*  g_ptr_array_new                (void);
1765 void        g_ptr_array_free               (GPtrArray   *array,
1766                                             gboolean     free_seg);
1767 void        g_ptr_array_set_size           (GPtrArray   *array,
1768                                             gint         length);
1769 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1770                                             guint        index);
1771 gpointer    g_ptr_array_remove_index_fast  (GPtrArray   *array,
1772                                             guint        index);
1773 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1774                                             gpointer     data);
1775 gboolean    g_ptr_array_remove_fast        (GPtrArray   *array,
1776                                             gpointer     data);
1777 void        g_ptr_array_add                (GPtrArray   *array,
1778                                             gpointer     data);
1779
1780 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1781  * but type-safe.
1782  */
1783
1784 GByteArray* g_byte_array_new               (void);
1785 void        g_byte_array_free              (GByteArray   *array,
1786                                             gboolean      free_segment);
1787 GByteArray* g_byte_array_append            (GByteArray   *array,
1788                                             const guint8 *data,
1789                                             guint         len);
1790 GByteArray* g_byte_array_prepend           (GByteArray   *array,
1791                                             const guint8 *data,
1792                                             guint         len);
1793 GByteArray* g_byte_array_set_size          (GByteArray   *array,
1794                                             guint         length);
1795 GByteArray* g_byte_array_remove_index      (GByteArray   *array,
1796                                             guint         index);
1797 GByteArray* g_byte_array_remove_index_fast (GByteArray   *array,
1798                                             guint         index);
1799
1800
1801 /* Hash Functions
1802  */
1803 gint  g_str_equal (gconstpointer   v,
1804                    gconstpointer   v2);
1805 guint g_str_hash  (gconstpointer   v);
1806
1807 gint  g_int_equal (gconstpointer   v,
1808                    gconstpointer   v2);
1809 guint g_int_hash  (gconstpointer   v);
1810
1811 /* This "hash" function will just return the key's adress as an
1812  * unsigned integer. Useful for hashing on plain adresses or
1813  * simple integer values.
1814  * passing NULL into g_hash_table_new() as GHashFunc has the
1815  * same effect as passing g_direct_hash().
1816  */
1817 guint g_direct_hash  (gconstpointer v);
1818 gint  g_direct_equal (gconstpointer v,
1819                       gconstpointer v2);
1820
1821
1822 /* Quarks (string<->id association)
1823  */
1824 GQuark    g_quark_try_string            (const gchar    *string);
1825 GQuark    g_quark_from_static_string    (const gchar    *string);
1826 GQuark    g_quark_from_string           (const gchar    *string);
1827 gchar*    g_quark_to_string             (GQuark          quark);
1828
1829
1830 /* Keyed Data List
1831  */
1832 void      g_datalist_init                (GData          **datalist);
1833 void      g_datalist_clear               (GData          **datalist);
1834 gpointer  g_datalist_id_get_data         (GData          **datalist,
1835                                           GQuark           key_id);
1836 void      g_datalist_id_set_data_full    (GData          **datalist,
1837                                           GQuark           key_id,
1838                                           gpointer         data,
1839                                           GDestroyNotify   destroy_func);
1840 void      g_datalist_id_remove_no_notify (GData          **datalist,
1841                                           GQuark           key_id);
1842 void      g_datalist_foreach             (GData          **datalist,
1843                                           GDataForeachFunc func,
1844                                           gpointer         user_data);
1845 #define   g_datalist_id_set_data(dl, q, d)      \
1846      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1847 #define   g_datalist_id_remove_data(dl, q)      \
1848      g_datalist_id_set_data ((dl), (q), NULL)
1849 #define   g_datalist_get_data(dl, k)            \
1850      (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1851 #define   g_datalist_set_data_full(dl, k, d, f) \
1852      g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1853 #define   g_datalist_remove_no_notify(dl, k)    \
1854      g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1855 #define   g_datalist_set_data(dl, k, d)         \
1856      g_datalist_set_data_full ((dl), (k), (d), NULL)
1857 #define   g_datalist_remove_data(dl, k)         \
1858      g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1859
1860
1861 /* Location Associated Keyed Data
1862  */
1863 void      g_dataset_destroy             (gconstpointer    dataset_location);
1864 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1865                                          GQuark           key_id);
1866 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1867                                          GQuark           key_id,
1868                                          gpointer         data,
1869                                          GDestroyNotify   destroy_func);
1870 void      g_dataset_id_remove_no_notify (gconstpointer    dataset_location,
1871                                          GQuark           key_id);
1872 void      g_dataset_foreach             (gconstpointer    dataset_location,
1873                                          GDataForeachFunc func,
1874                                          gpointer         user_data);
1875 #define   g_dataset_id_set_data(l, k, d)        \
1876      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1877 #define   g_dataset_id_remove_data(l, k)        \
1878      g_dataset_id_set_data ((l), (k), NULL)
1879 #define   g_dataset_get_data(l, k)              \
1880      (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1881 #define   g_dataset_set_data_full(l, k, d, f)   \
1882      g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1883 #define   g_dataset_remove_no_notify(l, k)      \
1884      g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1885 #define   g_dataset_set_data(l, k, d)           \
1886      g_dataset_set_data_full ((l), (k), (d), NULL)
1887 #define   g_dataset_remove_data(l, k)           \
1888      g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1889
1890
1891 /* GScanner: Flexible lexical scanner for general purpose.
1892  */
1893
1894 /* Character sets */
1895 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1896 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1897 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1898                         "\307\310\311\312\313\314\315\316\317\320"\
1899                         "\321\322\323\324\325\326"\
1900                         "\330\331\332\333\334\335\336"
1901 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1902                         "\347\350\351\352\353\354\355\356\357\360"\
1903                         "\361\362\363\364\365\366"\
1904                         "\370\371\372\373\374\375\376\377"
1905
1906 /* Error types */
1907 typedef enum
1908 {
1909   G_ERR_UNKNOWN,
1910   G_ERR_UNEXP_EOF,
1911   G_ERR_UNEXP_EOF_IN_STRING,
1912   G_ERR_UNEXP_EOF_IN_COMMENT,
1913   G_ERR_NON_DIGIT_IN_CONST,
1914   G_ERR_DIGIT_RADIX,
1915   G_ERR_FLOAT_RADIX,
1916   G_ERR_FLOAT_MALFORMED
1917 } GErrorType;
1918
1919 /* Token types */
1920 typedef enum
1921 {
1922   G_TOKEN_EOF                   =   0,
1923   
1924   G_TOKEN_LEFT_PAREN            = '(',
1925   G_TOKEN_RIGHT_PAREN           = ')',
1926   G_TOKEN_LEFT_CURLY            = '{',
1927   G_TOKEN_RIGHT_CURLY           = '}',
1928   G_TOKEN_LEFT_BRACE            = '[',
1929   G_TOKEN_RIGHT_BRACE           = ']',
1930   G_TOKEN_EQUAL_SIGN            = '=',
1931   G_TOKEN_COMMA                 = ',',
1932   
1933   G_TOKEN_NONE                  = 256,
1934   
1935   G_TOKEN_ERROR,
1936   
1937   G_TOKEN_CHAR,
1938   G_TOKEN_BINARY,
1939   G_TOKEN_OCTAL,
1940   G_TOKEN_INT,
1941   G_TOKEN_HEX,
1942   G_TOKEN_FLOAT,
1943   G_TOKEN_STRING,
1944   
1945   G_TOKEN_SYMBOL,
1946   G_TOKEN_IDENTIFIER,
1947   G_TOKEN_IDENTIFIER_NULL,
1948   
1949   G_TOKEN_COMMENT_SINGLE,
1950   G_TOKEN_COMMENT_MULTI,
1951   G_TOKEN_LAST
1952 } GTokenType;
1953
1954 union   _GTokenValue
1955 {
1956   gpointer      v_symbol;
1957   gchar         *v_identifier;
1958   gulong        v_binary;
1959   gulong        v_octal;
1960   gulong        v_int;
1961   gdouble       v_float;
1962   gulong        v_hex;
1963   gchar         *v_string;
1964   gchar         *v_comment;
1965   guchar        v_char;
1966   guint         v_error;
1967 };
1968
1969 struct  _GScannerConfig
1970 {
1971   /* Character sets
1972    */
1973   gchar         *cset_skip_characters;          /* default: " \t\n" */
1974   gchar         *cset_identifier_first;
1975   gchar         *cset_identifier_nth;
1976   gchar         *cpair_comment_single;          /* default: "#\n" */
1977   
1978   /* Should symbol lookup work case sensitive?
1979    */
1980   guint         case_sensitive : 1;
1981   
1982   /* Boolean values to be adjusted "on the fly"
1983    * to configure scanning behaviour.
1984    */
1985   guint         skip_comment_multi : 1;         /* C like comment */
1986   guint         skip_comment_single : 1;        /* single line comment */
1987   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1988   guint         scan_identifier : 1;
1989   guint         scan_identifier_1char : 1;
1990   guint         scan_identifier_NULL : 1;
1991   guint         scan_symbols : 1;
1992   guint         scan_binary : 1;
1993   guint         scan_octal : 1;
1994   guint         scan_float : 1;
1995   guint         scan_hex : 1;                   /* `0x0ff0' */
1996   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1997   guint         scan_string_sq : 1;             /* string: 'anything' */
1998   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1999   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
2000   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
2001   guint         identifier_2_string : 1;
2002   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
2003   guint         symbol_2_token : 1;
2004   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
2005 };
2006
2007 struct  _GScanner
2008 {
2009   /* unused fields */
2010   gpointer              user_data;
2011   guint                 max_parse_errors;
2012   
2013   /* g_scanner_error() increments this field */
2014   guint                 parse_errors;
2015   
2016   /* name of input stream, featured by the default message handler */
2017   const gchar           *input_name;
2018   
2019   /* data pointer for derived structures */
2020   gpointer              derived_data;
2021   
2022   /* link into the scanner configuration */
2023   GScannerConfig        *config;
2024   
2025   /* fields filled in after g_scanner_get_next_token() */
2026   GTokenType            token;
2027   GTokenValue           value;
2028   guint                 line;
2029   guint                 position;
2030   
2031   /* fields filled in after g_scanner_peek_next_token() */
2032   GTokenType            next_token;
2033   GTokenValue           next_value;
2034   guint                 next_line;
2035   guint                 next_position;
2036   
2037   /* to be considered private */
2038   GHashTable            *symbol_table;
2039   gint                  input_fd;
2040   const gchar           *text;
2041   const gchar           *text_end;
2042   gchar                 *buffer;
2043   guint                 scope_id;
2044   
2045   /* handler function for _warn and _error */
2046   GScannerMsgFunc       msg_handler;
2047 };
2048
2049 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
2050 void            g_scanner_destroy               (GScanner       *scanner);
2051 void            g_scanner_input_file            (GScanner       *scanner,
2052                                                  gint           input_fd);
2053 void            g_scanner_sync_file_offset      (GScanner       *scanner);
2054 void            g_scanner_input_text            (GScanner       *scanner,
2055                                                  const  gchar   *text,
2056                                                  guint          text_len);
2057 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
2058 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
2059 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
2060 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
2061 guint           g_scanner_cur_line              (GScanner       *scanner);
2062 guint           g_scanner_cur_position          (GScanner       *scanner);
2063 gboolean        g_scanner_eof                   (GScanner       *scanner);
2064 guint           g_scanner_set_scope             (GScanner       *scanner,
2065                                                  guint           scope_id);
2066 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
2067                                                  guint           scope_id,
2068                                                  const gchar    *symbol,
2069                                                  gpointer       value);
2070 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
2071                                                  guint           scope_id,
2072                                                  const gchar    *symbol);
2073 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
2074                                                  guint           scope_id,
2075                                                  const gchar    *symbol);
2076 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
2077                                                  guint           scope_id,
2078                                                  GHFunc          func,
2079                                                  gpointer        user_data);
2080 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
2081                                                  const gchar    *symbol);
2082 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
2083 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
2084 void            g_scanner_unexp_token           (GScanner       *scanner,
2085                                                  GTokenType     expected_token,
2086                                                  const gchar    *identifier_spec,
2087                                                  const gchar    *symbol_spec,
2088                                                  const gchar    *symbol_name,
2089                                                  const gchar    *message,
2090                                                  gint            is_error);
2091 void            g_scanner_error                 (GScanner       *scanner,
2092                                                  const gchar    *format,
2093                                                  ...) G_GNUC_PRINTF (2,3);
2094 void            g_scanner_warn                  (GScanner       *scanner,
2095                                                  const gchar    *format,
2096                                                  ...) G_GNUC_PRINTF (2,3);
2097 gint            g_scanner_stat_mode             (const gchar    *filename);
2098 /* keep downward source compatibility */
2099 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
2100   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
2101 } G_STMT_END
2102 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
2103   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2104 } G_STMT_END
2105 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2106   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2107 } G_STMT_END
2108
2109
2110 /* GCompletion
2111  */
2112
2113 struct _GCompletion
2114 {
2115   GList* items;
2116   GCompletionFunc func;
2117   
2118   gchar* prefix;
2119   GList* cache;
2120 };
2121
2122 GCompletion* g_completion_new          (GCompletionFunc func);
2123 void         g_completion_add_items    (GCompletion*    cmp,
2124                                         GList*          items);
2125 void         g_completion_remove_items (GCompletion*    cmp,
2126                                         GList*          items);
2127 void         g_completion_clear_items  (GCompletion*    cmp);
2128 GList*       g_completion_complete     (GCompletion*    cmp,
2129                                         gchar*          prefix,
2130                                         gchar**         new_prefix);
2131 void         g_completion_free         (GCompletion*    cmp);
2132
2133
2134 /* GDate
2135  *
2136  * Date calculations (not time for now, to be resolved). These are a
2137  * mutant combination of Steffen Beyer's DateCalc routines
2138  * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
2139  * date routines (written for in-house software).  Written by Havoc
2140  * Pennington <hp@pobox.com> 
2141  */
2142
2143 typedef guint16 GDateYear;
2144 typedef guint8  GDateDay;   /* day of the month */
2145 typedef struct _GDate GDate;
2146 /* make struct tm known without having to include time.h */
2147 struct tm;
2148
2149 /* enum used to specify order of appearance in parsed date strings */
2150 typedef enum
2151 {
2152   G_DATE_DAY   = 0,
2153   G_DATE_MONTH = 1,
2154   G_DATE_YEAR  = 2
2155 } GDateDMY;
2156
2157 /* actual week and month values */
2158 typedef enum
2159 {
2160   G_DATE_BAD_WEEKDAY  = 0,
2161   G_DATE_MONDAY       = 1,
2162   G_DATE_TUESDAY      = 2,
2163   G_DATE_WEDNESDAY    = 3,
2164   G_DATE_THURSDAY     = 4,
2165   G_DATE_FRIDAY       = 5,
2166   G_DATE_SATURDAY     = 6,
2167   G_DATE_SUNDAY       = 7
2168 } GDateWeekday;
2169 typedef enum
2170 {
2171   G_DATE_BAD_MONTH = 0,
2172   G_DATE_JANUARY   = 1,
2173   G_DATE_FEBRUARY  = 2,
2174   G_DATE_MARCH     = 3,
2175   G_DATE_APRIL     = 4,
2176   G_DATE_MAY       = 5,
2177   G_DATE_JUNE      = 6,
2178   G_DATE_JULY      = 7,
2179   G_DATE_AUGUST    = 8,
2180   G_DATE_SEPTEMBER = 9,
2181   G_DATE_OCTOBER   = 10,
2182   G_DATE_NOVEMBER  = 11,
2183   G_DATE_DECEMBER  = 12
2184 } GDateMonth;
2185
2186 #define G_DATE_BAD_JULIAN 0U
2187 #define G_DATE_BAD_DAY    0U
2188 #define G_DATE_BAD_YEAR   0U
2189
2190 /* Note: directly manipulating structs is generally a bad idea, but
2191  * in this case it's an *incredibly* bad idea, because all or part
2192  * of this struct can be invalid at any given time. Use the functions,
2193  * or you will get hosed, I promise.
2194  */
2195 struct _GDate
2196
2197   guint julian_days : 32; /* julian days representation - we use a
2198                            *  bitfield hoping that 64 bit platforms
2199                            *  will pack this whole struct in one big
2200                            *  int 
2201                            */
2202
2203   guint julian : 1;    /* julian is valid */
2204   guint dmy    : 1;    /* dmy is valid */
2205
2206   /* DMY representation */
2207   guint day    : 6;  
2208   guint month  : 4; 
2209   guint year   : 16; 
2210 };
2211
2212 /* g_date_new() returns an invalid date, you then have to _set() stuff 
2213  * to get a usable object. You can also allocate a GDate statically,
2214  * then call g_date_clear() to initialize.
2215  */
2216 GDate*       g_date_new                   (void);
2217 GDate*       g_date_new_dmy               (GDateDay     day, 
2218                                            GDateMonth   month, 
2219                                            GDateYear    year);
2220 GDate*       g_date_new_julian            (guint32      julian_day);
2221 void         g_date_free                  (GDate       *date);
2222
2223 /* check g_date_valid() after doing an operation that might fail, like
2224  * _parse.  Almost all g_date operations are undefined on invalid
2225  * dates (the exceptions are the mutators, since you need those to
2226  * return to validity).  
2227  */
2228 gboolean     g_date_valid                 (GDate       *date);
2229 gboolean     g_date_valid_day             (GDateDay     day);
2230 gboolean     g_date_valid_month           (GDateMonth   month);
2231 gboolean     g_date_valid_year            (GDateYear    year);
2232 gboolean     g_date_valid_weekday         (GDateWeekday weekday);
2233 gboolean     g_date_valid_julian          (guint32      julian_date);
2234 gboolean     g_date_valid_dmy             (GDateDay     day,
2235                                            GDateMonth   month,
2236                                            GDateYear    year);
2237
2238 GDateWeekday g_date_weekday               (GDate       *date);
2239 GDateMonth   g_date_month                 (GDate       *date);
2240 GDateYear    g_date_year                  (GDate       *date);
2241 GDateDay     g_date_day                   (GDate       *date);
2242 guint32      g_date_julian                (GDate       *date);
2243 guint        g_date_day_of_year           (GDate       *date);
2244
2245 /* First monday/sunday is the start of week 1; if we haven't reached
2246  * that day, return 0. These are not ISO weeks of the year; that
2247  * routine needs to be added.
2248  * these functions return the number of weeks, starting on the
2249  * corrsponding day
2250  */
2251 guint        g_date_monday_week_of_year   (GDate      *date);
2252 guint        g_date_sunday_week_of_year   (GDate      *date);
2253
2254 /* If you create a static date struct you need to clear it to get it
2255  * in a sane state before use. You can clear a whole array at
2256  * once with the ndates argument.
2257  */
2258 void         g_date_clear                 (GDate       *date, 
2259                                            guint        n_dates);
2260
2261 /* The parse routine is meant for dates typed in by a user, so it
2262  * permits many formats but tries to catch common typos. If your data
2263  * needs to be strictly validated, it is not an appropriate function.
2264  */
2265 void         g_date_set_parse             (GDate       *date,
2266                                            const gchar *str);
2267 void         g_date_set_time              (GDate       *date, 
2268                                            GTime        time);
2269 void         g_date_set_month             (GDate       *date, 
2270                                            GDateMonth   month);
2271 void         g_date_set_day               (GDate       *date, 
2272                                            GDateDay     day);
2273 void         g_date_set_year              (GDate       *date,
2274                                            GDateYear    year);
2275 void         g_date_set_dmy               (GDate       *date,
2276                                            GDateDay     day,
2277                                            GDateMonth   month,
2278                                            GDateYear    y);
2279 void         g_date_set_julian            (GDate       *date,
2280                                            guint32      julian_date);
2281 gboolean     g_date_is_first_of_month     (GDate       *date);
2282 gboolean     g_date_is_last_of_month      (GDate       *date);
2283
2284 /* To go forward by some number of weeks just go forward weeks*7 days */
2285 void         g_date_add_days              (GDate       *date, 
2286                                            guint        n_days);
2287 void         g_date_subtract_days         (GDate       *date, 
2288                                            guint        n_days);
2289
2290 /* If you add/sub months while day > 28, the day might change */
2291 void         g_date_add_months            (GDate       *date,
2292                                            guint        n_months);
2293 void         g_date_subtract_months       (GDate       *date,
2294                                            guint        n_months);
2295
2296 /* If it's feb 29, changing years can move you to the 28th */
2297 void         g_date_add_years             (GDate       *date,
2298                                            guint        n_years);
2299 void         g_date_subtract_years        (GDate       *date,
2300                                            guint        n_years);
2301 gboolean     g_date_is_leap_year          (GDateYear    year);
2302 guint8       g_date_days_in_month         (GDateMonth   month, 
2303                                            GDateYear    year);
2304 guint8       g_date_monday_weeks_in_year  (GDateYear    year);
2305 guint8       g_date_sunday_weeks_in_year  (GDateYear    year);
2306
2307 /* qsort-friendly (with a cast...) */
2308 gint         g_date_compare               (GDate       *lhs,
2309                                            GDate       *rhs);
2310 void         g_date_to_struct_tm          (GDate       *date,
2311                                            struct tm   *tm);
2312
2313 /* Just like strftime() except you can only use date-related formats.
2314  *   Using a time format is undefined.
2315  */
2316 gsize        g_date_strftime              (gchar       *s,
2317                                            gsize        slen,
2318                                            const gchar *format,
2319                                            GDate       *date);
2320
2321
2322 /* GRelation
2323  *
2324  * Indexed Relations.  Imagine a really simple table in a
2325  * database.  Relations are not ordered.  This data type is meant for
2326  * maintaining a N-way mapping.
2327  *
2328  * g_relation_new() creates a relation with FIELDS fields
2329  *
2330  * g_relation_destroy() frees all resources
2331  * g_tuples_destroy() frees the result of g_relation_select()
2332  *
2333  * g_relation_index() indexes relation FIELD with the provided
2334  *   equality and hash functions.  this must be done before any
2335  *   calls to insert are made.
2336  *
2337  * g_relation_insert() inserts a new tuple.  you are expected to
2338  *   provide the right number of fields.
2339  *
2340  * g_relation_delete() deletes all relations with KEY in FIELD
2341  * g_relation_select() returns ...
2342  * g_relation_count() counts ...
2343  */
2344
2345 GRelation* g_relation_new     (gint         fields);
2346 void       g_relation_destroy (GRelation   *relation);
2347 void       g_relation_index   (GRelation   *relation,
2348                                gint         field,
2349                                GHashFunc    hash_func,
2350                                GCompareFunc key_compare_func);
2351 void       g_relation_insert  (GRelation   *relation,
2352                                ...);
2353 gint       g_relation_delete  (GRelation   *relation,
2354                                gconstpointer  key,
2355                                gint         field);
2356 GTuples*   g_relation_select  (GRelation   *relation,
2357                                gconstpointer  key,
2358                                gint         field);
2359 gint       g_relation_count   (GRelation   *relation,
2360                                gconstpointer  key,
2361                                gint         field);
2362 gboolean   g_relation_exists  (GRelation   *relation,
2363                                ...);
2364 void       g_relation_print   (GRelation   *relation);
2365
2366 void       g_tuples_destroy   (GTuples     *tuples);
2367 gpointer   g_tuples_index     (GTuples     *tuples,
2368                                gint         index,
2369                                gint         field);
2370
2371
2372 /* Prime numbers.
2373  */
2374
2375 /* This function returns prime numbers spaced by approximately 1.5-2.0
2376  * and is for use in resizing data structures which prefer
2377  * prime-valued sizes.  The closest spaced prime function returns the
2378  * next largest prime, or the highest it knows about which is about
2379  * MAXINT/4.
2380  */
2381 guint      g_spaced_primes_closest (guint num);
2382
2383
2384 /* GIOChannel
2385  */
2386
2387 typedef struct _GIOFuncs GIOFuncs;
2388 typedef enum
2389 {
2390   G_IO_ERROR_NONE,
2391   G_IO_ERROR_AGAIN,
2392   G_IO_ERROR_INVAL,
2393   G_IO_ERROR_UNKNOWN
2394 } GIOError;
2395 typedef enum
2396 {
2397   G_SEEK_CUR,
2398   G_SEEK_SET,
2399   G_SEEK_END
2400 } GSeekType;
2401 typedef enum
2402 {
2403   G_IO_IN       GLIB_SYSDEF_POLLIN,
2404   G_IO_OUT      GLIB_SYSDEF_POLLOUT,
2405   G_IO_PRI      GLIB_SYSDEF_POLLPRI,
2406   G_IO_ERR      GLIB_SYSDEF_POLLERR,
2407   G_IO_HUP      GLIB_SYSDEF_POLLHUP,
2408   G_IO_NVAL     GLIB_SYSDEF_POLLNVAL
2409 } GIOCondition;
2410
2411 struct _GIOChannel
2412 {
2413   guint channel_flags;
2414   guint ref_count;
2415   GIOFuncs *funcs;
2416 };
2417
2418 typedef gboolean (*GIOFunc) (GIOChannel   *source,
2419                              GIOCondition  condition,
2420                              gpointer      data);
2421 struct _GIOFuncs
2422 {
2423   GIOError (*io_read)   (GIOChannel     *channel, 
2424                          gchar          *buf, 
2425                          guint           count,
2426                          guint          *bytes_read);
2427   GIOError (*io_write)  (GIOChannel     *channel, 
2428                          gchar          *buf, 
2429                          guint           count,
2430                          guint          *bytes_written);
2431   GIOError (*io_seek)   (GIOChannel     *channel, 
2432                          gint            offset, 
2433                          GSeekType       type);
2434   void (*io_close)      (GIOChannel     *channel);
2435   guint (*io_add_watch) (GIOChannel     *channel,
2436                          gint            priority,
2437                          GIOCondition    condition,
2438                          GIOFunc         func,
2439                          gpointer        user_data,
2440                          GDestroyNotify  notify);
2441   void (*io_free)       (GIOChannel     *channel);
2442 };
2443
2444 void        g_io_channel_init   (GIOChannel    *channel);
2445 void        g_io_channel_ref    (GIOChannel    *channel);
2446 void        g_io_channel_unref  (GIOChannel    *channel);
2447 GIOError    g_io_channel_read   (GIOChannel    *channel, 
2448                                  gchar         *buf, 
2449                                  guint          count,
2450                                  guint         *bytes_read);
2451 GIOError  g_io_channel_write    (GIOChannel    *channel, 
2452                                  gchar         *buf, 
2453                                  guint          count,
2454                                  guint         *bytes_written);
2455 GIOError  g_io_channel_seek     (GIOChannel    *channel,
2456                                  gint           offset, 
2457                                  GSeekType      type);
2458 void      g_io_channel_close    (GIOChannel    *channel);
2459 guint     g_io_add_watch_full   (GIOChannel    *channel,
2460                                  gint           priority,
2461                                  GIOCondition   condition,
2462                                  GIOFunc        func,
2463                                  gpointer       user_data,
2464                                  GDestroyNotify notify);
2465 guint    g_io_add_watch         (GIOChannel    *channel,
2466                                  GIOCondition   condition,
2467                                  GIOFunc        func,
2468                                  gpointer       user_data);
2469
2470
2471 /* Main loop
2472  */
2473 typedef struct _GTimeVal        GTimeVal;
2474 typedef struct _GSourceFuncs    GSourceFuncs;
2475 typedef struct _GMainLoop       GMainLoop;      /* Opaque */
2476
2477 struct _GTimeVal
2478 {
2479   glong tv_sec;
2480   glong tv_usec;
2481 };
2482 struct _GSourceFuncs
2483 {
2484   gboolean (*prepare)  (gpointer  source_data, 
2485                         GTimeVal *current_time,
2486                         gint     *timeout);
2487   gboolean (*check)    (gpointer  source_data,
2488                         GTimeVal *current_time);
2489   gboolean (*dispatch) (gpointer  source_data, 
2490                         GTimeVal *current_time,
2491                         gpointer  user_data);
2492   GDestroyNotify destroy;
2493 };
2494
2495 /* Standard priorities */
2496
2497 #define G_PRIORITY_HIGH            -100
2498 #define G_PRIORITY_DEFAULT          0
2499 #define G_PRIORITY_HIGH_IDLE        100
2500 #define G_PRIORITY_DEFAULT_IDLE     200
2501 #define G_PRIORITY_LOW              300
2502
2503 typedef gboolean (*GSourceFunc) (gpointer data);
2504
2505 /* Hooks for adding to the main loop */
2506 guint    g_source_add                        (gint           priority, 
2507                                               gboolean       can_recurse,
2508                                               GSourceFuncs  *funcs,
2509                                               gpointer       source_data, 
2510                                               gpointer       user_data,
2511                                               GDestroyNotify notify);
2512 gboolean g_source_remove                     (guint          tag);
2513 gboolean g_source_remove_by_user_data        (gpointer       user_data);
2514 gboolean g_source_remove_by_source_data      (gpointer       source_data);
2515 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
2516                                               gpointer       user_data);
2517
2518 void g_get_current_time             (GTimeVal      *result);
2519
2520 /* Running the main loop */
2521 GMainLoop*      g_main_new              (gboolean        is_running);
2522 void            g_main_run              (GMainLoop      *loop);
2523 void            g_main_quit             (GMainLoop      *loop);
2524 void            g_main_destroy          (GMainLoop      *loop);
2525 gboolean        g_main_is_running       (GMainLoop      *loop);
2526
2527 /* Run a single iteration of the mainloop. If block is FALSE,
2528  * will never block
2529  */
2530 gboolean        g_main_iteration        (gboolean       may_block);
2531
2532 /* See if any events are pending */
2533 gboolean        g_main_pending          (void);
2534
2535 /* Idles and timeouts */
2536 guint           g_timeout_add_full      (gint           priority,
2537                                          guint          interval, 
2538                                          GSourceFunc    function,
2539                                          gpointer       data,
2540                                          GDestroyNotify notify);
2541 guint           g_timeout_add           (guint          interval,
2542                                          GSourceFunc    function,
2543                                          gpointer       data);
2544 guint           g_idle_add              (GSourceFunc    function,
2545                                          gpointer       data);
2546 guint           g_idle_add_full         (gint           priority,
2547                                          GSourceFunc    function,
2548                                          gpointer       data,
2549                                          GDestroyNotify destroy);
2550 gboolean        g_idle_remove_by_data   (gpointer       data);
2551
2552 /* GPollFD
2553  *
2554  * System-specific IO and main loop calls
2555  *
2556  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
2557  * descriptor as provided by the C runtime) that can be used by
2558  * MsgWaitForMultipleObjects. This does *not* include file handles
2559  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
2560  * WSAEventSelect to signal events when a SOCKET is readable).
2561  *
2562  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
2563  * indicate polling for messages. These message queue GPollFDs should
2564  * be added with the g_main_poll_win32_msg_add function.
2565  *
2566  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
2567  * (GTK) programs, as GDK itself wants to read messages and convert them
2568  * to GDK events.
2569  *
2570  * So, unless you really know what you are doing, it's best not to try
2571  * to use the main loop polling stuff for your own needs on
2572  * Win32. It's really only written for the GIMP's needs so
2573  * far.
2574  */
2575
2576 typedef struct _GPollFD GPollFD;
2577 typedef gint    (*GPollFunc)    (GPollFD *ufds,
2578                                  guint    nfsd,
2579                                  gint     timeout);
2580 struct _GPollFD
2581 {
2582   gint          fd;
2583   gushort       events;
2584   gushort       revents;
2585 };
2586
2587 void        g_main_add_poll          (GPollFD    *fd,
2588                                       gint        priority);
2589 void        g_main_remove_poll       (GPollFD    *fd);
2590 void        g_main_set_poll_func     (GPollFunc   func);
2591
2592 /* On Unix, IO channels created with this function for any file
2593  * descriptor or socket.
2594  *
2595  * On Win32, use this only for plain files opened with the MSVCRT (the
2596  * Microsoft run-time C library) _open(), including file descriptors
2597  * 0, 1 and 2 (corresponding to stdin, stdout and stderr).
2598  * Actually, don't do even that, this code isn't done yet.
2599  *
2600  * The term file descriptor as used in the context of Win32 refers to
2601  * the emulated Unix-like file descriptors MSVCRT provides.
2602  */
2603 GIOChannel* g_io_channel_unix_new    (int         fd);
2604 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
2605
2606 #ifdef NATIVE_WIN32
2607
2608 GUTILS_C_VAR guint g_pipe_readable_msg;
2609
2610 #define G_WIN32_MSG_HANDLE 19981206
2611
2612 /* This is used to add polling for Windows messages. GDK (GTk+) programs
2613  * should *not* use this. (In fact, I can't think of any program that
2614  * would want to use this, but it's here just for completeness's sake.
2615  */
2616 void        g_main_poll_win32_msg_add(gint        priority,
2617                                       GPollFD    *fd,
2618                                       guint       hwnd);
2619
2620 /* An IO channel for Windows messages for window handle hwnd. */
2621 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
2622
2623 /* An IO channel for an anonymous pipe as returned from the MSVCRT
2624  * _pipe(), with no mechanism for the writer to tell the reader when
2625  * there is data in the pipe.
2626  *
2627  * This is not really implemented yet.
2628  */
2629 GIOChannel *g_io_channel_win32_new_pipe (int fd);
2630
2631 /* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
2632  * Windows user messages used to signal data in the pipe for the
2633  * reader.
2634  *
2635  * fd is the file descriptor. For the write end, peer is the thread id
2636  * of the reader, and peer_fd is his file descriptor for the read end
2637  * of the pipe.
2638  *
2639  * This is used by the GIMP, and works.
2640  */
2641 GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int   fd,
2642                                                       guint peer,
2643                                                       int   peer_fd);
2644
2645 void        g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
2646                                                      guint       peer,
2647                                                      int         peer_fd);
2648
2649 void        g_io_channel_win32_pipe_readable (int   fd,
2650                                               guint offset);
2651
2652 /* Get the C runtime file descriptor of a channel. */
2653 gint        g_io_channel_win32_get_fd (GIOChannel *channel);
2654
2655 /* An IO channel for a SOCK_STREAM winsock socket. The parameter is
2656  * actually a SOCKET.
2657  */
2658 GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
2659
2660 #endif
2661
2662 /* Windows emulation stubs for common Unix functions
2663  */
2664 #ifdef NATIVE_WIN32
2665 #  define MAXPATHLEN 1024
2666 #  ifdef _MSC_VER
2667 typedef int pid_t;
2668
2669 /* These POSIXish functions are available in the Microsoft C library
2670  * prefixed with underscore (which of course technically speaking is
2671  * the Right Thing, as they are non-ANSI. Not that being non-ANSI
2672  * prevents Microsoft from practically requiring you to include
2673  * <windows.h> every now and then...).
2674  *
2675  * You still need to include the appropriate headers to get the
2676  * prototypes, <io.h> or <direct.h>.
2677  *
2678  * For some functions, we provide emulators in glib, which are prefixed
2679  * with gwin_.
2680  */
2681 #    define getcwd              _getcwd
2682 #    define getpid              _getpid
2683 #    define access              _access
2684 #    define open                _open
2685 #    define read                _read
2686 #    define write               _write
2687 #    define lseek               _lseek
2688 #    define close               _close
2689 #    define pipe(phandles)      _pipe (phandles, 4096, _O_BINARY)
2690 #    define popen               _popen
2691 #    define pclose              _pclose
2692 #    define fdopen              _fdopen
2693 #    define ftruncate(fd, size) gwin_ftruncate (fd, size)
2694 #    define opendir             gwin_opendir
2695 #    define readdir             gwin_readdir
2696 #    define rewinddir           gwin_rewinddir
2697 #    define closedir            gwin_closedir
2698 #    define NAME_MAX 255
2699 struct DIR
2700 {
2701   gchar    *dir_name;
2702   gboolean  just_opened;
2703   guint     find_file_handle;
2704   gpointer  find_file_data;
2705 };
2706 typedef struct DIR DIR;
2707 struct dirent
2708 {
2709   gchar  d_name[NAME_MAX + 1];
2710 };
2711 /* emulation functions */
2712 extern int      gwin_ftruncate  (gint            f,
2713                                  guint           size);
2714 DIR*            gwin_opendir    (const gchar    *dirname);
2715 struct dirent*  gwin_readdir    (DIR            *dir);
2716 void            gwin_rewinddir  (DIR            *dir);
2717 gint            gwin_closedir   (DIR            *dir);
2718 #  endif /* _MSC_VER */
2719 #endif   /* NATIVE_WIN32 */
2720
2721
2722 /* GLib Thread support
2723  */
2724 typedef struct _GMutex          GMutex;
2725 typedef struct _GCond           GCond;
2726 typedef struct _GPrivate        GPrivate;
2727 typedef struct _GStaticPrivate  GStaticPrivate;
2728 typedef struct _GThreadFunctions GThreadFunctions;
2729 struct _GThreadFunctions
2730 {
2731   GMutex*  (*mutex_new)       (void);
2732   void     (*mutex_lock)      (GMutex           *mutex);
2733   gboolean (*mutex_trylock)   (GMutex           *mutex);
2734   void     (*mutex_unlock)    (GMutex           *mutex);
2735   void     (*mutex_free)      (GMutex           *mutex);
2736   GCond*   (*cond_new)        (void);
2737   void     (*cond_signal)     (GCond            *cond);
2738   void     (*cond_broadcast)  (GCond            *cond);
2739   void     (*cond_wait)       (GCond            *cond,
2740                                GMutex           *mutex);
2741   gboolean (*cond_timed_wait) (GCond            *cond,
2742                                GMutex           *mutex, 
2743                                GTimeVal         *end_time);
2744   void      (*cond_free)      (GCond            *cond);
2745   GPrivate* (*private_new)    (GDestroyNotify    destructor);
2746   gpointer  (*private_get)    (GPrivate         *private_key);
2747   void      (*private_set)    (GPrivate         *private_key,
2748                                gpointer          data);
2749 };
2750
2751 GUTILS_C_VAR GThreadFunctions   g_thread_functions_for_glib_use;
2752 GUTILS_C_VAR gboolean           g_thread_use_default_impl;
2753 GUTILS_C_VAR gboolean           g_threads_got_initialized;
2754
2755 /* initializes the mutex/cond/private implementation for glib, might
2756  * only be called once, and must not be called directly or indirectly
2757  * from another glib-function, e.g. as a callback.
2758  */
2759 void    g_thread_init   (GThreadFunctions       *vtable);
2760
2761 /* internal function for fallback static mutex implementation */
2762 GMutex* g_static_mutex_get_mutex_impl   (GMutex **mutex);
2763
2764 /* shorthands for conditional and unconditional function calls */
2765 #define G_THREAD_UF(name, arglist) \
2766     (*g_thread_functions_for_glib_use . name) arglist
2767 #define G_THREAD_CF(name, fail, arg) \
2768     (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
2769 /* keep in mind, all those mutexes and static mutexes are not 
2770  * recursive in general, don't rely on that
2771  */
2772 #define g_thread_supported()    (g_threads_got_initialized)
2773 #define g_mutex_new()            G_THREAD_UF (mutex_new,      ())
2774 #define g_mutex_lock(mutex)      G_THREAD_CF (mutex_lock,     (void)0, (mutex))
2775 #define g_mutex_trylock(mutex)   G_THREAD_CF (mutex_trylock,  TRUE,    (mutex))
2776 #define g_mutex_unlock(mutex)    G_THREAD_CF (mutex_unlock,   (void)0, (mutex))
2777 #define g_mutex_free(mutex)      G_THREAD_CF (mutex_free,     (void)0, (mutex))
2778 #define g_cond_new()             G_THREAD_UF (cond_new,       ())
2779 #define g_cond_signal(cond)      G_THREAD_CF (cond_signal,    (void)0, (cond))
2780 #define g_cond_broadcast(cond)   G_THREAD_CF (cond_broadcast, (void)0, (cond))
2781 #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait,      (void)0, (cond, \
2782                                                                         mutex))
2783 #define g_cond_free(cond)        G_THREAD_CF (cond_free,      (void)0, (cond))
2784 #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
2785                                                               TRUE, \
2786                                                               (cond, mutex, \
2787                                                                abs_time))
2788 #define g_private_new(destructor)         G_THREAD_UF (private_new, (destructor))
2789 #define g_private_get(private_key)        G_THREAD_CF (private_get, \
2790                                                        ((gpointer)private_key), \
2791                                                        (private_key))
2792 #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
2793                                                        (void) (private_key = \
2794                                                         (GPrivate*) (value)), \
2795                                                        (private_key, value))
2796 /* GStaticMutexes can be statically initialized with the value
2797  * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
2798  * much easier, than having to explicitly allocate the mutex before
2799  * use
2800  */
2801 #define g_static_mutex_lock(mutex) \
2802     g_mutex_lock (g_static_mutex_get_mutex (mutex))
2803 #define g_static_mutex_trylock(mutex) \
2804     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
2805 #define g_static_mutex_unlock(mutex) \
2806     g_mutex_unlock (g_static_mutex_get_mutex (mutex)) 
2807 struct _GStaticPrivate
2808 {
2809   guint index;
2810 };
2811 #define G_STATIC_PRIVATE_INIT { 0 }
2812 gpointer g_static_private_get (GStaticPrivate   *private_key);
2813 void     g_static_private_set (GStaticPrivate   *private_key, 
2814                                gpointer          data,
2815                                GDestroyNotify    notify);
2816
2817 /* these are some convenience macros that expand to nothing if GLib
2818  * was configured with --disable-threads. for using StaticMutexes,
2819  * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
2820  * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
2821  * declare such an globally defined lock. name is a unique identifier
2822  * for the protected varibale or code portion. locking, testing and
2823  * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
2824  * G_TRYLOCK() respectively.  
2825  */
2826 extern void glib_dummy_decl (void);
2827 #define G_LOCK_NAME(name)               (g__ ## name ## _lock)
2828 #ifdef  G_THREADS_ENABLED
2829 #  define G_LOCK_DEFINE_STATIC(name)    static G_LOCK_DEFINE (name)
2830 #  define G_LOCK_DEFINE(name)           \
2831     GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT 
2832 #  define G_LOCK_EXTERN(name)           extern GStaticMutex G_LOCK_NAME (name)
2833
2834 #  ifdef G_DEBUG_LOCKS
2835 #    define G_LOCK(name)                G_STMT_START{             \
2836         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2837                "file %s: line %d (%s): locking: %s ",             \
2838                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2839                #name);                                            \
2840         g_static_mutex_lock (&G_LOCK_NAME (name));                \
2841      }G_STMT_END
2842 #    define G_UNLOCK(name)              G_STMT_START{             \
2843         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2844                "file %s: line %d (%s): unlocking: %s ",           \
2845                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2846                #name);                                            \
2847        g_static_mutex_unlock (&G_LOCK_NAME (name));               \
2848      }G_STMT_END
2849 #    define G_TRYLOCK(name)             G_STMT_START{             \
2850         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2851                "file %s: line %d (%s): try locking: %s ",         \
2852                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2853                #name);                                            \
2854      }G_STMT_END,       g_static_mutex_trylock (&G_LOCK_NAME (name))
2855 #  else  /* !G_DEBUG_LOCKS */
2856 #    define G_LOCK(name) g_static_mutex_lock       (&G_LOCK_NAME (name)) 
2857 #    define G_UNLOCK(name) g_static_mutex_unlock   (&G_LOCK_NAME (name))
2858 #    define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
2859 #  endif /* !G_DEBUG_LOCKS */
2860 #else   /* !G_THREADS_ENABLED */
2861 #  define G_LOCK_DEFINE_STATIC(name)    extern void glib_dummy_decl (void)
2862 #  define G_LOCK_DEFINE(name)           extern void glib_dummy_decl (void)
2863 #  define G_LOCK_EXTERN(name)           extern void glib_dummy_decl (void)
2864 #  define G_LOCK(name)
2865 #  define G_UNLOCK(name)
2866 #  define G_TRYLOCK(name)               (FALSE)
2867 #endif  /* !G_THREADS_ENABLED */
2868
2869 #ifdef __cplusplus
2870 }
2871 #endif /* __cplusplus */
2872
2873
2874 #endif /* __G_LIB_H__ */