2006-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / eglib / src / glib.h
1 #ifndef __GLIB_H
2 #define __GLIB_H
3
4 #include <stdarg.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <ctype.h>
10 #include <eglib-config.h>
11
12 /*
13  * Basic data types
14  */
15 typedef int            gboolean;
16 typedef int            gint;
17 typedef unsigned int   guint;
18 typedef short          gshort;
19 typedef unsigned short gushort;
20 typedef long           glong;
21 typedef unsigned long  gulong;
22 typedef void *         gpointer;
23 typedef const void *   gconstpointer;
24 typedef char           gchar;
25 typedef unsigned char  guchar;
26
27 /* Types defined in terms of the stdint.h */
28 typedef int8_t         gint8;
29 typedef uint8_t        guint8;
30 typedef int16_t        gint16;
31 typedef uint16_t       guint16;
32 typedef int32_t        gint32;
33 typedef uint32_t       guint32;
34 typedef int64_t        gint64;
35 typedef uint64_t       guint64;
36 typedef float          gfloat;
37 typedef double         gdouble;
38 typedef uint16_t       gunichar2;
39 /*
40  * Macros
41  */
42 #define G_N_ELEMENTS(s)      (sizeof(s) / sizeof ((s) [0]))
43
44 #define FALSE                0
45 #define TRUE                 1
46
47 #define G_MAXINT32           INT32_MAX
48 #define G_MININT32           INT32_MIN
49
50 #define G_LITTLE_ENDIAN 1234
51 #define G_BIG_ENDIAN    4321
52 #define G_STMT_START    do 
53 #define G_STMT_END      while (0)
54
55 #define G_USEC_PER_SEC  1000000
56
57 #define ABS(a,b)        (((a)>(b)) ? ((a)-(b)) : ((b)-(a)))
58
59 #define G_STRUCT_OFFSET(p_type,field) \
60         ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
61
62
63 /*
64  * Allocation
65  */
66 #define g_new(type,size)        ((type *) malloc (sizeof (type) * (size)))
67 #define g_new0(type,size)       ((type *) calloc (sizeof (type), (size)))
68 #define g_newa(type,size)       ((type *) alloca (sizeof (type) * (size)))
69 #define g_realloc(obj,size)     realloc((obj), (size))
70 #define g_strdup(x)             strdup(x)
71 #define g_malloc(x)             malloc(x)
72 #define g_try_malloc(x)         malloc(x)
73 #define g_try_realloc(obj,size) realloc((obj),(size))
74 #define g_malloc0(x)            calloc(1,x)
75 #define g_memmove(dest,src,len) memmove (dest, src, len)
76 #define g_renew(struct_type, mem, n_structs) realloc (mem, sizeof (struct_type) * n_structs)
77 #define g_alloca(size)          alloca (size)
78 #define g_free                  free
79
80 gpointer g_memdup (gconstpointer mem, guint byte_size);
81
82 typedef struct {
83         gpointer (*malloc)      (gsize    n_bytes);
84         gpointer (*realloc)     (gpointer mem, gsize n_bytes);
85         void     (*free)        (gpointer mem);
86         gpointer (*calloc)      (gsize    n_blocks, gsize n_block_bytes);
87         gpointer (*try_malloc)  (gsize    n_bytes);
88         gpointer (*try_realloc) (gpointer mem, gsize n_bytes);
89 } GMemVTable;
90
91 #define g_mem_set_vtable(x)
92 /*
93  * Misc.
94  */
95 #define g_atexit(func)  ((void) atexit (func))
96
97 const gchar *    g_getenv(const gchar *variable);
98 gboolean         g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
99 void             g_unsetenv(const gchar *variable);
100
101 /*
102  * Precondition macros
103  */
104 #define g_return_if_fail(x)  G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END
105 #define g_return_val_if_fail(x,e)  G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END
106
107 /*
108  * Hashtables
109  */
110 typedef struct _GHashTable GHashTable;
111 typedef void     (*GFunc)          (gpointer data, gpointer user_data);
112 typedef gint     (*GCompareFunc)   (gconstpointer a, gconstpointer b);
113 typedef gint     (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
114 typedef void     (*GHFunc)         (gpointer key, gpointer value, gpointer user_data);
115 typedef gboolean (*GHRFunc)        (gpointer key, gpointer value, gpointer user_data);
116 typedef void     (*GDestroyNotify) (gpointer data);
117 typedef guint    (*GHashFunc)      (gconstpointer key);
118 typedef gboolean (*GEqualFunc)     (gconstpointer a, gconstpointer b);
119
120 GHashTable     *g_hash_table_new             (GHashFunc hash_func, GEqualFunc key_equal_func);
121 GHashTable     *g_hash_table_new_full        (GHashFunc hash_func, GEqualFunc key_equal_func,
122                                               GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
123 void            g_hash_table_insert_replace  (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
124 guint           g_hash_table_size            (GHashTable *hash);
125 gpointer        g_hash_table_lookup          (GHashTable *hash, gconstpointer key);
126 gboolean        g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
127 void            g_hash_table_foreach         (GHashTable *hash, GHFunc func, gpointer user_data);
128 gpointer        g_hash_table_find            (GHashTable *hash, GHRFunc predicate, gpointer user_data);
129 gboolean        g_hash_table_remove          (GHashTable *hash, gconstpointer key);
130 guint           g_hash_table_foreach_remove  (GHashTable *hash, GHRFunc func, gpointer user_data);
131 void            g_hash_table_destroy         (GHashTable *hash);
132
133 #define g_hash_table_insert(h,k,v)    g_hash_table_insert_replace ((h),(k),(v),FALSE)
134 #define g_hash_table_replace(h,k,v)   g_hash_table_insert_replace ((h),(k),(v),TRUE)
135
136 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
137 guint    g_direct_hash  (gconstpointer v1);
138 gboolean g_int_equal    (gconstpointer v1, gconstpointer v2);
139 guint    g_int_hash     (gconstpointer v1);
140 gboolean g_str_equal    (gconstpointer v1, gconstpointer v2);
141 guint    g_str_hash     (gconstpointer v1);
142
143 #define  g_assert(x)     G_STMT_START { if (!(x)) g_error ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x);  } G_STMT_END
144 #define  g_assert_not_reached() G_STMT_START { g_error ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); } G_STMT_END
145
146 /*
147  * Errors
148  */
149 typedef struct {
150         /* In the real glib, this is a GQuark, but we dont use/need that */
151         gpointer domain;
152         gint     code;
153         gchar   *message;
154 } GError;
155
156 void    g_error_free (GError *error);
157 GError *g_error_new  (gpointer domain, gint code, const char *format, ...);
158 void    g_set_error  (GError **err, gpointer domain, gint code, const gchar *format, ...);
159
160 /*
161  * Strings utility
162  */
163 gchar       *g_strdup_printf  (const gchar *format, ...);
164 gchar       *g_strdup_vprintf (const gchar *format, va_list args);
165 gchar       *g_strndup        (const gchar *str, gsize n);
166 const gchar *g_strerror       (gint errnum);
167 gchar       *g_strndup        (const gchar *str, gsize n);
168 void         g_strfreev       (gchar **str_array);
169 gchar       *g_strconcat      (const gchar *first, ...);
170 gchar      **g_strsplit       (const gchar *string, const gchar *delimiter, gint max_tokens);
171 gchar       *g_strreverse     (gchar *str);
172 gboolean     g_str_has_prefix (const gchar *str, const gchar *prefix);
173 gboolean     g_str_has_suffix (const gchar *str, const gchar *suffix);
174 guint        g_strv_length    (gchar **str_array);
175 gchar       *g_strjoin        (const gchar *separator, ...);
176 gchar       *g_strchug        (gchar *str);
177 gchar       *g_strchomp       (gchar *str);
178 gchar       *g_strdelimit     (gchar *string, const gchar *delimiters, gchar new_delimiter);
179
180 gchar       *g_filename_to_uri   (const gchar *filename, const gchar *hostname, GError **error);
181 gchar       *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
182
183 gint         g_printf          (gchar const *format, ...);
184 gint         g_fprintf         (FILE *file, gchar const *format, ...);
185 gint         g_sprintf         (gchar *string, gchar const *format, ...);
186 gint         g_snprintf        (gchar *string, gulong n, gchar const *format, ...);
187 #define g_vprintf vprintf
188 #define g_vfprintf vfprintf
189 #define g_vsprintf vsprintf
190 #define g_vsnprintf vsnprintf
191 #define g_vasprintf vasprintf
192
193 #ifdef HAVE_STRLCPY
194 #define g_strlcpy       strlcpy
195 #else
196 gsize       g_strlcpy          (gchar *dest, const gchar *src, gsize dest_size);
197 #endif
198
199 #define g_ascii_isspace(c) (isspace (c) != 0)
200 #define g_ascii_isalpha(c) (isalpha (c) != 0)
201 #define g_ascii_isprint(c) (isprint (c) != 0)
202 #define g_ascii_isxdigit(c) (isxdigit (c) != 0)
203 #define g_ascii_xdigit_value(c) ((isxdigit (c) == 0) ? -1 : \
204                                         ((c >= '0' && c <= '9') ? (c - '0') : \
205                                                 ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : \
206                                                  (c - 'A' + 10))))
207
208 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
209 #define g_strcasecmp strcasecmp
210 #define g_ascii_strcasecmp strcasecmp
211 #define g_strncasecmp strncasecmp
212 #define g_strstrip(a) g_strchug (g_strchomp (a))
213
214 #define G_STR_DELIMITERS "_-|> <."
215
216 /*
217  * String type
218  */
219 typedef struct {
220         char *str;
221         gsize len;
222         gsize allocated_len;
223 } GString;
224
225 GString     *g_string_new           (const gchar *init);
226 GString     *g_string_new_len       (const gchar *init, gssize len);
227 GString     *g_string_sized_new     (gsize default_size);
228 gchar       *g_string_free          (GString *string, gboolean free_segment);
229 GString     *g_string_append        (GString *string, const gchar *val);
230 void         g_string_printf        (GString *string, const gchar *format, ...);
231 void         g_string_append_printf (GString *string, const gchar *format, ...);
232 GString     *g_string_append_c      (GString *string, gchar c);
233 GString     *g_string_append        (GString *string, const gchar *val);
234 GString     *g_string_append_len    (GString *string, const gchar *val, gssize len);
235 GString     *g_string_truncate      (GString *string, gsize len);
236 GString     *g_string_prepend       (GString *string, const gchar *val);
237
238 #define g_string_sprintfa g_string_append_printf
239
240 /*
241  * Lists
242  */
243 typedef struct _GSList GSList;
244 struct _GSList {
245         gpointer data;
246         GSList *next;
247 };
248
249 GSList *g_slist_alloc         (void);
250 GSList *g_slist_append        (GSList        *list,
251                                gpointer       data);
252 GSList *g_slist_prepend       (GSList        *list,
253                                gpointer       data);
254 void    g_slist_free          (GSList        *list);
255 void    g_slist_free_1        (GSList        *list);
256 GSList *g_slist_copy          (GSList        *list);
257 GSList *g_slist_concat        (GSList        *list1,
258                                GSList        *list2);
259 void    g_slist_foreach       (GSList        *list,
260                                GFunc          func,
261                                gpointer       user_data);
262 GSList *g_slist_last          (GSList        *list);
263 GSList *g_slist_find          (GSList        *list,
264                                gconstpointer  data);
265 GSList *g_slist_remove        (GSList        *list,
266                                gconstpointer  data);
267 GSList *g_slist_remove_all    (GSList        *list,
268                                gconstpointer  data);
269 GSList *g_slist_reverse       (GSList        *list);
270 guint   g_slist_length        (GSList        *list);
271 GSList *g_slist_remove_link   (GSList        *list,
272                                GSList        *link);
273 GSList *g_slist_delete_link   (GSList        *list,
274                                GSList        *link);
275 GSList *g_slist_insert_sorted (GSList        *list,
276                                gpointer       data,
277                                GCompareFunc   func);
278 GSList *g_slist_insert_before (GSList        *list,
279                                GSList        *sibling,
280                                gpointer       data);
281 GSList *g_slist_sort          (GSList        *list,
282                                GCompareFunc   func);
283
284 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
285
286 typedef struct _GList GList;
287 struct _GList {
288   gpointer data;
289   GList *next;
290   GList *prev;
291 };
292
293 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL);
294
295 GList *g_list_alloc         (void);
296 GList *g_list_append        (GList         *list,
297                              gpointer       data);
298 GList *g_list_prepend       (GList         *list,
299                              gpointer       data);
300 void   g_list_free          (GList         *list);
301 void   g_list_free_1        (GList         *list);
302 GList *g_list_copy          (GList         *list);
303 guint  g_list_length        (GList         *list);
304 gint   g_list_index         (GList         *list,
305                              gconstpointer  data);
306 GList *g_list_nth           (GList         *list,
307                              guint          n);
308 gpointer g_list_nth_data      (GList         *list,
309                              guint          n);
310 GList *g_list_last          (GList         *list);
311 GList *g_list_concat        (GList         *list1,
312                              GList         *list2);
313 void   g_list_foreach       (GList         *list,
314                              GFunc          func,
315                              gpointer       user_data);
316 GList *g_list_first         (GList         *list);
317 GList *g_list_find          (GList         *list,
318                              gconstpointer  data);
319 GList *g_list_remove        (GList         *list,
320                              gconstpointer  data);
321 GList *g_list_reverse       (GList         *list);
322 GList *g_list_remove_link   (GList         *list,
323                              GList         *link);
324 GList *g_list_delete_link   (GList         *list,
325                              GList         *link);
326 GList *g_list_insert_sorted (GList         *list,
327                              gpointer       data,
328                              GCompareFunc   func);
329 GList *g_list_insert_before (GList         *list,
330                              GList         *sibling,
331                              gpointer       data);
332 GList *g_list_sort          (GList         *sort,
333                              GCompareFunc   func);
334
335 /*
336  * Array
337  */
338
339 typedef struct _GArray GArray;
340 struct _GArray {
341         gchar *data;
342         gint len;
343 };
344
345 GArray *g_array_new               (gboolean zero_terminated, gboolean clear_, guint element_size);
346 gchar*  g_array_free              (GArray *array, gboolean free_segment);
347 GArray *g_array_append_vals       (GArray *array, gconstpointer data, guint len);
348 GArray* g_array_insert_vals       (GArray *array, guint index_, gconstpointer data, guint len);
349 GArray* g_array_remove_index      (GArray *array, guint index_);
350
351 #define g_array_append_val(a,v)   (g_array_append_vals((a),&(v),1))
352 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
353 #define g_array_index(a,t,i)      *(t*)(((a)->data) + sizeof(t) * (i))
354
355 /*
356  * Pointer Array
357  */
358
359 typedef struct _GPtrArray GPtrArray;
360 struct _GPtrArray {
361         gpointer *pdata;
362         guint len;
363 };
364
365 GPtrArray *g_ptr_array_new                ();
366 GPtrArray *g_ptr_array_sized_new          (guint reserved_size);
367 void       g_ptr_array_add                (GPtrArray *array, gpointer data);
368 gboolean   g_ptr_array_remove             (GPtrArray *array, gpointer data);
369 gpointer   g_ptr_array_remove_index       (GPtrArray *array, guint index);
370 gboolean   g_ptr_array_remove_fast        (GPtrArray *array, gpointer data);
371 gpointer   g_ptr_array_remove_index_fast  (GPtrArray *array, gpointer data);
372 void       g_ptr_array_sort               (GPtrArray *array, GCompareFunc compare_func);
373 void       g_ptr_array_sort_with_data     (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
374 void       g_ptr_array_set_size           (GPtrArray *array, gint length);
375 gpointer  *g_ptr_array_free               (GPtrArray *array, gboolean free_seg);
376 void       g_ptr_array_foreach            (GPtrArray *array, GFunc func, gpointer user_data);
377 #define    g_ptr_array_index(array,index) (array)->pdata[(index)]
378
379 /*
380  * Queues
381  */
382 typedef struct {
383         GList *head;
384         GList *tail;
385         guint length;
386 } GQueue;
387
388 gpointer g_queue_pop_head  (GQueue   *queue);
389 void     g_queue_push_head (GQueue   *queue,
390                             gpointer  data);
391 gboolean g_queue_is_empty  (GQueue   *queue);
392 GQueue  *g_queue_new       (void);
393 void     g_queue_free      (GQueue   *queue);
394
395
396 /*
397  * Modules
398  */
399 typedef enum {
400         G_MODULE_BIND_LAZY = 0x01,
401         G_MODULE_BIND_LOCAL = 0x02,
402         G_MODULE_BIND_MASK = 0x03
403 } GModuleFlags;
404 typedef struct _GModule GModule;
405
406 GModule *g_module_open (const gchar *file, GModuleFlags flags);
407 gboolean g_module_symbol (GModule *module, const gchar *symbol_name,
408                           gpointer *symbol);
409 const gchar *g_module_error (void);
410 gboolean g_module_close (GModule *module);
411 gchar *  g_module_build_path (const gchar *directory, const gchar *module_name);
412 /*
413  * Messages
414  */
415 #ifndef G_LOG_DOMAIN
416 #define G_LOG_DOMAIN ((gchar*) 0)
417 #endif
418
419 typedef enum {
420         G_LOG_FLAG_RECURSION          = 1 << 0,
421         G_LOG_FLAG_FATAL              = 1 << 1,
422         
423         G_LOG_LEVEL_ERROR             = 1 << 2,
424         G_LOG_LEVEL_CRITICAL          = 1 << 3,
425         G_LOG_LEVEL_WARNING           = 1 << 4,
426         G_LOG_LEVEL_MESSAGE           = 1 << 5,
427         G_LOG_LEVEL_INFO              = 1 << 6,
428         G_LOG_LEVEL_DEBUG             = 1 << 7,
429         
430         G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
431 } GLogLevelFlags;
432
433 void           g_print                (const gchar *format, ...);
434 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
435 GLogLevelFlags g_log_set_fatal_mask   (const gchar *log_domain, GLogLevelFlags fatal_mask);
436 void           g_logv                 (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
437 void           g_log                  (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
438
439 #define g_error(format...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format)
440 #define g_critical(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format)
441 #define g_warning(format...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format)
442 #define g_message(format...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format)
443 #define g_debug(format...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
444
445 #define g_log_set_handler(a,b,c,d)
446 #define g_printerr(format...) fprintf (stderr, format)
447 /*
448  * Conversions
449  */
450
451 gpointer g_convert_error_quark();
452
453
454 /*
455  * Unicode Manipulation: most of this is not used by Mono by default, it is
456  * only used if the old collation code is activated, so this is only the
457  * bare minimum to build.
458  */
459 typedef guint32 gunichar;
460
461 typedef enum {
462         G_UNICODE_LOWERCASE_LETTER,
463 } GUnicodeType;
464
465 gunichar       g_unichar_tolower (gunichar c);
466 GUnicodeType   g_unichar_type    (gunichar c);
467
468 #ifndef MAX
469 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
470 #endif
471
472 /* FIXME: Implement these two for gcc */
473 #define G_LIKELY(x) (x)
474 #define G_UNLIKELY(x) (x)
475
476 /*
477  * Unicode conversion
478  */
479
480 #define G_CONVERT_ERROR g_convert_error_quark()
481
482 typedef enum {
483         G_CONVERT_ERROR_NO_CONVERSION,
484         G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
485         G_CONVERT_ERROR_FAILED,
486         G_CONVERT_ERROR_PARTIAL_INPUT,
487         G_CONVERT_ERROR_BAD_URI,
488         G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
489 } GConvertError;
490
491 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong     *items_written, GError **error);
492 glong     utf8_to_utf16_len (const gchar *str, glong len, glong *items_read, GError **error);
493 gchar     *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong     *items_written, GError **error);
494 glong     utf16_to_utf8_len (const gunichar2 *str, glong len, glong *items_read, GError **error);
495
496 /*
497  * Path
498  */
499 gchar  *g_build_path           (const gchar *separator, const gchar *first_element, ...);
500 #define g_build_filename(x...) g_build_path(G_DIR_SEPARATOR_S, x)
501 gchar  *g_path_get_dirname     (const gchar *filename);
502 gchar  *g_path_get_basename    (const char *filename);
503 gchar  *g_find_program_in_path (const gchar *program);
504 gchar  *g_get_current_dir      (void);
505 gboolean g_path_is_absolute    (const char *filename);
506
507 const gchar *g_get_home_dir    (void);
508 const gchar *g_get_tmp_dir     (void);
509 const gchar *g_get_user_name   (void);
510
511 /*
512  * Shell
513  */
514
515 gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
516
517 /*
518  * Spawn
519  */
520 typedef enum {
521         G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
522         G_SPAWN_DO_NOT_REAP_CHILD      = 1 << 1,
523         G_SPAWN_SEARCH_PATH            = 1 << 2,
524         G_SPAWN_STDOUT_TO_DEV_NULL     = 1 << 3,
525         G_SPAWN_STDERR_TO_DEV_NULL     = 1 << 4,
526         G_SPAWN_CHILD_INHERITS_STDIN   = 1 << 5,
527         G_SPAWN_FILE_AND_ARGV_ZERO     = 1 << 6
528 } GSpawnFlags;
529
530 typedef pid_t GPid;
531
532 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
533
534 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
535 gboolean g_spawn_async_with_pipes  (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
536                                 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
537
538
539 /*
540  * Timer
541  */
542 typedef struct _GTimer GTimer;
543
544 GTimer *g_timer_new (void);
545 void g_timer_destroy (GTimer *timer);
546 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
547 void g_timer_stop (GTimer *timer);
548 void g_timer_start (GTimer *timer);
549
550 /*
551  * Date and time
552  */
553 typedef struct {
554         glong tv_sec;
555         glong tv_usec;
556 } GTimeVal;
557
558 void g_get_current_time (GTimeVal *result);
559
560 /*
561  * File
562  */
563
564 typedef enum {
565         G_FILE_ERROR_EXIST,
566         G_FILE_ERROR_ISDIR,
567         G_FILE_ERROR_ACCES,
568         G_FILE_ERROR_NAMETOOLONG,
569         G_FILE_ERROR_NOENT,
570         G_FILE_ERROR_NOTDIR,
571         G_FILE_ERROR_NXIO,
572         G_FILE_ERROR_NODEV,
573         G_FILE_ERROR_ROFS,
574         G_FILE_ERROR_TXTBSY,
575         G_FILE_ERROR_FAULT,
576         G_FILE_ERROR_LOOP,
577         G_FILE_ERROR_NOSPC,
578         G_FILE_ERROR_NOMEM,
579         G_FILE_ERROR_MFILE,
580         G_FILE_ERROR_NFILE,
581         G_FILE_ERROR_BADF,
582         G_FILE_ERROR_INVAL,
583         G_FILE_ERROR_PIPE,
584         G_FILE_ERROR_AGAIN,
585         G_FILE_ERROR_INTR,
586         G_FILE_ERROR_IO,
587         G_FILE_ERROR_PERM,
588         G_FILE_ERROR_NOSYS,
589         G_FILE_ERROR_FAILED
590 } GFileError;
591
592 typedef enum {
593         G_FILE_TEST_IS_REGULAR = 1 << 0,
594         G_FILE_TEST_IS_SYMLINK = 1 << 1,
595         G_FILE_TEST_IS_DIR = 1 << 2,
596         G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
597         G_FILE_TEST_EXISTS = 1 << 4
598 } GFileTest;
599
600
601 gboolean   g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
602 GFileError g_file_error_from_errno (gint err_no);
603 gint       g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
604 gboolean   g_file_test (const gchar *filename, GFileTest test);
605
606 /*
607  * Pattern matching
608  */
609 typedef struct _GPatternSpec GPatternSpec;
610 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
611 void           g_pattern_spec_free (GPatternSpec *pspec);
612 gboolean       g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
613
614 /*
615  * Directory
616  */
617 typedef struct _GDir GDir;
618 GDir        *g_dir_open (const gchar *path, guint flags, GError **error);
619 const gchar *g_dir_read_name (GDir *dir);
620 void         g_dir_rewind (GDir *dir);
621 void         g_dir_close (GDir *dir);
622
623 /*
624  * GMarkup
625  */
626 typedef struct _GMarkupParseContext GMarkupParseContext;
627
628 typedef enum
629 {
630         G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
631         G_MARKUP_TREAT_CDATA_AS_TEXT              = 1 << 1
632 } GMarkupParseFlags;
633
634 typedef struct {
635         void (*start_element)  (GMarkupParseContext *context,
636                                 const gchar *element_name,
637                                 const gchar **attribute_names,
638                                 const gchar **attribute_values,
639                                 gpointer user_data,
640                                 GError **error);
641
642         void (*end_element)    (GMarkupParseContext *context,
643                                 const gchar         *element_name,
644                                 gpointer             user_data,
645                                 GError             **error);
646         
647         void (*text)           (GMarkupParseContext *context,
648                                 const gchar         *text,
649                                 gsize                text_len,  
650                                 gpointer             user_data,
651                                 GError             **error);
652         
653         void (*passthrough)    (GMarkupParseContext *context,
654                                 const gchar         *passthrough_text,
655                                 gsize                text_len,  
656                                 gpointer             user_data,
657                                 GError             **error);
658         void (*error)          (GMarkupParseContext *context,
659                                 GError              *error,
660                                 gpointer             user_data);
661 } GMarkupParser;
662
663 GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
664                                                    GMarkupParseFlags flags,
665                                                    gpointer user_data,
666                                                    GDestroyNotify user_data_dnotify);
667 void                 g_markup_parse_context_free  (GMarkupParseContext *context);
668 gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
669                                                    const gchar *text, gssize text_len,
670                                                    GError **error);
671 gboolean         g_markup_parse_context_end_parse (GMarkupParseContext *context,
672                                                    GError **error);
673
674 /*
675  * Character set conversion
676  */
677 gboolean  g_get_charset        (char **charset);
678 gchar    *g_locale_to_utf8     (const gchar *opsysstring, gssize len,
679                                 gsize *bytes_read, gsize *bytes_written,
680                                 GError **error);
681 gchar    *g_locale_from_utf8   (const gchar *utf8string, gssize len, gsize *bytes_read,
682                                 gsize *bytes_written, GError **error);
683 gchar    *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
684                                 gsize *bytes_written, GError **error);
685 gchar    *g_convert            (const gchar *str, gssize len,
686                                 const gchar *to_codeset, const gchar *from_codeset,
687                                 gsize *bytes_read, gsize *bytes_written, GError **error);
688 gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **end);
689
690 #endif
691