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