1.1 --- a/epoc32/include/stdapis/glib-2.0/glib/gutils.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/glib-2.0/glib/gutils.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,452 @@
1.4 -gutils.h
1.5 +/* GLIB - Library of useful routines for C programming
1.6 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.7 + * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.8 + *
1.9 + * This library is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU Lesser General Public
1.11 + * License as published by the Free Software Foundation; either
1.12 + * version 2 of the License, or (at your option) any later version.
1.13 + *
1.14 + * This library is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.17 + * Lesser General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU Lesser General Public
1.20 + * License along with this library; if not, write to the
1.21 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.22 + * Boston, MA 02111-1307, USA.
1.23 + */
1.24 +
1.25 +/*
1.26 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.27 + * file for a list of people on the GLib Team. See the ChangeLog
1.28 + * files for a list of changes. These files are distributed with
1.29 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.30 + */
1.31 +
1.32 +#ifndef __G_UTILS_H__
1.33 +#define __G_UTILS_H__
1.34 +
1.35 +#include <_ansi.h>
1.36 +#include <glib/gtypes.h>
1.37 +#include <stdarg.h>
1.38 +
1.39 +G_BEGIN_DECLS
1.40 +
1.41 +#if defined(G_OS_WIN32) || defined(__SYMBIAN32__)
1.42 +
1.43 +/* On Win32, the canonical directory separator is the backslash, and
1.44 + * the search path separator is the semicolon. Note that also the
1.45 + * (forward) slash works as directory separator.
1.46 + */
1.47 +#define G_DIR_SEPARATOR '\\'
1.48 +#define G_DIR_SEPARATOR_S "\\"
1.49 +#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
1.50 +#define G_SEARCHPATH_SEPARATOR ';'
1.51 +#define G_SEARCHPATH_SEPARATOR_S ";"
1.52 +
1.53 +#else /* !G_OS_WIN32 */
1.54 +
1.55 +/* Unix */
1.56 +
1.57 +#define G_DIR_SEPARATOR '/'
1.58 +#define G_DIR_SEPARATOR_S "/"
1.59 +#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
1.60 +#define G_SEARCHPATH_SEPARATOR ':'
1.61 +#define G_SEARCHPATH_SEPARATOR_S ":"
1.62 +
1.63 +#endif /* !G_OS_WIN32 */
1.64 +
1.65 +/* Define G_VA_COPY() to do the right thing for copying va_list variables.
1.66 + * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
1.67 + */
1.68 +#if !defined (G_VA_COPY)
1.69 +# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
1.70 +# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
1.71 +# elif defined (G_VA_COPY_AS_ARRAY)
1.72 +# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
1.73 +# else /* va_list is a pointer */
1.74 +# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
1.75 +# endif /* va_list is a pointer */
1.76 +#endif /* !G_VA_COPY */
1.77 +
1.78 +/* inlining hassle. for compilers that don't allow the `inline' keyword,
1.79 + * mostly because of strict ANSI C compliance or dumbness, we try to fall
1.80 + * back to either `__inline__' or `__inline'.
1.81 + * G_CAN_INLINE is defined in glibconfig.h if the compiler seems to be
1.82 + * actually *capable* to do function inlining, in which case inline
1.83 + * function bodies do make sense. we also define G_INLINE_FUNC to properly
1.84 + * export the function prototypes if no inlining can be performed.
1.85 + * inline function bodies have to be special cased with G_CAN_INLINE and a
1.86 + * .c file specific macro to allow one compiled instance with extern linkage
1.87 + * of the functions by defining G_IMPLEMENT_INLINES and the .c file macro.
1.88 + */
1.89 +#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
1.90 +# undef inline
1.91 +# define inline __inline__
1.92 +#elif !defined (G_HAVE_INLINE)
1.93 +# undef inline
1.94 +# if defined (G_HAVE___INLINE__)
1.95 +# define inline __inline__
1.96 +# elif defined (G_HAVE___INLINE)
1.97 +# define inline __inline
1.98 +# else /* !inline && !__inline__ && !__inline */
1.99 +# define inline /* don't inline, then */
1.100 +# endif
1.101 +#endif
1.102 +#ifdef G_IMPLEMENT_INLINES
1.103 +# define G_INLINE_FUNC
1.104 +# undef G_CAN_INLINE
1.105 +#elif defined (__GNUC__)
1.106 +# ifdef __SYMBIAN32__
1.107 +# define G_INLINE_FUNC extern __inline
1.108 +# else
1.109 +# define G_INLINE_FUNC extern inline
1.110 +# endif
1.111 +#elif defined (G_CAN_INLINE)
1.112 +# ifdef __SYMBIAN32__
1.113 +# define G_INLINE_FUNC static __inline
1.114 +# else
1.115 +# define G_INLINE_FUNC static inline
1.116 +# endif
1.117 +#else /* can't inline */
1.118 +# define G_INLINE_FUNC
1.119 +#endif /* !G_INLINE_FUNC */
1.120 +
1.121 +/* Retrive static string info
1.122 + */
1.123 +#ifdef G_OS_WIN32
1.124 +#define g_get_user_name g_get_user_name_utf8
1.125 +#define g_get_real_name g_get_real_name_utf8
1.126 +#define g_get_home_dir g_get_home_dir_utf8
1.127 +#define g_get_tmp_dir g_get_tmp_dir_utf8
1.128 +#endif
1.129 +
1.130 +IMPORT_C G_CONST_RETURN gchar* g_get_user_name (void);
1.131 +IMPORT_C G_CONST_RETURN gchar* g_get_real_name (void);
1.132 +IMPORT_C G_CONST_RETURN gchar* g_get_home_dir (void);
1.133 +IMPORT_C G_CONST_RETURN gchar* g_get_tmp_dir (void);
1.134 +IMPORT_C G_CONST_RETURN gchar* g_get_host_name (void);
1.135 +IMPORT_C gchar* g_get_prgname (void);
1.136 +IMPORT_C void g_set_prgname (const gchar *prgname);
1.137 +IMPORT_C G_CONST_RETURN gchar* g_get_application_name (void);
1.138 +IMPORT_C void g_set_application_name (const gchar *application_name);
1.139 +
1.140 +IMPORT_C G_CONST_RETURN gchar* g_get_user_data_dir (void);
1.141 +IMPORT_C G_CONST_RETURN gchar* g_get_user_config_dir (void);
1.142 +IMPORT_C G_CONST_RETURN gchar* g_get_user_cache_dir (void);
1.143 +IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_data_dirs (void);
1.144 +
1.145 +#ifdef G_OS_WIN32
1.146 +G_CONST_RETURN gchar* G_CONST_RETURN * g_win32_get_system_data_dirs_for_module (gconstpointer address);
1.147 +#endif
1.148 +
1.149 +#if defined (G_OS_WIN32) && defined (G_CAN_INLINE) && !defined (__cplusplus)
1.150 +static inline G_CONST_RETURN gchar * G_CONST_RETURN *
1.151 +g_win32_get_system_data_dirs (void)
1.152 +{
1.153 + return g_win32_get_system_data_dirs_for_module ((gconstpointer) &g_win32_get_system_data_dirs);
1.154 +}
1.155 +#define g_get_system_data_dirs g_win32_get_system_data_dirs
1.156 +#endif
1.157 +
1.158 +IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void);
1.159 +
1.160 +IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void);
1.161 +
1.162 +typedef struct _GDebugKey GDebugKey;
1.163 +struct _GDebugKey
1.164 +{
1.165 + gchar *key;
1.166 + guint value;
1.167 +};
1.168 +
1.169 +/* Miscellaneous utility functions
1.170 + */
1.171 +IMPORT_C guint g_parse_debug_string (const gchar *string,
1.172 + const GDebugKey *keys,
1.173 + guint nkeys);
1.174 +
1.175 +IMPORT_C gint g_snprintf (gchar *string,
1.176 + gulong n,
1.177 + gchar const *format,
1.178 + ...) G_GNUC_PRINTF (3, 4);
1.179 +IMPORT_C gint g_vsnprintf (gchar *string,
1.180 + gulong n,
1.181 + gchar const *format,
1.182 + va_list args);
1.183 +
1.184 +/* Check if a file name is an absolute path */
1.185 +IMPORT_C gboolean g_path_is_absolute (const gchar *file_name);
1.186 +
1.187 +/* In case of absolute paths, skip the root part */
1.188 +IMPORT_C G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name);
1.189 +
1.190 +#ifndef G_DISABLE_DEPRECATED
1.191 +
1.192 +/* These two functions are deprecated and will be removed in the next
1.193 + * major release of GLib. Use g_path_get_dirname/g_path_get_basename
1.194 + * instead. Whatch out! The string returned by g_path_get_basename
1.195 + * must be g_freed, while the string returned by g_basename must not.*/
1.196 +IMPORT_C G_CONST_RETURN gchar* g_basename (const gchar *file_name);
1.197 +#define g_dirname g_path_get_dirname
1.198 +
1.199 +#endif /* G_DISABLE_DEPRECATED */
1.200 +
1.201 +#ifdef G_OS_WIN32
1.202 +#define g_get_current_dir g_get_current_dir_utf8
1.203 +#endif
1.204 +
1.205 +/* The returned strings are newly allocated with g_malloc() */
1.206 +IMPORT_C gchar* g_get_current_dir (void);
1.207 +IMPORT_C gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
1.208 +IMPORT_C gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
1.209 +
1.210 +/* Set the pointer at the specified location to NULL */
1.211 +IMPORT_C void g_nullify_pointer (gpointer *nullify_location);
1.212 +
1.213 +/* return the environment string for the variable. The returned memory
1.214 + * must not be freed. */
1.215 +#ifdef G_OS_WIN32
1.216 +#define g_getenv g_getenv_utf8
1.217 +#define g_setenv g_setenv_utf8
1.218 +#define g_unsetenv g_unsetenv_utf8
1.219 +#define g_find_program_in_path g_find_program_in_path_utf8
1.220 +#endif
1.221 +
1.222 +IMPORT_C G_CONST_RETURN gchar* g_getenv (const gchar *variable);
1.223 +IMPORT_C gboolean g_setenv (const gchar *variable,
1.224 + const gchar *value,
1.225 + gboolean overwrite);
1.226 +IMPORT_C void g_unsetenv (const gchar *variable);
1.227 +IMPORT_C gchar** g_listenv (void);
1.228 +const gchar* _g_getenv_nomalloc (const gchar *variable,
1.229 + gchar buffer[1024]);
1.230 +
1.231 +/* we try to provide a usefull equivalent for ATEXIT if it is
1.232 + * not defined, but use is actually abandoned. people should
1.233 + * use g_atexit() instead.
1.234 + */
1.235 +typedef void (*GVoidFunc) (void);
1.236 +#ifndef ATEXIT
1.237 +# define ATEXIT(proc) g_ATEXIT(proc)
1.238 +#else
1.239 +# define G_NATIVE_ATEXIT
1.240 +#endif /* ATEXIT */
1.241 +/* we use a GLib function as a replacement for ATEXIT, so
1.242 + * the programmer is not required to check the return value
1.243 + * (if there is any in the implementation) and doesn't encounter
1.244 + * missing include files.
1.245 + */
1.246 +IMPORT_C void g_atexit (GVoidFunc func);
1.247 +
1.248 +#ifdef G_OS_WIN32
1.249 +/* It's a bad idea to wrap atexit() on Windows. If the GLib DLL calls
1.250 + * atexit(), the function will be called when the GLib DLL is detached
1.251 + * from the program, which is not what the caller wants. The caller
1.252 + * wants the function to be called when it *itself* exits (or is
1.253 + * detached, in case the caller, too, is a DLL).
1.254 + */
1.255 +int atexit (void (*)(void));
1.256 +#define g_atexit(func) atexit(func)
1.257 +#endif
1.258 +
1.259 +/* Look for an executable in PATH, following execvp() rules */
1.260 +IMPORT_C gchar* g_find_program_in_path (const gchar *program);
1.261 +
1.262 +/* Bit tests
1.263 + */
1.264 +G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask,
1.265 + gint nth_bit);
1.266 +G_INLINE_FUNC gint g_bit_nth_msf (gulong mask,
1.267 + gint nth_bit);
1.268 +G_INLINE_FUNC guint g_bit_storage (gulong number);
1.269 +
1.270 +/* Trash Stacks
1.271 + * elements need to be >= sizeof (gpointer)
1.272 + */
1.273 +typedef struct _GTrashStack GTrashStack;
1.274 +struct _GTrashStack
1.275 +{
1.276 + GTrashStack *next;
1.277 +};
1.278 +
1.279 +G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
1.280 + gpointer data_p);
1.281 +G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
1.282 +G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
1.283 +G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
1.284 +
1.285 +/* inline function implementations
1.286 + */
1.287 +#if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
1.288 +G_INLINE_FUNC gint
1.289 +g_bit_nth_lsf (gulong mask,
1.290 + gint nth_bit)
1.291 +{
1.292 + do
1.293 + {
1.294 + nth_bit++;
1.295 + if (mask & (1UL << nth_bit))
1.296 + return nth_bit;
1.297 + }
1.298 + while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1));
1.299 + return -1;
1.300 +}
1.301 +G_INLINE_FUNC gint
1.302 +g_bit_nth_msf (gulong mask,
1.303 + gint nth_bit)
1.304 +{
1.305 + if (nth_bit < 0)
1.306 + nth_bit = GLIB_SIZEOF_LONG * 8;
1.307 + do
1.308 + {
1.309 + nth_bit--;
1.310 + if (mask & (1UL << nth_bit))
1.311 + return nth_bit;
1.312 + }
1.313 + while (nth_bit > 0);
1.314 + return -1;
1.315 +}
1.316 +G_INLINE_FUNC guint
1.317 +g_bit_storage (gulong number)
1.318 +{
1.319 + register guint n_bits = 0;
1.320 +
1.321 + do
1.322 + {
1.323 + n_bits++;
1.324 + number >>= 1;
1.325 + }
1.326 + while (number);
1.327 + return n_bits;
1.328 +}
1.329 +G_INLINE_FUNC void
1.330 +g_trash_stack_push (GTrashStack **stack_p,
1.331 + gpointer data_p)
1.332 +{
1.333 + GTrashStack *data = (GTrashStack *) data_p;
1.334 +
1.335 + data->next = *stack_p;
1.336 + *stack_p = data;
1.337 +}
1.338 +G_INLINE_FUNC gpointer
1.339 +g_trash_stack_pop (GTrashStack **stack_p)
1.340 +{
1.341 + GTrashStack *data;
1.342 +
1.343 + data = *stack_p;
1.344 + if (data)
1.345 + {
1.346 + *stack_p = data->next;
1.347 + /* NULLify private pointer here, most platforms store NULL as
1.348 + * subsequent 0 bytes
1.349 + */
1.350 + data->next = NULL;
1.351 + }
1.352 +
1.353 + return data;
1.354 +}
1.355 +G_INLINE_FUNC gpointer
1.356 +g_trash_stack_peek (GTrashStack **stack_p)
1.357 +{
1.358 + GTrashStack *data;
1.359 +
1.360 + data = *stack_p;
1.361 +
1.362 + return data;
1.363 +}
1.364 +G_INLINE_FUNC guint
1.365 +g_trash_stack_height (GTrashStack **stack_p)
1.366 +{
1.367 + GTrashStack *data;
1.368 + guint i = 0;
1.369 +
1.370 + for (data = *stack_p; data; data = data->next)
1.371 + i++;
1.372 +
1.373 + return i;
1.374 +}
1.375 +#endif /* G_CAN_INLINE || __G_UTILS_C__ */
1.376 +
1.377 +/* Glib version.
1.378 + * we prefix variable declarations so they can
1.379 + * properly get exported in windows dlls.
1.380 + */
1.381 +GLIB_VAR const guint glib_major_version;
1.382 +GLIB_VAR const guint glib_minor_version;
1.383 +GLIB_VAR const guint glib_micro_version;
1.384 +GLIB_VAR const guint glib_interface_age;
1.385 +GLIB_VAR const guint glib_binary_age;
1.386 +
1.387 +#ifdef __SYMBIAN32__
1.388 +IMPORT_C const guint *_glib_major_version();
1.389 +IMPORT_C const guint *_glib_minor_version();
1.390 +IMPORT_C const guint *_glib_micro_version();
1.391 +IMPORT_C const guint *_glib_interface_age();
1.392 +IMPORT_C const guint *_glib_binary_age();
1.393 +#endif /* __SYMBIAN32__ */
1.394 +
1.395 +IMPORT_C const gchar * glib_check_version (guint required_major,
1.396 + guint required_minor,
1.397 + guint required_micro);
1.398 +
1.399 +#define GLIB_CHECK_VERSION(major,minor,micro) \
1.400 + (GLIB_MAJOR_VERSION > (major) || \
1.401 + (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
1.402 + (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
1.403 + GLIB_MICRO_VERSION >= (micro)))
1.404 +
1.405 +G_END_DECLS
1.406 +
1.407 +/*
1.408 + * On Windows, this macro defines a DllMain function that stores the
1.409 + * actual DLL name that the code being compiled will be included in.
1.410 + * STATIC should be empty or 'static'. DLL_NAME is the name of the
1.411 + * (pointer to the) char array where the DLL name will be stored. If
1.412 + * this is used, you must also include <windows.h>. If you need a more complex
1.413 + * DLL entry point function, you cannot use this.
1.414 + *
1.415 + * On non-Windows platforms, expands to nothing.
1.416 + */
1.417 +
1.418 +#ifndef G_PLATFORM_WIN32
1.419 +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
1.420 +#else
1.421 +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
1.422 +static char *dll_name; \
1.423 + \
1.424 +BOOL WINAPI \
1.425 +DllMain (HINSTANCE hinstDLL, \
1.426 + DWORD fdwReason, \
1.427 + LPVOID lpvReserved) \
1.428 +{ \
1.429 + wchar_t wcbfr[1000]; \
1.430 + char cpbfr[1000]; \
1.431 + char *tem; \
1.432 + switch (fdwReason) \
1.433 + { \
1.434 + case DLL_PROCESS_ATTACH: \
1.435 + if (GetVersion () < 0x80000000) \
1.436 + { \
1.437 + GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
1.438 + tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \
1.439 + dll_name = g_path_get_basename (tem); \
1.440 + g_free (tem); \
1.441 + } \
1.442 + else \
1.443 + { \
1.444 + GetModuleFileNameA ((HMODULE) hinstDLL, cpbfr, G_N_ELEMENTS (cpbfr)); \
1.445 + tem = g_locale_to_utf8 (cpbfr, -1, NULL, NULL, NULL); \
1.446 + dll_name = g_path_get_basename (tem); \
1.447 + g_free (tem); \
1.448 + } \
1.449 + break; \
1.450 + } \
1.451 + \
1.452 + return TRUE; \
1.453 +}
1.454 +#endif /* G_PLATFORM_WIN32 */
1.455 +
1.456 +#endif /* __G_UTILS_H__ */