1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
22 /* system specific config file
24 #include <glibconfig.h>
26 /* include varargs functions for assertment macros
30 /* optionally feature DMALLOC memory allocation debugger
39 /* On native Win32, directory separator is the backslash, and search path
40 * separator is the semicolon.
42 #define G_DIR_SEPARATOR '\\'
43 #define G_DIR_SEPARATOR_S "\\"
44 #define G_SEARCHPATH_SEPARATOR ';'
45 #define G_SEARCHPATH_SEPARATOR_S ";"
47 #else /* !NATIVE_WIN32 */
51 #define G_DIR_SEPARATOR '/'
52 #define G_DIR_SEPARATOR_S "/"
53 #define G_SEARCHPATH_SEPARATOR ':'
54 #define G_SEARCHPATH_SEPARATOR_S ":"
56 #endif /* !NATIVE_WIN32 */
59 /* Make MSVC more pedantic, this is a recommended pragma list
60 * from _Win32_Programming_ by Rector and Newcomer.
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)
81 #pragma warning(disable:4244) /* No possible loss of data warnings, please */
84 /* glib provides definitions for the extrema of many
85 * of the standard types. These are:
97 * We include limits.h before float.h to work around a egcs 1.1
98 * oddity on Solaris 2.5.1
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
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 */
122 # define G_MINFLOAT FLT_MIN
123 # define G_MAXFLOAT FLT_MAX
124 # define G_MINDOUBLE DBL_MIN
125 # define G_MAXDOUBLE DBL_MAX
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 */
137 #endif /* __cplusplus */
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.
146 #define NULL ((void*) 0)
154 #define TRUE (!FALSE)
158 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
161 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
164 #define ABS(a) (((a) < 0) ? -(a) : (a))
167 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
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.
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 */
184 /* Provide convenience macros for handling structure
185 * fields through their offsets.
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)))
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.
205 #ifndef G_INLINE_FUNC
206 # define G_CAN_INLINE 1
209 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
211 # define inline __inline__
213 #else /* !G_HAVE_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
228 #ifndef G_INLINE_FUNC
231 # define G_INLINE_FUNC extern inline
234 # define G_INLINE_FUNC extern
236 # else /* !__GNUC__ */
238 # define G_INLINE_FUNC static inline
240 # define G_INLINE_FUNC extern
242 # endif /* !__GNUC__ */
243 #endif /* !G_INLINE_FUNC */
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 ...
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)'.
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 )
260 # if (defined (sun) || defined (__sun__))
261 # define G_STMT_START if (1)
262 # define G_STMT_END else (void)0
264 # define G_STMT_START do
265 # define G_STMT_END while (0)
271 /* Provide macros to feature the GCC function attribute.
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
292 #define G_GNUC_UNUSED
293 #endif /* !__GNUC__ */
296 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
297 * macros, so we can refer to them as strings unconditionally.
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__ */
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.
315 # ifdef NeXT /* @#%@! NeXTStep */
316 # define ATEXIT(proc) (!atexit (proc))
318 # define ATEXIT(proc) (atexit (proc))
320 # elif defined (HAVE_ON_EXIT)
321 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
323 # error Could not determine proper atexit() implementation
326 # define G_NATIVE_ATEXIT
329 /* Hacker macro to place breakpoints for x86 machines.
330 * Actual use is strongly deprecated of course ;)
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__ */
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).
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__ */
359 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
360 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
362 sizeof (type) * (pre_alloc), \
365 #define g_chunk_new(type, chunk) ( \
366 (type *) g_mem_chunk_alloc (chunk) \
368 #define g_chunk_new0(type, chunk) ( \
369 (type *) g_mem_chunk_alloc0 (chunk) \
371 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
372 g_mem_chunk_free ((mem_chunk), (mem)); \
376 #define g_string(x) #x
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.
386 #ifdef G_DISABLE_ASSERT
388 #define g_assert(expr)
389 #define g_assert_not_reached()
391 #else /* !G_DISABLE_ASSERT */
395 #define g_assert(expr) G_STMT_START{ \
397 g_log (G_LOG_DOMAIN, \
399 "file %s: line %d (%s): assertion failed: (%s)", \
402 __PRETTY_FUNCTION__, \
405 #define g_assert_not_reached() G_STMT_START{ \
406 g_log (G_LOG_DOMAIN, \
408 "file %s: line %d (%s): should not be reached", \
411 __PRETTY_FUNCTION__); }G_STMT_END
413 #else /* !__GNUC__ */
415 #define g_assert(expr) G_STMT_START{ \
417 g_log (G_LOG_DOMAIN, \
419 "file %s: line %d: assertion failed: (%s)", \
424 #define g_assert_not_reached() G_STMT_START{ \
425 g_log (G_LOG_DOMAIN, \
427 "file %s: line %d: should not be reached", \
429 __LINE__); }G_STMT_END
431 #endif /* __GNUC__ */
433 #endif /* !G_DISABLE_ASSERT */
436 #ifdef G_DISABLE_CHECKS
438 #define g_return_if_fail(expr)
439 #define g_return_val_if_fail(expr,val)
441 #else /* !G_DISABLE_CHECKS */
445 #define g_return_if_fail(expr) G_STMT_START{ \
448 g_log (G_LOG_DOMAIN, \
449 G_LOG_LEVEL_CRITICAL, \
450 "file %s: line %d (%s): assertion `%s' failed.", \
453 __PRETTY_FUNCTION__, \
458 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
461 g_log (G_LOG_DOMAIN, \
462 G_LOG_LEVEL_CRITICAL, \
463 "file %s: line %d (%s): assertion `%s' failed.", \
466 __PRETTY_FUNCTION__, \
471 #else /* !__GNUC__ */
473 #define g_return_if_fail(expr) G_STMT_START{ \
476 g_log (G_LOG_DOMAIN, \
477 G_LOG_LEVEL_CRITICAL, \
478 "file %s: line %d: assertion `%s' failed.", \
485 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
488 g_log (G_LOG_DOMAIN, \
489 G_LOG_LEVEL_CRITICAL, \
490 "file %s: line %d: assertion `%s' failed.", \
497 #endif /* !__GNUC__ */
499 #endif /* !G_DISABLE_CHECKS */
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.
510 typedef short gshort;
513 typedef gint gboolean;
515 typedef unsigned char guchar;
516 typedef unsigned short gushort;
517 typedef unsigned long gulong;
518 typedef unsigned int guint;
520 typedef float gfloat;
521 typedef double gdouble;
523 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
524 * Since gldouble isn't used anywhere, just disable it for now */
527 #ifdef HAVE_LONG_DOUBLE
528 typedef long double gldouble;
529 #else /* HAVE_LONG_DOUBLE */
530 typedef double gldouble;
531 #endif /* HAVE_LONG_DOUBLE */
534 typedef void* gpointer;
535 typedef const void *gconstpointer;
537 #if (SIZEOF_CHAR == 1)
538 typedef signed char gint8;
539 typedef unsigned char guint8;
540 #endif /* SIZEOF_CHAR */
542 #if (SIZEOF_SHORT == 2)
543 typedef signed short gint16;
544 typedef unsigned short guint16;
545 #endif /* SIZEOF_SHORT */
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 */
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;
569 /* Define macros for storing integers inside pointers
571 #if (SIZEOF_INT == SIZEOF_VOID_P)
573 #define GPOINTER_TO_INT(p) ((gint)(p))
574 #define GPOINTER_TO_UINT(p) ((guint)(p))
576 #define GINT_TO_POINTER(i) ((gpointer)(i))
577 #define GUINT_TO_POINTER(u) ((gpointer)(u))
579 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
581 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
582 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
584 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
585 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
588 #error SIZEOF_VOID_P unknown - This should never happen
591 typedef gint32 gssize;
592 typedef guint32 gsize;
593 typedef guint32 GQuark;
594 typedef gint32 GTime;
597 /* Portable endian checks and conversions
600 #define G_LITTLE_ENDIAN 1234
601 #define G_BIG_ENDIAN 4321
602 #define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */
604 #ifdef WORDS_BIGENDIAN
605 #define G_BYTE_ORDER G_BIG_ENDIAN
607 #define G_BYTE_ORDER G_LITTLE_ENDIAN
610 /* Basic bit swapping functions
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)))
621 /* Intel specific stuff for speed
623 #if defined (__i386__) && (defined __GNUC__)
625 # define GUINT16_SWAP_LE_BE_X86(val) \
627 ({ register guint16 __v; \
628 if (__builtin_constant_p (val)) \
629 __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \
631 __asm__ __volatile__ ("rorw $8, %w0" \
633 : "0" ((guint16) (val)) \
637 # define GUINT16_SWAP_LE_BE(val) \
638 ((guint16) GUINT16_SWAP_LE_BE_X86 ((guint16) (val)))
640 # if !defined(__i486__) && !defined(__i586__) \
641 && !defined(__pentium__) && !defined(__pentiumpro__) && !defined(__i686__)
642 # define GUINT32_SWAP_LE_BE_X86(val) \
644 ({ register guint32 __v; \
645 if (__builtin_constant_p (val)) \
646 __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
648 __asm__ __volatile__ ("rorw $8, %w0\n\t" \
652 : "0" ((guint32) (val)) \
656 # else /* 486 and higher has bswap */
657 # define GUINT32_SWAP_LE_BE_X86(val) \
659 ({ register guint32 __v; \
660 if (__builtin_constant_p (val)) \
661 __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
663 __asm__ __volatile__ ("bswap %0" \
665 : "0" ((guint32) (val))); \
667 # endif /* processor specific 32-bit stuff */
669 # define GUINT32_SWAP_LE_BE(val) \
670 ((guint32) GUINT32_SWAP_LE_BE_X86 ((guint32) (val)))
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__ */
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)))
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)))
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))
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))
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))
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))
753 /* PDP stuff not implemented */
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))
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))
805 /* Portable versions of host-network order stuff
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))
814 * we prefix variable declarations so they can
815 * properly get exported in windows dlls.
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 */
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;
833 /* Forward declarations of glib types.
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;
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
879 /* Log level shift offset for user defined
880 * log levels (0-7 are used by GLib).
882 #define G_LOG_LEVEL_USER_SHIFT (8)
884 /* Glib log levels and flags.
889 G_LOG_FLAG_RECURSION = 1 << 0,
890 G_LOG_FLAG_FATAL = 1 << 1,
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,
900 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
903 /* GLib log levels that are considered fatal by default */
904 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
907 typedef gpointer (*GCacheNewFunc) (gpointer key);
908 typedef gpointer (*GCacheDupFunc) (gpointer value);
909 typedef void (*GCacheDestroyFunc) (gpointer value);
910 typedef gint (*GCompareFunc) (gconstpointer a,
912 typedef gchar* (*GCompletionFunc) (gpointer);
913 typedef void (*GDestroyNotify) (gpointer data);
914 typedef void (*GDataForeachFunc) (GQuark key_id,
917 typedef void (*GFunc) (gpointer data,
919 typedef guint (*GHashFunc) (gconstpointer key);
920 typedef void (*GHFunc) (gpointer key,
923 typedef gboolean (*GHRFunc) (gpointer key,
926 typedef gint (*GHookCompareFunc) (GHook *new_hook,
928 typedef gboolean (*GHookFindFunc) (GHook *hook,
930 typedef void (*GHookMarshaller) (GHook *hook,
932 typedef void (*GHookFunc) (gpointer data);
933 typedef gboolean (*GHookCheckFunc) (gpointer data);
934 typedef void (*GHookFreeFunc) (GHookList *hook_list,
936 typedef void (*GLogFunc) (const gchar *log_domain,
937 GLogLevelFlags log_level,
938 const gchar *message,
940 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
942 typedef void (*GNodeForeachFunc) (GNode *node,
944 typedef gint (*GSearchFunc) (gpointer key,
946 typedef void (*GScannerMsgFunc) (GScanner *scanner,
949 typedef gint (*GTraverseFunc) (gpointer key,
952 typedef void (*GVoidFunc) (void);
1004 /* Doubly linked lists
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,
1011 GList* g_list_prepend (GList *list,
1013 GList* g_list_insert (GList *list,
1016 GList* g_list_insert_sorted (GList *list,
1019 GList* g_list_concat (GList *list1,
1021 GList* g_list_remove (GList *list,
1023 GList* g_list_remove_link (GList *list,
1025 GList* g_list_reverse (GList *list);
1026 GList* g_list_nth (GList *list,
1028 GList* g_list_find (GList *list,
1030 GList* g_list_find_custom (GList *list,
1033 gint g_list_position (GList *list,
1035 gint g_list_index (GList *list,
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,
1042 gpointer user_data);
1043 gpointer g_list_nth_data (GList *list,
1045 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
1046 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
1049 /* Singly linked lists
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,
1056 GSList* g_slist_prepend (GSList *list,
1058 GSList* g_slist_insert (GSList *list,
1061 GSList* g_slist_insert_sorted (GSList *list,
1064 GSList* g_slist_concat (GSList *list1,
1066 GSList* g_slist_remove (GSList *list,
1068 GSList* g_slist_remove_link (GSList *list,
1070 GSList* g_slist_reverse (GSList *list);
1071 GSList* g_slist_nth (GSList *list,
1073 GSList* g_slist_find (GSList *list,
1075 GSList* g_slist_find_custom (GSList *list,
1078 gint g_slist_position (GSList *list,
1080 gint g_slist_index (GSList *list,
1082 GSList* g_slist_last (GSList *list);
1083 guint g_slist_length (GSList *list);
1084 void g_slist_foreach (GSList *list,
1086 gpointer user_data);
1087 gpointer g_slist_nth_data (GSList *list,
1089 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
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);
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,
1108 void g_hash_table_remove (GHashTable *hash_table,
1110 gpointer g_hash_table_lookup (GHashTable *hash_table,
1112 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
1113 gconstpointer lookup_key,
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,
1120 gpointer user_data);
1121 gint g_hash_table_foreach_remove (GHashTable *hash_table,
1123 gpointer user_data);
1124 gint g_hash_table_size (GHashTable *hash_table);
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,
1139 void g_cache_remove (GCache *cache,
1141 void g_cache_key_foreach (GCache *cache,
1143 gpointer user_data);
1144 void g_cache_value_foreach (GCache *cache,
1146 gpointer user_data);
1149 /* Balanced binary trees
1151 GTree* g_tree_new (GCompareFunc key_compare_func);
1152 void g_tree_destroy (GTree *tree);
1153 void g_tree_insert (GTree *tree,
1156 void g_tree_remove (GTree *tree,
1158 gpointer g_tree_lookup (GTree *tree,
1160 void g_tree_traverse (GTree *tree,
1161 GTraverseFunc traverse_func,
1162 GTraverseType traverse_type,
1164 gpointer g_tree_search (GTree *tree,
1165 GSearchFunc search_func,
1167 gint g_tree_height (GTree *tree);
1168 gint g_tree_nnodes (GTree *tree);
1172 /* N-way tree implementation
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)
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,
1194 GNode* g_node_insert_before (GNode *parent,
1197 GNode* g_node_prepend (GNode *parent,
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,
1204 guint g_node_depth (GNode *node);
1205 GNode* g_node_find (GNode *root,
1206 GTraverseType order,
1207 GTraverseFlags flags,
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))
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.
1227 void g_node_traverse (GNode *root,
1228 GTraverseType order,
1229 GTraverseFlags flags,
1231 GNodeTraverseFunc func,
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.
1239 guint g_node_max_height (GNode *root);
1241 void g_node_children_foreach (GNode *node,
1242 GTraverseFlags flags,
1243 GNodeForeachFunc func,
1245 void g_node_reverse_children (GNode *node);
1246 guint g_node_n_children (GNode *node);
1247 GNode* g_node_nth_child (GNode *node,
1249 GNode* g_node_last_child (GNode *node);
1250 GNode* g_node_find_child (GNode *node,
1251 GTraverseFlags flags,
1253 gint g_node_child_position (GNode *node,
1255 gint g_node_child_index (GNode *node,
1258 GNode* g_node_first_sibling (GNode *node);
1259 GNode* g_node_last_sibling (GNode *node);
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)
1269 /* Callback maintenance functions
1271 #define G_HOOK_FLAG_USER_SHIFT (4)
1274 G_HOOK_FLAG_ACTIVE = 1 << 0,
1275 G_HOOK_FLAG_IN_CALL = 1 << 1,
1276 G_HOOK_FLAG_MASK = 0x0f
1285 GMemChunk *hook_memchunk;
1286 GHookFreeFunc hook_free; /* virtual function */
1298 GDestroyNotify destroy;
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)
1312 void g_hook_list_init (GHookList *hook_list,
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,
1318 void g_hook_ref (GHookList *hook_list,
1320 void g_hook_unref (GHookList *hook_list,
1322 gboolean g_hook_destroy (GHookList *hook_list,
1324 void g_hook_destroy_link (GHookList *hook_list,
1326 void g_hook_prepend (GHookList *hook_list,
1328 void g_hook_insert_before (GHookList *hook_list,
1331 void g_hook_insert_sorted (GHookList *hook_list,
1333 GHookCompareFunc func);
1334 GHook* g_hook_get (GHookList *hook_list,
1336 GHook* g_hook_find (GHookList *hook_list,
1337 gboolean need_valids,
1340 GHook* g_hook_find_data (GHookList *hook_list,
1341 gboolean need_valids,
1343 GHook* g_hook_find_func (GHookList *hook_list,
1344 gboolean need_valids,
1346 GHook* g_hook_find_func_data (GHookList *hook_list,
1347 gboolean need_valids,
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);
1355 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1356 gint g_hook_compare_ids (GHook *new_hook,
1359 /* convenience macros */
1360 #define g_hook_append( hook_list, hook ) \
1361 g_hook_insert_before ((hook_list), NULL, (hook))
1363 /* invoke all valid hooks with the (*GHookFunc) signature.
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.
1370 void g_hook_list_invoke_check (GHookList *hook_list,
1371 gboolean may_recurse);
1372 /* invoke a marshaller on all valid hooks.
1374 void g_hook_list_marshal (GHookList *hook_list,
1375 gboolean may_recurse,
1376 GHookMarshaller marshaller,
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().
1389 void g_on_error_query (const gchar *prg_name);
1390 void g_on_error_stack_trace (const gchar *prg_name);
1393 /* Logging mechanism
1395 extern const gchar *g_log_domain_glib;
1396 guint g_log_set_handler (const gchar *log_domain,
1397 GLogLevelFlags log_levels,
1399 gpointer user_data);
1400 void g_log_remove_handler (const gchar *log_domain,
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,
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 */
1421 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1422 G_LOG_LEVEL_ERROR, \
1424 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1425 G_LOG_LEVEL_MESSAGE, \
1427 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1428 G_LOG_LEVEL_WARNING, \
1430 #else /* !__GNUC__ */
1432 g_error (const gchar *format,
1436 va_start (args, format);
1437 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1441 g_message (const gchar *format,
1445 va_start (args, format);
1446 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1450 g_warning (const gchar *format,
1454 va_start (args, format);
1455 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1458 #endif /* !__GNUC__ */
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);
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);
1476 /* Memory allocation and debugging
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)
1485 #else /* !USE_DMALLOC */
1487 gpointer g_malloc (gulong size);
1488 gpointer g_malloc0 (gulong size);
1489 gpointer g_realloc (gpointer mem,
1491 void g_free (gpointer mem);
1493 #endif /* !USE_DMALLOC */
1495 void g_mem_profile (void);
1496 void g_mem_check (gpointer mem);
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).
1507 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1508 * want to know what's going on inside do you?)
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.
1518 #define G_ALLOC_ONLY 1
1519 #define G_ALLOC_AND_FREE 2
1521 GMemChunk* g_mem_chunk_new (gchar *name,
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,
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);
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
1543 void g_blow_chunks (void);
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);
1557 /* String utility functions that modify a string argument or
1558 * return a constant string that must not be freed.
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,
1566 gchar* g_strerror (gint errnum);
1567 gchar* g_strsignal (gint signum);
1568 gint g_strcasecmp (const gchar *s1,
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))
1580 /* String utility functions that return a newly allocated string which
1581 * ought to be freed from the caller at some point.
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,
1588 gchar* g_strndup (const gchar *str,
1590 gchar* g_strnfill (guint length,
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,
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.
1607 gchar** g_strsplit (const gchar *string,
1608 const gchar *delimiter,
1610 gchar* g_strjoinv (const gchar *separator,
1612 void g_strfreev (gchar **str_array);
1616 /* calculate a string size, guarranteed to fit format + args.
1618 guint g_printf_string_upper_bound (const gchar* format,
1622 /* Retrive static string info
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);
1632 /* Miscellaneous utility functions
1634 guint g_parse_debug_string (const gchar *string,
1637 gint g_snprintf (gchar *string,
1639 gchar const *format,
1640 ...) G_GNUC_PRINTF (3, 4);
1641 gint g_vsnprintf (gchar *string,
1643 gchar const *format,
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);
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);
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.
1662 #define g_memmove(dest, src, size) G_STMT_START { \
1663 memmove ((dest), (src), (size)); \
1666 #define g_memmove(dest, src, size) G_STMT_START { \
1667 bcopy ((src), (dest), (size)); \
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.
1676 void g_atexit (GVoidFunc func);
1681 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1685 g_bit_nth_lsf (guint32 mask,
1691 if (mask & (1 << (guint) nth_bit))
1694 while (nth_bit < 32);
1697 #endif /* G_CAN_INLINE */
1699 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1703 g_bit_nth_msf (guint32 mask,
1711 if (mask & (1 << (guint) nth_bit))
1714 while (nth_bit > 0);
1717 #endif /* G_CAN_INLINE */
1719 G_INLINE_FUNC guint g_bit_storage (guint number);
1722 g_bit_storage (guint number)
1724 register guint n_bits = 0;
1734 #endif /* G_CAN_INLINE */
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);
1748 GString* g_string_new (const gchar *init);
1749 GString* g_string_sized_new (guint dfl_size);
1750 void g_string_free (GString *string,
1752 GString* g_string_assign (GString *lval,
1754 GString* g_string_truncate (GString *string,
1756 GString* g_string_append (GString *string,
1758 GString* g_string_append_c (GString *string,
1760 GString* g_string_prepend (GString *string,
1762 GString* g_string_prepend_c (GString *string,
1764 GString* g_string_insert (GString *string,
1767 GString* g_string_insert_c (GString *string,
1770 GString* g_string_erase (GString *string,
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);
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])
1790 GArray* g_array_new (gboolean zero_terminated,
1792 guint element_size);
1793 void g_array_free (GArray *array,
1794 gboolean free_segment);
1795 GArray* g_array_append_vals (GArray *array,
1798 GArray* g_array_prepend_vals (GArray *array,
1801 GArray* g_array_set_size (GArray *array,
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.
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,
1812 void g_ptr_array_set_size (GPtrArray *array,
1814 gpointer g_ptr_array_remove_index (GPtrArray *array,
1816 gboolean g_ptr_array_remove (GPtrArray *array,
1818 void g_ptr_array_add (GPtrArray *array,
1821 /* Byte arrays, an array of guint8. Implemented as a GArray,
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,
1831 GByteArray* g_byte_array_prepend (GByteArray *array,
1834 GByteArray* g_byte_array_set_size (GByteArray *array,
1840 gint g_str_equal (gconstpointer v,
1842 guint g_str_hash (gconstpointer v);
1844 gint g_int_equal (gconstpointer v,
1846 guint g_int_hash (gconstpointer v);
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.
1852 guint g_direct_hash (gconstpointer v);
1853 gint g_direct_equal (gconstpointer v,
1857 /* Quarks (string<->id association)
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);
1867 void g_datalist_init (GData **datalist);
1868 void g_datalist_clear (GData **datalist);
1869 gpointer g_datalist_id_get_data (GData **datalist,
1871 void g_datalist_id_set_data_full (GData **datalist,
1874 GDestroyNotify destroy_func);
1875 void g_datalist_id_remove_no_notify (GData **datalist,
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)
1896 /* Location Associated Keyed Data
1898 void g_dataset_destroy (gconstpointer dataset_location);
1899 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1901 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1904 GDestroyNotify destroy_func);
1905 void g_dataset_id_remove_no_notify (gconstpointer dataset_location,
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)
1926 /* GScanner: Flexible lexical scanner for general purpose.
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"
1946 G_ERR_UNEXP_EOF_IN_STRING,
1947 G_ERR_UNEXP_EOF_IN_COMMENT,
1948 G_ERR_NON_DIGIT_IN_CONST,
1951 G_ERR_FLOAT_MALFORMED
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 = ',',
1982 G_TOKEN_IDENTIFIER_NULL,
1984 G_TOKEN_COMMENT_SINGLE,
1985 G_TOKEN_COMMENT_MULTI,
1992 gchar *v_identifier;
2004 struct _GScannerConfig
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" */
2013 /* Should symbol lookup work case sensitive?
2015 guint case_sensitive : 1;
2017 /* Boolean values to be adjusted "on the fly"
2018 * to configure scanning behaviour.
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? */
2046 guint max_parse_errors;
2048 /* g_scanner_error() increments this field */
2051 /* name of input stream, featured by the default message handler */
2052 const gchar *input_name;
2054 /* data pointer for derived structures */
2055 gpointer derived_data;
2057 /* link into the scanner configuration */
2058 GScannerConfig *config;
2060 /* fields filled in after g_scanner_get_next_token() */
2066 /* fields filled in after g_scanner_peek_next_token() */
2067 GTokenType next_token;
2068 GTokenValue next_value;
2070 guint next_position;
2072 /* to be considered private */
2073 GHashTable *symbol_table;
2076 const gchar *text_end;
2080 /* handler function for _warn and _error */
2081 GScannerMsgFunc msg_handler;
2084 GScanner* g_scanner_new (GScannerConfig *config_templ);
2085 void g_scanner_destroy (GScanner *scanner);
2086 void g_scanner_input_file (GScanner *scanner,
2088 void g_scanner_sync_file_offset (GScanner *scanner);
2089 void g_scanner_input_text (GScanner *scanner,
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,
2101 void g_scanner_scope_add_symbol (GScanner *scanner,
2103 const gchar *symbol,
2105 void g_scanner_scope_remove_symbol (GScanner *scanner,
2107 const gchar *symbol);
2108 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
2110 const gchar *symbol);
2111 void g_scanner_scope_foreach_symbol (GScanner *scanner,
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,
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)); \
2137 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
2138 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2140 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2141 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2150 GCompletionFunc func;
2156 GCompletion* g_completion_new (GCompletionFunc func);
2157 void g_completion_add_items (GCompletion* cmp,
2159 void g_completion_remove_items (GCompletion* cmp,
2161 void g_completion_clear_items (GCompletion* cmp);
2162 GList* g_completion_complete (GCompletion* cmp,
2164 gchar** new_prefix);
2165 void g_completion_free (GCompletion* cmp);
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.
2172 * g_relation_new() creates a relation with FIELDS fields
2174 * g_relation_destroy() frees all resources
2175 * g_tuples_destroy() frees the result of g_relation_select()
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.
2181 * g_relation_insert() inserts a new tuple. you are expected to
2182 * provide the right number of fields.
2184 * g_relation_delete() deletes all relations with KEY in FIELD
2185 * g_relation_select() returns ...
2186 * g_relation_count() counts ...
2189 GRelation* g_relation_new (gint fields);
2190 void g_relation_destroy (GRelation *relation);
2191 void g_relation_index (GRelation *relation,
2193 GHashFunc hash_func,
2194 GCompareFunc key_compare_func);
2195 void g_relation_insert (GRelation *relation,
2197 gint g_relation_delete (GRelation *relation,
2200 GTuples* g_relation_select (GRelation *relation,
2203 gint g_relation_count (GRelation *relation,
2206 gboolean g_relation_exists (GRelation *relation,
2208 void g_relation_print (GRelation *relation);
2210 void g_tuples_destroy (GTuples *tuples);
2211 gpointer g_tuples_index (GTuples *tuples,
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
2225 guint g_spaced_primes_closest (guint num);
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
2237 gint fd; /* file handle (pseudo such in 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.
2245 guint peer_offset; /* in input channels where the writer's
2246 * offset is, so we don't try to read too much
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
2260 /* Windows emulation stubs for common unix functions
2264 #define MAXPATHLEN 1024
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...).
2275 * You still need to include the appropriate headers to get the
2276 * prototypes, <io.h> or <direct.h>.
2278 * For some functions, we provide emulators in glib, which are prefixed
2281 #define getcwd _getcwd
2282 #define getpid _getpid
2283 #define access _access
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
2299 #define NAME_MAX 255
2305 gboolean just_opened;
2306 guint find_file_handle;
2307 gpointer find_file_data;
2309 typedef struct DIR DIR;
2312 gchar d_name[NAME_MAX + 1];
2315 /* emulation functions */
2316 extern int gwin_ftruncate (gint f,
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);
2323 #endif /* _MSC_VER */
2325 #endif /* NATIVE_WIN32 */
2330 #endif /* __cplusplus */
2333 #endif /* __G_LIB_H__ */