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 simple enum value macro wrappers that ease automated
185 * enum value stringification code. [abandoned]
187 #if !defined (G_CODE_GENERATION)
188 #define G_ENUM( EnumerationName ) EnumerationName
189 #define G_FLAGS( EnumerationName ) EnumerationName
190 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
191 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
192 #else /* G_CODE_GENERATION */
193 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
194 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
195 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
196 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
197 #endif /* G_CODE_GENERATION */
200 /* inlining hassle. for compilers that don't allow the `inline' keyword,
201 * mostly because of strict ANSI C compliance or dumbness, we try to fall
202 * back to either `__inline__' or `__inline'.
203 * we define G_CAN_INLINE, if the compiler seems to be actually
204 * *capable* to do function inlining, in which case inline function bodys
205 * do make sense. we also define G_INLINE_FUNC to properly export the
206 * function prototypes if no inlinig can be performed.
207 * we special case most of the stuff, so inline functions can have a normal
208 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
210 #ifndef G_INLINE_FUNC
211 # define G_CAN_INLINE 1
214 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
216 # define inline __inline__
218 #else /* !G_HAVE_INLINE */
220 # if defined (G_HAVE___INLINE__)
221 # define inline __inline__
222 # else /* !inline && !__inline__ */
223 # if defined (G_HAVE___INLINE)
224 # define inline __inline
225 # else /* !inline && !__inline__ && !__inline */
226 # define inline /* don't inline, then */
227 # ifndef G_INLINE_FUNC
233 #ifndef G_INLINE_FUNC
236 # define G_INLINE_FUNC extern inline
239 # define G_INLINE_FUNC extern
241 # else /* !__GNUC__ */
243 # define G_INLINE_FUNC static inline
245 # define G_INLINE_FUNC extern
247 # endif /* !__GNUC__ */
248 #endif /* !G_INLINE_FUNC */
251 /* Provide simple macro statement wrappers (adapted from Perl):
252 * G_STMT_START { statements; } G_STMT_END;
253 * can be used as a single statement, as in
254 * if (x) G_STMT_START { ... } G_STMT_END; else ...
256 * For gcc we will wrap the statements within `({' and `})' braces.
257 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
258 * and otherwise within `do' and `while (0)'.
260 #if !(defined (G_STMT_START) && defined (G_STMT_END))
261 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
262 # define G_STMT_START (void)(
263 # define G_STMT_END )
265 # if (defined (sun) || defined (__sun__))
266 # define G_STMT_START if (1)
267 # define G_STMT_END else (void)0
269 # define G_STMT_START do
270 # define G_STMT_END while (0)
276 /* Provide macros to feature the GCC function attribute.
278 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
279 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
280 __attribute__((format (printf, format_idx, arg_idx)))
281 #define G_GNUC_SCANF( format_idx, arg_idx ) \
282 __attribute__((format (scanf, format_idx, arg_idx)))
283 #define G_GNUC_FORMAT( arg_idx ) \
284 __attribute__((format_arg (arg_idx)))
285 #define G_GNUC_NORETURN \
286 __attribute__((noreturn))
287 #define G_GNUC_CONST \
288 __attribute__((const))
289 #define G_GNUC_UNUSED \
290 __attribute__((unused))
291 #else /* !__GNUC__ */
292 #define G_GNUC_PRINTF( format_idx, arg_idx )
293 #define G_GNUC_SCANF( format_idx, arg_idx )
294 #define G_GNUC_FORMAT( arg_idx )
295 #define G_GNUC_NORETURN
297 #define G_GNUC_UNUSED
298 #endif /* !__GNUC__ */
301 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
302 * macros, so we can refer to them as strings unconditionally.
305 #define G_GNUC_FUNCTION (__FUNCTION__)
306 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
307 #else /* !__GNUC__ */
308 #define G_GNUC_FUNCTION ("")
309 #define G_GNUC_PRETTY_FUNCTION ("")
310 #endif /* !__GNUC__ */
313 /* we try to provide a usefull equivalent for ATEXIT if it is
314 * not defined, but use is actually abandoned. people should
315 * use g_atexit() instead.
316 * keep this in sync with gutils.c.
320 # ifdef NeXT /* @#%@! NeXTStep */
321 # define ATEXIT(proc) (!atexit (proc))
323 # define ATEXIT(proc) (atexit (proc))
325 # elif defined (HAVE_ON_EXIT)
326 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
328 # error Could not determine proper atexit() implementation
331 # define G_NATIVE_ATEXIT
334 /* Hacker macro to place breakpoints for x86 machines.
335 * Actual use is strongly deprecated of course ;)
337 #if defined (__i386__) && defined (__GNUC__)
338 #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
339 #else /* !__i386__ */
340 #define G_BREAKPOINT()
341 #endif /* __i386__ */
344 /* Provide macros for easily allocating memory. The macros
345 * will cast the allocated memory to the specified type
346 * in order to avoid compiler warnings. (Makes the code neater).
350 # define g_new(type, count) (ALLOC (type, count))
351 # define g_new0(type, count) (CALLOC (type, count))
352 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
353 #else /* __DMALLOC_H__ */
354 # define g_new(type, count) \
355 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
356 # define g_new0(type, count) \
357 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
358 # define g_renew(type, mem, count) \
359 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
360 #endif /* __DMALLOC_H__ */
362 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
363 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
365 sizeof (type) * (pre_alloc), \
368 #define g_chunk_new(type, chunk) ( \
369 (type *) g_mem_chunk_alloc (chunk) \
371 #define g_chunk_new0(type, chunk) ( \
372 (type *) g_mem_chunk_alloc0 (chunk) \
374 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
375 g_mem_chunk_free ((mem_chunk), (mem)); \
379 #define g_string(x) #x
382 /* Provide macros for error handling. The "assert" macros will
383 * exit on failure. The "return" macros will exit the current
384 * function. Two different definitions are given for the macros
385 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
386 * __PRETTY_FUNCTION__ capability.
389 #ifdef G_DISABLE_ASSERT
391 #define g_assert(expr)
392 #define g_assert_not_reached()
394 #else /* !G_DISABLE_ASSERT */
398 #define g_assert(expr) G_STMT_START{ \
400 g_log (G_LOG_DOMAIN, \
402 "file %s: line %d (%s): assertion failed: (%s)", \
405 __PRETTY_FUNCTION__, \
408 #define g_assert_not_reached() G_STMT_START{ \
409 g_log (G_LOG_DOMAIN, \
411 "file %s: line %d (%s): should not be reached", \
414 __PRETTY_FUNCTION__); }G_STMT_END
416 #else /* !__GNUC__ */
418 #define g_assert(expr) G_STMT_START{ \
420 g_log (G_LOG_DOMAIN, \
422 "file %s: line %d: assertion failed: (%s)", \
427 #define g_assert_not_reached() G_STMT_START{ \
428 g_log (G_LOG_DOMAIN, \
430 "file %s: line %d: should not be reached", \
432 __LINE__); }G_STMT_END
434 #endif /* __GNUC__ */
436 #endif /* !G_DISABLE_ASSERT */
439 #ifdef G_DISABLE_CHECKS
441 #define g_return_if_fail(expr)
442 #define g_return_val_if_fail(expr,val)
444 #else /* !G_DISABLE_CHECKS */
448 #define g_return_if_fail(expr) G_STMT_START{ \
451 g_log (G_LOG_DOMAIN, \
452 G_LOG_LEVEL_CRITICAL, \
453 "file %s: line %d (%s): assertion `%s' failed.", \
456 __PRETTY_FUNCTION__, \
461 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
464 g_log (G_LOG_DOMAIN, \
465 G_LOG_LEVEL_CRITICAL, \
466 "file %s: line %d (%s): assertion `%s' failed.", \
469 __PRETTY_FUNCTION__, \
474 #else /* !__GNUC__ */
476 #define g_return_if_fail(expr) G_STMT_START{ \
479 g_log (G_LOG_DOMAIN, \
480 G_LOG_LEVEL_CRITICAL, \
481 "file %s: line %d: assertion `%s' failed.", \
488 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
491 g_log (G_LOG_DOMAIN, \
492 G_LOG_LEVEL_CRITICAL, \
493 "file %s: line %d: assertion `%s' failed.", \
500 #endif /* !__GNUC__ */
502 #endif /* !G_DISABLE_CHECKS */
505 /* Provide type definitions for commonly used types.
506 * These are useful because a "gint8" can be adjusted
507 * to be 1 byte (8 bits) on all platforms. Similarly and
508 * more importantly, "gint32" can be adjusted to be
509 * 4 bytes (32 bits) on all platforms.
513 typedef short gshort;
516 typedef gint gboolean;
518 typedef unsigned char guchar;
519 typedef unsigned short gushort;
520 typedef unsigned long gulong;
521 typedef unsigned int guint;
523 typedef float gfloat;
524 typedef double gdouble;
526 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
527 * Since gldouble isn't used anywhere, just disable it for now */
530 #ifdef HAVE_LONG_DOUBLE
531 typedef long double gldouble;
532 #else /* HAVE_LONG_DOUBLE */
533 typedef double gldouble;
534 #endif /* HAVE_LONG_DOUBLE */
537 typedef void* gpointer;
538 typedef const void *gconstpointer;
540 #if (SIZEOF_CHAR == 1)
541 typedef signed char gint8;
542 typedef unsigned char guint8;
543 #endif /* SIZEOF_CHAR */
545 #if (SIZEOF_SHORT == 2)
546 typedef signed short gint16;
547 typedef unsigned short guint16;
548 #endif /* SIZEOF_SHORT */
550 #if (SIZEOF_INT == 4)
551 typedef signed int gint32;
552 typedef unsigned int guint32;
553 #elif (SIZEOF_LONG == 4)
554 typedef signed long gint32;
555 typedef unsigned long guint32;
556 #endif /* SIZEOF_INT */
558 #if (SIZEOF_LONG == 8)
559 #define HAVE_GINT64 1
560 typedef signed long gint64;
561 typedef unsigned long guint64;
562 #elif (SIZEOF_LONG_LONG == 8)
563 #define HAVE_GINT64 1
564 typedef signed long long gint64;
565 typedef unsigned long long guint64;
572 /* Define macros for storing integers inside pointers
574 #if (SIZEOF_INT == SIZEOF_VOID_P)
576 #define GPOINTER_TO_INT(p) ((gint)(p))
577 #define GPOINTER_TO_UINT(p) ((guint)(p))
579 #define GINT_TO_POINTER(i) ((gpointer)(i))
580 #define GUINT_TO_POINTER(u) ((gpointer)(u))
582 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
584 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
585 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
587 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
588 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
591 #error SIZEOF_VOID_P unknown - This should never happen
594 typedef gint32 gssize;
595 typedef guint32 gsize;
596 typedef guint32 GQuark;
597 typedef gint32 GTime;
600 /* Portable endian checks and conversions
603 #define G_LITTLE_ENDIAN 1234
604 #define G_BIG_ENDIAN 4321
605 #define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */
607 #ifdef WORDS_BIGENDIAN
608 #define G_BYTE_ORDER G_BIG_ENDIAN
610 #define G_BYTE_ORDER G_LITTLE_ENDIAN
613 /* Basic bit swapping functions
615 #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
616 (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
617 (((guint16) (val) & (guint16) 0xff00U) >> 8)))
618 #define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \
619 (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
620 (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \
621 (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \
622 (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
624 /* Intel specific stuff for speed
626 #if defined (__i386__) && (defined __GNUC__)
628 # define GUINT16_SWAP_LE_BE_X86(val) \
630 ({ register guint16 __v; \
631 if (__builtin_constant_p (val)) \
632 __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \
634 __asm__ __volatile__ ("rorw $8, %w0" \
636 : "0" ((guint16) (val)) \
640 # define GUINT16_SWAP_LE_BE(val) \
641 ((guint16) GUINT16_SWAP_LE_BE_X86 ((guint16) (val)))
643 # if !defined(__i486__) && !defined(__i586__) \
644 && !defined(__pentium__) && !defined(__pentiumpro__) && !defined(__i686__)
645 # define GUINT32_SWAP_LE_BE_X86(val) \
647 ({ register guint32 __v; \
648 if (__builtin_constant_p (val)) \
649 __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
651 __asm__ __volatile__ ("rorw $8, %w0\n\t" \
655 : "0" ((guint32) (val)) \
659 # else /* 486 and higher has bswap */
660 # define GUINT32_SWAP_LE_BE_X86(val) \
662 ({ register guint32 __v; \
663 if (__builtin_constant_p (val)) \
664 __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
666 __asm__ __volatile__ ("bswap %0" \
668 : "0" ((guint32) (val))); \
670 # endif /* processor specific 32-bit stuff */
672 # define GUINT32_SWAP_LE_BE(val) \
673 ((guint32) GUINT32_SWAP_LE_BE_X86 ((guint32) (val)))
675 #else /* !__i386__ */
676 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
677 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
678 #endif /* __i386__ */
681 #define GUINT64_SWAP_LE_BE(val) ((guint64) ( \
682 (((guint64) (val) & (guint64) 0x00000000000000ffU) << 56) | \
683 (((guint64) (val) & (guint64) 0x000000000000ff00U) << 40) | \
684 (((guint64) (val) & (guint64) 0x0000000000ff0000U) << 24) | \
685 (((guint64) (val) & (guint64) 0x00000000ff000000U) << 8) | \
686 (((guint64) (val) & (guint64) 0x000000ff00000000U) >> 8) | \
687 (((guint64) (val) & (guint64) 0x0000ff0000000000U) >> 24) | \
688 (((guint64) (val) & (guint64) 0x00ff000000000000U) >> 40) | \
689 (((guint64) (val) & (guint64) 0xff00000000000000U) >> 56)))
692 #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val))
693 #define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val))
694 #define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \
695 (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
696 (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
697 #define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \
698 (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
699 (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
701 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
702 # define GINT16_TO_LE(val) ((gint16) (val))
703 # define GUINT16_TO_LE(val) ((guint16) (val))
704 # define GINT16_TO_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
705 # define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val))
706 # define GINT16_FROM_LE(val) ((gint16) (val))
707 # define GUINT16_FROM_LE(val) ((guint16) (val))
708 # define GINT16_FROM_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
709 # define GUINT16_FROM_BE(val) (GUINT16_SWAP_LE_BE (val))
710 # define GINT32_TO_LE(val) ((gint32) (val))
711 # define GUINT32_TO_LE(val) ((guint32) (val))
712 # define GINT32_TO_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
713 # define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val))
714 # define GINT32_FROM_LE(val) ((gint32) (val))
715 # define GUINT32_FROM_LE(val) ((guint32) (val))
716 # define GINT32_FROM_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
717 # define GUINT32_FROM_BE(val) (GUINT32_SWAP_LE_BE (val))
719 # define GINT64_TO_LE(val) ((gint64) (val))
720 # define GUINT64_TO_LE(val) ((guint64) (val))
721 # define GINT64_TO_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
722 # define GUINT64_TO_BE(val) (GUINT64_SWAP_LE_BE (val))
723 # define GINT64_FROM_LE(val) ((gint64) (val))
724 # define GUINT64_FROM_LE(val) ((guint64) (val))
725 # define GINT64_FROM_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
726 # define GUINT64_FROM_BE(val) (GUINT64_SWAP_LE_BE (val))
728 #elif G_BYTE_ORDER == G_BIG_ENDIAN
729 # define GINT16_TO_BE(val) ((gint16) (val))
730 # define GUINT16_TO_BE(val) ((guint16) (val))
731 # define GINT16_TO_LE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
732 # define GUINT16_TO_LE(val) (GUINT16_SWAP_LE_BE (val))
733 # define GINT16_FROM_BE(val) ((gint16) (val))
734 # define GUINT16_FROM_BE(val) ((guint16) (val))
735 # define GINT16_FROM_LE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
736 # define GUINT16_FROM_LE(val) (GUINT16_SWAP_LE_BE (val))
737 # define GINT32_TO_BE(val) ((gint32) (val))
738 # define GUINT32_TO_BE(val) ((guint32) (val))
739 # define GINT32_TO_LE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
740 # define GUINT32_TO_LE(val) (GUINT32_SWAP_LE_BE (val))
741 # define GINT32_FROM_BE(val) ((gint32) (val))
742 # define GUINT32_FROM_BE(val) ((guint32) (val))
743 # define GINT32_FROM_LE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
744 # define GUINT32_FROM_LE(val) (GUINT32_SWAP_LE_BE (val))
746 # define GINT64_TO_BE(val) ((gint64) (val))
747 # define GUINT64_TO_BE(val) ((guint64) (val))
748 # define GINT64_TO_LE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
749 # define GUINT64_TO_LE(val) (GUINT64_SWAP_LE_BE (val))
750 # define GINT64_FROM_BE(val) ((gint64) (val))
751 # define GUINT64_FROM_BE(val) ((guint64) (val))
752 # define GINT64_FROM_LE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
753 # define GUINT64_FROM_LE(val) (GUINT64_SWAP_LE_BE (val))
756 /* PDP stuff not implemented */
759 #if (SIZEOF_LONG == 8)
760 # define GLONG_TO_LE(val) ((glong) GINT64_TO_LE (val))
761 # define GULONG_TO_LE(val) ((gulong) GUINT64_TO_LE (val))
762 # define GLONG_TO_BE(val) ((glong) GINT64_TO_BE (val))
763 # define GULONG_TO_BE(val) ((gulong) GUINT64_TO_BE (val))
764 # define GLONG_FROM_LE(val) ((glong) GINT64_FROM_LE (val))
765 # define GULONG_FROM_LE(val) ((gulong) GUINT64_FROM_LE (val))
766 # define GLONG_FROM_BE(val) ((glong) GINT64_FROM_BE (val))
767 # define GULONG_FROM_BE(val) ((gulong) GUINT64_FROM_BE (val))
768 #elif (SIZEOF_LONG == 4)
769 # define GLONG_TO_LE(val) ((glong) GINT32_TO_LE (val))
770 # define GULONG_TO_LE(val) ((gulong) GUINT32_TO_LE (val))
771 # define GLONG_TO_BE(val) ((glong) GINT32_TO_BE (val))
772 # define GULONG_TO_BE(val) ((gulong) GUINT32_TO_BE (val))
773 # define GLONG_FROM_LE(val) ((glong) GINT32_FROM_LE (val))
774 # define GULONG_FROM_LE(val) ((gulong) GUINT32_FROM_LE (val))
775 # define GLONG_FROM_BE(val) ((glong) GINT32_FROM_BE (val))
776 # define GULONG_FROM_BE(val) ((gulong) GUINT32_FROM_BE (val))
779 #if (SIZEOF_INT == 8)
780 # define GINT_TO_LE(val) ((gint) GINT64_TO_LE (val))
781 # define GUINT_TO_LE(val) ((guint) GUINT64_TO_LE (val))
782 # define GINT_TO_BE(val) ((gint) GINT64_TO_BE (val))
783 # define GUINT_TO_BE(val) ((guint) GUINT64_TO_BE (val))
784 # define GINT_FROM_LE(val) ((gint) GINT64_FROM_LE (val))
785 # define GUINT_FROM_LE(val) ((guint) GUINT64_FROM_LE (val))
786 # define GINT_FROM_BE(val) ((gint) GINT64_FROM_BE (val))
787 # define GUINT_FROM_BE(val) ((guint) GUINT64_FROM_BE (val))
788 #elif (SIZEOF_INT == 4)
789 # define GINT_TO_LE(val) ((gint) GINT32_TO_LE (val))
790 # define GUINT_TO_LE(val) ((guint) GUINT32_TO_LE (val))
791 # define GINT_TO_BE(val) ((gint) GINT32_TO_BE (val))
792 # define GUINT_TO_BE(val) ((guint) GUINT32_TO_BE (val))
793 # define GINT_FROM_LE(val) ((gint) GINT32_FROM_LE (val))
794 # define GUINT_FROM_LE(val) ((guint) GUINT32_FROM_LE (val))
795 # define GINT_FROM_BE(val) ((gint) GINT32_FROM_BE (val))
796 # define GUINT_FROM_BE(val) ((guint) GUINT32_FROM_BE (val))
797 #elif (SIZEOF_INT == 2)
798 # define GINT_TO_LE(val) ((gint) GINT16_TO_LE (val))
799 # define GUINT_TO_LE(val) ((guint) GUINT16_TO_LE (val))
800 # define GINT_TO_BE(val) ((gint) GINT16_TO_BE (val))
801 # define GUINT_TO_BE(val) ((guint) GUINT16_TO_BE (val))
802 # define GINT_FROM_LE(val) ((gint) GINT16_FROM_LE (val))
803 # define GUINT_FROM_LE(val) ((guint) GUINT16_FROM_LE (val))
804 # define GINT_FROM_BE(val) ((gint) GINT16_FROM_BE (val))
805 # define GUINT_FROM_BE(val) ((guint) GUINT16_FROM_BE (val))
808 /* Portable versions of host-network order stuff
810 #define g_ntohl(val) (GUINT32_FROM_BE (val))
811 #define g_ntohs(val) (GUINT16_FROM_BE (val))
812 #define g_htonl(val) (GUINT32_TO_BE (val))
813 #define g_htons(val) (GUINT16_TO_BE (val))
817 * we prefix variable declarations so they can
818 * properly get exported in windows dlls.
821 # ifdef GLIB_COMPILATION
822 # define GUTILS_C_VAR __declspec(dllexport)
823 # else /* !GLIB_COMPILATION */
824 # define GUTILS_C_VAR __declspec(dllimport)
825 # endif /* !GLIB_COMPILATION */
826 #else /* !NATIVE_WIN32 */
827 # define GUTILS_C_VAR extern
828 #endif /* !NATIVE_WIN32 */
830 GUTILS_C_VAR const guint glib_major_version;
831 GUTILS_C_VAR const guint glib_minor_version;
832 GUTILS_C_VAR const guint glib_micro_version;
833 GUTILS_C_VAR const guint glib_interface_age;
834 GUTILS_C_VAR const guint glib_binary_age;
836 /* Forward declarations of glib types.
839 typedef struct _GArray GArray;
840 typedef struct _GByteArray GByteArray;
841 typedef struct _GCache GCache;
842 typedef struct _GCompletion GCompletion;
843 typedef struct _GData GData;
844 typedef struct _GDebugKey GDebugKey;
845 typedef struct _GHashTable GHashTable;
846 typedef struct _GHook GHook;
847 typedef struct _GHookList GHookList;
848 typedef struct _GList GList;
849 typedef struct _GListAllocator GListAllocator;
850 typedef struct _GMemChunk GMemChunk;
851 typedef struct _GNode GNode;
852 typedef struct _GPtrArray GPtrArray;
853 typedef struct _GRelation GRelation;
854 typedef struct _GScanner GScanner;
855 typedef struct _GScannerConfig GScannerConfig;
856 typedef struct _GSList GSList;
857 typedef struct _GString GString;
858 typedef struct _GStringChunk GStringChunk;
859 typedef struct _GTimer GTimer;
860 typedef struct _GTree GTree;
861 typedef struct _GTuples GTuples;
862 typedef union _GTokenValue GTokenValue;
863 typedef struct _GIOChannel GIOChannel;
868 G_TRAVERSE_LEAFS = 1 << 0,
869 G_TRAVERSE_NON_LEAFS = 1 << 1,
870 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
871 G_TRAVERSE_MASK = 0x03
882 /* Log level shift offset for user defined
883 * log levels (0-7 are used by GLib).
885 #define G_LOG_LEVEL_USER_SHIFT (8)
887 /* Glib log levels and flags.
892 G_LOG_FLAG_RECURSION = 1 << 0,
893 G_LOG_FLAG_FATAL = 1 << 1,
895 /* GLib log levels */
896 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
897 G_LOG_LEVEL_CRITICAL = 1 << 3,
898 G_LOG_LEVEL_WARNING = 1 << 4,
899 G_LOG_LEVEL_MESSAGE = 1 << 5,
900 G_LOG_LEVEL_INFO = 1 << 6,
901 G_LOG_LEVEL_DEBUG = 1 << 7,
903 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
906 /* GLib log levels that are considered fatal by default */
907 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
910 typedef gpointer (*GCacheNewFunc) (gpointer key);
911 typedef gpointer (*GCacheDupFunc) (gpointer value);
912 typedef void (*GCacheDestroyFunc) (gpointer value);
913 typedef gint (*GCompareFunc) (gconstpointer a,
915 typedef gchar* (*GCompletionFunc) (gpointer);
916 typedef void (*GDestroyNotify) (gpointer data);
917 typedef void (*GDataForeachFunc) (GQuark key_id,
920 typedef void (*GFunc) (gpointer data,
922 typedef guint (*GHashFunc) (gconstpointer key);
923 typedef void (*GHFunc) (gpointer key,
926 typedef gboolean (*GHRFunc) (gpointer key,
929 typedef gint (*GHookCompareFunc) (GHook *new_hook,
931 typedef gboolean (*GHookFindFunc) (GHook *hook,
933 typedef void (*GHookMarshaller) (GHook *hook,
935 typedef void (*GHookFunc) (gpointer data);
936 typedef gboolean (*GHookCheckFunc) (gpointer data);
937 typedef void (*GLogFunc) (const gchar *log_domain,
938 GLogLevelFlags log_level,
939 const gchar *message,
941 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
943 typedef void (*GNodeForeachFunc) (GNode *node,
945 typedef gint (*GSearchFunc) (gpointer key,
947 typedef void (*GScannerMsgFunc) (GScanner *scanner,
950 typedef gint (*GTraverseFunc) (gpointer key,
953 typedef void (*GVoidFunc) (void);
1005 /* Doubly linked lists
1007 GList* g_list_alloc (void);
1008 void g_list_free (GList *list);
1009 void g_list_free_1 (GList *list);
1010 GList* g_list_append (GList *list,
1012 GList* g_list_prepend (GList *list,
1014 GList* g_list_insert (GList *list,
1017 GList* g_list_insert_sorted (GList *list,
1020 GList* g_list_concat (GList *list1,
1022 GList* g_list_remove (GList *list,
1024 GList* g_list_remove_link (GList *list,
1026 GList* g_list_reverse (GList *list);
1027 GList* g_list_nth (GList *list,
1029 GList* g_list_find (GList *list,
1031 GList* g_list_find_custom (GList *list,
1034 gint g_list_position (GList *list,
1036 gint g_list_index (GList *list,
1038 GList* g_list_last (GList *list);
1039 GList* g_list_first (GList *list);
1040 guint g_list_length (GList *list);
1041 void g_list_foreach (GList *list,
1043 gpointer user_data);
1044 gpointer g_list_nth_data (GList *list,
1046 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
1047 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
1050 /* Singly linked lists
1052 GSList* g_slist_alloc (void);
1053 void g_slist_free (GSList *list);
1054 void g_slist_free_1 (GSList *list);
1055 GSList* g_slist_append (GSList *list,
1057 GSList* g_slist_prepend (GSList *list,
1059 GSList* g_slist_insert (GSList *list,
1062 GSList* g_slist_insert_sorted (GSList *list,
1065 GSList* g_slist_concat (GSList *list1,
1067 GSList* g_slist_remove (GSList *list,
1069 GSList* g_slist_remove_link (GSList *list,
1071 GSList* g_slist_reverse (GSList *list);
1072 GSList* g_slist_nth (GSList *list,
1074 GSList* g_slist_find (GSList *list,
1076 GSList* g_slist_find_custom (GSList *list,
1079 gint g_slist_position (GSList *list,
1081 gint g_slist_index (GSList *list,
1083 GSList* g_slist_last (GSList *list);
1084 guint g_slist_length (GSList *list);
1085 void g_slist_foreach (GSList *list,
1087 gpointer user_data);
1088 gpointer g_slist_nth_data (GSList *list,
1090 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
1095 GListAllocator* g_list_allocator_new (void);
1096 void g_list_allocator_free (GListAllocator* allocator);
1097 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
1098 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
1103 GHashTable* g_hash_table_new (GHashFunc hash_func,
1104 GCompareFunc key_compare_func);
1105 void g_hash_table_destroy (GHashTable *hash_table);
1106 void g_hash_table_insert (GHashTable *hash_table,
1109 void g_hash_table_remove (GHashTable *hash_table,
1111 gpointer g_hash_table_lookup (GHashTable *hash_table,
1113 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
1114 gconstpointer lookup_key,
1117 void g_hash_table_freeze (GHashTable *hash_table);
1118 void g_hash_table_thaw (GHashTable *hash_table);
1119 void g_hash_table_foreach (GHashTable *hash_table,
1121 gpointer user_data);
1122 gint g_hash_table_foreach_remove (GHashTable *hash_table,
1124 gpointer user_data);
1125 gint g_hash_table_size (GHashTable *hash_table);
1130 GCache* g_cache_new (GCacheNewFunc value_new_func,
1131 GCacheDestroyFunc value_destroy_func,
1132 GCacheDupFunc key_dup_func,
1133 GCacheDestroyFunc key_destroy_func,
1134 GHashFunc hash_key_func,
1135 GHashFunc hash_value_func,
1136 GCompareFunc key_compare_func);
1137 void g_cache_destroy (GCache *cache);
1138 gpointer g_cache_insert (GCache *cache,
1140 void g_cache_remove (GCache *cache,
1142 void g_cache_key_foreach (GCache *cache,
1144 gpointer user_data);
1145 void g_cache_value_foreach (GCache *cache,
1147 gpointer user_data);
1150 /* Balanced binary trees
1152 GTree* g_tree_new (GCompareFunc key_compare_func);
1153 void g_tree_destroy (GTree *tree);
1154 void g_tree_insert (GTree *tree,
1157 void g_tree_remove (GTree *tree,
1159 gpointer g_tree_lookup (GTree *tree,
1161 void g_tree_traverse (GTree *tree,
1162 GTraverseFunc traverse_func,
1163 GTraverseType traverse_type,
1165 gpointer g_tree_search (GTree *tree,
1166 GSearchFunc search_func,
1168 gint g_tree_height (GTree *tree);
1169 gint g_tree_nnodes (GTree *tree);
1173 /* N-way tree implementation
1184 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
1185 ((GNode*) (node))->prev == NULL && \
1186 ((GNode*) (node))->next == NULL)
1187 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
1189 GNode* g_node_new (gpointer data);
1190 void g_node_destroy (GNode *root);
1191 void g_node_unlink (GNode *node);
1192 GNode* g_node_insert (GNode *parent,
1195 GNode* g_node_insert_before (GNode *parent,
1198 GNode* g_node_prepend (GNode *parent,
1200 guint g_node_n_nodes (GNode *root,
1201 GTraverseFlags flags);
1202 GNode* g_node_get_root (GNode *node);
1203 gboolean g_node_is_ancestor (GNode *node,
1205 guint g_node_depth (GNode *node);
1206 GNode* g_node_find (GNode *root,
1207 GTraverseType order,
1208 GTraverseFlags flags,
1211 /* convenience macros */
1212 #define g_node_append(parent, node) \
1213 g_node_insert_before ((parent), NULL, (node))
1214 #define g_node_insert_data(parent, position, data) \
1215 g_node_insert ((parent), (position), g_node_new (data))
1216 #define g_node_insert_data_before(parent, sibling, data) \
1217 g_node_insert_before ((parent), (sibling), g_node_new (data))
1218 #define g_node_prepend_data(parent, data) \
1219 g_node_prepend ((parent), g_node_new (data))
1220 #define g_node_append_data(parent, data) \
1221 g_node_insert_before ((parent), NULL, g_node_new (data))
1223 /* traversal function, assumes that `node' is root
1224 * (only traverses `node' and its subtree).
1225 * this function is just a high level interface to
1226 * low level traversal functions, optimized for speed.
1228 void g_node_traverse (GNode *root,
1229 GTraverseType order,
1230 GTraverseFlags flags,
1232 GNodeTraverseFunc func,
1235 /* return the maximum tree height starting with `node', this is an expensive
1236 * operation, since we need to visit all nodes. this could be shortened by
1237 * adding `guint height' to struct _GNode, but then again, this is not very
1238 * often needed, and would make g_node_insert() more time consuming.
1240 guint g_node_max_height (GNode *root);
1242 void g_node_children_foreach (GNode *node,
1243 GTraverseFlags flags,
1244 GNodeForeachFunc func,
1246 void g_node_reverse_children (GNode *node);
1247 guint g_node_n_children (GNode *node);
1248 GNode* g_node_nth_child (GNode *node,
1250 GNode* g_node_last_child (GNode *node);
1251 GNode* g_node_find_child (GNode *node,
1252 GTraverseFlags flags,
1254 gint g_node_child_position (GNode *node,
1256 gint g_node_child_index (GNode *node,
1259 GNode* g_node_first_sibling (GNode *node);
1260 GNode* g_node_last_sibling (GNode *node);
1262 #define g_node_prev_sibling(node) ((node) ? \
1263 ((GNode*) (node))->prev : NULL)
1264 #define g_node_next_sibling(node) ((node) ? \
1265 ((GNode*) (node))->next : NULL)
1266 #define g_node_first_child(node) ((node) ? \
1267 ((GNode*) (node))->children : NULL)
1270 /* Callback maintenance functions
1272 #define G_HOOK_FLAG_USER_SHIFT (4)
1275 G_HOOK_FLAG_ACTIVE = 1 << 0,
1276 G_HOOK_FLAG_IN_CALL = 1 << 1,
1277 G_HOOK_FLAG_MASK = 0x0f
1286 GMemChunk *hook_memchunk;
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__ */