00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __G_UTILS_H__
00029 #define __G_UTILS_H__
00030
00031 #include <_ansi.h>
00032 #include <glib/gtypes.h>
00033 #include <stdarg.h>
00034
00035 G_BEGIN_DECLS
00036
00037 #if defined(G_OS_WIN32) || defined(SYMBIAN)
00038
00039
00040
00041
00042
00043 #define G_DIR_SEPARATOR '\\'
00044 #define G_DIR_SEPARATOR_S "\\"
00045 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
00046 #define G_SEARCHPATH_SEPARATOR ';'
00047 #define G_SEARCHPATH_SEPARATOR_S ";"
00048
00049 #else
00050
00051
00052
00053 #define G_DIR_SEPARATOR '/'
00054 #define G_DIR_SEPARATOR_S "/"
00055 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
00056 #define G_SEARCHPATH_SEPARATOR ':'
00057 #define G_SEARCHPATH_SEPARATOR_S ":"
00058
00059 #endif
00060
00061
00062
00063
00064 #if !defined (G_VA_COPY)
00065 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
00066 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
00067 # elif defined (G_VA_COPY_AS_ARRAY)
00068 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
00069 # else
00070 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
00071 # endif
00072 #endif
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
00086 # undef inline
00087 # define inline __inline__
00088 #elif !defined (G_HAVE_INLINE)
00089 # undef inline
00090 # if defined (G_HAVE___INLINE__)
00091 # define inline __inline__
00092 # elif defined (G_HAVE___INLINE)
00093 # define inline __inline
00094 # else
00095 # define inline
00096 # endif
00097 #endif
00098 #ifdef G_IMPLEMENT_INLINES
00099 # define G_INLINE_FUNC
00100 # undef G_CAN_INLINE
00101 #elif defined (__GNUC__)
00102 # ifdef SYMBIAN
00103 # define G_INLINE_FUNC extern __inline
00104 # else
00105 # define G_INLINE_FUNC extern inline
00106 # endif
00107 #elif defined (G_CAN_INLINE)
00108 # ifdef SYMBIAN
00109 # define G_INLINE_FUNC static __inline
00110 # else
00111 # define G_INLINE_FUNC static inline
00112 # endif
00113 #else
00114 # define G_INLINE_FUNC
00115 #endif
00116
00117
00118
00119 #ifdef G_OS_WIN32
00120 #define g_get_user_name g_get_user_name_utf8
00121 #define g_get_real_name g_get_real_name_utf8
00122 #define g_get_home_dir g_get_home_dir_utf8
00123 #define g_get_tmp_dir g_get_tmp_dir_utf8
00124 #endif
00125
00126 IMPORT_C G_CONST_RETURN gchar* g_get_user_name (void);
00127 IMPORT_C G_CONST_RETURN gchar* g_get_real_name (void);
00128 IMPORT_C G_CONST_RETURN gchar* g_get_home_dir (void);
00129 IMPORT_C G_CONST_RETURN gchar* g_get_tmp_dir (void);
00130 IMPORT_C G_CONST_RETURN gchar* g_get_host_name (void);
00131 IMPORT_C gchar* g_get_prgname (void);
00132 IMPORT_C void g_set_prgname (const gchar *prgname);
00133 IMPORT_C G_CONST_RETURN gchar* g_get_application_name (void);
00134 IMPORT_C void g_set_application_name (const gchar *application_name);
00135
00136 IMPORT_C G_CONST_RETURN gchar* g_get_user_data_dir (void);
00137 IMPORT_C G_CONST_RETURN gchar* g_get_user_config_dir (void);
00138 IMPORT_C G_CONST_RETURN gchar* g_get_user_cache_dir (void);
00139 IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_data_dirs (void);
00140
00141 #ifdef G_OS_WIN32
00142 G_CONST_RETURN gchar* G_CONST_RETURN * g_win32_get_system_data_dirs_for_module (gconstpointer address);
00143 #endif
00144
00145 #if defined (G_OS_WIN32) && defined (G_CAN_INLINE) && !defined (__cplusplus)
00146 static inline G_CONST_RETURN gchar * G_CONST_RETURN *
00147 g_win32_get_system_data_dirs (void)
00148 {
00149 return g_win32_get_system_data_dirs_for_module ((gconstpointer) &g_win32_get_system_data_dirs);
00150 }
00151 #define g_get_system_data_dirs g_win32_get_system_data_dirs
00152 #endif
00153
00154 IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void);
00155
00156 IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void);
00157
00158 typedef struct _GDebugKey GDebugKey;
00159 struct _GDebugKey
00160 {
00161 gchar *key;
00162 guint value;
00163 };
00164
00165
00166
00167 IMPORT_C guint g_parse_debug_string (const gchar *string,
00168 const GDebugKey *keys,
00169 guint nkeys);
00170
00171 IMPORT_C gint g_snprintf (gchar *string,
00172 gulong n,
00173 gchar const *format,
00174 ...) G_GNUC_PRINTF (3, 4);
00175 IMPORT_C gint g_vsnprintf (gchar *string,
00176 gulong n,
00177 gchar const *format,
00178 va_list args);
00179
00180
00181 IMPORT_C gboolean g_path_is_absolute (const gchar *file_name);
00182
00183
00184 IMPORT_C G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name);
00185
00186 #ifndef G_DISABLE_DEPRECATED
00187
00188
00189
00190
00191
00192 IMPORT_C G_CONST_RETURN gchar* g_basename (const gchar *file_name);
00193 #define g_dirname g_path_get_dirname
00194
00195 #endif
00196
00197 #ifdef G_OS_WIN32
00198 #define g_get_current_dir g_get_current_dir_utf8
00199 #endif
00200
00201
00202 IMPORT_C gchar* g_get_current_dir (void);
00203 IMPORT_C gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
00204 IMPORT_C gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
00205
00206
00207 IMPORT_C void g_nullify_pointer (gpointer *nullify_location);
00208
00209
00210
00211 #ifdef G_OS_WIN32
00212 #define g_getenv g_getenv_utf8
00213 #define g_setenv g_setenv_utf8
00214 #define g_unsetenv g_unsetenv_utf8
00215 #define g_find_program_in_path g_find_program_in_path_utf8
00216 #endif
00217
00218 IMPORT_C G_CONST_RETURN gchar* g_getenv (const gchar *variable);
00219 IMPORT_C gboolean g_setenv (const gchar *variable,
00220 const gchar *value,
00221 gboolean overwrite);
00222 IMPORT_C void g_unsetenv (const gchar *variable);
00223 IMPORT_C gchar** g_listenv (void);
00224 const gchar* _g_getenv_nomalloc (const gchar *variable,
00225 gchar buffer[1024]);
00226
00227
00228
00229
00230
00231 typedef void (*GVoidFunc) (void);
00232 #ifndef ATEXIT
00233 # define ATEXIT(proc) g_ATEXIT(proc)
00234 #else
00235 # define G_NATIVE_ATEXIT
00236 #endif
00237
00238
00239
00240
00241
00242 IMPORT_C void g_atexit (GVoidFunc func);
00243
00244 #ifdef G_OS_WIN32
00245
00246
00247
00248
00249
00250
00251 int atexit (void (*)(void));
00252 #define g_atexit(func) atexit(func)
00253 #endif
00254
00255
00256 IMPORT_C gchar* g_find_program_in_path (const gchar *program);
00257
00258
00259
00260 G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask,
00261 gint nth_bit);
00262 G_INLINE_FUNC gint g_bit_nth_msf (gulong mask,
00263 gint nth_bit);
00264 G_INLINE_FUNC guint g_bit_storage (gulong number);
00265
00266
00267
00268
00269 typedef struct _GTrashStack GTrashStack;
00270 struct _GTrashStack
00271 {
00272 GTrashStack *next;
00273 };
00274
00275 G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
00276 gpointer data_p);
00277 G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
00278 G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
00279 G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
00280
00281
00282
00283 #if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
00284 G_INLINE_FUNC gint
00285 g_bit_nth_lsf (gulong mask,
00286 gint nth_bit)
00287 {
00288 do
00289 {
00290 nth_bit++;
00291 if (mask & (1UL << nth_bit))
00292 return nth_bit;
00293 }
00294 while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1));
00295 return -1;
00296 }
00297 G_INLINE_FUNC gint
00298 g_bit_nth_msf (gulong mask,
00299 gint nth_bit)
00300 {
00301 if (nth_bit < 0)
00302 nth_bit = GLIB_SIZEOF_LONG * 8;
00303 do
00304 {
00305 nth_bit--;
00306 if (mask & (1UL << nth_bit))
00307 return nth_bit;
00308 }
00309 while (nth_bit > 0);
00310 return -1;
00311 }
00312 G_INLINE_FUNC guint
00313 g_bit_storage (gulong number)
00314 {
00315 register guint n_bits = 0;
00316
00317 do
00318 {
00319 n_bits++;
00320 number >>= 1;
00321 }
00322 while (number);
00323 return n_bits;
00324 }
00325 G_INLINE_FUNC void
00326 g_trash_stack_push (GTrashStack **stack_p,
00327 gpointer data_p)
00328 {
00329 GTrashStack *data = (GTrashStack *) data_p;
00330
00331 data->next = *stack_p;
00332 *stack_p = data;
00333 }
00334 G_INLINE_FUNC gpointer
00335 g_trash_stack_pop (GTrashStack **stack_p)
00336 {
00337 GTrashStack *data;
00338
00339 data = *stack_p;
00340 if (data)
00341 {
00342 *stack_p = data->next;
00343
00344
00345
00346 data->next = NULL;
00347 }
00348
00349 return data;
00350 }
00351 G_INLINE_FUNC gpointer
00352 g_trash_stack_peek (GTrashStack **stack_p)
00353 {
00354 GTrashStack *data;
00355
00356 data = *stack_p;
00357
00358 return data;
00359 }
00360 G_INLINE_FUNC guint
00361 g_trash_stack_height (GTrashStack **stack_p)
00362 {
00363 GTrashStack *data;
00364 guint i = 0;
00365
00366 for (data = *stack_p; data; data = data->next)
00367 i++;
00368
00369 return i;
00370 }
00371 #endif
00372
00373
00374
00375
00376
00377 GLIB_VAR const guint glib_major_version;
00378 GLIB_VAR const guint glib_minor_version;
00379 GLIB_VAR const guint glib_micro_version;
00380 GLIB_VAR const guint glib_interface_age;
00381 GLIB_VAR const guint glib_binary_age;
00382
00383 #ifdef SYMBIAN
00384 IMPORT_C const guint *_glib_major_version();
00385 IMPORT_C const guint *_glib_minor_version();
00386 IMPORT_C const guint *_glib_micro_version();
00387 IMPORT_C const guint *_glib_interface_age();
00388 IMPORT_C const guint *_glib_binary_age();
00389 #endif
00390
00391 IMPORT_C const gchar * glib_check_version (guint required_major,
00392 guint required_minor,
00393 guint required_micro);
00394
00395 #define GLIB_CHECK_VERSION(major,minor,micro) \
00396 (GLIB_MAJOR_VERSION > (major) || \
00397 (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
00398 (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
00399 GLIB_MICRO_VERSION >= (micro)))
00400
00401 G_END_DECLS
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 #ifndef G_PLATFORM_WIN32
00415 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
00416 #else
00417 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
00418 static char *dll_name; \
00419 \
00420 BOOL WINAPI \
00421 DllMain (HINSTANCE hinstDLL, \
00422 DWORD fdwReason, \
00423 LPVOID lpvReserved) \
00424 { \
00425 wchar_t wcbfr[1000]; \
00426 char cpbfr[1000]; \
00427 char *tem; \
00428 switch (fdwReason) \
00429 { \
00430 case DLL_PROCESS_ATTACH: \
00431 if (GetVersion () < 0x80000000) \
00432 { \
00433 GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
00434 tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \
00435 dll_name = g_path_get_basename (tem); \
00436 g_free (tem); \
00437 } \
00438 else \
00439 { \
00440 GetModuleFileNameA ((HMODULE) hinstDLL, cpbfr, G_N_ELEMENTS (cpbfr)); \
00441 tem = g_locale_to_utf8 (cpbfr, -1, NULL, NULL, NULL); \
00442 dll_name = g_path_get_basename (tem); \
00443 g_free (tem); \
00444 } \
00445 break; \
00446 } \
00447 \
00448 return TRUE; \
00449 }
00450 #endif
00451
00452 #endif