removed old G_ENUM(), G_FLAGS(), G_NV() and G_SV() macros. added macros
[platform/upstream/glib.git] / glib / 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 #ifndef __G_LIB_H__
20 #define __G_LIB_H__
21
22 /* system specific config file
23  */
24 #include <glibconfig.h>
25
26 /* include varargs functions for assertment macros
27  */
28 #include <stdarg.h>
29
30 /* optionally feature DMALLOC memory allocation debugger
31  */
32 #ifdef USE_DMALLOC
33 #include "dmalloc.h"
34 #endif
35
36
37 #ifdef NATIVE_WIN32
38
39 /* On native Win32, directory separator is the backslash, and search path
40  * separator is the semicolon.
41  */
42 #define G_DIR_SEPARATOR '\\'
43 #define G_DIR_SEPARATOR_S "\\"
44 #define G_SEARCHPATH_SEPARATOR ';'
45 #define G_SEARCHPATH_SEPARATOR_S ";"
46
47 #else  /* !NATIVE_WIN32 */
48
49 /* Unix */
50
51 #define G_DIR_SEPARATOR '/'
52 #define G_DIR_SEPARATOR_S "/"
53 #define G_SEARCHPATH_SEPARATOR ':'
54 #define G_SEARCHPATH_SEPARATOR_S ":"
55
56 #endif /* !NATIVE_WIN32 */
57
58 #ifdef _MSC_VER
59 /* Make MSVC more pedantic, this is a recommended pragma list
60  * from _Win32_Programming_ by Rector and Newcomer.
61  */
62 #pragma warning(error:4002)
63 #pragma warning(error:4003)
64 #pragma warning(1:4010)
65 #pragma warning(error:4013)
66 #pragma warning(1:4016)
67 #pragma warning(error:4020)
68 #pragma warning(error:4021)
69 #pragma warning(error:4027)
70 #pragma warning(error:4029)
71 #pragma warning(error:4033)
72 #pragma warning(error:4035)
73 #pragma warning(error:4045)
74 #pragma warning(error:4047)
75 #pragma warning(error:4049)
76 #pragma warning(error:4053)
77 #pragma warning(error:4071)
78 #pragma warning(disable:4101)
79 #pragma warning(error:4150)
80
81 #pragma warning(disable:4244)   /* No possible loss of data warnings, please */
82 #endif /* _MSC_VER */
83
84 /* glib provides definitions for the extrema of many
85  *  of the standard types. These are:
86  * G_MINFLOAT
87  * G_MAXFLOAT
88  * G_MINDOUBLE
89  * G_MAXDOUBLE
90  * G_MINSHORT
91  * G_MAXSHORT
92  * G_MININT
93  * G_MAXINT
94  * G_MINLONG
95  * G_MAXLONG
96  *
97  * We include limits.h before float.h to work around a egcs 1.1
98  * oddity on Solaris 2.5.1
99  */
100 #ifdef HAVE_LIMITS_H
101 #  include <limits.h>
102 #  define G_MINSHORT  SHRT_MIN
103 #  define G_MAXSHORT  SHRT_MAX
104 #  define G_MININT    INT_MIN
105 #  define G_MAXINT    INT_MAX
106 #  define G_MINLONG   LONG_MIN
107 #  define G_MAXLONG   LONG_MAX
108 #elif HAVE_VALUES_H
109 #  ifdef HAVE_FLOAT_H
110 #    include <values.h>
111 #  endif /* HAVE_FLOAT_H */
112 #  define G_MINSHORT  MINSHORT
113 #  define G_MAXSHORT  MAXSHORT
114 #  define G_MININT    MININT
115 #  define G_MAXINT    MAXINT
116 #  define G_MINLONG   MINLONG
117 #  define G_MAXLONG   MAXLONG
118 #endif /* HAVE_VALUES_H */
119
120 #ifdef HAVE_FLOAT_H
121 #  include <float.h>
122 #  define G_MINFLOAT   FLT_MIN
123 #  define G_MAXFLOAT   FLT_MAX
124 #  define G_MINDOUBLE  DBL_MIN
125 #  define G_MAXDOUBLE  DBL_MAX
126 #elif HAVE_VALUES_H
127 #  include <values.h>
128 #  define G_MINFLOAT  MINFLOAT
129 #  define G_MAXFLOAT  MAXFLOAT
130 #  define G_MINDOUBLE MINDOUBLE
131 #  define G_MAXDOUBLE MAXDOUBLE
132 #endif /* HAVE_VALUES_H */
133
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif /* __cplusplus */
138
139
140 /* Provide definitions for some commonly used macros.
141  *  Some of them are only provided if they haven't already
142  *  been defined. It is assumed that if they are already
143  *  defined then the current definition is correct.
144  */
145 #ifndef NULL
146 #define NULL    ((void*) 0)
147 #endif
148
149 #ifndef FALSE
150 #define FALSE   (0)
151 #endif
152
153 #ifndef TRUE
154 #define TRUE    (!FALSE)
155 #endif
156
157 #undef  MAX
158 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
159
160 #undef  MIN
161 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
162
163 #undef  ABS
164 #define ABS(a)     (((a) < 0) ? -(a) : (a))
165
166 #undef  CLAMP
167 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
168
169
170 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
171  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
172  */
173 #if !defined (G_VA_COPY)
174 #  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
175 #  define G_VA_COPY(ap1, ap2)     (*(ap1) = *(ap2))
176 #  elif defined (G_VA_COPY_AS_ARRAY)
177 #  define G_VA_COPY(ap1, ap2)     g_memmove ((ap1), (ap2), sizeof (va_list))
178 #  else /* va_list is a pointer */
179 #  define G_VA_COPY(ap1, ap2)     ((ap1) = (ap2))
180 #  endif /* va_list is a pointer */
181 #endif /* !G_VA_COPY */
182
183
184 /* Provide convenience macros for handling structure
185  * fields through their offsets.
186  */
187 #define G_STRUCT_OFFSET(struct_type, member)    \
188     ((gulong) ((gchar*) &((struct_type*) 0)->member))
189 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
190     ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset)))
191 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
192     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
193
194
195 /* inlining hassle. for compilers that don't allow the `inline' keyword,
196  * mostly because of strict ANSI C compliance or dumbness, we try to fall
197  * back to either `__inline__' or `__inline'.
198  * we define G_CAN_INLINE, if the compiler seems to be actually
199  * *capable* to do function inlining, in which case inline function bodys
200  * do make sense. we also define G_INLINE_FUNC to properly export the
201  * function prototypes if no inlinig can be performed.
202  * we special case most of the stuff, so inline functions can have a normal
203  * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
204  */
205 #ifndef G_INLINE_FUNC
206 #  define G_CAN_INLINE 1
207 #endif
208 #ifdef G_HAVE_INLINE
209 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
210 #    undef inline
211 #    define inline __inline__
212 #  endif
213 #else /* !G_HAVE_INLINE */
214 #  undef inline
215 #  if defined (G_HAVE___INLINE__)
216 #    define inline __inline__
217 #  else /* !inline && !__inline__ */
218 #    if defined (G_HAVE___INLINE)
219 #      define inline __inline
220 #    else /* !inline && !__inline__ && !__inline */
221 #      define inline /* don't inline, then */
222 #      ifndef G_INLINE_FUNC
223 #        undef G_CAN_INLINE
224 #      endif
225 #    endif
226 #  endif
227 #endif
228 #ifndef G_INLINE_FUNC
229 #  ifdef __GNUC__
230 #    ifdef __OPTIMIZE__
231 #      define G_INLINE_FUNC extern inline
232 #    else
233 #      undef G_CAN_INLINE
234 #      define G_INLINE_FUNC extern
235 #    endif
236 #  else /* !__GNUC__ */
237 #    ifdef G_CAN_INLINE
238 #      define G_INLINE_FUNC static inline
239 #    else
240 #      define G_INLINE_FUNC extern
241 #    endif
242 #  endif /* !__GNUC__ */
243 #endif /* !G_INLINE_FUNC */
244
245
246 /* Provide simple macro statement wrappers (adapted from Perl):
247  *  G_STMT_START { statements; } G_STMT_END;
248  *  can be used as a single statement, as in
249  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
250  *
251  *  For gcc we will wrap the statements within `({' and `})' braces.
252  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
253  *  and otherwise within `do' and `while (0)'.
254  */
255 #if !(defined (G_STMT_START) && defined (G_STMT_END))
256 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
257 #    define G_STMT_START        (void)(
258 #    define G_STMT_END          )
259 #  else
260 #    if (defined (sun) || defined (__sun__))
261 #      define G_STMT_START      if (1)
262 #      define G_STMT_END        else (void)0
263 #    else
264 #      define G_STMT_START      do
265 #      define G_STMT_END        while (0)
266 #    endif
267 #  endif
268 #endif
269
270
271 /* Provide macros to feature the GCC function attribute.
272  */
273 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
274 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
275   __attribute__((format (printf, format_idx, arg_idx)))
276 #define G_GNUC_SCANF( format_idx, arg_idx )     \
277   __attribute__((format (scanf, format_idx, arg_idx)))
278 #define G_GNUC_FORMAT( arg_idx )                \
279   __attribute__((format_arg (arg_idx)))
280 #define G_GNUC_NORETURN                         \
281   __attribute__((noreturn))
282 #define G_GNUC_CONST                            \
283   __attribute__((const))
284 #define G_GNUC_UNUSED                           \
285   __attribute__((unused))
286 #else   /* !__GNUC__ */
287 #define G_GNUC_PRINTF( format_idx, arg_idx )
288 #define G_GNUC_SCANF( format_idx, arg_idx )
289 #define G_GNUC_FORMAT( arg_idx )
290 #define G_GNUC_NORETURN
291 #define G_GNUC_CONST
292 #define G_GNUC_UNUSED
293 #endif  /* !__GNUC__ */
294
295
296 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
297  * macros, so we can refer to them as strings unconditionally.
298  */
299 #ifdef  __GNUC__
300 #define G_GNUC_FUNCTION         (__FUNCTION__)
301 #define G_GNUC_PRETTY_FUNCTION  (__PRETTY_FUNCTION__)
302 #else   /* !__GNUC__ */
303 #define G_GNUC_FUNCTION         ("")
304 #define G_GNUC_PRETTY_FUNCTION  ("")
305 #endif  /* !__GNUC__ */
306
307
308 /* we try to provide a usefull equivalent for ATEXIT if it is
309  * not defined, but use is actually abandoned. people should
310  * use g_atexit() instead.
311  * keep this in sync with gutils.c.
312  */
313 #ifndef ATEXIT
314 #  ifdef HAVE_ATEXIT
315 #    ifdef NeXT /* @#%@! NeXTStep */
316 #      define ATEXIT(proc)   (!atexit (proc))
317 #    else /* !NeXT */
318 #      define ATEXIT(proc)   (atexit (proc))
319 #    endif /* !NeXT */
320 #  elif defined (HAVE_ON_EXIT)
321 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
322 #  else
323 #  error Could not determine proper atexit() implementation
324 #  endif
325 #else
326 #  define G_NATIVE_ATEXIT
327 #endif /* ATEXIT */
328
329 /* Hacker macro to place breakpoints for x86 machines.
330  * Actual use is strongly deprecated of course ;)
331  */
332 #if defined (__i386__) && defined (__GNUC__)
333 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
334 #elif defined (__alpha__) && defined (__GNUC__)
335 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
336 #else   /* !__i386__ && !__alpha__ */
337 #define G_BREAKPOINT()
338 #endif  /* __i386__ */
339
340
341 /* Provide macros for easily allocating memory. The macros
342  *  will cast the allocated memory to the specified type
343  *  in order to avoid compiler warnings. (Makes the code neater).
344  */
345
346 #ifdef __DMALLOC_H__
347 #  define g_new(type, count)            (ALLOC (type, count))
348 #  define g_new0(type, count)           (CALLOC (type, count))
349 #  define g_renew(type, mem, count)     (REALLOC (mem, type, count))
350 #else /* __DMALLOC_H__ */
351 #  define g_new(type, count)      \
352       ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
353 #  define g_new0(type, count)     \
354       ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
355 #  define g_renew(type, mem, count)       \
356       ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
357 #endif /* __DMALLOC_H__ */
358
359 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
360   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
361                    sizeof (type), \
362                    sizeof (type) * (pre_alloc), \
363                    (alloc_type)) \
364 )
365 #define g_chunk_new(type, chunk)        ( \
366   (type *) g_mem_chunk_alloc (chunk) \
367 )
368 #define g_chunk_new0(type, chunk)       ( \
369   (type *) g_mem_chunk_alloc0 (chunk) \
370 )
371 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
372   g_mem_chunk_free ((mem_chunk), (mem)); \
373 } G_STMT_END
374
375
376 #define g_string(x) #x
377
378
379 /* Provide macros for error handling. The "assert" macros will
380  *  exit on failure. The "return" macros will exit the current
381  *  function. Two different definitions are given for the macros
382  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
383  *  __PRETTY_FUNCTION__ capability.
384  */
385
386 #ifdef G_DISABLE_ASSERT
387
388 #define g_assert(expr)
389 #define g_assert_not_reached()
390
391 #else /* !G_DISABLE_ASSERT */
392
393 #ifdef __GNUC__
394
395 #define g_assert(expr)                  G_STMT_START{           \
396      if (!(expr))                                               \
397        g_log (G_LOG_DOMAIN,                                     \
398               G_LOG_LEVEL_ERROR,                                \
399               "file %s: line %d (%s): assertion failed: (%s)",  \
400               __FILE__,                                         \
401               __LINE__,                                         \
402               __PRETTY_FUNCTION__,                              \
403               #expr);                   }G_STMT_END
404
405 #define g_assert_not_reached()          G_STMT_START{           \
406      g_log (G_LOG_DOMAIN,                                       \
407             G_LOG_LEVEL_ERROR,                                  \
408             "file %s: line %d (%s): should not be reached",     \
409             __FILE__,                                           \
410             __LINE__,                                           \
411             __PRETTY_FUNCTION__);       }G_STMT_END
412
413 #else /* !__GNUC__ */
414
415 #define g_assert(expr)                  G_STMT_START{           \
416      if (!(expr))                                               \
417        g_log (G_LOG_DOMAIN,                                     \
418               G_LOG_LEVEL_ERROR,                                \
419               "file %s: line %d: assertion failed: (%s)",       \
420               __FILE__,                                         \
421               __LINE__,                                         \
422               #expr);                   }G_STMT_END
423
424 #define g_assert_not_reached()          G_STMT_START{   \
425      g_log (G_LOG_DOMAIN,                               \
426             G_LOG_LEVEL_ERROR,                          \
427             "file %s: line %d: should not be reached",  \
428             __FILE__,                                   \
429             __LINE__);          }G_STMT_END
430
431 #endif /* __GNUC__ */
432
433 #endif /* !G_DISABLE_ASSERT */
434
435
436 #ifdef G_DISABLE_CHECKS
437
438 #define g_return_if_fail(expr)
439 #define g_return_val_if_fail(expr,val)
440
441 #else /* !G_DISABLE_CHECKS */
442
443 #ifdef __GNUC__
444
445 #define g_return_if_fail(expr)          G_STMT_START{                   \
446      if (!(expr))                                                       \
447        {                                                                \
448          g_log (G_LOG_DOMAIN,                                           \
449                 G_LOG_LEVEL_CRITICAL,                                   \
450                 "file %s: line %d (%s): assertion `%s' failed.",        \
451                 __FILE__,                                               \
452                 __LINE__,                                               \
453                 __PRETTY_FUNCTION__,                                    \
454                 #expr);                                                 \
455          return;                                                        \
456        };                               }G_STMT_END
457
458 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
459      if (!(expr))                                                       \
460        {                                                                \
461          g_log (G_LOG_DOMAIN,                                           \
462                 G_LOG_LEVEL_CRITICAL,                                   \
463                 "file %s: line %d (%s): assertion `%s' failed.",        \
464                 __FILE__,                                               \
465                 __LINE__,                                               \
466                 __PRETTY_FUNCTION__,                                    \
467                 #expr);                                                 \
468          return val;                                                    \
469        };                               }G_STMT_END
470
471 #else /* !__GNUC__ */
472
473 #define g_return_if_fail(expr)          G_STMT_START{           \
474      if (!(expr))                                               \
475        {                                                        \
476          g_log (G_LOG_DOMAIN,                                   \
477                 G_LOG_LEVEL_CRITICAL,                           \
478                 "file %s: line %d: assertion `%s' failed.",     \
479                 __FILE__,                                       \
480                 __LINE__,                                       \
481                 #expr);                                         \
482          return;                                                \
483        };                               }G_STMT_END
484
485 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
486      if (!(expr))                                               \
487        {                                                        \
488          g_log (G_LOG_DOMAIN,                                   \
489                 G_LOG_LEVEL_CRITICAL,                           \
490                 "file %s: line %d: assertion `%s' failed.",     \
491                 __FILE__,                                       \
492                 __LINE__,                                       \
493                 #expr);                                         \
494          return val;                                            \
495        };                               }G_STMT_END
496
497 #endif /* !__GNUC__ */
498
499 #endif /* !G_DISABLE_CHECKS */
500
501
502 /* Provide type definitions for commonly used types.
503  *  These are useful because a "gint8" can be adjusted
504  *  to be 1 byte (8 bits) on all platforms. Similarly and
505  *  more importantly, "gint32" can be adjusted to be
506  *  4 bytes (32 bits) on all platforms.
507  */
508
509 typedef char   gchar;
510 typedef short  gshort;
511 typedef long   glong;
512 typedef int    gint;
513 typedef gint   gboolean;
514
515 typedef unsigned char   guchar;
516 typedef unsigned short  gushort;
517 typedef unsigned long   gulong;
518 typedef unsigned int    guint;
519
520 typedef float   gfloat;
521 typedef double  gdouble;
522
523 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
524  * Since gldouble isn't used anywhere, just disable it for now */
525
526 #if 0
527 #ifdef HAVE_LONG_DOUBLE
528 typedef long double gldouble;
529 #else /* HAVE_LONG_DOUBLE */
530 typedef double gldouble;
531 #endif /* HAVE_LONG_DOUBLE */
532 #endif /* 0 */
533
534 typedef void* gpointer;
535 typedef const void *gconstpointer;
536
537 #if (SIZEOF_CHAR == 1)
538 typedef signed char     gint8;
539 typedef unsigned char   guint8;
540 #endif /* SIZEOF_CHAR */
541
542 #if (SIZEOF_SHORT == 2)
543 typedef signed short    gint16;
544 typedef unsigned short  guint16;
545 #endif /* SIZEOF_SHORT */
546
547 #if (SIZEOF_INT == 4)
548 typedef signed int      gint32;
549 typedef unsigned int    guint32;
550 #elif (SIZEOF_LONG == 4)
551 typedef signed long     gint32;
552 typedef unsigned long   guint32;
553 #endif /* SIZEOF_INT */
554
555 #if (SIZEOF_LONG == 8)
556 #define HAVE_GINT64 1
557 typedef signed long gint64;
558 typedef unsigned long guint64;
559 #elif (SIZEOF_LONG_LONG == 8)
560 #define HAVE_GINT64 1
561 typedef signed long long gint64;
562 typedef unsigned long long guint64;
563 #else
564 /* No gint64 */
565 #undef HAVE_GINT64
566 #endif
567
568
569 /* Define macros for storing integers inside pointers
570  */
571 #if (SIZEOF_INT == SIZEOF_VOID_P)
572
573 #define GPOINTER_TO_INT(p) ((gint)(p))
574 #define GPOINTER_TO_UINT(p) ((guint)(p))
575
576 #define GINT_TO_POINTER(i) ((gpointer)(i))
577 #define GUINT_TO_POINTER(u) ((gpointer)(u))
578
579 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
580
581 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
582 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
583
584 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
585 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
586
587 #else
588 #error SIZEOF_VOID_P unknown - This should never happen
589 #endif
590
591 typedef gint32  gssize;
592 typedef guint32 gsize;
593 typedef guint32 GQuark;
594 typedef gint32  GTime;
595
596
597 /* Portable endian checks and conversions
598  */
599
600 #define G_LITTLE_ENDIAN 1234
601 #define G_BIG_ENDIAN    4321
602 #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
603
604 #ifdef WORDS_BIGENDIAN
605 #define G_BYTE_ORDER G_BIG_ENDIAN
606 #else
607 #define G_BYTE_ORDER G_LITTLE_ENDIAN
608 #endif
609
610 /* Basic bit swapping functions
611  */
612 #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
613     (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
614     (((guint16) (val) & (guint16) 0xff00U) >> 8)))
615 #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
616     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
617     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
618     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
619     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
620
621 /* Intel specific stuff for speed
622  */
623 #if defined (__i386__) && (defined __GNUC__)
624
625 #  define GUINT16_SWAP_LE_BE_X86(val) \
626      (__extension__                                             \
627       ({ register guint16 __v;                                  \
628          if (__builtin_constant_p (val))                        \
629            __v = GUINT16_SWAP_LE_BE_CONSTANT (val);             \
630          else                                                   \
631            __asm__ __volatile__ ("rorw $8, %w0"                 \
632                                  : "=r" (__v)                   \
633                                  : "0" ((guint16) (val))        \
634                                  : "cc");                       \
635         __v; }))
636
637 #  define GUINT16_SWAP_LE_BE(val) \
638      ((guint16) GUINT16_SWAP_LE_BE_X86 ((guint16) (val)))
639
640 #  if !defined(__i486__) && !defined(__i586__) \
641       && !defined(__pentium__) && !defined(__pentiumpro__) && !defined(__i686__)
642 #     define GUINT32_SWAP_LE_BE_X86(val) \
643         (__extension__                                          \
644          ({ register guint32 __v;                               \
645             if (__builtin_constant_p (val))                     \
646               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
647           else                                                  \
648             __asm__ __volatile__ ("rorw $8, %w0\n\t"            \
649                                   "rorl $16, %0\n\t"            \
650                                   "rorw $8, %w0"                \
651                                   : "=r" (__v)                  \
652                                   : "0" ((guint32) (val))       \
653                                   : "cc");                      \
654         __v; }))
655
656 #  else /* 486 and higher has bswap */
657 #     define GUINT32_SWAP_LE_BE_X86(val) \
658         (__extension__                                          \
659          ({ register guint32 __v;                               \
660             if (__builtin_constant_p (val))                     \
661               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
662           else                                                  \
663             __asm__ __volatile__ ("bswap %0"                    \
664                                   : "=r" (__v)                  \
665                                   : "0" ((guint32) (val)));     \
666         __v; }))
667 #  endif /* processor specific 32-bit stuff */
668
669 #  define GUINT32_SWAP_LE_BE(val) \
670      ((guint32) GUINT32_SWAP_LE_BE_X86 ((guint32) (val)))
671
672 #else /* !__i386__ */
673 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
674 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
675 #endif /* __i386__ */
676
677 #ifdef HAVE_GINT64
678 #define GUINT64_SWAP_LE_BE(val)         ((guint64) ( \
679     (((guint64) (val) & (guint64) 0x00000000000000ffU) << 56) | \
680     (((guint64) (val) & (guint64) 0x000000000000ff00U) << 40) | \
681     (((guint64) (val) & (guint64) 0x0000000000ff0000U) << 24) | \
682     (((guint64) (val) & (guint64) 0x00000000ff000000U) <<  8) | \
683     (((guint64) (val) & (guint64) 0x000000ff00000000U) >>  8) | \
684     (((guint64) (val) & (guint64) 0x0000ff0000000000U) >> 24) | \
685     (((guint64) (val) & (guint64) 0x00ff000000000000U) >> 40) | \
686     (((guint64) (val) & (guint64) 0xff00000000000000U) >> 56)))
687 #endif
688
689 #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
690 #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
691 #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
692     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
693     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
694 #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
695     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
696     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
697
698 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
699 #  define GINT16_TO_LE(val)             ((gint16) (val))
700 #  define GUINT16_TO_LE(val)            ((guint16) (val))
701 #  define GINT16_TO_BE(val)             ((gint16) GUINT16_SWAP_LE_BE (val))
702 #  define GUINT16_TO_BE(val)            (GUINT16_SWAP_LE_BE (val))
703 #  define GINT16_FROM_LE(val)           ((gint16) (val))
704 #  define GUINT16_FROM_LE(val)          ((guint16) (val))
705 #  define GINT16_FROM_BE(val)           ((gint16) GUINT16_SWAP_LE_BE (val))
706 #  define GUINT16_FROM_BE(val)          (GUINT16_SWAP_LE_BE (val))
707 #  define GINT32_TO_LE(val)             ((gint32) (val))
708 #  define GUINT32_TO_LE(val)            ((guint32) (val))
709 #  define GINT32_TO_BE(val)             ((gint32) GUINT32_SWAP_LE_BE (val))
710 #  define GUINT32_TO_BE(val)            (GUINT32_SWAP_LE_BE (val))
711 #  define GINT32_FROM_LE(val)           ((gint32) (val))
712 #  define GUINT32_FROM_LE(val)          ((guint32) (val))
713 #  define GINT32_FROM_BE(val)           ((gint32) GUINT32_SWAP_LE_BE (val))
714 #  define GUINT32_FROM_BE(val)          (GUINT32_SWAP_LE_BE (val))
715 #  ifdef HAVE_GINT64
716 #  define GINT64_TO_LE(val)             ((gint64) (val))
717 #  define GUINT64_TO_LE(val)            ((guint64) (val))
718 #  define GINT64_TO_BE(val)             ((gint64) GUINT64_SWAP_LE_BE (val))
719 #  define GUINT64_TO_BE(val)            (GUINT64_SWAP_LE_BE (val))
720 #  define GINT64_FROM_LE(val)           ((gint64) (val))
721 #  define GUINT64_FROM_LE(val)          ((guint64) (val))
722 #  define GINT64_FROM_BE(val)           ((gint64) GUINT64_SWAP_LE_BE (val))
723 #  define GUINT64_FROM_BE(val)          (GUINT64_SWAP_LE_BE (val))
724 #  endif
725 #elif G_BYTE_ORDER == G_BIG_ENDIAN
726 #  define GINT16_TO_BE(val)             ((gint16) (val))
727 #  define GUINT16_TO_BE(val)            ((guint16) (val))
728 #  define GINT16_TO_LE(val)             ((gint16) GUINT16_SWAP_LE_BE (val))
729 #  define GUINT16_TO_LE(val)            (GUINT16_SWAP_LE_BE (val))
730 #  define GINT16_FROM_BE(val)           ((gint16) (val))
731 #  define GUINT16_FROM_BE(val)          ((guint16) (val))
732 #  define GINT16_FROM_LE(val)           ((gint16) GUINT16_SWAP_LE_BE (val))
733 #  define GUINT16_FROM_LE(val)          (GUINT16_SWAP_LE_BE (val))
734 #  define GINT32_TO_BE(val)             ((gint32) (val))
735 #  define GUINT32_TO_BE(val)            ((guint32) (val))
736 #  define GINT32_TO_LE(val)             ((gint32) GUINT32_SWAP_LE_BE (val))
737 #  define GUINT32_TO_LE(val)            (GUINT32_SWAP_LE_BE (val))
738 #  define GINT32_FROM_BE(val)           ((gint32) (val))
739 #  define GUINT32_FROM_BE(val)          ((guint32) (val))
740 #  define GINT32_FROM_LE(val)           ((gint32) GUINT32_SWAP_LE_BE (val))
741 #  define GUINT32_FROM_LE(val)          (GUINT32_SWAP_LE_BE (val))
742 #  ifdef HAVE_GINT64
743 #  define GINT64_TO_BE(val)             ((gint64) (val))
744 #  define GUINT64_TO_BE(val)            ((guint64) (val))
745 #  define GINT64_TO_LE(val)             ((gint64) GUINT64_SWAP_LE_BE (val))
746 #  define GUINT64_TO_LE(val)            (GUINT64_SWAP_LE_BE (val))
747 #  define GINT64_FROM_BE(val)           ((gint64) (val))
748 #  define GUINT64_FROM_BE(val)          ((guint64) (val))
749 #  define GINT64_FROM_LE(val)           ((gint64) GUINT64_SWAP_LE_BE (val))
750 #  define GUINT64_FROM_LE(val)          (GUINT64_SWAP_LE_BE (val))
751 #  endif
752 #else
753 /* PDP stuff not implemented */
754 #endif
755
756 #if (SIZEOF_LONG == 8)
757 #  define GLONG_TO_LE(val)              ((glong) GINT64_TO_LE (val))
758 #  define GULONG_TO_LE(val)             ((gulong) GUINT64_TO_LE (val))
759 #  define GLONG_TO_BE(val)              ((glong) GINT64_TO_BE (val))
760 #  define GULONG_TO_BE(val)             ((gulong) GUINT64_TO_BE (val))
761 #  define GLONG_FROM_LE(val)            ((glong) GINT64_FROM_LE (val))
762 #  define GULONG_FROM_LE(val)           ((gulong) GUINT64_FROM_LE (val))
763 #  define GLONG_FROM_BE(val)            ((glong) GINT64_FROM_BE (val))
764 #  define GULONG_FROM_BE(val)           ((gulong) GUINT64_FROM_BE (val))
765 #elif (SIZEOF_LONG == 4)
766 #  define GLONG_TO_LE(val)              ((glong) GINT32_TO_LE (val))
767 #  define GULONG_TO_LE(val)             ((gulong) GUINT32_TO_LE (val))
768 #  define GLONG_TO_BE(val)              ((glong) GINT32_TO_BE (val))
769 #  define GULONG_TO_BE(val)             ((gulong) GUINT32_TO_BE (val))
770 #  define GLONG_FROM_LE(val)            ((glong) GINT32_FROM_LE (val))
771 #  define GULONG_FROM_LE(val)           ((gulong) GUINT32_FROM_LE (val))
772 #  define GLONG_FROM_BE(val)            ((glong) GINT32_FROM_BE (val))
773 #  define GULONG_FROM_BE(val)           ((gulong) GUINT32_FROM_BE (val))
774 #endif
775
776 #if (SIZEOF_INT == 8)
777 #  define GINT_TO_LE(val)               ((gint) GINT64_TO_LE (val))
778 #  define GUINT_TO_LE(val)              ((guint) GUINT64_TO_LE (val))
779 #  define GINT_TO_BE(val)               ((gint) GINT64_TO_BE (val))
780 #  define GUINT_TO_BE(val)              ((guint) GUINT64_TO_BE (val))
781 #  define GINT_FROM_LE(val)             ((gint) GINT64_FROM_LE (val))
782 #  define GUINT_FROM_LE(val)            ((guint) GUINT64_FROM_LE (val))
783 #  define GINT_FROM_BE(val)             ((gint) GINT64_FROM_BE (val))
784 #  define GUINT_FROM_BE(val)            ((guint) GUINT64_FROM_BE (val))
785 #elif (SIZEOF_INT == 4)
786 #  define GINT_TO_LE(val)               ((gint) GINT32_TO_LE (val))
787 #  define GUINT_TO_LE(val)              ((guint) GUINT32_TO_LE (val))
788 #  define GINT_TO_BE(val)               ((gint) GINT32_TO_BE (val))
789 #  define GUINT_TO_BE(val)              ((guint) GUINT32_TO_BE (val))
790 #  define GINT_FROM_LE(val)             ((gint) GINT32_FROM_LE (val))
791 #  define GUINT_FROM_LE(val)            ((guint) GUINT32_FROM_LE (val))
792 #  define GINT_FROM_BE(val)             ((gint) GINT32_FROM_BE (val))
793 #  define GUINT_FROM_BE(val)            ((guint) GUINT32_FROM_BE (val))
794 #elif (SIZEOF_INT == 2)
795 #  define GINT_TO_LE(val)               ((gint) GINT16_TO_LE (val))
796 #  define GUINT_TO_LE(val)              ((guint) GUINT16_TO_LE (val))
797 #  define GINT_TO_BE(val)               ((gint) GINT16_TO_BE (val))
798 #  define GUINT_TO_BE(val)              ((guint) GUINT16_TO_BE (val))
799 #  define GINT_FROM_LE(val)             ((gint) GINT16_FROM_LE (val))
800 #  define GUINT_FROM_LE(val)            ((guint) GUINT16_FROM_LE (val))
801 #  define GINT_FROM_BE(val)             ((gint) GINT16_FROM_BE (val))
802 #  define GUINT_FROM_BE(val)            ((guint) GUINT16_FROM_BE (val))
803 #endif
804
805 /* Portable versions of host-network order stuff
806  */
807 #define g_ntohl(val) (GUINT32_FROM_BE (val))
808 #define g_ntohs(val) (GUINT16_FROM_BE (val))
809 #define g_htonl(val) (GUINT32_TO_BE (val))
810 #define g_htons(val) (GUINT16_TO_BE (val))
811
812
813 /* Glib version.
814  * we prefix variable declarations so they can
815  * properly get exported in windows dlls.
816  */
817 #ifdef NATIVE_WIN32
818 #  ifdef GLIB_COMPILATION
819 #    define GUTILS_C_VAR __declspec(dllexport)
820 #  else /* !GLIB_COMPILATION */
821 #    define GUTILS_C_VAR __declspec(dllimport)
822 #  endif /* !GLIB_COMPILATION */
823 #else /* !NATIVE_WIN32 */
824 #  define GUTILS_C_VAR extern
825 #endif /* !NATIVE_WIN32 */
826
827 GUTILS_C_VAR const guint glib_major_version;
828 GUTILS_C_VAR const guint glib_minor_version;
829 GUTILS_C_VAR const guint glib_micro_version;
830 GUTILS_C_VAR const guint glib_interface_age;
831 GUTILS_C_VAR const guint glib_binary_age;
832
833 /* Forward declarations of glib types.
834  */
835
836 typedef struct _GArray          GArray;
837 typedef struct _GByteArray      GByteArray;
838 typedef struct _GCache          GCache;
839 typedef struct _GCompletion     GCompletion;
840 typedef struct _GData           GData;
841 typedef struct _GDebugKey       GDebugKey;
842 typedef struct _GHashTable      GHashTable;
843 typedef struct _GHook           GHook;
844 typedef struct _GHookList       GHookList;
845 typedef struct _GList           GList;
846 typedef struct _GListAllocator  GListAllocator;
847 typedef struct _GMemChunk       GMemChunk;
848 typedef struct _GNode           GNode;
849 typedef struct _GPtrArray       GPtrArray;
850 typedef struct _GRelation       GRelation;
851 typedef struct _GScanner        GScanner;
852 typedef struct _GScannerConfig  GScannerConfig;
853 typedef struct _GSList          GSList;
854 typedef struct _GString         GString;
855 typedef struct _GStringChunk    GStringChunk;
856 typedef struct _GTimer          GTimer;
857 typedef struct _GTree           GTree;
858 typedef struct _GTuples         GTuples;
859 typedef union  _GTokenValue     GTokenValue;
860 typedef struct _GIOChannel      GIOChannel;
861
862
863 typedef enum
864 {
865   G_TRAVERSE_LEAFS      = 1 << 0,
866   G_TRAVERSE_NON_LEAFS  = 1 << 1,
867   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
868   G_TRAVERSE_MASK       = 0x03
869 } GTraverseFlags;
870
871 typedef enum
872 {
873   G_IN_ORDER,
874   G_PRE_ORDER,
875   G_POST_ORDER,
876   G_LEVEL_ORDER
877 } GTraverseType;
878
879 /* Log level shift offset for user defined
880  * log levels (0-7 are used by GLib).
881  */
882 #define G_LOG_LEVEL_USER_SHIFT  (8)
883
884 /* Glib log levels and flags.
885  */
886 typedef enum
887 {
888   /* log flags */
889   G_LOG_FLAG_RECURSION          = 1 << 0,
890   G_LOG_FLAG_FATAL              = 1 << 1,
891   
892   /* GLib log levels */
893   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
894   G_LOG_LEVEL_CRITICAL          = 1 << 3,
895   G_LOG_LEVEL_WARNING           = 1 << 4,
896   G_LOG_LEVEL_MESSAGE           = 1 << 5,
897   G_LOG_LEVEL_INFO              = 1 << 6,
898   G_LOG_LEVEL_DEBUG             = 1 << 7,
899   
900   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
901 } GLogLevelFlags;
902
903 /* GLib log levels that are considered fatal by default */
904 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
905
906
907 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
908 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
909 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
910 typedef gint            (*GCompareFunc)         (gconstpointer  a,
911                                                  gconstpointer  b);
912 typedef gchar*          (*GCompletionFunc)      (gpointer);
913 typedef void            (*GDestroyNotify)       (gpointer       data);
914 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
915                                                  gpointer       data,
916                                                  gpointer       user_data);
917 typedef void            (*GFunc)                (gpointer       data,
918                                                  gpointer       user_data);
919 typedef guint           (*GHashFunc)            (gconstpointer  key);
920 typedef void            (*GHFunc)               (gpointer       key,
921                                                  gpointer       value,
922                                                  gpointer       user_data);
923 typedef gboolean        (*GHRFunc)              (gpointer       key,
924                                                  gpointer       value,
925                                                  gpointer       user_data);
926 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
927                                                  GHook          *sibling);
928 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
929                                                  gpointer        data);
930 typedef void            (*GHookMarshaller)      (GHook          *hook,
931                                                  gpointer        data);
932 typedef void            (*GHookFunc)            (gpointer        data);
933 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
934 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
935                                                  GHook          *hook);
936 typedef void            (*GLogFunc)             (const gchar   *log_domain,
937                                                  GLogLevelFlags log_level,
938                                                  const gchar   *message,
939                                                  gpointer       user_data);
940 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
941                                                  gpointer       data);
942 typedef void            (*GNodeForeachFunc)     (GNode         *node,
943                                                  gpointer       data);
944 typedef gint            (*GSearchFunc)          (gpointer       key,
945                                                  gpointer       data);
946 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
947                                                  gchar         *message,
948                                                  gint           error);
949 typedef gint            (*GTraverseFunc)        (gpointer       key,
950                                                  gpointer       value,
951                                                  gpointer       data);
952 typedef void            (*GVoidFunc)            (void);
953
954
955 struct _GList
956 {
957   gpointer data;
958   GList *next;
959   GList *prev;
960 };
961
962 struct _GSList
963 {
964   gpointer data;
965   GSList *next;
966 };
967
968 struct _GString
969 {
970   gchar *str;
971   gint len;
972 };
973
974 struct _GArray
975 {
976   gchar *data;
977   guint len;
978 };
979
980 struct _GByteArray
981 {
982   guint8 *data;
983   guint   len;
984 };
985
986 struct _GPtrArray
987 {
988   gpointer *pdata;
989   guint     len;
990 };
991
992 struct _GTuples
993 {
994   guint len;
995 };
996
997 struct _GDebugKey
998 {
999   gchar *key;
1000   guint  value;
1001 };
1002
1003
1004 /* Doubly linked lists
1005  */
1006 GList* g_list_alloc             (void);
1007 void   g_list_free              (GList          *list);
1008 void   g_list_free_1            (GList          *list);
1009 GList* g_list_append            (GList          *list,
1010                                  gpointer        data);
1011 GList* g_list_prepend           (GList          *list,
1012                                  gpointer        data);
1013 GList* g_list_insert            (GList          *list,
1014                                  gpointer        data,
1015                                  gint            position);
1016 GList* g_list_insert_sorted     (GList          *list,
1017                                  gpointer        data,
1018                                  GCompareFunc    func);
1019 GList* g_list_concat            (GList          *list1,
1020                                  GList          *list2);
1021 GList* g_list_remove            (GList          *list,
1022                                  gpointer        data);
1023 GList* g_list_remove_link       (GList          *list,
1024                                  GList          *llink);
1025 GList* g_list_reverse           (GList          *list);
1026 GList* g_list_nth               (GList          *list,
1027                                  guint           n);
1028 GList* g_list_find              (GList          *list,
1029                                  gpointer        data);
1030 GList* g_list_find_custom       (GList          *list,
1031                                  gpointer        data,
1032                                  GCompareFunc    func);
1033 gint   g_list_position          (GList          *list,
1034                                  GList          *llink);
1035 gint   g_list_index             (GList          *list,
1036                                  gpointer        data);
1037 GList* g_list_last              (GList          *list);
1038 GList* g_list_first             (GList          *list);
1039 guint  g_list_length            (GList          *list);
1040 void   g_list_foreach           (GList          *list,
1041                                  GFunc           func,
1042                                  gpointer        user_data);
1043 gpointer g_list_nth_data        (GList          *list,
1044                                  guint           n);
1045 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
1046 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
1047
1048
1049 /* Singly linked lists
1050  */
1051 GSList* g_slist_alloc           (void);
1052 void    g_slist_free            (GSList         *list);
1053 void    g_slist_free_1          (GSList         *list);
1054 GSList* g_slist_append          (GSList         *list,
1055                                  gpointer        data);
1056 GSList* g_slist_prepend         (GSList         *list,
1057                                  gpointer        data);
1058 GSList* g_slist_insert          (GSList         *list,
1059                                  gpointer        data,
1060                                  gint            position);
1061 GSList* g_slist_insert_sorted   (GSList         *list,
1062                                  gpointer        data,
1063                                  GCompareFunc    func);
1064 GSList* g_slist_concat          (GSList         *list1,
1065                                  GSList         *list2);
1066 GSList* g_slist_remove          (GSList         *list,
1067                                  gpointer        data);
1068 GSList* g_slist_remove_link     (GSList         *list,
1069                                  GSList         *llink);
1070 GSList* g_slist_reverse         (GSList         *list);
1071 GSList* g_slist_nth             (GSList         *list,
1072                                  guint           n);
1073 GSList* g_slist_find            (GSList         *list,
1074                                  gpointer        data);
1075 GSList* g_slist_find_custom     (GSList         *list,
1076                                  gpointer        data,
1077                                  GCompareFunc    func);
1078 gint    g_slist_position        (GSList         *list,
1079                                  GSList         *llink);
1080 gint    g_slist_index           (GSList         *list,
1081                                  gpointer        data);
1082 GSList* g_slist_last            (GSList         *list);
1083 guint   g_slist_length          (GSList         *list);
1084 void    g_slist_foreach         (GSList         *list,
1085                                  GFunc           func,
1086                                  gpointer        user_data);
1087 gpointer g_slist_nth_data       (GSList         *list,
1088                                  guint           n);
1089 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
1090
1091
1092 /* List Allocators
1093  */
1094 GListAllocator* g_list_allocator_new  (void);
1095 void            g_list_allocator_free (GListAllocator* allocator);
1096 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
1097 GListAllocator* g_list_set_allocator  (GListAllocator* allocator);
1098
1099
1100 /* Hash tables
1101  */
1102 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
1103                                          GCompareFunc    key_compare_func);
1104 void        g_hash_table_destroy        (GHashTable     *hash_table);
1105 void        g_hash_table_insert         (GHashTable     *hash_table,
1106                                          gpointer        key,
1107                                          gpointer        value);
1108 void        g_hash_table_remove         (GHashTable     *hash_table,
1109                                          gconstpointer   key);
1110 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
1111                                          gconstpointer   key);
1112 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
1113                                          gconstpointer   lookup_key,
1114                                          gpointer       *orig_key,
1115                                          gpointer       *value);
1116 void        g_hash_table_freeze         (GHashTable     *hash_table);
1117 void        g_hash_table_thaw           (GHashTable     *hash_table);
1118 void        g_hash_table_foreach        (GHashTable     *hash_table,
1119                                          GHFunc          func,
1120                                          gpointer        user_data);
1121 gint        g_hash_table_foreach_remove (GHashTable     *hash_table,
1122                                          GHRFunc         func,
1123                                          gpointer        user_data);
1124 gint        g_hash_table_size           (GHashTable     *hash_table);
1125
1126
1127 /* Caches
1128  */
1129 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
1130                                 GCacheDestroyFunc  value_destroy_func,
1131                                 GCacheDupFunc      key_dup_func,
1132                                 GCacheDestroyFunc  key_destroy_func,
1133                                 GHashFunc          hash_key_func,
1134                                 GHashFunc          hash_value_func,
1135                                 GCompareFunc       key_compare_func);
1136 void     g_cache_destroy       (GCache            *cache);
1137 gpointer g_cache_insert        (GCache            *cache,
1138                                 gpointer           key);
1139 void     g_cache_remove        (GCache            *cache,
1140                                 gpointer           value);
1141 void     g_cache_key_foreach   (GCache            *cache,
1142                                 GHFunc             func,
1143                                 gpointer           user_data);
1144 void     g_cache_value_foreach (GCache            *cache,
1145                                 GHFunc             func,
1146                                 gpointer           user_data);
1147
1148
1149 /* Balanced binary trees
1150  */
1151 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
1152 void     g_tree_destroy  (GTree         *tree);
1153 void     g_tree_insert   (GTree         *tree,
1154                           gpointer       key,
1155                           gpointer       value);
1156 void     g_tree_remove   (GTree         *tree,
1157                           gpointer       key);
1158 gpointer g_tree_lookup   (GTree         *tree,
1159                           gpointer       key);
1160 void     g_tree_traverse (GTree         *tree,
1161                           GTraverseFunc  traverse_func,
1162                           GTraverseType  traverse_type,
1163                           gpointer       data);
1164 gpointer g_tree_search   (GTree         *tree,
1165                           GSearchFunc    search_func,
1166                           gpointer       data);
1167 gint     g_tree_height   (GTree         *tree);
1168 gint     g_tree_nnodes   (GTree         *tree);
1169
1170
1171
1172 /* N-way tree implementation
1173  */
1174 struct _GNode
1175 {
1176   gpointer data;
1177   GNode   *next;
1178   GNode   *prev;
1179   GNode   *parent;
1180   GNode   *children;
1181 };
1182
1183 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
1184                                  ((GNode*) (node))->prev == NULL && \
1185                                  ((GNode*) (node))->next == NULL)
1186 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
1187
1188 GNode*   g_node_new             (gpointer          data);
1189 void     g_node_destroy         (GNode            *root);
1190 void     g_node_unlink          (GNode            *node);
1191 GNode*   g_node_insert          (GNode            *parent,
1192                                  gint              position,
1193                                  GNode            *node);
1194 GNode*   g_node_insert_before   (GNode            *parent,
1195                                  GNode            *sibling,
1196                                  GNode            *node);
1197 GNode*   g_node_prepend         (GNode            *parent,
1198                                  GNode            *node);
1199 guint    g_node_n_nodes         (GNode            *root,
1200                                  GTraverseFlags    flags);
1201 GNode*   g_node_get_root        (GNode            *node);
1202 gboolean g_node_is_ancestor     (GNode            *node,
1203                                  GNode            *descendant);
1204 guint    g_node_depth           (GNode            *node);
1205 GNode*   g_node_find            (GNode            *root,
1206                                  GTraverseType     order,
1207                                  GTraverseFlags    flags,
1208                                  gpointer          data);
1209
1210 /* convenience macros */
1211 #define g_node_append(parent, node)                             \
1212      g_node_insert_before ((parent), NULL, (node))
1213 #define g_node_insert_data(parent, position, data)              \
1214      g_node_insert ((parent), (position), g_node_new (data))
1215 #define g_node_insert_data_before(parent, sibling, data)        \
1216      g_node_insert_before ((parent), (sibling), g_node_new (data))
1217 #define g_node_prepend_data(parent, data)                       \
1218      g_node_prepend ((parent), g_node_new (data))
1219 #define g_node_append_data(parent, data)                        \
1220      g_node_insert_before ((parent), NULL, g_node_new (data))
1221
1222 /* traversal function, assumes that `node' is root
1223  * (only traverses `node' and its subtree).
1224  * this function is just a high level interface to
1225  * low level traversal functions, optimized for speed.
1226  */
1227 void     g_node_traverse        (GNode            *root,
1228                                  GTraverseType     order,
1229                                  GTraverseFlags    flags,
1230                                  gint              max_depth,
1231                                  GNodeTraverseFunc func,
1232                                  gpointer          data);
1233
1234 /* return the maximum tree height starting with `node', this is an expensive
1235  * operation, since we need to visit all nodes. this could be shortened by
1236  * adding `guint height' to struct _GNode, but then again, this is not very
1237  * often needed, and would make g_node_insert() more time consuming.
1238  */
1239 guint    g_node_max_height       (GNode *root);
1240
1241 void     g_node_children_foreach (GNode           *node,
1242                                   GTraverseFlags   flags,
1243                                   GNodeForeachFunc func,
1244                                   gpointer         data);
1245 void     g_node_reverse_children (GNode           *node);
1246 guint    g_node_n_children       (GNode           *node);
1247 GNode*   g_node_nth_child        (GNode           *node,
1248                                   guint            n);
1249 GNode*   g_node_last_child       (GNode           *node);
1250 GNode*   g_node_find_child       (GNode           *node,
1251                                   GTraverseFlags   flags,
1252                                   gpointer         data);
1253 gint     g_node_child_position   (GNode           *node,
1254                                   GNode           *child);
1255 gint     g_node_child_index      (GNode           *node,
1256                                   gpointer         data);
1257
1258 GNode*   g_node_first_sibling    (GNode           *node);
1259 GNode*   g_node_last_sibling     (GNode           *node);
1260
1261 #define  g_node_prev_sibling(node)      ((node) ? \
1262                                          ((GNode*) (node))->prev : NULL)
1263 #define  g_node_next_sibling(node)      ((node) ? \
1264                                          ((GNode*) (node))->next : NULL)
1265 #define  g_node_first_child(node)       ((node) ? \
1266                                          ((GNode*) (node))->children : NULL)
1267
1268
1269 /* Callback maintenance functions
1270  */
1271 #define G_HOOK_FLAG_USER_SHIFT  (4)
1272 typedef enum
1273 {
1274   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1275   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1276   G_HOOK_FLAG_MASK      = 0x0f
1277 } GHookFlagMask;
1278
1279 struct _GHookList
1280 {
1281   guint          seq_id;
1282   guint          hook_size;
1283   guint          is_setup : 1;
1284   GHook         *hooks;
1285   GMemChunk     *hook_memchunk;
1286   GHookFreeFunc  hook_free; /* virtual function */
1287 };
1288
1289 struct _GHook
1290 {
1291   gpointer       data;
1292   GHook         *next;
1293   GHook         *prev;
1294   guint          ref_count;
1295   guint          hook_id;
1296   guint          flags;
1297   gpointer       func;
1298   GDestroyNotify destroy;
1299 };
1300
1301 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
1302                                           G_HOOK_FLAG_ACTIVE) != 0)
1303 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
1304                                           G_HOOK_FLAG_IN_CALL) != 0)
1305 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
1306                                          G_HOOK_ACTIVE (hook))
1307 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
1308                                          ((GHook*) hook)->prev == NULL && \
1309                                          ((GHook*) hook)->hook_id == 0 && \
1310                                          ((GHook*) hook)->ref_count == 0)
1311
1312 void     g_hook_list_init               (GHookList              *hook_list,
1313                                          guint                   hook_size);
1314 void     g_hook_list_clear              (GHookList              *hook_list);
1315 GHook*   g_hook_alloc                   (GHookList              *hook_list);
1316 void     g_hook_free                    (GHookList              *hook_list,
1317                                          GHook                  *hook);
1318 void     g_hook_ref                     (GHookList              *hook_list,
1319                                          GHook                  *hook);
1320 void     g_hook_unref                   (GHookList              *hook_list,
1321                                          GHook                  *hook);
1322 gboolean g_hook_destroy                 (GHookList              *hook_list,
1323                                          guint                   hook_id);
1324 void     g_hook_destroy_link            (GHookList              *hook_list,
1325                                          GHook                  *hook);
1326 void     g_hook_prepend                 (GHookList              *hook_list,
1327                                          GHook                  *hook);
1328 void     g_hook_insert_before           (GHookList              *hook_list,
1329                                          GHook                  *sibling,
1330                                          GHook                  *hook);
1331 void     g_hook_insert_sorted           (GHookList              *hook_list,
1332                                          GHook                  *hook,
1333                                          GHookCompareFunc        func);
1334 GHook*   g_hook_get                     (GHookList              *hook_list,
1335                                          guint                   hook_id);
1336 GHook*   g_hook_find                    (GHookList              *hook_list,
1337                                          gboolean                need_valids,
1338                                          GHookFindFunc           func,
1339                                          gpointer                data);
1340 GHook*   g_hook_find_data               (GHookList              *hook_list,
1341                                          gboolean                need_valids,
1342                                          gpointer                data);
1343 GHook*   g_hook_find_func               (GHookList              *hook_list,
1344                                          gboolean                need_valids,
1345                                          gpointer                func);
1346 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1347                                          gboolean                need_valids,
1348                                          gpointer                func,
1349                                          gpointer                data);
1350 GHook*   g_hook_first_valid             (GHookList              *hook_list,
1351                                          gboolean                may_be_in_call);
1352 GHook*   g_hook_next_valid              (GHook                  *hook,
1353                                          gboolean                may_be_in_call);
1354
1355 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1356 gint     g_hook_compare_ids             (GHook                  *new_hook,
1357                                          GHook                  *sibling);
1358
1359 /* convenience macros */
1360 #define  g_hook_append( hook_list, hook )  \
1361      g_hook_insert_before ((hook_list), NULL, (hook))
1362
1363 /* invoke all valid hooks with the (*GHookFunc) signature.
1364  */
1365 void     g_hook_list_invoke             (GHookList              *hook_list,
1366                                          gboolean                may_recurse);
1367 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1368  * and destroy the hook if FALSE is returned.
1369  */
1370 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1371                                          gboolean                may_recurse);
1372 /* invoke a marshaller on all valid hooks.
1373  */
1374 void     g_hook_list_marshal            (GHookList              *hook_list,
1375                                          gboolean                may_recurse,
1376                                          GHookMarshaller         marshaller,
1377                                          gpointer                data);
1378
1379
1380 /* Fatal error handlers.
1381  * g_on_error_query() will prompt the user to either
1382  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1383  * g_on_error_stack_trace() invokes gdb, which attaches to the current
1384  * process and shows a stack trace.
1385  * These function may cause different actions on non-unix platforms.
1386  * The prg_name arg is required by gdb to find the executable, if it is
1387  * passed as NULL, g_on_error_query() will try g_get_prgname().
1388  */
1389 void g_on_error_query (const gchar *prg_name);
1390 void g_on_error_stack_trace (const gchar *prg_name);
1391
1392
1393 /* Logging mechanism
1394  */
1395 extern          const gchar             *g_log_domain_glib;
1396 guint           g_log_set_handler       (const gchar    *log_domain,
1397                                          GLogLevelFlags  log_levels,
1398                                          GLogFunc        log_func,
1399                                          gpointer        user_data);
1400 void            g_log_remove_handler    (const gchar    *log_domain,
1401                                          guint           handler_id);
1402 void            g_log_default_handler   (const gchar    *log_domain,
1403                                          GLogLevelFlags  log_level,
1404                                          const gchar    *message,
1405                                          gpointer        unused_data);
1406 void            g_log                   (const gchar    *log_domain,
1407                                          GLogLevelFlags  log_level,
1408                                          const gchar    *format,
1409                                          ...) G_GNUC_PRINTF (3, 4);
1410 void            g_logv                  (const gchar    *log_domain,
1411                                          GLogLevelFlags  log_level,
1412                                          const gchar    *format,
1413                                          va_list         args);
1414 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1415                                          GLogLevelFlags  fatal_mask);
1416 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1417 #ifndef G_LOG_DOMAIN
1418 #define G_LOG_DOMAIN    (NULL)
1419 #endif  /* G_LOG_DOMAIN */
1420 #ifdef  __GNUC__
1421 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1422                                                G_LOG_LEVEL_ERROR, \
1423                                                format, ##args)
1424 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1425                                                G_LOG_LEVEL_MESSAGE, \
1426                                                format, ##args)
1427 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1428                                                G_LOG_LEVEL_WARNING, \
1429                                                format, ##args)
1430 #else   /* !__GNUC__ */
1431 static inline void
1432 g_error (const gchar *format,
1433          ...)
1434 {
1435   va_list args;
1436   va_start (args, format);
1437   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1438   va_end (args);
1439 }
1440 static inline void
1441 g_message (const gchar *format,
1442            ...)
1443 {
1444   va_list args;
1445   va_start (args, format);
1446   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1447   va_end (args);
1448 }
1449 static inline void
1450 g_warning (const gchar *format,
1451            ...)
1452 {
1453   va_list args;
1454   va_start (args, format);
1455   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1456   va_end (args);
1457 }
1458 #endif  /* !__GNUC__ */
1459
1460 typedef void    (*GPrintFunc)           (const gchar    *string);
1461 void            g_print                 (const gchar    *format,
1462                                          ...) G_GNUC_PRINTF (1, 2);
1463 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1464 void            g_printerr              (const gchar    *format,
1465                                          ...) G_GNUC_PRINTF (1, 2);
1466 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1467
1468 /* deprecated compatibility functions, use g_log_set_handler() instead */
1469 typedef void            (*GErrorFunc)           (const gchar *str);
1470 typedef void            (*GWarningFunc)         (const gchar *str);
1471 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1472 GWarningFunc g_set_warning_handler (GWarningFunc func);
1473 GPrintFunc   g_set_message_handler (GPrintFunc func);
1474
1475
1476 /* Memory allocation and debugging
1477  */
1478 #ifdef USE_DMALLOC
1479
1480 #define g_malloc(size)       ((gpointer) MALLOC (size))
1481 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1482 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1483 #define g_free(mem)          FREE (mem)
1484
1485 #else /* !USE_DMALLOC */
1486
1487 gpointer g_malloc      (gulong    size);
1488 gpointer g_malloc0     (gulong    size);
1489 gpointer g_realloc     (gpointer  mem,
1490                         gulong    size);
1491 void     g_free        (gpointer  mem);
1492
1493 #endif /* !USE_DMALLOC */
1494
1495 void     g_mem_profile (void);
1496 void     g_mem_check   (gpointer  mem);
1497
1498
1499 /* "g_mem_chunk_new" creates a new memory chunk.
1500  * Memory chunks are used to allocate pieces of memory which are
1501  *  always the same size. Lists are a good example of such a data type.
1502  * The memory chunk allocates and frees blocks of memory as needed.
1503  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1504  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1505  *  fault...somewhere).
1506  *
1507  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1508  *  want to know what's going on inside do you?)
1509  */
1510
1511 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1512  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1513  *  atom. (They are also useful for lists which use MemChunk to allocate
1514  *  memory but are also part of the MemChunk implementation).
1515  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1516  */
1517
1518 #define G_ALLOC_ONLY      1
1519 #define G_ALLOC_AND_FREE  2
1520
1521 GMemChunk* g_mem_chunk_new     (gchar     *name,
1522                                 gint       atom_size,
1523                                 gulong     area_size,
1524                                 gint       type);
1525 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1526 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1527 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1528 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1529                                 gpointer   mem);
1530 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1531 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1532 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1533 void       g_mem_chunk_info    (void);
1534
1535 /* Ah yes...we have a "g_blow_chunks" function.
1536  * "g_blow_chunks" simply compresses all the chunks. This operation
1537  *  consists of freeing every memory area that should be freed (but
1538  *  which we haven't gotten around to doing yet). And, no,
1539  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1540  *  much better name than "g_mem_chunk_clean_all" or something
1541  *  similar.
1542  */
1543 void g_blow_chunks (void);
1544
1545
1546 /* Timer
1547  */
1548 GTimer* g_timer_new     (void);
1549 void    g_timer_destroy (GTimer  *timer);
1550 void    g_timer_start   (GTimer  *timer);
1551 void    g_timer_stop    (GTimer  *timer);
1552 void    g_timer_reset   (GTimer  *timer);
1553 gdouble g_timer_elapsed (GTimer  *timer,
1554                          gulong  *microseconds);
1555
1556
1557 /* String utility functions that modify a string argument or
1558  * return a constant string that must not be freed.
1559  */
1560 #define  G_STR_DELIMITERS       "_-|> <."
1561 gchar*   g_strdelimit           (gchar       *string,
1562                                  const gchar *delimiters,
1563                                  gchar        new_delimiter);
1564 gdouble  g_strtod               (const gchar *nptr,
1565                                  gchar      **endptr);
1566 gchar*   g_strerror             (gint         errnum);
1567 gchar*   g_strsignal            (gint         signum);
1568 gint     g_strcasecmp           (const gchar *s1,
1569                                  const gchar *s2);
1570 void     g_strdown              (gchar       *string);
1571 void     g_strup                (gchar       *string);
1572 void     g_strreverse           (gchar       *string);
1573 /* removes leading spaces */
1574 gchar*   g_strchug              (gchar        *string);
1575 /* removes trailing spaces */
1576 gchar*  g_strchomp              (gchar        *string);
1577 /* removes leading & trailing spaces */
1578 #define g_strstrip( string )    g_strchomp (g_strchug (string))
1579
1580 /* String utility functions that return a newly allocated string which
1581  * ought to be freed from the caller at some point.
1582  */
1583 gchar*   g_strdup               (const gchar *str);
1584 gchar*   g_strdup_printf        (const gchar *format,
1585                                  ...) G_GNUC_PRINTF (1, 2);
1586 gchar*   g_strdup_vprintf       (const gchar *format,
1587                                  va_list      args);
1588 gchar*   g_strndup              (const gchar *str,
1589                                  guint        n);
1590 gchar*   g_strnfill             (guint        length,
1591                                  gchar        fill_char);
1592 gchar*   g_strconcat            (const gchar *string1,
1593                                  ...); /* NULL terminated */
1594 gchar*   g_strjoin              (const gchar  *separator,
1595                                  ...); /* NULL terminated */
1596 gchar*   g_strescape            (gchar        *string);
1597 gpointer g_memdup               (gconstpointer mem,
1598                                  guint         byte_size);
1599
1600 /* NULL terminated string arrays.
1601  * g_strsplit() splits up string into max_tokens tokens at delim and
1602  * returns a newly allocated string array.
1603  * g_strjoinv() concatenates all of str_array's strings, sliding in an
1604  * optional separator, the returned string is newly allocated.
1605  * g_strfreev() frees the array itself and all of its strings.
1606  */
1607 gchar**  g_strsplit             (const gchar  *string,
1608                                  const gchar  *delimiter,
1609                                  gint          max_tokens);
1610 gchar*   g_strjoinv             (const gchar  *separator,
1611                                  gchar       **str_array);
1612 void     g_strfreev             (gchar       **str_array);
1613
1614
1615
1616 /* calculate a string size, guarranteed to fit format + args.
1617  */
1618 guint   g_printf_string_upper_bound (const gchar* format,
1619                                      va_list      args);
1620
1621
1622 /* Retrive static string info
1623  */
1624 gchar*  g_get_user_name         (void);
1625 gchar*  g_get_real_name         (void);
1626 gchar*  g_get_home_dir          (void);
1627 gchar*  g_get_tmp_dir           (void);
1628 gchar*  g_get_prgname           (void);
1629 void    g_set_prgname           (const gchar *prgname);
1630
1631
1632 /* Miscellaneous utility functions
1633  */
1634 guint   g_parse_debug_string    (const gchar *string,
1635                                  GDebugKey   *keys,
1636                                  guint        nkeys);
1637 gint    g_snprintf              (gchar       *string,
1638                                  gulong       n,
1639                                  gchar const *format,
1640                                  ...) G_GNUC_PRINTF (3, 4);
1641 gint    g_vsnprintf             (gchar       *string,
1642                                  gulong       n,
1643                                  gchar const *format,
1644                                  va_list      args);
1645 gchar*  g_basename              (const gchar *file_name);
1646 /* Check if a file name is an absolute path */
1647 gboolean g_path_is_absolute     (const gchar *file_name);
1648 /* In case of absolute paths, skip the root part */
1649 gchar*  g_path_skip_root        (gchar       *file_name);
1650
1651 /* strings are newly allocated with g_malloc() */
1652 gchar*  g_dirname               (const gchar *file_name);
1653 gchar*  g_get_current_dir       (void);
1654 gchar*  g_getenv                (const gchar *variable);
1655
1656 /* We make the assumption that if memmove isn't available, then
1657  * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1658  * necessarily handle overlapping copies).
1659  * Either way, g_memmove() will not return a value.
1660  */
1661 #ifdef HAVE_MEMMOVE
1662 #define g_memmove(dest, src, size)      G_STMT_START {  \
1663      memmove ((dest), (src), (size));                   \
1664 } G_STMT_END
1665 #else
1666 #define g_memmove(dest, src, size)      G_STMT_START {  \
1667      bcopy ((src), (dest), (size));                     \
1668 } G_STMT_END
1669 #endif
1670
1671 /* we use a GLib function as a replacement for ATEXIT, so
1672  * the programmer is not required to check the return value
1673  * (if there is any in the implementation) and doesn't encounter
1674  * missing include files.
1675  */
1676 void    g_atexit                (GVoidFunc    func);
1677
1678
1679 /* Bit tests
1680  */
1681 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1682                                        gint    nth_bit);
1683 #ifdef  G_CAN_INLINE
1684 G_INLINE_FUNC gint
1685 g_bit_nth_lsf (guint32 mask,
1686                gint    nth_bit)
1687 {
1688   do
1689     {
1690       nth_bit++;
1691       if (mask & (1 << (guint) nth_bit))
1692         return nth_bit;
1693     }
1694   while (nth_bit < 32);
1695   return -1;
1696 }
1697 #endif  /* G_CAN_INLINE */
1698
1699 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1700                                        gint    nth_bit);
1701 #ifdef G_CAN_INLINE
1702 G_INLINE_FUNC gint
1703 g_bit_nth_msf (guint32 mask,
1704                gint    nth_bit)
1705 {
1706   if (nth_bit < 0)
1707     nth_bit = 33;
1708   do
1709     {
1710       nth_bit--;
1711       if (mask & (1 << (guint) nth_bit))
1712         return nth_bit;
1713     }
1714   while (nth_bit > 0);
1715   return -1;
1716 }
1717 #endif  /* G_CAN_INLINE */
1718
1719 G_INLINE_FUNC guint     g_bit_storage (guint number);
1720 #ifdef G_CAN_INLINE
1721 G_INLINE_FUNC guint
1722 g_bit_storage (guint number)
1723 {
1724   register guint n_bits = 0;
1725   
1726   do
1727     {
1728       n_bits++;
1729       number >>= 1;
1730     }
1731   while (number);
1732   return n_bits;
1733 }
1734 #endif  /* G_CAN_INLINE */
1735
1736 /* String Chunks
1737  */
1738 GStringChunk* g_string_chunk_new           (gint size);
1739 void          g_string_chunk_free          (GStringChunk *chunk);
1740 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1741                                             const gchar  *string);
1742 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1743                                             const gchar  *string);
1744
1745
1746 /* Strings
1747  */
1748 GString* g_string_new       (const gchar *init);
1749 GString* g_string_sized_new (guint        dfl_size);
1750 void     g_string_free      (GString     *string,
1751                              gint         free_segment);
1752 GString* g_string_assign    (GString     *lval,
1753                              const gchar *rval);
1754 GString* g_string_truncate  (GString     *string,
1755                              gint         len);
1756 GString* g_string_append    (GString     *string,
1757                              const gchar *val);
1758 GString* g_string_append_c  (GString     *string,
1759                              gchar        c);
1760 GString* g_string_prepend   (GString     *string,
1761                              const gchar *val);
1762 GString* g_string_prepend_c (GString     *string,
1763                              gchar        c);
1764 GString* g_string_insert    (GString     *string,
1765                              gint         pos,
1766                              const gchar *val);
1767 GString* g_string_insert_c  (GString     *string,
1768                              gint         pos,
1769                              gchar        c);
1770 GString* g_string_erase     (GString     *string,
1771                              gint         pos,
1772                              gint         len);
1773 GString* g_string_down      (GString     *string);
1774 GString* g_string_up        (GString     *string);
1775 void     g_string_sprintf   (GString     *string,
1776                              const gchar *format,
1777                              ...) G_GNUC_PRINTF (2, 3);
1778 void     g_string_sprintfa  (GString     *string,
1779                              const gchar *format,
1780                              ...) G_GNUC_PRINTF (2, 3);
1781
1782
1783 /* Resizable arrays
1784  */
1785
1786 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1787 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1788 #define g_array_index(a,t,i) (((t*)a->data)[i])
1789
1790 GArray* g_array_new          (gboolean      zero_terminated,
1791                               gboolean      clear,
1792                               guint         element_size);
1793 void    g_array_free         (GArray       *array,
1794                               gboolean      free_segment);
1795 GArray* g_array_append_vals  (GArray       *array,
1796                               gconstpointer data,
1797                               guint         len);
1798 GArray* g_array_prepend_vals (GArray       *array,
1799                               gconstpointer data,
1800                               guint         len);
1801 GArray* g_array_set_size     (GArray       *array,
1802                               guint         length);
1803
1804 /* Resizable pointer array.  This interface is much less complicated
1805  * than the above.  Add appends appends a pointer.  Remove fills any
1806  * cleared spot and shortens the array.
1807  */
1808 #define     g_ptr_array_index(array,index) (array->pdata)[index]
1809 GPtrArray*  g_ptr_array_new                (void);
1810 void        g_ptr_array_free               (GPtrArray   *array,
1811                                             gboolean     free_seg);
1812 void        g_ptr_array_set_size           (GPtrArray   *array,
1813                                             gint         length);
1814 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1815                                             gint         index);
1816 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1817                                             gpointer     data);
1818 void        g_ptr_array_add                (GPtrArray   *array,
1819                                             gpointer     data);
1820
1821 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1822  * but type-safe.
1823  */
1824
1825 GByteArray* g_byte_array_new      (void);
1826 void        g_byte_array_free     (GByteArray   *array,
1827                                    gboolean      free_segment);
1828 GByteArray* g_byte_array_append   (GByteArray   *array,
1829                                    const guint8 *data,
1830                                    guint         len);
1831 GByteArray* g_byte_array_prepend  (GByteArray   *array,
1832                                    const guint8 *data,
1833                                    guint         len);
1834 GByteArray* g_byte_array_set_size (GByteArray   *array,
1835                                    guint         length);
1836
1837
1838 /* Hash Functions
1839  */
1840 gint  g_str_equal (gconstpointer   v,
1841                    gconstpointer   v2);
1842 guint g_str_hash  (gconstpointer   v);
1843
1844 gint  g_int_equal (gconstpointer   v,
1845                    gconstpointer   v2);
1846 guint g_int_hash  (gconstpointer   v);
1847
1848 /* This "hash" function will just return the key's adress as an
1849  * unsigned integer. Useful for hashing on plain adresses or
1850  * simple integer values.
1851  */
1852 guint g_direct_hash  (gconstpointer v);
1853 gint  g_direct_equal (gconstpointer v,
1854                       gconstpointer v2);
1855
1856
1857 /* Quarks (string<->id association)
1858  */
1859 GQuark    g_quark_try_string            (const gchar    *string);
1860 GQuark    g_quark_from_static_string    (const gchar    *string);
1861 GQuark    g_quark_from_string           (const gchar    *string);
1862 gchar*    g_quark_to_string             (GQuark          quark);
1863
1864
1865 /* Keyed Data List
1866  */
1867 void      g_datalist_init                (GData          **datalist);
1868 void      g_datalist_clear               (GData          **datalist);
1869 gpointer  g_datalist_id_get_data         (GData          **datalist,
1870                                           GQuark           key_id);
1871 void      g_datalist_id_set_data_full    (GData          **datalist,
1872                                           GQuark           key_id,
1873                                           gpointer         data,
1874                                           GDestroyNotify   destroy_func);
1875 void      g_datalist_id_remove_no_notify (GData          **datalist,
1876                                           GQuark           key_id);
1877 void      g_datalist_foreach             (GData          **datalist,
1878                                           GDataForeachFunc func,
1879                                           gpointer         user_data);
1880 #define   g_datalist_id_set_data(dl, q, d)      \
1881      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1882 #define   g_datalist_id_remove_data(dl, q)      \
1883      g_datalist_id_set_data ((dl), (q), NULL)
1884 #define   g_datalist_get_data(dl, k)            \
1885      (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1886 #define   g_datalist_set_data_full(dl, k, d, f) \
1887      g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1888 #define   g_datalist_remove_no_notify(dl, k)    \
1889      g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1890 #define   g_datalist_set_data(dl, k, d)         \
1891      g_datalist_set_data_full ((dl), (k), (d), NULL)
1892 #define   g_datalist_remove_data(dl, k)         \
1893      g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1894
1895
1896 /* Location Associated Keyed Data
1897  */
1898 void      g_dataset_destroy             (gconstpointer    dataset_location);
1899 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1900                                          GQuark           key_id);
1901 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1902                                          GQuark           key_id,
1903                                          gpointer         data,
1904                                          GDestroyNotify   destroy_func);
1905 void      g_dataset_id_remove_no_notify (gconstpointer    dataset_location,
1906                                          GQuark           key_id);
1907 void      g_dataset_foreach             (gconstpointer    dataset_location,
1908                                          GDataForeachFunc func,
1909                                          gpointer         user_data);
1910 #define   g_dataset_id_set_data(l, k, d)        \
1911      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1912 #define   g_dataset_id_remove_data(l, k)        \
1913      g_dataset_id_set_data ((l), (k), NULL)
1914 #define   g_dataset_get_data(l, k)              \
1915      (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1916 #define   g_dataset_set_data_full(l, k, d, f)   \
1917      g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1918 #define   g_dataset_remove_no_notify(l, k)      \
1919      g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1920 #define   g_dataset_set_data(l, k, d)           \
1921      g_dataset_set_data_full ((l), (k), (d), NULL)
1922 #define   g_dataset_remove_data(l, k)           \
1923      g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1924
1925
1926 /* GScanner: Flexible lexical scanner for general purpose.
1927  */
1928
1929 /* Character sets */
1930 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1931 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1932 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1933                         "\307\310\311\312\313\314\315\316\317\320"\
1934                         "\321\322\323\324\325\326"\
1935                         "\330\331\332\333\334\335\336"
1936 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1937                         "\347\350\351\352\353\354\355\356\357\360"\
1938                         "\361\362\363\364\365\366"\
1939                         "\370\371\372\373\374\375\376\377"
1940
1941 /* Error types */
1942 typedef enum
1943 {
1944   G_ERR_UNKNOWN,
1945   G_ERR_UNEXP_EOF,
1946   G_ERR_UNEXP_EOF_IN_STRING,
1947   G_ERR_UNEXP_EOF_IN_COMMENT,
1948   G_ERR_NON_DIGIT_IN_CONST,
1949   G_ERR_DIGIT_RADIX,
1950   G_ERR_FLOAT_RADIX,
1951   G_ERR_FLOAT_MALFORMED
1952 } GErrorType;
1953
1954 /* Token types */
1955 typedef enum
1956 {
1957   G_TOKEN_EOF                   =   0,
1958   
1959   G_TOKEN_LEFT_PAREN            = '(',
1960   G_TOKEN_RIGHT_PAREN           = ')',
1961   G_TOKEN_LEFT_CURLY            = '{',
1962   G_TOKEN_RIGHT_CURLY           = '}',
1963   G_TOKEN_LEFT_BRACE            = '[',
1964   G_TOKEN_RIGHT_BRACE           = ']',
1965   G_TOKEN_EQUAL_SIGN            = '=',
1966   G_TOKEN_COMMA                 = ',',
1967   
1968   G_TOKEN_NONE                  = 256,
1969   
1970   G_TOKEN_ERROR,
1971   
1972   G_TOKEN_CHAR,
1973   G_TOKEN_BINARY,
1974   G_TOKEN_OCTAL,
1975   G_TOKEN_INT,
1976   G_TOKEN_HEX,
1977   G_TOKEN_FLOAT,
1978   G_TOKEN_STRING,
1979   
1980   G_TOKEN_SYMBOL,
1981   G_TOKEN_IDENTIFIER,
1982   G_TOKEN_IDENTIFIER_NULL,
1983   
1984   G_TOKEN_COMMENT_SINGLE,
1985   G_TOKEN_COMMENT_MULTI,
1986   G_TOKEN_LAST
1987 } GTokenType;
1988
1989 union   _GTokenValue
1990 {
1991   gpointer      v_symbol;
1992   gchar         *v_identifier;
1993   gulong        v_binary;
1994   gulong        v_octal;
1995   gulong        v_int;
1996   gdouble       v_float;
1997   gulong        v_hex;
1998   gchar         *v_string;
1999   gchar         *v_comment;
2000   guchar        v_char;
2001   guint         v_error;
2002 };
2003
2004 struct  _GScannerConfig
2005 {
2006   /* Character sets
2007    */
2008   gchar         *cset_skip_characters;          /* default: " \t\n" */
2009   gchar         *cset_identifier_first;
2010   gchar         *cset_identifier_nth;
2011   gchar         *cpair_comment_single;          /* default: "#\n" */
2012   
2013   /* Should symbol lookup work case sensitive?
2014    */
2015   guint         case_sensitive : 1;
2016   
2017   /* Boolean values to be adjusted "on the fly"
2018    * to configure scanning behaviour.
2019    */
2020   guint         skip_comment_multi : 1;         /* C like comment */
2021   guint         skip_comment_single : 1;        /* single line comment */
2022   guint         scan_comment_multi : 1;         /* scan multi line comments? */
2023   guint         scan_identifier : 1;
2024   guint         scan_identifier_1char : 1;
2025   guint         scan_identifier_NULL : 1;
2026   guint         scan_symbols : 1;
2027   guint         scan_binary : 1;
2028   guint         scan_octal : 1;
2029   guint         scan_float : 1;
2030   guint         scan_hex : 1;                   /* `0x0ff0' */
2031   guint         scan_hex_dollar : 1;            /* `$0ff0' */
2032   guint         scan_string_sq : 1;             /* string: 'anything' */
2033   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
2034   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
2035   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
2036   guint         identifier_2_string : 1;
2037   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
2038   guint         symbol_2_token : 1;
2039   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
2040 };
2041
2042 struct  _GScanner
2043 {
2044   /* unused fields */
2045   gpointer              user_data;
2046   guint                 max_parse_errors;
2047   
2048   /* g_scanner_error() increments this field */
2049   guint                 parse_errors;
2050   
2051   /* name of input stream, featured by the default message handler */
2052   const gchar           *input_name;
2053   
2054   /* data pointer for derived structures */
2055   gpointer              derived_data;
2056   
2057   /* link into the scanner configuration */
2058   GScannerConfig        *config;
2059   
2060   /* fields filled in after g_scanner_get_next_token() */
2061   GTokenType            token;
2062   GTokenValue           value;
2063   guint                 line;
2064   guint                 position;
2065   
2066   /* fields filled in after g_scanner_peek_next_token() */
2067   GTokenType            next_token;
2068   GTokenValue           next_value;
2069   guint                 next_line;
2070   guint                 next_position;
2071   
2072   /* to be considered private */
2073   GHashTable            *symbol_table;
2074   gint                  input_fd;
2075   const gchar           *text;
2076   const gchar           *text_end;
2077   gchar                 *buffer;
2078   guint                 scope_id;
2079   
2080   /* handler function for _warn and _error */
2081   GScannerMsgFunc       msg_handler;
2082 };
2083
2084 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
2085 void            g_scanner_destroy               (GScanner       *scanner);
2086 void            g_scanner_input_file            (GScanner       *scanner,
2087                                                  gint           input_fd);
2088 void            g_scanner_sync_file_offset      (GScanner       *scanner);
2089 void            g_scanner_input_text            (GScanner       *scanner,
2090                                                  const  gchar   *text,
2091                                                  guint          text_len);
2092 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
2093 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
2094 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
2095 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
2096 guint           g_scanner_cur_line              (GScanner       *scanner);
2097 guint           g_scanner_cur_position          (GScanner       *scanner);
2098 gboolean        g_scanner_eof                   (GScanner       *scanner);
2099 guint           g_scanner_set_scope             (GScanner       *scanner,
2100                                                  guint           scope_id);
2101 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
2102                                                  guint           scope_id,
2103                                                  const gchar    *symbol,
2104                                                  gpointer       value);
2105 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
2106                                                  guint           scope_id,
2107                                                  const gchar    *symbol);
2108 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
2109                                                  guint           scope_id,
2110                                                  const gchar    *symbol);
2111 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
2112                                                  guint           scope_id,
2113                                                  GHFunc          func,
2114                                                  gpointer        func_data);
2115 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
2116                                                  const gchar    *symbol);
2117 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
2118 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
2119 void            g_scanner_unexp_token           (GScanner       *scanner,
2120                                                  GTokenType     expected_token,
2121                                                  const gchar    *identifier_spec,
2122                                                  const gchar    *symbol_spec,
2123                                                  const gchar    *symbol_name,
2124                                                  const gchar    *message,
2125                                                  gint            is_error);
2126 void            g_scanner_error                 (GScanner       *scanner,
2127                                                  const gchar    *format,
2128                                                  ...) G_GNUC_PRINTF (2,3);
2129 void            g_scanner_warn                  (GScanner       *scanner,
2130                                                  const gchar    *format,
2131                                                  ...) G_GNUC_PRINTF (2,3);
2132 gint            g_scanner_stat_mode             (const gchar    *filename);
2133 /* keep downward source compatibility */
2134 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
2135   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
2136 } G_STMT_END
2137 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
2138   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2139 } G_STMT_END
2140 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2141   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2142 } G_STMT_END
2143
2144
2145 /* Completion */
2146
2147 struct _GCompletion
2148 {
2149   GList* items;
2150   GCompletionFunc func;
2151   
2152   gchar* prefix;
2153   GList* cache;
2154 };
2155
2156 GCompletion* g_completion_new          (GCompletionFunc func);
2157 void         g_completion_add_items    (GCompletion*    cmp,
2158                                         GList*          items);
2159 void         g_completion_remove_items (GCompletion*    cmp,
2160                                         GList*          items);
2161 void         g_completion_clear_items  (GCompletion*    cmp);
2162 GList*       g_completion_complete     (GCompletion*    cmp,
2163                                         gchar*          prefix,
2164                                         gchar**         new_prefix);
2165 void         g_completion_free         (GCompletion*    cmp);
2166
2167
2168 /* GRelation: Indexed Relations.  Imagine a really simple table in a
2169  * database.  Relations are not ordered.  This data type is meant for
2170  * maintaining a N-way mapping.
2171  *
2172  * g_relation_new() creates a relation with FIELDS fields
2173  *
2174  * g_relation_destroy() frees all resources
2175  * g_tuples_destroy() frees the result of g_relation_select()
2176  *
2177  * g_relation_index() indexes relation FIELD with the provided
2178  *   equality and hash functions.  this must be done before any
2179  *   calls to insert are made.
2180  *
2181  * g_relation_insert() inserts a new tuple.  you are expected to
2182  *   provide the right number of fields.
2183  *
2184  * g_relation_delete() deletes all relations with KEY in FIELD
2185  * g_relation_select() returns ...
2186  * g_relation_count() counts ...
2187  */
2188
2189 GRelation* g_relation_new     (gint         fields);
2190 void       g_relation_destroy (GRelation   *relation);
2191 void       g_relation_index   (GRelation   *relation,
2192                                gint         field,
2193                                GHashFunc    hash_func,
2194                                GCompareFunc key_compare_func);
2195 void       g_relation_insert  (GRelation   *relation,
2196                                ...);
2197 gint       g_relation_delete  (GRelation   *relation,
2198                                gconstpointer  key,
2199                                gint         field);
2200 GTuples*   g_relation_select  (GRelation   *relation,
2201                                gconstpointer  key,
2202                                gint         field);
2203 gint       g_relation_count   (GRelation   *relation,
2204                                gconstpointer  key,
2205                                gint         field);
2206 gboolean   g_relation_exists  (GRelation   *relation,
2207                                ...);
2208 void       g_relation_print   (GRelation   *relation);
2209
2210 void       g_tuples_destroy   (GTuples     *tuples);
2211 gpointer   g_tuples_index     (GTuples     *tuples,
2212                                gint         index,
2213                                gint         field);
2214
2215
2216 /* Prime numbers.
2217  */
2218
2219 /* This function returns prime numbers spaced by approximately 1.5-2.0
2220  * and is for use in resizing data structures which prefer
2221  * prime-valued sizes.  The closest spaced prime function returns the
2222  * next largest prime, or the highest it knows about which is about
2223  * MAXINT/4.
2224  */
2225 guint      g_spaced_primes_closest (guint num);
2226
2227
2228 /* IO Channels.
2229  * These are used for plug-in communication in the GIMP, for instance.
2230  * On Unix, it's simply an encapsulated file descriptor (a pipe).
2231  * On Windows, it's a handle to an anonymouos pipe, *and* (in the case
2232  * of the writable end) a thread id to post a message to when you have written
2233  * stuff.
2234  */
2235 struct _GIOChannel
2236 {
2237   gint fd;                      /* file handle (pseudo such in Win32) */
2238 #ifdef NATIVE_WIN32
2239   guint peer;                   /* thread to post message to */
2240   guint peer_fd;                /* read handle (in the other process) */
2241   guint offset;                 /* counter of accumulated bytes, to
2242                                  * be included in the message posted
2243                                  * so we keep in sync.
2244                                  */
2245   guint peer_offset;            /* in input channels where the writer's
2246                                  * offset is, so we don't try to read too much
2247                                  */
2248 #endif
2249 };
2250
2251 GIOChannel *g_iochannel_new            (gint        fd);
2252 void        g_iochannel_free           (GIOChannel *channel);
2253 void        g_iochannel_close_and_free (GIOChannel *channel);
2254 void        g_iochannel_wakeup_peer    (GIOChannel *channel);
2255 #ifndef NATIVE_WIN32
2256 #  define   g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END
2257 #endif
2258
2259
2260 /* Windows emulation stubs for common unix functions
2261  */
2262 #ifdef NATIVE_WIN32
2263
2264 #define MAXPATHLEN 1024
2265
2266 #ifdef _MSC_VER
2267 typedef int pid_t;
2268
2269 /* These POSIXish functions are available in the Microsoft C library
2270  * prefixed with underscore (which of course technically speaking is
2271  * the Right Thing, as they are non-ANSI. Not that being non-ANSI
2272  * prevents Microsoft from practically requiring you to include
2273  * <windows.h> every now and then...).
2274  *
2275  * You still need to include the appropriate headers to get the
2276  * prototypes, <io.h> or <direct.h>.
2277  *
2278  * For some functions, we provide emulators in glib, which are prefixed
2279  * with gwin_.
2280  */
2281 #define getcwd                  _getcwd
2282 #define getpid                  _getpid
2283 #define access                  _access
2284 #define open                    _open
2285 #define read                    _read
2286 #define write                   _write
2287 #define lseek                   _lseek
2288 #define close                   _close
2289 #define pipe(phandles)          _pipe (phandles, 4096, _O_BINARY)
2290 #define popen                   _popen
2291 #define pclose                  _pclose
2292 #define fdopen                  _fdopen
2293 #define ftruncate(fd, size)     gwin_ftruncate (fd, size)
2294 #define opendir                 gwin_opendir
2295 #define readdir                 gwin_readdir
2296 #define rewinddir               gwin_rewinddir
2297 #define closedir                gwin_closedir
2298
2299 #define NAME_MAX 255
2300
2301 struct DIR
2302 {
2303   gchar    *dir_name;
2304
2305   gboolean  just_opened;
2306   guint     find_file_handle;
2307   gpointer  find_file_data;
2308 };
2309 typedef struct DIR DIR;
2310 struct dirent
2311 {
2312   gchar  d_name[NAME_MAX + 1];
2313 };
2314
2315 /* emulation functions */
2316 extern int      gwin_ftruncate  (gint            f,
2317                                  guint           size);
2318 DIR*            gwin_opendir    (const gchar    *dirname);
2319 struct dirent*  gwin_readdir    (DIR            *dir);
2320 void            gwin_rewinddir  (DIR            *dir);
2321 gint            gwin_closedir   (DIR            *dir);
2322
2323 #endif /* _MSC_VER */
2324
2325 #endif /* NATIVE_WIN32 */
2326
2327
2328 #ifdef __cplusplus
2329 }
2330 #endif /* __cplusplus */
2331
2332
2333 #endif /* __G_LIB_H__ */