#ifndef __G_UTILS_H__
#define __G_UTILS_H__
#include <glib/gtypes.h>
#include <stdarg.h>
G_BEGIN_DECLS
#ifdef G_OS_WIN32
#define G_DIR_SEPARATOR '\\'
#define G_DIR_SEPARATOR_S "\\"
#define G_SEARCHPATH_SEPARATOR ';'
#define G_SEARCHPATH_SEPARATOR_S ";"
#else
#define G_DIR_SEPARATOR '/'
#define G_DIR_SEPARATOR_S "/"
#define G_SEARCHPATH_SEPARATOR ':'
#define G_SEARCHPATH_SEPARATOR_S ":"
#endif
#if !defined (G_VA_COPY)
# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
# elif defined (G_VA_COPY_AS_ARRAY)
# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
# else
# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
# endif
#endif
#ifdef G_IMPLEMENT_INLINES
# define G_INLINE_FUNC extern
# undef G_CAN_INLINE
#endif
#ifndef G_INLINE_FUNC
# define G_CAN_INLINE 1
#endif
#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
# undef inline
# define inline __inline__
#elif !defined (G_HAVE_INLINE)
# undef inline
# if defined (G_HAVE___INLINE__)
# define inline __inline__
# elif defined (G_HAVE___INLINE)
# define inline __inline
# else
# define inline
# ifndef G_INLINE_FUNC
# undef G_CAN_INLINE
# endif
# endif
#endif
#ifndef G_INLINE_FUNC
# if defined (__GNUC__) && defined (__OPTIMIZE__)
# define G_INLINE_FUNC extern inline
# elif defined (G_CAN_INLINE) && !defined (__GNUC__)
# define G_INLINE_FUNC static inline
# else
# define G_INLINE_FUNC extern
# undef G_CAN_INLINE
# endif
#endif
G_CONST_RETURN gchar* g_get_user_name (void);
G_CONST_RETURN gchar* g_get_real_name (void);
G_CONST_RETURN gchar* g_get_home_dir (void);
G_CONST_RETURN gchar* g_get_tmp_dir (void);
gchar* g_get_prgname (void);
void g_set_prgname (const gchar *prgname);
G_CONST_RETURN gchar* g_get_application_name (void);
void g_set_application_name (const gchar *application_name);
typedef struct _GDebugKey GDebugKey;
struct _GDebugKey
{
gchar *key;
guint value;
};
guint g_parse_debug_string (const gchar *string,
const GDebugKey *keys,
guint nkeys);
gint g_snprintf (gchar *string,
gulong n,
gchar const *format,
...) G_GNUC_PRINTF (3, 4);
gint g_vsnprintf (gchar *string,
gulong n,
gchar const *format,
va_list args);
gboolean g_path_is_absolute (const gchar *file_name);
G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name);
#ifndef G_DISABLE_DEPRECATED
G_CONST_RETURN gchar* g_basename (const gchar *file_name);
#define g_dirname g_path_get_dirname
#endif
gchar* g_get_current_dir (void);
gchar* g_path_get_basename (const gchar *file_name);
gchar* g_path_get_dirname (const gchar *file_name);
void g_nullify_pointer (gpointer *nullify_location);
G_CONST_RETURN gchar* g_getenv (const gchar *variable);
gboolean g_setenv (const gchar *variable,
const gchar *value,
gboolean overwrite);
void g_unsetenv (const gchar *variable);
typedef void (*GVoidFunc) (void);
#ifndef ATEXIT
# define ATEXIT(proc) g_ATEXIT(proc)
#else
# define G_NATIVE_ATEXIT
#endif
void g_atexit (GVoidFunc func);
gchar* g_find_program_in_path (const gchar *program);
G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask,
gint nth_bit);
G_INLINE_FUNC gint g_bit_nth_msf (gulong mask,
gint nth_bit);
G_INLINE_FUNC guint g_bit_storage (gulong number);
typedef struct _GTrashStack GTrashStack;
struct _GTrashStack
{
GTrashStack *next;
};
G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
gpointer data_p);
G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
#if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
G_INLINE_FUNC gint
g_bit_nth_lsf (gulong mask,
gint nth_bit)
{
do
{
nth_bit++;
if (mask & (1UL << nth_bit))
return nth_bit;
}
while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1));
return -1;
}
G_INLINE_FUNC gint
g_bit_nth_msf (gulong mask,
gint nth_bit)
{
if (nth_bit < 0)
nth_bit = GLIB_SIZEOF_LONG * 8;
do
{
nth_bit--;
if (mask & (1UL << nth_bit))
return nth_bit;
}
while (nth_bit > 0);
return -1;
}
G_INLINE_FUNC guint
g_bit_storage (gulong number)
{
register guint n_bits = 0;
do
{
n_bits++;
number >>= 1;
}
while (number);
return n_bits;
}
G_INLINE_FUNC void
g_trash_stack_push (GTrashStack **stack_p,
gpointer data_p)
{
GTrashStack *data = (GTrashStack *) data_p;
data->next = *stack_p;
*stack_p = data;
}
G_INLINE_FUNC gpointer
g_trash_stack_pop (GTrashStack **stack_p)
{
GTrashStack *data;
data = *stack_p;
if (data)
{
*stack_p = data->next;
data->next = NULL;
}
return data;
}
G_INLINE_FUNC gpointer
g_trash_stack_peek (GTrashStack **stack_p)
{
GTrashStack *data;
data = *stack_p;
return data;
}
G_INLINE_FUNC guint
g_trash_stack_height (GTrashStack **stack_p)
{
GTrashStack *data;
guint i = 0;
for (data = *stack_p; data; data = data->next)
i++;
return i;
}
#endif
GLIB_VAR const guint glib_major_version;
GLIB_VAR const guint glib_minor_version;
GLIB_VAR const guint glib_micro_version;
GLIB_VAR const guint glib_interface_age;
GLIB_VAR const guint glib_binary_age;
#define GLIB_CHECK_VERSION(major,minor,micro) \
(GLIB_MAJOR_VERSION > (major) || \
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
GLIB_MICRO_VERSION >= (micro)))
G_END_DECLS
#ifndef G_PLATFORM_WIN32
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
#else
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
static char *dll_name; \
\
BOOL WINAPI \
DllMain (HINSTANCE hinstDLL, \
DWORD fdwReason, \
LPVOID lpvReserved) \
{ \
char bfr[1000]; \
switch (fdwReason) \
{ \
case DLL_PROCESS_ATTACH: \
GetModuleFileName ((HMODULE) hinstDLL, bfr, sizeof (bfr)); \
dll_name = g_path_get_basename (bfr); \
break; \
} \
\
return TRUE; \
}
#endif
#endif