Added the macros G_(U)?INT_(8|16|32|64)_FORMAT to use for printf and (much
[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
679 /* Forward declarations of glib types.
680  */
681 typedef struct _GAllocator      GAllocator;
682 typedef struct _GArray          GArray;
683 typedef struct _GByteArray      GByteArray;
684 typedef struct _GCache          GCache;
685 typedef struct _GCompletion     GCompletion;
686 typedef struct _GData           GData;
687 typedef struct _GDebugKey       GDebugKey;
688 typedef struct _GHashTable      GHashTable;
689 typedef struct _GHook           GHook;
690 typedef struct _GHookList       GHookList;
691 typedef struct _GList           GList;
692 typedef struct _GMemChunk       GMemChunk;
693 typedef struct _GNode           GNode;
694 typedef struct _GPtrArray       GPtrArray;
695 typedef struct _GQueue          GQueue;
696 typedef struct _GRelation       GRelation;
697 typedef struct _GScanner        GScanner;
698 typedef struct _GScannerConfig  GScannerConfig;
699 typedef struct _GSList          GSList;
700 typedef struct _GStack          GStack;
701 typedef struct _GString         GString;
702 typedef struct _GStringChunk    GStringChunk;
703 typedef struct _GTimer          GTimer;
704 typedef struct _GTree           GTree;
705 typedef struct _GTuples         GTuples;
706 typedef union  _GTokenValue     GTokenValue;
707 typedef struct _GIOChannel      GIOChannel;
708
709 typedef enum
710 {
711   G_TRAVERSE_LEAFS      = 1 << 0,
712   G_TRAVERSE_NON_LEAFS  = 1 << 1,
713   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
714   G_TRAVERSE_MASK       = 0x03
715 } GTraverseFlags;
716
717 typedef enum
718 {
719   G_IN_ORDER,
720   G_PRE_ORDER,
721   G_POST_ORDER,
722   G_LEVEL_ORDER
723 } GTraverseType;
724
725 /* Log level shift offset for user defined
726  * log levels (0-7 are used by GLib).
727  */
728 #define G_LOG_LEVEL_USER_SHIFT  (8)
729
730 /* Glib log levels and flags.
731  */
732 typedef enum
733 {
734   /* log flags */
735   G_LOG_FLAG_RECURSION          = 1 << 0,
736   G_LOG_FLAG_FATAL              = 1 << 1,
737   
738   /* GLib log levels */
739   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
740   G_LOG_LEVEL_CRITICAL          = 1 << 3,
741   G_LOG_LEVEL_WARNING           = 1 << 4,
742   G_LOG_LEVEL_MESSAGE           = 1 << 5,
743   G_LOG_LEVEL_INFO              = 1 << 6,
744   G_LOG_LEVEL_DEBUG             = 1 << 7,
745   
746   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
747 } GLogLevelFlags;
748
749 /* GLib log levels that are considered fatal by default */
750 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
751
752
753 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
754 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
755 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
756 typedef gint            (*GCompareFunc)         (gconstpointer  a,
757                                                  gconstpointer  b);
758 typedef gchar*          (*GCompletionFunc)      (gpointer);
759 typedef void            (*GDestroyNotify)       (gpointer       data);
760 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
761                                                  gpointer       data,
762                                                  gpointer       user_data);
763 typedef void            (*GFunc)                (gpointer       data,
764                                                  gpointer       user_data);
765 typedef guint           (*GHashFunc)            (gconstpointer  key);
766 typedef void            (*GFreeFunc)            (gpointer       data);
767 typedef void            (*GHFunc)               (gpointer       key,
768                                                  gpointer       value,
769                                                  gpointer       user_data);
770 typedef gboolean        (*GHRFunc)              (gpointer       key,
771                                                  gpointer       value,
772                                                  gpointer       user_data);
773 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
774                                                  GHook          *sibling);
775 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
776                                                  gpointer        data);
777 typedef void            (*GHookMarshaller)      (GHook          *hook,
778                                                  gpointer        data);
779 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
780                                                  gpointer        data);
781 typedef void            (*GHookFunc)            (gpointer        data);
782 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
783 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
784                                                  GHook          *hook);
785 typedef void            (*GLogFunc)             (const gchar   *log_domain,
786                                                  GLogLevelFlags log_level,
787                                                  const gchar   *message,
788                                                  gpointer       user_data);
789 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
790                                                  gpointer       data);
791 typedef void            (*GNodeForeachFunc)     (GNode         *node,
792                                                  gpointer       data);
793 typedef gint            (*GSearchFunc)          (gpointer       key,
794                                                  gpointer       data);
795 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
796                                                  gchar         *message,
797                                                  gint           error);
798 typedef gint            (*GTraverseFunc)        (gpointer       key,
799                                                  gpointer       value,
800                                                  gpointer       data);
801 typedef void            (*GVoidFunc)            (void);
802
803
804 struct _GList
805 {
806   gpointer data;
807   GList *next;
808   GList *prev;
809 };
810
811 struct _GSList
812 {
813   gpointer data;
814   GSList *next;
815 };
816
817 struct _GStack
818 {
819   GList *list;
820 };
821
822 struct _GQueue
823 {
824   GList *list;
825   GList *list_end;
826   guint list_size;
827 };
828
829 struct _GString
830 {
831   gchar *str;
832   gint len;
833 };
834
835 struct _GArray
836 {
837   gchar *data;
838   guint len;
839 };
840
841 struct _GByteArray
842 {
843   guint8 *data;
844   guint   len;
845 };
846
847 struct _GPtrArray
848 {
849   gpointer *pdata;
850   guint     len;
851 };
852
853 struct _GTuples
854 {
855   guint len;
856 };
857
858 struct _GDebugKey
859 {
860   gchar *key;
861   guint  value;
862 };
863
864
865 /* Doubly linked lists
866  */
867 void   g_list_push_allocator    (GAllocator     *allocator);
868 void   g_list_pop_allocator     (void);
869 GList* g_list_alloc             (void);
870 void   g_list_free              (GList          *list);
871 void   g_list_free_1            (GList          *list);
872 GList* g_list_append            (GList          *list,
873                                  gpointer        data);
874 GList* g_list_prepend           (GList          *list,
875                                  gpointer        data);
876 GList* g_list_insert            (GList          *list,
877                                  gpointer        data,
878                                  gint            position);
879 GList* g_list_insert_sorted     (GList          *list,
880                                  gpointer        data,
881                                  GCompareFunc    func);
882 GList* g_list_concat            (GList          *list1,
883                                  GList          *list2);
884 GList* g_list_delete            (GList          *list,
885                                  GList          *link);
886 GList* g_list_remove            (GList          *list,
887                                  gpointer        data);
888 GList* g_list_remove_link       (GList          *list,
889                                  GList          *llink);
890 GList* g_list_reverse           (GList          *list);
891 GList* g_list_copy              (GList          *list);
892 GList* g_list_nth               (GList          *list,
893                                  guint           n);
894 GList* g_list_find              (GList          *list,
895                                  gpointer        data);
896 GList* g_list_find_custom       (GList          *list,
897                                  gpointer        data,
898                                  GCompareFunc    func);
899 gint   g_list_position          (GList          *list,
900                                  GList          *llink);
901 gint   g_list_index             (GList          *list,
902                                  gpointer        data);
903 GList* g_list_last              (GList          *list);
904 GList* g_list_first             (GList          *list);
905 guint  g_list_length            (GList          *list);
906 void   g_list_foreach           (GList          *list,
907                                  GFunc           func,
908                                  gpointer        user_data);
909 GList* g_list_sort              (GList          *list,
910                                  GCompareFunc    compare_func);
911 gpointer g_list_nth_data        (GList          *list,
912                                  guint           n);
913 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
914 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
915
916
917 /* Singly linked lists
918  */
919 void    g_slist_push_allocator  (GAllocator     *allocator);
920 void    g_slist_pop_allocator   (void);
921 GSList* g_slist_alloc           (void);
922 void    g_slist_free            (GSList         *list);
923 void    g_slist_free_1          (GSList         *list);
924 GSList* g_slist_append          (GSList         *list,
925                                  gpointer        data);
926 GSList* g_slist_prepend         (GSList         *list,
927                                  gpointer        data);
928 GSList* g_slist_insert          (GSList         *list,
929                                  gpointer        data,
930                                  gint            position);
931 GSList* g_slist_insert_sorted   (GSList         *list,
932                                  gpointer        data,
933                                  GCompareFunc    func);
934 GSList* g_slist_concat          (GSList         *list1,
935                                  GSList         *list2);
936 GSList* g_slist_remove          (GSList         *list,
937                                  gpointer        data);
938 GSList* g_slist_remove_link     (GSList         *list,
939                                  GSList         *llink);
940 GSList* g_slist_reverse         (GSList         *list);
941 GSList* g_slist_copy            (GSList         *list);
942 GSList* g_slist_nth             (GSList         *list,
943                                  guint           n);
944 GSList* g_slist_find            (GSList         *list,
945                                  gpointer        data);
946 GSList* g_slist_find_custom     (GSList         *list,
947                                  gpointer        data,
948                                  GCompareFunc    func);
949 gint    g_slist_position        (GSList         *list,
950                                  GSList         *llink);
951 gint    g_slist_index           (GSList         *list,
952                                  gpointer        data);
953 GSList* g_slist_last            (GSList         *list);
954 guint   g_slist_length          (GSList         *list);
955 void    g_slist_foreach         (GSList         *list,
956                                  GFunc           func,
957                                  gpointer        user_data);
958 GSList*  g_slist_sort           (GSList          *list,
959                                  GCompareFunc    compare_func);
960 gpointer g_slist_nth_data       (GSList         *list,
961                                  guint           n);
962 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
963
964
965 /* Stacks
966  */
967
968 GStack * g_stack_new    (void);
969 void     g_stack_free   (GStack *stack);
970 gpointer g_stack_pop    (GStack *stack);
971
972 #define g_stack_empty(stack) \
973         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? FALSE : TRUE)
974
975 #define g_stack_peek(stack) \
976         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
977                 ((GStack *)(stack))->list->data : NULL)
978
979 #define g_stack_index(stack,ptr) \
980         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
981                 g_list_index (((GStack *)(stack))->list, (ptr)) : -1)
982
983 #define g_stack_push(stack,data) G_STMT_START {                         \
984             if ((GStack *)(stack))                                      \
985               ((GStack *)(stack))->list =                               \
986                   g_list_prepend (((GStack *)(stack))->list, (data));   \
987           } G_STMT_END
988
989
990
991 /* Queues
992  */
993
994 GQueue *        g_queue_new             (void);
995 void            g_queue_free            (GQueue *q);
996 guint           g_queue_get_size        (GQueue *q);
997 void            g_queue_push_front      (GQueue *q, gpointer data);
998 void            g_queue_push_back       (GQueue *q, gpointer data);
999 gpointer        g_queue_pop_front       (GQueue *q);
1000 gpointer        g_queue_pop_back        (GQueue *q);
1001
1002 #define g_queue_empty(queue) \
1003         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? FALSE : TRUE)
1004
1005 #define g_queue_peek_front(queue) \
1006         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1007                 ((GQueue *)(queue))->list->data : NULL)
1008
1009 #define g_queue_peek_back(queue) \
1010         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list_end) ? \
1011                 ((GQueue *)(queue))->list_end->data : NULL)
1012
1013 #define g_queue_index(queue,ptr) \
1014         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1015                 g_list_index (((GQueue *)(queue))->list, (ptr)) : -1)
1016
1017 #define         g_queue_push            g_queue_push_back
1018 #define         g_queue_pop             g_queue_pop_front
1019 #define         g_queue_peek            g_queue_peek_front
1020
1021
1022
1023
1024
1025 /* Hash tables
1026  */
1027 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
1028                                          GCompareFunc    key_compare_func);
1029 void        g_hash_table_destroy        (GHashTable     *hash_table);
1030 void        g_hash_table_insert         (GHashTable     *hash_table,
1031                                          gpointer        key,
1032                                          gpointer        value);
1033 void        g_hash_table_remove         (GHashTable     *hash_table,
1034                                          gconstpointer   key);
1035 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
1036                                          gconstpointer   key);
1037 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
1038                                          gconstpointer   lookup_key,
1039                                          gpointer       *orig_key,
1040                                          gpointer       *value);
1041 void        g_hash_table_freeze         (GHashTable     *hash_table);
1042 void        g_hash_table_thaw           (GHashTable     *hash_table);
1043 void        g_hash_table_foreach        (GHashTable     *hash_table,
1044                                          GHFunc          func,
1045                                          gpointer        user_data);
1046 guint       g_hash_table_foreach_remove (GHashTable     *hash_table,
1047                                          GHRFunc         func,
1048                                          gpointer        user_data);
1049 guint       g_hash_table_size           (GHashTable     *hash_table);
1050
1051
1052 /* Caches
1053  */
1054 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
1055                                 GCacheDestroyFunc  value_destroy_func,
1056                                 GCacheDupFunc      key_dup_func,
1057                                 GCacheDestroyFunc  key_destroy_func,
1058                                 GHashFunc          hash_key_func,
1059                                 GHashFunc          hash_value_func,
1060                                 GCompareFunc       key_compare_func);
1061 void     g_cache_destroy       (GCache            *cache);
1062 gpointer g_cache_insert        (GCache            *cache,
1063                                 gpointer           key);
1064 void     g_cache_remove        (GCache            *cache,
1065                                 gpointer           value);
1066 void     g_cache_key_foreach   (GCache            *cache,
1067                                 GHFunc             func,
1068                                 gpointer           user_data);
1069 void     g_cache_value_foreach (GCache            *cache,
1070                                 GHFunc             func,
1071                                 gpointer           user_data);
1072
1073
1074 /* Balanced binary trees
1075  */
1076 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
1077 void     g_tree_destroy  (GTree         *tree);
1078 void     g_tree_insert   (GTree         *tree,
1079                           gpointer       key,
1080                           gpointer       value);
1081 void     g_tree_remove   (GTree         *tree,
1082                           gpointer       key);
1083 gpointer g_tree_lookup   (GTree         *tree,
1084                           gpointer       key);
1085 void     g_tree_traverse (GTree         *tree,
1086                           GTraverseFunc  traverse_func,
1087                           GTraverseType  traverse_type,
1088                           gpointer       data);
1089 gpointer g_tree_search   (GTree         *tree,
1090                           GSearchFunc    search_func,
1091                           gpointer       data);
1092 gint     g_tree_height   (GTree         *tree);
1093 gint     g_tree_nnodes   (GTree         *tree);
1094
1095
1096
1097 /* N-way tree implementation
1098  */
1099 struct _GNode
1100 {
1101   gpointer data;
1102   GNode   *next;
1103   GNode   *prev;
1104   GNode   *parent;
1105   GNode   *children;
1106 };
1107
1108 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
1109                                  ((GNode*) (node))->prev == NULL && \
1110                                  ((GNode*) (node))->next == NULL)
1111 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
1112
1113 void     g_node_push_allocator  (GAllocator       *allocator);
1114 void     g_node_pop_allocator   (void);
1115 GNode*   g_node_new             (gpointer          data);
1116 void     g_node_destroy         (GNode            *root);
1117 void     g_node_unlink          (GNode            *node);
1118 GNode*   g_node_insert          (GNode            *parent,
1119                                  gint              position,
1120                                  GNode            *node);
1121 GNode*   g_node_insert_before   (GNode            *parent,
1122                                  GNode            *sibling,
1123                                  GNode            *node);
1124 GNode*   g_node_prepend         (GNode            *parent,
1125                                  GNode            *node);
1126 guint    g_node_n_nodes         (GNode            *root,
1127                                  GTraverseFlags    flags);
1128 GNode*   g_node_get_root        (GNode            *node);
1129 gboolean g_node_is_ancestor     (GNode            *node,
1130                                  GNode            *descendant);
1131 guint    g_node_depth           (GNode            *node);
1132 GNode*   g_node_find            (GNode            *root,
1133                                  GTraverseType     order,
1134                                  GTraverseFlags    flags,
1135                                  gpointer          data);
1136
1137 /* convenience macros */
1138 #define g_node_append(parent, node)                             \
1139      g_node_insert_before ((parent), NULL, (node))
1140 #define g_node_insert_data(parent, position, data)              \
1141      g_node_insert ((parent), (position), g_node_new (data))
1142 #define g_node_insert_data_before(parent, sibling, data)        \
1143      g_node_insert_before ((parent), (sibling), g_node_new (data))
1144 #define g_node_prepend_data(parent, data)                       \
1145      g_node_prepend ((parent), g_node_new (data))
1146 #define g_node_append_data(parent, data)                        \
1147      g_node_insert_before ((parent), NULL, g_node_new (data))
1148
1149 /* traversal function, assumes that `node' is root
1150  * (only traverses `node' and its subtree).
1151  * this function is just a high level interface to
1152  * low level traversal functions, optimized for speed.
1153  */
1154 void     g_node_traverse        (GNode            *root,
1155                                  GTraverseType     order,
1156                                  GTraverseFlags    flags,
1157                                  gint              max_depth,
1158                                  GNodeTraverseFunc func,
1159                                  gpointer          data);
1160
1161 /* return the maximum tree height starting with `node', this is an expensive
1162  * operation, since we need to visit all nodes. this could be shortened by
1163  * adding `guint height' to struct _GNode, but then again, this is not very
1164  * often needed, and would make g_node_insert() more time consuming.
1165  */
1166 guint    g_node_max_height       (GNode *root);
1167
1168 void     g_node_children_foreach (GNode           *node,
1169                                   GTraverseFlags   flags,
1170                                   GNodeForeachFunc func,
1171                                   gpointer         data);
1172 void     g_node_reverse_children (GNode           *node);
1173 guint    g_node_n_children       (GNode           *node);
1174 GNode*   g_node_nth_child        (GNode           *node,
1175                                   guint            n);
1176 GNode*   g_node_last_child       (GNode           *node);
1177 GNode*   g_node_find_child       (GNode           *node,
1178                                   GTraverseFlags   flags,
1179                                   gpointer         data);
1180 gint     g_node_child_position   (GNode           *node,
1181                                   GNode           *child);
1182 gint     g_node_child_index      (GNode           *node,
1183                                   gpointer         data);
1184
1185 GNode*   g_node_first_sibling    (GNode           *node);
1186 GNode*   g_node_last_sibling     (GNode           *node);
1187
1188 #define  g_node_prev_sibling(node)      ((node) ? \
1189                                          ((GNode*) (node))->prev : NULL)
1190 #define  g_node_next_sibling(node)      ((node) ? \
1191                                          ((GNode*) (node))->next : NULL)
1192 #define  g_node_first_child(node)       ((node) ? \
1193                                          ((GNode*) (node))->children : NULL)
1194
1195
1196 /* Callback maintenance functions
1197  */
1198 #define G_HOOK_FLAG_USER_SHIFT  (4)
1199 typedef enum
1200 {
1201   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1202   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1203   G_HOOK_FLAG_MASK      = 0x0f
1204 } GHookFlagMask;
1205
1206 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
1207
1208 struct _GHookList
1209 {
1210   guint          seq_id;
1211   guint          hook_size;
1212   guint          is_setup : 1;
1213   GHook         *hooks;
1214   GMemChunk     *hook_memchunk;
1215   GHookFreeFunc  hook_free; /* virtual function */
1216   GHookFreeFunc  hook_destroy; /* virtual function */
1217 };
1218
1219 struct _GHook
1220 {
1221   gpointer       data;
1222   GHook         *next;
1223   GHook         *prev;
1224   guint          ref_count;
1225   guint          hook_id;
1226   guint          flags;
1227   gpointer       func;
1228   GDestroyNotify destroy;
1229 };
1230
1231 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
1232                                           G_HOOK_FLAG_ACTIVE) != 0)
1233 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
1234                                           G_HOOK_FLAG_IN_CALL) != 0)
1235 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
1236                                          G_HOOK_ACTIVE (hook))
1237 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
1238                                          ((GHook*) hook)->prev == NULL && \
1239                                          ((GHook*) hook)->hook_id == 0 && \
1240                                          ((GHook*) hook)->ref_count == 0)
1241
1242 void     g_hook_list_init               (GHookList              *hook_list,
1243                                          guint                   hook_size);
1244 void     g_hook_list_clear              (GHookList              *hook_list);
1245 GHook*   g_hook_alloc                   (GHookList              *hook_list);
1246 void     g_hook_free                    (GHookList              *hook_list,
1247                                          GHook                  *hook);
1248 void     g_hook_ref                     (GHookList              *hook_list,
1249                                          GHook                  *hook);
1250 void     g_hook_unref                   (GHookList              *hook_list,
1251                                          GHook                  *hook);
1252 gboolean g_hook_destroy                 (GHookList              *hook_list,
1253                                          guint                   hook_id);
1254 void     g_hook_destroy_link            (GHookList              *hook_list,
1255                                          GHook                  *hook);
1256 void     g_hook_prepend                 (GHookList              *hook_list,
1257                                          GHook                  *hook);
1258 void     g_hook_insert_before           (GHookList              *hook_list,
1259                                          GHook                  *sibling,
1260                                          GHook                  *hook);
1261 void     g_hook_insert_sorted           (GHookList              *hook_list,
1262                                          GHook                  *hook,
1263                                          GHookCompareFunc        func);
1264 GHook*   g_hook_get                     (GHookList              *hook_list,
1265                                          guint                   hook_id);
1266 GHook*   g_hook_find                    (GHookList              *hook_list,
1267                                          gboolean                need_valids,
1268                                          GHookFindFunc           func,
1269                                          gpointer                data);
1270 GHook*   g_hook_find_data               (GHookList              *hook_list,
1271                                          gboolean                need_valids,
1272                                          gpointer                data);
1273 GHook*   g_hook_find_func               (GHookList              *hook_list,
1274                                          gboolean                need_valids,
1275                                          gpointer                func);
1276 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1277                                          gboolean                need_valids,
1278                                          gpointer                func,
1279                                          gpointer                data);
1280 /* return the first valid hook, and increment its reference count */
1281 GHook*   g_hook_first_valid             (GHookList              *hook_list,
1282                                          gboolean                may_be_in_call);
1283 /* return the next valid hook with incremented reference count, and
1284  * decrement the reference count of the original hook
1285  */
1286 GHook*   g_hook_next_valid              (GHookList              *hook_list,
1287                                          GHook                  *hook,
1288                                          gboolean                may_be_in_call);
1289
1290 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1291 gint     g_hook_compare_ids             (GHook                  *new_hook,
1292                                          GHook                  *sibling);
1293
1294 /* convenience macros */
1295 #define  g_hook_append( hook_list, hook )  \
1296      g_hook_insert_before ((hook_list), NULL, (hook))
1297
1298 /* invoke all valid hooks with the (*GHookFunc) signature.
1299  */
1300 void     g_hook_list_invoke             (GHookList              *hook_list,
1301                                          gboolean                may_recurse);
1302 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1303  * and destroy the hook if FALSE is returned.
1304  */
1305 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1306                                          gboolean                may_recurse);
1307 /* invoke a marshaller on all valid hooks.
1308  */
1309 void     g_hook_list_marshal            (GHookList              *hook_list,
1310                                          gboolean                may_recurse,
1311                                          GHookMarshaller         marshaller,
1312                                          gpointer                data);
1313 void     g_hook_list_marshal_check      (GHookList              *hook_list,
1314                                          gboolean                may_recurse,
1315                                          GHookCheckMarshaller    marshaller,
1316                                          gpointer                data);
1317
1318
1319 /* Fatal error handlers.
1320  * g_on_error_query() will prompt the user to either
1321  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1322  * g_on_error_stack_trace() invokes gdb, which attaches to the current
1323  * process and shows a stack trace.
1324  * These function may cause different actions on non-unix platforms.
1325  * The prg_name arg is required by gdb to find the executable, if it is
1326  * passed as NULL, g_on_error_query() will try g_get_prgname().
1327  */
1328 void g_on_error_query (const gchar *prg_name);
1329 void g_on_error_stack_trace (const gchar *prg_name);
1330
1331
1332 /* Logging mechanism
1333  */
1334 extern          const gchar             *g_log_domain_glib;
1335 guint           g_log_set_handler       (const gchar    *log_domain,
1336                                          GLogLevelFlags  log_levels,
1337                                          GLogFunc        log_func,
1338                                          gpointer        user_data);
1339 void            g_log_remove_handler    (const gchar    *log_domain,
1340                                          guint           handler_id);
1341 void            g_log_default_handler   (const gchar    *log_domain,
1342                                          GLogLevelFlags  log_level,
1343                                          const gchar    *message,
1344                                          gpointer        unused_data);
1345 void            g_log                   (const gchar    *log_domain,
1346                                          GLogLevelFlags  log_level,
1347                                          const gchar    *format,
1348                                          ...) G_GNUC_PRINTF (3, 4);
1349 void            g_logv                  (const gchar    *log_domain,
1350                                          GLogLevelFlags  log_level,
1351                                          const gchar    *format,
1352                                          va_list         args);
1353 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1354                                          GLogLevelFlags  fatal_mask);
1355 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1356 #ifndef G_LOG_DOMAIN
1357 #define G_LOG_DOMAIN    ((gchar*) 0)
1358 #endif  /* G_LOG_DOMAIN */
1359 #ifdef  __GNUC__
1360 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1361                                                G_LOG_LEVEL_ERROR, \
1362                                                format, ##args)
1363 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1364                                                G_LOG_LEVEL_MESSAGE, \
1365                                                format, ##args)
1366 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1367                                                G_LOG_LEVEL_WARNING, \
1368                                                format, ##args)
1369 #else   /* !__GNUC__ */
1370 static void
1371 g_error (const gchar *format,
1372          ...)
1373 {
1374   va_list args;
1375   va_start (args, format);
1376   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1377   va_end (args);
1378 }
1379 static void
1380 g_message (const gchar *format,
1381            ...)
1382 {
1383   va_list args;
1384   va_start (args, format);
1385   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1386   va_end (args);
1387 }
1388 static void
1389 g_warning (const gchar *format,
1390            ...)
1391 {
1392   va_list args;
1393   va_start (args, format);
1394   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1395   va_end (args);
1396 }
1397 #endif  /* !__GNUC__ */
1398
1399 typedef void    (*GPrintFunc)           (const gchar    *string);
1400 void            g_print                 (const gchar    *format,
1401                                          ...) G_GNUC_PRINTF (1, 2);
1402 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1403 void            g_printerr              (const gchar    *format,
1404                                          ...) G_GNUC_PRINTF (1, 2);
1405 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1406
1407 /* deprecated compatibility functions, use g_log_set_handler() instead */
1408 typedef void            (*GErrorFunc)           (const gchar *str);
1409 typedef void            (*GWarningFunc)         (const gchar *str);
1410 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1411 GWarningFunc g_set_warning_handler (GWarningFunc func);
1412 GPrintFunc   g_set_message_handler (GPrintFunc func);
1413
1414
1415 /* Memory allocation and debugging
1416  */
1417 #ifdef USE_DMALLOC
1418
1419 #define g_malloc(size)       ((gpointer) MALLOC (size))
1420 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1421 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1422 #define g_free(mem)          FREE (mem)
1423
1424 #else /* !USE_DMALLOC */
1425
1426 gpointer g_malloc      (gulong    size);
1427 gpointer g_malloc0     (gulong    size);
1428 gpointer g_realloc     (gpointer  mem,
1429                         gulong    size);
1430 void     g_free        (gpointer  mem);
1431
1432 #endif /* !USE_DMALLOC */
1433
1434 void     g_mem_profile (void);
1435 void     g_mem_check   (gpointer  mem);
1436
1437 /* Generic allocators
1438  */
1439 GAllocator* g_allocator_new   (const gchar  *name,
1440                                guint         n_preallocs);
1441 void        g_allocator_free  (GAllocator   *allocator);
1442
1443 #define G_ALLOCATOR_LIST        (1)
1444 #define G_ALLOCATOR_SLIST       (2)
1445 #define G_ALLOCATOR_NODE        (3)
1446
1447
1448 /* "g_mem_chunk_new" creates a new memory chunk.
1449  * Memory chunks are used to allocate pieces of memory which are
1450  *  always the same size. Lists are a good example of such a data type.
1451  * The memory chunk allocates and frees blocks of memory as needed.
1452  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1453  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1454  *  fault...somewhere).
1455  *
1456  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1457  *  want to know what's going on inside do you?)
1458  */
1459
1460 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1461  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1462  *  atom. (They are also useful for lists which use MemChunk to allocate
1463  *  memory but are also part of the MemChunk implementation).
1464  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1465  */
1466
1467 #define G_ALLOC_ONLY      1
1468 #define G_ALLOC_AND_FREE  2
1469
1470 GMemChunk* g_mem_chunk_new     (gchar     *name,
1471                                 gint       atom_size,
1472                                 gulong     area_size,
1473                                 gint       type);
1474 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1475 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1476 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1477 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1478                                 gpointer   mem);
1479 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1480 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1481 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1482 void       g_mem_chunk_info    (void);
1483
1484 /* Ah yes...we have a "g_blow_chunks" function.
1485  * "g_blow_chunks" simply compresses all the chunks. This operation
1486  *  consists of freeing every memory area that should be freed (but
1487  *  which we haven't gotten around to doing yet). And, no,
1488  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1489  *  much better name than "g_mem_chunk_clean_all" or something
1490  *  similar.
1491  */
1492 void g_blow_chunks (void);
1493
1494
1495 /* Timer
1496  */
1497 GTimer* g_timer_new     (void);
1498 void    g_timer_destroy (GTimer  *timer);
1499 void    g_timer_start   (GTimer  *timer);
1500 void    g_timer_stop    (GTimer  *timer);
1501 void    g_timer_reset   (GTimer  *timer);
1502 gdouble g_timer_elapsed (GTimer  *timer,
1503                          gulong  *microseconds);
1504
1505
1506 /* String utility functions that modify a string argument or
1507  * return a constant string that must not be freed.
1508  */
1509 #define  G_STR_DELIMITERS       "_-|> <."
1510 gchar*   g_strdelimit           (gchar       *string,
1511                                  const gchar *delimiters,
1512                                  gchar        new_delimiter);
1513 gdouble  g_strtod               (const gchar *nptr,
1514                                  gchar      **endptr);
1515 gchar*   g_strerror             (gint         errnum);
1516 gchar*   g_strsignal            (gint         signum);
1517 gint     g_strcasecmp           (const gchar *s1,
1518                                  const gchar *s2);
1519 gint     g_strncasecmp          (const gchar *s1,
1520                                  const gchar *s2,
1521                                  guint        n);
1522 void     g_strdown              (gchar       *string);
1523 void     g_strup                (gchar       *string);
1524 void     g_strreverse           (gchar       *string);
1525 /* removes leading spaces */
1526 gchar*   g_strchug              (gchar        *string);
1527 /* removes trailing spaces */
1528 gchar*  g_strchomp              (gchar        *string);
1529 /* removes leading & trailing spaces */
1530 #define g_strstrip( string )    g_strchomp (g_strchug (string))
1531
1532 /* String utility functions that return a newly allocated string which
1533  * ought to be freed from the caller at some point.
1534  */
1535 gchar*   g_strdup               (const gchar *str);
1536 gchar*   g_strdup_printf        (const gchar *format,
1537                                  ...) G_GNUC_PRINTF (1, 2);
1538 gchar*   g_strdup_vprintf       (const gchar *format,
1539                                  va_list      args);
1540 gchar*   g_strndup              (const gchar *str,
1541                                  guint        n);
1542 gchar*   g_strnfill             (guint        length,
1543                                  gchar        fill_char);
1544 gchar*   g_strconcat            (const gchar *string1,
1545                                  ...); /* NULL terminated */
1546 gchar*   g_strjoin              (const gchar  *separator,
1547                                  ...); /* NULL terminated */
1548 gchar*   g_strescape            (gchar        *string);
1549 gpointer g_memdup               (gconstpointer mem,
1550                                  guint         byte_size);
1551
1552 /* NULL terminated string arrays.
1553  * g_strsplit() splits up string into max_tokens tokens at delim and
1554  * returns a newly allocated string array.
1555  * g_strjoinv() concatenates all of str_array's strings, sliding in an
1556  * optional separator, the returned string is newly allocated.
1557  * g_strfreev() frees the array itself and all of its strings.
1558  */
1559 gchar**  g_strsplit             (const gchar  *string,
1560                                  const gchar  *delimiter,
1561                                  gint          max_tokens);
1562 gchar*   g_strjoinv             (const gchar  *separator,
1563                                  gchar       **str_array);
1564 void     g_strfreev             (gchar       **str_array);
1565
1566
1567
1568 /* calculate a string size, guarranteed to fit format + args.
1569  */
1570 guint   g_printf_string_upper_bound (const gchar* format,
1571                                      va_list      args);
1572
1573
1574 /* Retrive static string info
1575  */
1576 gchar*  g_get_user_name         (void);
1577 gchar*  g_get_real_name         (void);
1578 gchar*  g_get_home_dir          (void);
1579 gchar*  g_get_tmp_dir           (void);
1580 gchar*  g_get_prgname           (void);
1581 void    g_set_prgname           (const gchar *prgname);
1582
1583
1584 /* Miscellaneous utility functions
1585  */
1586 guint   g_parse_debug_string    (const gchar *string,
1587                                  GDebugKey   *keys,
1588                                  guint        nkeys);
1589 gint    g_snprintf              (gchar       *string,
1590                                  gulong       n,
1591                                  gchar const *format,
1592                                  ...) G_GNUC_PRINTF (3, 4);
1593 gint    g_vsnprintf             (gchar       *string,
1594                                  gulong       n,
1595                                  gchar const *format,
1596                                  va_list      args);
1597 gchar*  g_basename              (const gchar *file_name);
1598 /* Check if a file name is an absolute path */
1599 gboolean g_path_is_absolute     (const gchar *file_name);
1600 /* In case of absolute paths, skip the root part */
1601 gchar*  g_path_skip_root        (gchar       *file_name);
1602
1603 /* strings are newly allocated with g_malloc() */
1604 gchar*  g_dirname               (const gchar *file_name);
1605 gchar*  g_get_current_dir       (void);
1606 gchar*  g_getenv                (const gchar *variable);
1607
1608
1609 /* we use a GLib function as a replacement for ATEXIT, so
1610  * the programmer is not required to check the return value
1611  * (if there is any in the implementation) and doesn't encounter
1612  * missing include files.
1613  */
1614 void    g_atexit                (GVoidFunc    func);
1615
1616
1617 /* Bit tests
1618  */
1619 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1620                                        gint    nth_bit);
1621 #ifdef  G_CAN_INLINE
1622 G_INLINE_FUNC gint
1623 g_bit_nth_lsf (guint32 mask,
1624                gint    nth_bit)
1625 {
1626   do
1627     {
1628       nth_bit++;
1629       if (mask & (1 << (guint) nth_bit))
1630         return nth_bit;
1631     }
1632   while (nth_bit < 32);
1633   return -1;
1634 }
1635 #endif  /* G_CAN_INLINE */
1636
1637 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1638                                        gint    nth_bit);
1639 #ifdef G_CAN_INLINE
1640 G_INLINE_FUNC gint
1641 g_bit_nth_msf (guint32 mask,
1642                gint    nth_bit)
1643 {
1644   if (nth_bit < 0)
1645     nth_bit = 32;
1646   do
1647     {
1648       nth_bit--;
1649       if (mask & (1 << (guint) nth_bit))
1650         return nth_bit;
1651     }
1652   while (nth_bit > 0);
1653   return -1;
1654 }
1655 #endif  /* G_CAN_INLINE */
1656
1657 G_INLINE_FUNC guint     g_bit_storage (guint number);
1658 #ifdef G_CAN_INLINE
1659 G_INLINE_FUNC guint
1660 g_bit_storage (guint number)
1661 {
1662   register guint n_bits = 0;
1663   
1664   do
1665     {
1666       n_bits++;
1667       number >>= 1;
1668     }
1669   while (number);
1670   return n_bits;
1671 }
1672 #endif  /* G_CAN_INLINE */
1673
1674 /* String Chunks
1675  */
1676 GStringChunk* g_string_chunk_new           (gint size);
1677 void          g_string_chunk_free          (GStringChunk *chunk);
1678 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1679                                             const gchar  *string);
1680 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1681                                             const gchar  *string);
1682
1683
1684 /* Strings
1685  */
1686 GString* g_string_new       (const gchar *init);
1687 GString* g_string_sized_new (guint        dfl_size);
1688 void     g_string_free      (GString     *string,
1689                              gint         free_segment);
1690 GString* g_string_assign    (GString     *lval,
1691                              const gchar *rval);
1692 GString* g_string_truncate  (GString     *string,
1693                              gint         len);
1694 GString* g_string_append    (GString     *string,
1695                              const gchar *val);
1696 GString* g_string_append_c  (GString     *string,
1697                              gchar        c);
1698 GString* g_string_prepend   (GString     *string,
1699                              const gchar *val);
1700 GString* g_string_prepend_c (GString     *string,
1701                              gchar        c);
1702 GString* g_string_insert    (GString     *string,
1703                              gint         pos,
1704                              const gchar *val);
1705 GString* g_string_insert_c  (GString     *string,
1706                              gint         pos,
1707                              gchar        c);
1708 GString* g_string_erase     (GString     *string,
1709                              gint         pos,
1710                              gint         len);
1711 GString* g_string_down      (GString     *string);
1712 GString* g_string_up        (GString     *string);
1713 void     g_string_sprintf   (GString     *string,
1714                              const gchar *format,
1715                              ...) G_GNUC_PRINTF (2, 3);
1716 void     g_string_sprintfa  (GString     *string,
1717                              const gchar *format,
1718                              ...) G_GNUC_PRINTF (2, 3);
1719
1720
1721 /* Resizable arrays, remove fills any cleared spot and shortens the
1722  * array, while preserving the order. remove_fast will distort the
1723  * order by moving the last element to the position of the removed 
1724  */
1725
1726 #define g_array_append_val(a,v)   g_array_append_vals (a, &v, 1)
1727 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &v, 1)
1728 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1)
1729 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
1730
1731 GArray* g_array_new               (gboolean         zero_terminated,
1732                                    gboolean         clear,
1733                                    guint            element_size);
1734 void    g_array_free              (GArray          *array,
1735                                    gboolean         free_segment);
1736 GArray* g_array_append_vals       (GArray          *array,
1737                                    gconstpointer    data,
1738                                    guint            len);
1739 GArray* g_array_prepend_vals      (GArray          *array,
1740                                    gconstpointer    data,
1741                                    guint            len);
1742 GArray* g_array_insert_vals       (GArray          *array,
1743                                    guint            index,
1744                                    gconstpointer    data,
1745                                    guint            len);
1746 GArray* g_array_set_size          (GArray          *array,
1747                                    guint            length);
1748 GArray* g_array_remove_index      (GArray          *array,
1749                                    guint            index);
1750 GArray* g_array_remove_index_fast (GArray          *array,
1751                                    guint            index);
1752
1753 /* Resizable pointer array.  This interface is much less complicated
1754  * than the above.  Add appends appends a pointer.  Remove fills any
1755  * cleared spot and shortens the array. remove_fast will again distort
1756  * order.  
1757  */
1758 #define     g_ptr_array_index(array,index) (array->pdata)[index]
1759 GPtrArray*  g_ptr_array_new                (void);
1760 void        g_ptr_array_free               (GPtrArray   *array,
1761                                             gboolean     free_seg);
1762 void        g_ptr_array_set_size           (GPtrArray   *array,
1763                                             gint         length);
1764 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1765                                             guint        index);
1766 gpointer    g_ptr_array_remove_index_fast  (GPtrArray   *array,
1767                                             guint        index);
1768 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1769                                             gpointer     data);
1770 gboolean    g_ptr_array_remove_fast        (GPtrArray   *array,
1771                                             gpointer     data);
1772 void        g_ptr_array_add                (GPtrArray   *array,
1773                                             gpointer     data);
1774
1775 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1776  * but type-safe.
1777  */
1778
1779 GByteArray* g_byte_array_new               (void);
1780 void        g_byte_array_free              (GByteArray   *array,
1781                                             gboolean      free_segment);
1782 GByteArray* g_byte_array_append            (GByteArray   *array,
1783                                             const guint8 *data,
1784                                             guint         len);
1785 GByteArray* g_byte_array_prepend           (GByteArray   *array,
1786                                             const guint8 *data,
1787                                             guint         len);
1788 GByteArray* g_byte_array_set_size          (GByteArray   *array,
1789                                             guint         length);
1790 GByteArray* g_byte_array_remove_index      (GByteArray   *array,
1791                                             guint         index);
1792 GByteArray* g_byte_array_remove_index_fast (GByteArray   *array,
1793                                             guint         index);
1794
1795
1796 /* Hash Functions
1797  */
1798 gint  g_str_equal (gconstpointer   v,
1799                    gconstpointer   v2);
1800 guint g_str_hash  (gconstpointer   v);
1801
1802 gint  g_int_equal (gconstpointer   v,
1803                    gconstpointer   v2);
1804 guint g_int_hash  (gconstpointer   v);
1805
1806 /* This "hash" function will just return the key's adress as an
1807  * unsigned integer. Useful for hashing on plain adresses or
1808  * simple integer values.
1809  * passing NULL into g_hash_table_new() as GHashFunc has the
1810  * same effect as passing g_direct_hash().
1811  */
1812 guint g_direct_hash  (gconstpointer v);
1813 gint  g_direct_equal (gconstpointer v,
1814                       gconstpointer v2);
1815
1816
1817 /* Quarks (string<->id association)
1818  */
1819 GQuark    g_quark_try_string            (const gchar    *string);
1820 GQuark    g_quark_from_static_string    (const gchar    *string);
1821 GQuark    g_quark_from_string           (const gchar    *string);
1822 gchar*    g_quark_to_string             (GQuark          quark);
1823
1824
1825 /* Keyed Data List
1826  */
1827 void      g_datalist_init                (GData          **datalist);
1828 void      g_datalist_clear               (GData          **datalist);
1829 gpointer  g_datalist_id_get_data         (GData          **datalist,
1830                                           GQuark           key_id);
1831 void      g_datalist_id_set_data_full    (GData          **datalist,
1832                                           GQuark           key_id,
1833                                           gpointer         data,
1834                                           GDestroyNotify   destroy_func);
1835 void      g_datalist_id_remove_no_notify (GData          **datalist,
1836                                           GQuark           key_id);
1837 void      g_datalist_foreach             (GData          **datalist,
1838                                           GDataForeachFunc func,
1839                                           gpointer         user_data);
1840 #define   g_datalist_id_set_data(dl, q, d)      \
1841      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1842 #define   g_datalist_id_remove_data(dl, q)      \
1843      g_datalist_id_set_data ((dl), (q), NULL)
1844 #define   g_datalist_get_data(dl, k)            \
1845      (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1846 #define   g_datalist_set_data_full(dl, k, d, f) \
1847      g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1848 #define   g_datalist_remove_no_notify(dl, k)    \
1849      g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1850 #define   g_datalist_set_data(dl, k, d)         \
1851      g_datalist_set_data_full ((dl), (k), (d), NULL)
1852 #define   g_datalist_remove_data(dl, k)         \
1853      g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1854
1855
1856 /* Location Associated Keyed Data
1857  */
1858 void      g_dataset_destroy             (gconstpointer    dataset_location);
1859 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1860                                          GQuark           key_id);
1861 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1862                                          GQuark           key_id,
1863                                          gpointer         data,
1864                                          GDestroyNotify   destroy_func);
1865 void      g_dataset_id_remove_no_notify (gconstpointer    dataset_location,
1866                                          GQuark           key_id);
1867 void      g_dataset_foreach             (gconstpointer    dataset_location,
1868                                          GDataForeachFunc func,
1869                                          gpointer         user_data);
1870 #define   g_dataset_id_set_data(l, k, d)        \
1871      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1872 #define   g_dataset_id_remove_data(l, k)        \
1873      g_dataset_id_set_data ((l), (k), NULL)
1874 #define   g_dataset_get_data(l, k)              \
1875      (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1876 #define   g_dataset_set_data_full(l, k, d, f)   \
1877      g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1878 #define   g_dataset_remove_no_notify(l, k)      \
1879      g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1880 #define   g_dataset_set_data(l, k, d)           \
1881      g_dataset_set_data_full ((l), (k), (d), NULL)
1882 #define   g_dataset_remove_data(l, k)           \
1883      g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1884
1885
1886 /* GScanner: Flexible lexical scanner for general purpose.
1887  */
1888
1889 /* Character sets */
1890 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1891 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1892 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1893                         "\307\310\311\312\313\314\315\316\317\320"\
1894                         "\321\322\323\324\325\326"\
1895                         "\330\331\332\333\334\335\336"
1896 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1897                         "\347\350\351\352\353\354\355\356\357\360"\
1898                         "\361\362\363\364\365\366"\
1899                         "\370\371\372\373\374\375\376\377"
1900
1901 /* Error types */
1902 typedef enum
1903 {
1904   G_ERR_UNKNOWN,
1905   G_ERR_UNEXP_EOF,
1906   G_ERR_UNEXP_EOF_IN_STRING,
1907   G_ERR_UNEXP_EOF_IN_COMMENT,
1908   G_ERR_NON_DIGIT_IN_CONST,
1909   G_ERR_DIGIT_RADIX,
1910   G_ERR_FLOAT_RADIX,
1911   G_ERR_FLOAT_MALFORMED
1912 } GErrorType;
1913
1914 /* Token types */
1915 typedef enum
1916 {
1917   G_TOKEN_EOF                   =   0,
1918   
1919   G_TOKEN_LEFT_PAREN            = '(',
1920   G_TOKEN_RIGHT_PAREN           = ')',
1921   G_TOKEN_LEFT_CURLY            = '{',
1922   G_TOKEN_RIGHT_CURLY           = '}',
1923   G_TOKEN_LEFT_BRACE            = '[',
1924   G_TOKEN_RIGHT_BRACE           = ']',
1925   G_TOKEN_EQUAL_SIGN            = '=',
1926   G_TOKEN_COMMA                 = ',',
1927   
1928   G_TOKEN_NONE                  = 256,
1929   
1930   G_TOKEN_ERROR,
1931   
1932   G_TOKEN_CHAR,
1933   G_TOKEN_BINARY,
1934   G_TOKEN_OCTAL,
1935   G_TOKEN_INT,
1936   G_TOKEN_HEX,
1937   G_TOKEN_FLOAT,
1938   G_TOKEN_STRING,
1939   
1940   G_TOKEN_SYMBOL,
1941   G_TOKEN_IDENTIFIER,
1942   G_TOKEN_IDENTIFIER_NULL,
1943   
1944   G_TOKEN_COMMENT_SINGLE,
1945   G_TOKEN_COMMENT_MULTI,
1946   G_TOKEN_LAST
1947 } GTokenType;
1948
1949 union   _GTokenValue
1950 {
1951   gpointer      v_symbol;
1952   gchar         *v_identifier;
1953   gulong        v_binary;
1954   gulong        v_octal;
1955   gulong        v_int;
1956   gdouble       v_float;
1957   gulong        v_hex;
1958   gchar         *v_string;
1959   gchar         *v_comment;
1960   guchar        v_char;
1961   guint         v_error;
1962 };
1963
1964 struct  _GScannerConfig
1965 {
1966   /* Character sets
1967    */
1968   gchar         *cset_skip_characters;          /* default: " \t\n" */
1969   gchar         *cset_identifier_first;
1970   gchar         *cset_identifier_nth;
1971   gchar         *cpair_comment_single;          /* default: "#\n" */
1972   
1973   /* Should symbol lookup work case sensitive?
1974    */
1975   guint         case_sensitive : 1;
1976   
1977   /* Boolean values to be adjusted "on the fly"
1978    * to configure scanning behaviour.
1979    */
1980   guint         skip_comment_multi : 1;         /* C like comment */
1981   guint         skip_comment_single : 1;        /* single line comment */
1982   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1983   guint         scan_identifier : 1;
1984   guint         scan_identifier_1char : 1;
1985   guint         scan_identifier_NULL : 1;
1986   guint         scan_symbols : 1;
1987   guint         scan_binary : 1;
1988   guint         scan_octal : 1;
1989   guint         scan_float : 1;
1990   guint         scan_hex : 1;                   /* `0x0ff0' */
1991   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1992   guint         scan_string_sq : 1;             /* string: 'anything' */
1993   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1994   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
1995   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
1996   guint         identifier_2_string : 1;
1997   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
1998   guint         symbol_2_token : 1;
1999   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
2000 };
2001
2002 struct  _GScanner
2003 {
2004   /* unused fields */
2005   gpointer              user_data;
2006   guint                 max_parse_errors;
2007   
2008   /* g_scanner_error() increments this field */
2009   guint                 parse_errors;
2010   
2011   /* name of input stream, featured by the default message handler */
2012   const gchar           *input_name;
2013   
2014   /* data pointer for derived structures */
2015   gpointer              derived_data;
2016   
2017   /* link into the scanner configuration */
2018   GScannerConfig        *config;
2019   
2020   /* fields filled in after g_scanner_get_next_token() */
2021   GTokenType            token;
2022   GTokenValue           value;
2023   guint                 line;
2024   guint                 position;
2025   
2026   /* fields filled in after g_scanner_peek_next_token() */
2027   GTokenType            next_token;
2028   GTokenValue           next_value;
2029   guint                 next_line;
2030   guint                 next_position;
2031   
2032   /* to be considered private */
2033   GHashTable            *symbol_table;
2034   gint                  input_fd;
2035   const gchar           *text;
2036   const gchar           *text_end;
2037   gchar                 *buffer;
2038   guint                 scope_id;
2039   
2040   /* handler function for _warn and _error */
2041   GScannerMsgFunc       msg_handler;
2042 };
2043
2044 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
2045 void            g_scanner_destroy               (GScanner       *scanner);
2046 void            g_scanner_input_file            (GScanner       *scanner,
2047                                                  gint           input_fd);
2048 void            g_scanner_sync_file_offset      (GScanner       *scanner);
2049 void            g_scanner_input_text            (GScanner       *scanner,
2050                                                  const  gchar   *text,
2051                                                  guint          text_len);
2052 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
2053 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
2054 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
2055 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
2056 guint           g_scanner_cur_line              (GScanner       *scanner);
2057 guint           g_scanner_cur_position          (GScanner       *scanner);
2058 gboolean        g_scanner_eof                   (GScanner       *scanner);
2059 guint           g_scanner_set_scope             (GScanner       *scanner,
2060                                                  guint           scope_id);
2061 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
2062                                                  guint           scope_id,
2063                                                  const gchar    *symbol,
2064                                                  gpointer       value);
2065 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
2066                                                  guint           scope_id,
2067                                                  const gchar    *symbol);
2068 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
2069                                                  guint           scope_id,
2070                                                  const gchar    *symbol);
2071 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
2072                                                  guint           scope_id,
2073                                                  GHFunc          func,
2074                                                  gpointer        user_data);
2075 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
2076                                                  const gchar    *symbol);
2077 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
2078 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
2079 void            g_scanner_unexp_token           (GScanner       *scanner,
2080                                                  GTokenType     expected_token,
2081                                                  const gchar    *identifier_spec,
2082                                                  const gchar    *symbol_spec,
2083                                                  const gchar    *symbol_name,
2084                                                  const gchar    *message,
2085                                                  gint            is_error);
2086 void            g_scanner_error                 (GScanner       *scanner,
2087                                                  const gchar    *format,
2088                                                  ...) G_GNUC_PRINTF (2,3);
2089 void            g_scanner_warn                  (GScanner       *scanner,
2090                                                  const gchar    *format,
2091                                                  ...) G_GNUC_PRINTF (2,3);
2092 gint            g_scanner_stat_mode             (const gchar    *filename);
2093 /* keep downward source compatibility */
2094 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
2095   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
2096 } G_STMT_END
2097 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
2098   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2099 } G_STMT_END
2100 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2101   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2102 } G_STMT_END
2103
2104
2105 /* GCompletion
2106  */
2107
2108 struct _GCompletion
2109 {
2110   GList* items;
2111   GCompletionFunc func;
2112   
2113   gchar* prefix;
2114   GList* cache;
2115 };
2116
2117 GCompletion* g_completion_new          (GCompletionFunc func);
2118 void         g_completion_add_items    (GCompletion*    cmp,
2119                                         GList*          items);
2120 void         g_completion_remove_items (GCompletion*    cmp,
2121                                         GList*          items);
2122 void         g_completion_clear_items  (GCompletion*    cmp);
2123 GList*       g_completion_complete     (GCompletion*    cmp,
2124                                         gchar*          prefix,
2125                                         gchar**         new_prefix);
2126 void         g_completion_free         (GCompletion*    cmp);
2127
2128
2129 /* GDate
2130  *
2131  * Date calculations (not time for now, to be resolved). These are a
2132  * mutant combination of Steffen Beyer's DateCalc routines
2133  * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
2134  * date routines (written for in-house software).  Written by Havoc
2135  * Pennington <hp@pobox.com> 
2136  */
2137
2138 typedef guint16 GDateYear;
2139 typedef guint8  GDateDay;   /* day of the month */
2140 typedef struct _GDate GDate;
2141 /* make struct tm known without having to include time.h */
2142 struct tm;
2143
2144 /* enum used to specify order of appearance in parsed date strings */
2145 typedef enum
2146 {
2147   G_DATE_DAY   = 0,
2148   G_DATE_MONTH = 1,
2149   G_DATE_YEAR  = 2
2150 } GDateDMY;
2151
2152 /* actual week and month values */
2153 typedef enum
2154 {
2155   G_DATE_BAD_WEEKDAY  = 0,
2156   G_DATE_MONDAY       = 1,
2157   G_DATE_TUESDAY      = 2,
2158   G_DATE_WEDNESDAY    = 3,
2159   G_DATE_THURSDAY     = 4,
2160   G_DATE_FRIDAY       = 5,
2161   G_DATE_SATURDAY     = 6,
2162   G_DATE_SUNDAY       = 7
2163 } GDateWeekday;
2164 typedef enum
2165 {
2166   G_DATE_BAD_MONTH = 0,
2167   G_DATE_JANUARY   = 1,
2168   G_DATE_FEBRUARY  = 2,
2169   G_DATE_MARCH     = 3,
2170   G_DATE_APRIL     = 4,
2171   G_DATE_MAY       = 5,
2172   G_DATE_JUNE      = 6,
2173   G_DATE_JULY      = 7,
2174   G_DATE_AUGUST    = 8,
2175   G_DATE_SEPTEMBER = 9,
2176   G_DATE_OCTOBER   = 10,
2177   G_DATE_NOVEMBER  = 11,
2178   G_DATE_DECEMBER  = 12
2179 } GDateMonth;
2180
2181 #define G_DATE_BAD_JULIAN 0U
2182 #define G_DATE_BAD_DAY    0U
2183 #define G_DATE_BAD_YEAR   0U
2184
2185 /* Note: directly manipulating structs is generally a bad idea, but
2186  * in this case it's an *incredibly* bad idea, because all or part
2187  * of this struct can be invalid at any given time. Use the functions,
2188  * or you will get hosed, I promise.
2189  */
2190 struct _GDate
2191
2192   guint julian_days : 32; /* julian days representation - we use a
2193                            *  bitfield hoping that 64 bit platforms
2194                            *  will pack this whole struct in one big
2195                            *  int 
2196                            */
2197
2198   guint julian : 1;    /* julian is valid */
2199   guint dmy    : 1;    /* dmy is valid */
2200
2201   /* DMY representation */
2202   guint day    : 6;  
2203   guint month  : 4; 
2204   guint year   : 16; 
2205 };
2206
2207 /* g_date_new() returns an invalid date, you then have to _set() stuff 
2208  * to get a usable object. You can also allocate a GDate statically,
2209  * then call g_date_clear() to initialize.
2210  */
2211 GDate*       g_date_new                   (void);
2212 GDate*       g_date_new_dmy               (GDateDay     day, 
2213                                            GDateMonth   month, 
2214                                            GDateYear    year);
2215 GDate*       g_date_new_julian            (guint32      julian_day);
2216 void         g_date_free                  (GDate       *date);
2217
2218 /* check g_date_valid() after doing an operation that might fail, like
2219  * _parse.  Almost all g_date operations are undefined on invalid
2220  * dates (the exceptions are the mutators, since you need those to
2221  * return to validity).  
2222  */
2223 gboolean     g_date_valid                 (GDate       *date);
2224 gboolean     g_date_valid_day             (GDateDay     day);
2225 gboolean     g_date_valid_month           (GDateMonth   month);
2226 gboolean     g_date_valid_year            (GDateYear    year);
2227 gboolean     g_date_valid_weekday         (GDateWeekday weekday);
2228 gboolean     g_date_valid_julian          (guint32      julian_date);
2229 gboolean     g_date_valid_dmy             (GDateDay     day,
2230                                            GDateMonth   month,
2231                                            GDateYear    year);
2232
2233 GDateWeekday g_date_weekday               (GDate       *date);
2234 GDateMonth   g_date_month                 (GDate       *date);
2235 GDateYear    g_date_year                  (GDate       *date);
2236 GDateDay     g_date_day                   (GDate       *date);
2237 guint32      g_date_julian                (GDate       *date);
2238 guint        g_date_day_of_year           (GDate       *date);
2239
2240 /* First monday/sunday is the start of week 1; if we haven't reached
2241  * that day, return 0. These are not ISO weeks of the year; that
2242  * routine needs to be added.
2243  * these functions return the number of weeks, starting on the
2244  * corrsponding day
2245  */
2246 guint        g_date_monday_week_of_year   (GDate      *date);
2247 guint        g_date_sunday_week_of_year   (GDate      *date);
2248
2249 /* If you create a static date struct you need to clear it to get it
2250  * in a sane state before use. You can clear a whole array at
2251  * once with the ndates argument.
2252  */
2253 void         g_date_clear                 (GDate       *date, 
2254                                            guint        n_dates);
2255
2256 /* The parse routine is meant for dates typed in by a user, so it
2257  * permits many formats but tries to catch common typos. If your data
2258  * needs to be strictly validated, it is not an appropriate function.
2259  */
2260 void         g_date_set_parse             (GDate       *date,
2261                                            const gchar *str);
2262 void         g_date_set_time              (GDate       *date, 
2263                                            GTime        time);
2264 void         g_date_set_month             (GDate       *date, 
2265                                            GDateMonth   month);
2266 void         g_date_set_day               (GDate       *date, 
2267                                            GDateDay     day);
2268 void         g_date_set_year              (GDate       *date,
2269                                            GDateYear    year);
2270 void         g_date_set_dmy               (GDate       *date,
2271                                            GDateDay     day,
2272                                            GDateMonth   month,
2273                                            GDateYear    y);
2274 void         g_date_set_julian            (GDate       *date,
2275                                            guint32      julian_date);
2276 gboolean     g_date_is_first_of_month     (GDate       *date);
2277 gboolean     g_date_is_last_of_month      (GDate       *date);
2278
2279 /* To go forward by some number of weeks just go forward weeks*7 days */
2280 void         g_date_add_days              (GDate       *date, 
2281                                            guint        n_days);
2282 void         g_date_subtract_days         (GDate       *date, 
2283                                            guint        n_days);
2284
2285 /* If you add/sub months while day > 28, the day might change */
2286 void         g_date_add_months            (GDate       *date,
2287                                            guint        n_months);
2288 void         g_date_subtract_months       (GDate       *date,
2289                                            guint        n_months);
2290
2291 /* If it's feb 29, changing years can move you to the 28th */
2292 void         g_date_add_years             (GDate       *date,
2293                                            guint        n_years);
2294 void         g_date_subtract_years        (GDate       *date,
2295                                            guint        n_years);
2296 gboolean     g_date_is_leap_year          (GDateYear    year);
2297 guint8       g_date_days_in_month         (GDateMonth   month, 
2298                                            GDateYear    year);
2299 guint8       g_date_monday_weeks_in_year  (GDateYear    year);
2300 guint8       g_date_sunday_weeks_in_year  (GDateYear    year);
2301
2302 /* qsort-friendly (with a cast...) */
2303 gint         g_date_compare               (GDate       *lhs,
2304                                            GDate       *rhs);
2305 void         g_date_to_struct_tm          (GDate       *date,
2306                                            struct tm   *tm);
2307
2308 /* Just like strftime() except you can only use date-related formats.
2309  *   Using a time format is undefined.
2310  */
2311 gsize        g_date_strftime              (gchar       *s,
2312                                            gsize        slen,
2313                                            const gchar *format,
2314                                            GDate       *date);
2315
2316
2317 /* GRelation
2318  *
2319  * Indexed Relations.  Imagine a really simple table in a
2320  * database.  Relations are not ordered.  This data type is meant for
2321  * maintaining a N-way mapping.
2322  *
2323  * g_relation_new() creates a relation with FIELDS fields
2324  *
2325  * g_relation_destroy() frees all resources
2326  * g_tuples_destroy() frees the result of g_relation_select()
2327  *
2328  * g_relation_index() indexes relation FIELD with the provided
2329  *   equality and hash functions.  this must be done before any
2330  *   calls to insert are made.
2331  *
2332  * g_relation_insert() inserts a new tuple.  you are expected to
2333  *   provide the right number of fields.
2334  *
2335  * g_relation_delete() deletes all relations with KEY in FIELD
2336  * g_relation_select() returns ...
2337  * g_relation_count() counts ...
2338  */
2339
2340 GRelation* g_relation_new     (gint         fields);
2341 void       g_relation_destroy (GRelation   *relation);
2342 void       g_relation_index   (GRelation   *relation,
2343                                gint         field,
2344                                GHashFunc    hash_func,
2345                                GCompareFunc key_compare_func);
2346 void       g_relation_insert  (GRelation   *relation,
2347                                ...);
2348 gint       g_relation_delete  (GRelation   *relation,
2349                                gconstpointer  key,
2350                                gint         field);
2351 GTuples*   g_relation_select  (GRelation   *relation,
2352                                gconstpointer  key,
2353                                gint         field);
2354 gint       g_relation_count   (GRelation   *relation,
2355                                gconstpointer  key,
2356                                gint         field);
2357 gboolean   g_relation_exists  (GRelation   *relation,
2358                                ...);
2359 void       g_relation_print   (GRelation   *relation);
2360
2361 void       g_tuples_destroy   (GTuples     *tuples);
2362 gpointer   g_tuples_index     (GTuples     *tuples,
2363                                gint         index,
2364                                gint         field);
2365
2366
2367 /* Prime numbers.
2368  */
2369
2370 /* This function returns prime numbers spaced by approximately 1.5-2.0
2371  * and is for use in resizing data structures which prefer
2372  * prime-valued sizes.  The closest spaced prime function returns the
2373  * next largest prime, or the highest it knows about which is about
2374  * MAXINT/4.
2375  */
2376 guint      g_spaced_primes_closest (guint num);
2377
2378
2379 /* GIOChannel
2380  */
2381
2382 typedef struct _GIOFuncs GIOFuncs;
2383 typedef enum
2384 {
2385   G_IO_ERROR_NONE,
2386   G_IO_ERROR_AGAIN,
2387   G_IO_ERROR_INVAL,
2388   G_IO_ERROR_UNKNOWN
2389 } GIOError;
2390 typedef enum
2391 {
2392   G_SEEK_CUR,
2393   G_SEEK_SET,
2394   G_SEEK_END
2395 } GSeekType;
2396 typedef enum
2397 {
2398   G_IO_IN       GLIB_SYSDEF_POLLIN,
2399   G_IO_OUT      GLIB_SYSDEF_POLLOUT,
2400   G_IO_PRI      GLIB_SYSDEF_POLLPRI,
2401   G_IO_ERR      GLIB_SYSDEF_POLLERR,
2402   G_IO_HUP      GLIB_SYSDEF_POLLHUP,
2403   G_IO_NVAL     GLIB_SYSDEF_POLLNVAL
2404 } GIOCondition;
2405
2406 struct _GIOChannel
2407 {
2408   guint channel_flags;
2409   guint ref_count;
2410   GIOFuncs *funcs;
2411 };
2412
2413 typedef gboolean (*GIOFunc) (GIOChannel   *source,
2414                              GIOCondition  condition,
2415                              gpointer      data);
2416 struct _GIOFuncs
2417 {
2418   GIOError (*io_read)   (GIOChannel     *channel, 
2419                          gchar          *buf, 
2420                          guint           count,
2421                          guint          *bytes_read);
2422   GIOError (*io_write)  (GIOChannel     *channel, 
2423                          gchar          *buf, 
2424                          guint           count,
2425                          guint          *bytes_written);
2426   GIOError (*io_seek)   (GIOChannel     *channel, 
2427                          gint            offset, 
2428                          GSeekType       type);
2429   void (*io_close)      (GIOChannel     *channel);
2430   guint (*io_add_watch) (GIOChannel     *channel,
2431                          gint            priority,
2432                          GIOCondition    condition,
2433                          GIOFunc         func,
2434                          gpointer        user_data,
2435                          GDestroyNotify  notify);
2436   void (*io_free)       (GIOChannel     *channel);
2437 };
2438
2439 void        g_io_channel_init   (GIOChannel    *channel);
2440 void        g_io_channel_ref    (GIOChannel    *channel);
2441 void        g_io_channel_unref  (GIOChannel    *channel);
2442 GIOError    g_io_channel_read   (GIOChannel    *channel, 
2443                                  gchar         *buf, 
2444                                  guint          count,
2445                                  guint         *bytes_read);
2446 GIOError  g_io_channel_write    (GIOChannel    *channel, 
2447                                  gchar         *buf, 
2448                                  guint          count,
2449                                  guint         *bytes_written);
2450 GIOError  g_io_channel_seek     (GIOChannel    *channel,
2451                                  gint           offset, 
2452                                  GSeekType      type);
2453 void      g_io_channel_close    (GIOChannel    *channel);
2454 guint     g_io_add_watch_full   (GIOChannel    *channel,
2455                                  gint           priority,
2456                                  GIOCondition   condition,
2457                                  GIOFunc        func,
2458                                  gpointer       user_data,
2459                                  GDestroyNotify notify);
2460 guint    g_io_add_watch         (GIOChannel    *channel,
2461                                  GIOCondition   condition,
2462                                  GIOFunc        func,
2463                                  gpointer       user_data);
2464
2465
2466 /* Main loop
2467  */
2468 typedef struct _GTimeVal        GTimeVal;
2469 typedef struct _GSourceFuncs    GSourceFuncs;
2470 typedef struct _GMainLoop       GMainLoop;      /* Opaque */
2471
2472 struct _GTimeVal
2473 {
2474   glong tv_sec;
2475   glong tv_usec;
2476 };
2477 struct _GSourceFuncs
2478 {
2479   gboolean (*prepare)  (gpointer  source_data, 
2480                         GTimeVal *current_time,
2481                         gint     *timeout);
2482   gboolean (*check)    (gpointer  source_data,
2483                         GTimeVal *current_time);
2484   gboolean (*dispatch) (gpointer  source_data, 
2485                         GTimeVal *current_time,
2486                         gpointer  user_data);
2487   GDestroyNotify destroy;
2488 };
2489
2490 /* Standard priorities */
2491
2492 #define G_PRIORITY_HIGH            -100
2493 #define G_PRIORITY_DEFAULT          0
2494 #define G_PRIORITY_HIGH_IDLE        100
2495 #define G_PRIORITY_DEFAULT_IDLE     200
2496 #define G_PRIORITY_LOW              300
2497
2498 typedef gboolean (*GSourceFunc) (gpointer data);
2499
2500 /* Hooks for adding to the main loop */
2501 guint    g_source_add                        (gint           priority, 
2502                                               gboolean       can_recurse,
2503                                               GSourceFuncs  *funcs,
2504                                               gpointer       source_data, 
2505                                               gpointer       user_data,
2506                                               GDestroyNotify notify);
2507 gboolean g_source_remove                     (guint          tag);
2508 gboolean g_source_remove_by_user_data        (gpointer       user_data);
2509 gboolean g_source_remove_by_source_data      (gpointer       source_data);
2510 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
2511                                               gpointer       user_data);
2512
2513 void g_get_current_time             (GTimeVal      *result);
2514
2515 /* Running the main loop */
2516 GMainLoop*      g_main_new              (gboolean        is_running);
2517 void            g_main_run              (GMainLoop      *loop);
2518 void            g_main_quit             (GMainLoop      *loop);
2519 void            g_main_destroy          (GMainLoop      *loop);
2520 gboolean        g_main_is_running       (GMainLoop      *loop);
2521
2522 /* Run a single iteration of the mainloop. If block is FALSE,
2523  * will never block
2524  */
2525 gboolean        g_main_iteration        (gboolean       may_block);
2526
2527 /* See if any events are pending */
2528 gboolean        g_main_pending          (void);
2529
2530 /* Idles and timeouts */
2531 guint           g_timeout_add_full      (gint           priority,
2532                                          guint          interval, 
2533                                          GSourceFunc    function,
2534                                          gpointer       data,
2535                                          GDestroyNotify notify);
2536 guint           g_timeout_add           (guint          interval,
2537                                          GSourceFunc    function,
2538                                          gpointer       data);
2539 guint           g_idle_add              (GSourceFunc    function,
2540                                          gpointer       data);
2541 guint           g_idle_add_full         (gint           priority,
2542                                          GSourceFunc    function,
2543                                          gpointer       data,
2544                                          GDestroyNotify destroy);
2545 gboolean        g_idle_remove_by_data   (gpointer       data);
2546
2547 /* GPollFD
2548  *
2549  * System-specific IO and main loop calls
2550  *
2551  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
2552  * descriptor as provided by the C runtime) that can be used by
2553  * MsgWaitForMultipleObjects. This does *not* include file handles
2554  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
2555  * WSAEventSelect to signal events when a SOCKET is readable).
2556  *
2557  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
2558  * indicate polling for messages. These message queue GPollFDs should
2559  * be added with the g_main_poll_win32_msg_add function.
2560  *
2561  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
2562  * (GTK) programs, as GDK itself wants to read messages and convert them
2563  * to GDK events.
2564  *
2565  * So, unless you really know what you are doing, it's best not to try
2566  * to use the main loop polling stuff for your own needs on
2567  * Win32. It's really only written for the GIMP's needs so
2568  * far.
2569  */
2570
2571 typedef struct _GPollFD GPollFD;
2572 typedef gint    (*GPollFunc)    (GPollFD *ufds,
2573                                  guint    nfsd,
2574                                  gint     timeout);
2575 struct _GPollFD
2576 {
2577   gint          fd;
2578   gushort       events;
2579   gushort       revents;
2580 };
2581
2582 void        g_main_add_poll          (GPollFD    *fd,
2583                                       gint        priority);
2584 void        g_main_remove_poll       (GPollFD    *fd);
2585 void        g_main_set_poll_func     (GPollFunc   func);
2586
2587 /* On Unix, IO channels created with this function for any file
2588  * descriptor or socket.
2589  *
2590  * On Win32, use this only for plain files opened with the MSVCRT (the
2591  * Microsoft run-time C library) _open(), including file descriptors
2592  * 0, 1 and 2 (corresponding to stdin, stdout and stderr).
2593  * Actually, don't do even that, this code isn't done yet.
2594  *
2595  * The term file descriptor as used in the context of Win32 refers to
2596  * the emulated Unix-like file descriptors MSVCRT provides.
2597  */
2598 GIOChannel* g_io_channel_unix_new    (int         fd);
2599 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
2600
2601 #ifdef NATIVE_WIN32
2602
2603 GUTILS_C_VAR guint g_pipe_readable_msg;
2604
2605 #define G_WIN32_MSG_HANDLE 19981206
2606
2607 /* This is used to add polling for Windows messages. GDK (GTk+) programs
2608  * should *not* use this. (In fact, I can't think of any program that
2609  * would want to use this, but it's here just for completeness's sake.
2610  */
2611 void        g_main_poll_win32_msg_add(gint        priority,
2612                                       GPollFD    *fd,
2613                                       guint       hwnd);
2614
2615 /* An IO channel for Windows messages for window handle hwnd. */
2616 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
2617
2618 /* An IO channel for an anonymous pipe as returned from the MSVCRT
2619  * _pipe(), with no mechanism for the writer to tell the reader when
2620  * there is data in the pipe.
2621  *
2622  * This is not really implemented yet.
2623  */
2624 GIOChannel *g_io_channel_win32_new_pipe (int fd);
2625
2626 /* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
2627  * Windows user messages used to signal data in the pipe for the
2628  * reader.
2629  *
2630  * fd is the file descriptor. For the write end, peer is the thread id
2631  * of the reader, and peer_fd is his file descriptor for the read end
2632  * of the pipe.
2633  *
2634  * This is used by the GIMP, and works.
2635  */
2636 GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int   fd,
2637                                                       guint peer,
2638                                                       int   peer_fd);
2639
2640 void        g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
2641                                                      guint       peer,
2642                                                      int         peer_fd);
2643
2644 void        g_io_channel_win32_pipe_readable (int   fd,
2645                                               guint offset);
2646
2647 /* Get the C runtime file descriptor of a channel. */
2648 gint        g_io_channel_win32_get_fd (GIOChannel *channel);
2649
2650 /* An IO channel for a SOCK_STREAM winsock socket. The parameter is
2651  * actually a SOCKET.
2652  */
2653 GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
2654
2655 #endif
2656
2657 /* Windows emulation stubs for common Unix functions
2658  */
2659 #ifdef NATIVE_WIN32
2660 #  define MAXPATHLEN 1024
2661 #  ifdef _MSC_VER
2662 typedef int pid_t;
2663
2664 /* These POSIXish functions are available in the Microsoft C library
2665  * prefixed with underscore (which of course technically speaking is
2666  * the Right Thing, as they are non-ANSI. Not that being non-ANSI
2667  * prevents Microsoft from practically requiring you to include
2668  * <windows.h> every now and then...).
2669  *
2670  * You still need to include the appropriate headers to get the
2671  * prototypes, <io.h> or <direct.h>.
2672  *
2673  * For some functions, we provide emulators in glib, which are prefixed
2674  * with gwin_.
2675  */
2676 #    define getcwd              _getcwd
2677 #    define getpid              _getpid
2678 #    define access              _access
2679 #    define open                _open
2680 #    define read                _read
2681 #    define write               _write
2682 #    define lseek               _lseek
2683 #    define close               _close
2684 #    define pipe(phandles)      _pipe (phandles, 4096, _O_BINARY)
2685 #    define popen               _popen
2686 #    define pclose              _pclose
2687 #    define fdopen              _fdopen
2688 #    define ftruncate(fd, size) gwin_ftruncate (fd, size)
2689 #    define opendir             gwin_opendir
2690 #    define readdir             gwin_readdir
2691 #    define rewinddir           gwin_rewinddir
2692 #    define closedir            gwin_closedir
2693 #    define NAME_MAX 255
2694 struct DIR
2695 {
2696   gchar    *dir_name;
2697   gboolean  just_opened;
2698   guint     find_file_handle;
2699   gpointer  find_file_data;
2700 };
2701 typedef struct DIR DIR;
2702 struct dirent
2703 {
2704   gchar  d_name[NAME_MAX + 1];
2705 };
2706 /* emulation functions */
2707 extern int      gwin_ftruncate  (gint            f,
2708                                  guint           size);
2709 DIR*            gwin_opendir    (const gchar    *dirname);
2710 struct dirent*  gwin_readdir    (DIR            *dir);
2711 void            gwin_rewinddir  (DIR            *dir);
2712 gint            gwin_closedir   (DIR            *dir);
2713 #  endif /* _MSC_VER */
2714 #endif   /* NATIVE_WIN32 */
2715
2716
2717 /* GLib Thread support
2718  */
2719 typedef struct _GMutex          GMutex;
2720 typedef struct _GCond           GCond;
2721 typedef struct _GPrivate        GPrivate;
2722 typedef struct _GStaticPrivate  GStaticPrivate;
2723 typedef struct _GThreadFunctions GThreadFunctions;
2724 struct _GThreadFunctions
2725 {
2726   GMutex*  (*mutex_new)       (void);
2727   void     (*mutex_lock)      (GMutex           *mutex);
2728   gboolean (*mutex_trylock)   (GMutex           *mutex);
2729   void     (*mutex_unlock)    (GMutex           *mutex);
2730   void     (*mutex_free)      (GMutex           *mutex);
2731   GCond*   (*cond_new)        (void);
2732   void     (*cond_signal)     (GCond            *cond);
2733   void     (*cond_broadcast)  (GCond            *cond);
2734   void     (*cond_wait)       (GCond            *cond,
2735                                GMutex           *mutex);
2736   gboolean (*cond_timed_wait) (GCond            *cond,
2737                                GMutex           *mutex, 
2738                                GTimeVal         *end_time);
2739   void      (*cond_free)      (GCond            *cond);
2740   GPrivate* (*private_new)    (GDestroyNotify    destructor);
2741   gpointer  (*private_get)    (GPrivate         *private_key);
2742   void      (*private_set)    (GPrivate         *private_key,
2743                                gpointer          data);
2744 };
2745
2746 GUTILS_C_VAR GThreadFunctions   g_thread_functions_for_glib_use;
2747 GUTILS_C_VAR gboolean           g_thread_use_default_impl;
2748 GUTILS_C_VAR gboolean           g_threads_got_initialized;
2749
2750 /* initializes the mutex/cond/private implementation for glib, might
2751  * only be called once, and must not be called directly or indirectly
2752  * from another glib-function, e.g. as a callback.
2753  */
2754 void    g_thread_init   (GThreadFunctions       *vtable);
2755
2756 /* internal function for fallback static mutex implementation */
2757 GMutex* g_static_mutex_get_mutex_impl   (GMutex **mutex);
2758
2759 /* shorthands for conditional and unconditional function calls */
2760 #define G_THREAD_UF(name, arglist) \
2761     (*g_thread_functions_for_glib_use . name) arglist
2762 #define G_THREAD_CF(name, fail, arg) \
2763     (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
2764 /* keep in mind, all those mutexes and static mutexes are not 
2765  * recursive in general, don't rely on that
2766  */
2767 #define g_thread_supported()    (g_threads_got_initialized)
2768 #define g_mutex_new()            G_THREAD_UF (mutex_new,      ())
2769 #define g_mutex_lock(mutex)      G_THREAD_CF (mutex_lock,     (void)0, (mutex))
2770 #define g_mutex_trylock(mutex)   G_THREAD_CF (mutex_trylock,  TRUE,    (mutex))
2771 #define g_mutex_unlock(mutex)    G_THREAD_CF (mutex_unlock,   (void)0, (mutex))
2772 #define g_mutex_free(mutex)      G_THREAD_CF (mutex_free,     (void)0, (mutex))
2773 #define g_cond_new()             G_THREAD_UF (cond_new,       ())
2774 #define g_cond_signal(cond)      G_THREAD_CF (cond_signal,    (void)0, (cond))
2775 #define g_cond_broadcast(cond)   G_THREAD_CF (cond_broadcast, (void)0, (cond))
2776 #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait,      (void)0, (cond, \
2777                                                                         mutex))
2778 #define g_cond_free(cond)        G_THREAD_CF (cond_free,      (void)0, (cond))
2779 #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
2780                                                               TRUE, \
2781                                                               (cond, mutex, \
2782                                                                abs_time))
2783 #define g_private_new(destructor)         G_THREAD_UF (private_new, (destructor))
2784 #define g_private_get(private_key)        G_THREAD_CF (private_get, \
2785                                                        ((gpointer)private_key), \
2786                                                        (private_key))
2787 #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
2788                                                        (void) (private_key = \
2789                                                         (GPrivate*) (value)), \
2790                                                        (private_key, value))
2791 /* GStaticMutexes can be statically initialized with the value
2792  * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
2793  * much easier, than having to explicitly allocate the mutex before
2794  * use
2795  */
2796 #define g_static_mutex_lock(mutex) \
2797     g_mutex_lock (g_static_mutex_get_mutex (mutex))
2798 #define g_static_mutex_trylock(mutex) \
2799     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
2800 #define g_static_mutex_unlock(mutex) \
2801     g_mutex_unlock (g_static_mutex_get_mutex (mutex)) 
2802 struct _GStaticPrivate
2803 {
2804   guint index;
2805 };
2806 #define G_STATIC_PRIVATE_INIT { 0 }
2807 gpointer g_static_private_get (GStaticPrivate   *private_key);
2808 void     g_static_private_set (GStaticPrivate   *private_key, 
2809                                gpointer          data,
2810                                GDestroyNotify    notify);
2811
2812 /* these are some convenience macros that expand to nothing if GLib
2813  * was configured with --disable-threads. for using StaticMutexes,
2814  * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
2815  * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
2816  * declare such an globally defined lock. name is a unique identifier
2817  * for the protected varibale or code portion. locking, testing and
2818  * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
2819  * G_TRYLOCK() respectively.  
2820  */
2821 extern void glib_dummy_decl (void);
2822 #define G_LOCK_NAME(name)               (g__ ## name ## _lock)
2823 #ifdef  G_THREADS_ENABLED
2824 #  define G_LOCK_DEFINE_STATIC(name)    static G_LOCK_DEFINE (name)
2825 #  define G_LOCK_DEFINE(name)           \
2826     GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT 
2827 #  define G_LOCK_EXTERN(name)           extern GStaticMutex G_LOCK_NAME (name)
2828
2829 #  ifdef G_DEBUG_LOCKS
2830 #    define G_LOCK(name)                G_STMT_START{             \
2831         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2832                "file %s: line %d (%s): locking: %s ",             \
2833                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2834                #name);                                            \
2835         g_static_mutex_lock (&G_LOCK_NAME (name));                \
2836      }G_STMT_END
2837 #    define G_UNLOCK(name)              G_STMT_START{             \
2838         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2839                "file %s: line %d (%s): unlocking: %s ",           \
2840                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2841                #name);                                            \
2842        g_static_mutex_unlock (&G_LOCK_NAME (name));               \
2843      }G_STMT_END
2844 #    define G_TRYLOCK(name)             G_STMT_START{             \
2845         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2846                "file %s: line %d (%s): try locking: %s ",         \
2847                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2848                #name);                                            \
2849      }G_STMT_END,       g_static_mutex_trylock (&G_LOCK_NAME (name))
2850 #  else  /* !G_DEBUG_LOCKS */
2851 #    define G_LOCK(name) g_static_mutex_lock       (&G_LOCK_NAME (name)) 
2852 #    define G_UNLOCK(name) g_static_mutex_unlock   (&G_LOCK_NAME (name))
2853 #    define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
2854 #  endif /* !G_DEBUG_LOCKS */
2855 #else   /* !G_THREADS_ENABLED */
2856 #  define G_LOCK_DEFINE_STATIC(name)    extern void glib_dummy_decl (void)
2857 #  define G_LOCK_DEFINE(name)           extern void glib_dummy_decl (void)
2858 #  define G_LOCK_EXTERN(name)           extern void glib_dummy_decl (void)
2859 #  define G_LOCK(name)
2860 #  define G_UNLOCK(name)
2861 #  define G_TRYLOCK(name)               (FALSE)
2862 #endif  /* !G_THREADS_ENABLED */
2863
2864 #ifdef __cplusplus
2865 }
2866 #endif /* __cplusplus */
2867
2868
2869 #endif /* __G_LIB_H__ */