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 #ifndef __G_UTILS_H__
00028 #define __G_UTILS_H__
00029
00030 #include <g_types.h>
00031 #include <stdarg.h>
00032
00033 G_BEGIN_DECLS
00034
00035 #ifdef G_OS_WIN32
00036
00037
00038
00039
00040 #define G_DIR_SEPARATOR '\\'
00041 #define G_DIR_SEPARATOR_S "\\"
00042 #define G_SEARCHPATH_SEPARATOR ';'
00043 #define G_SEARCHPATH_SEPARATOR_S ";"
00044
00045 #else
00046
00047
00048
00049 #define G_DIR_SEPARATOR '/'
00050 #define G_DIR_SEPARATOR_S "/"
00051 #define G_SEARCHPATH_SEPARATOR ':'
00052 #define G_SEARCHPATH_SEPARATOR_S ":"
00053
00054 #endif
00055
00056
00057
00058
00059 #if !defined (G_VA_COPY)
00060 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
00061 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
00062 # elif defined (G_VA_COPY_AS_ARRAY)
00063 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
00064 # else
00065 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
00066 # endif
00067 #endif
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #ifdef G_IMPLEMENT_INLINES
00081 # define G_INLINE_FUNC extern
00082 # undef G_CAN_INLINE
00083 #endif
00084 #ifndef G_INLINE_FUNC
00085 # define G_CAN_INLINE 1
00086 #endif
00087 #if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
00088 # undef inline
00089 # define inline __inline__
00090 #elif !defined (G_HAVE_INLINE)
00091 # undef inline
00092 # if defined (G_HAVE___INLINE__)
00093 # define inline __inline__
00094 # elif defined (G_HAVE___INLINE)
00095 # define inline __inline
00096 # else
00097 # define inline
00098 # ifndef G_INLINE_FUNC
00099 # undef G_CAN_INLINE
00100 # endif
00101 # endif
00102 #endif
00103 #ifndef G_INLINE_FUNC
00104 # if defined (__GNUC__) && (__OPTIMIZE__)
00105 # define G_INLINE_FUNC extern inline
00106 # elif defined (G_CAN_INLINE) && !defined (__GNUC__)
00107 # define G_INLINE_FUNC static inline
00108 # else
00109 # define G_INLINE_FUNC extern
00110 # undef G_CAN_INLINE
00111 # endif
00112 #endif
00113
00114
00115
00116 gchar* g_get_user_name (void);
00117 gchar* g_get_real_name (void);
00118 gchar* g_get_home_dir (void);
00119 gchar* g_get_tmp_dir (void);
00120 gchar* g_get_prgname (void);
00121 void g_set_prgname (const gchar *prgname);
00122
00123
00124 typedef struct _GDebugKey GDebugKey;
00125 struct _GDebugKey
00126 {
00127 gchar *key;
00128 guint value;
00129 };
00130
00131
00132
00133 guint g_parse_debug_string (const gchar *string,
00134 GDebugKey *keys,
00135 guint nkeys);
00136 gint g_snprintf (gchar *string,
00137 gulong n,
00138 gchar const *format,
00139 ...) G_GNUC_PRINTF (3, 4);
00140 gint g_vsnprintf (gchar *string,
00141 gulong n,
00142 gchar const *format,
00143 va_list args);
00144
00145 gboolean g_path_is_absolute (const gchar *file_name);
00146
00147 gchar* g_path_skip_root (gchar *file_name);
00148
00149
00150
00151
00152
00153 gchar* g_basename (const gchar *file_name);
00154 gchar* g_dirname (const gchar *file_name);
00155
00156
00157 gchar* g_get_current_dir (void);
00158 gchar* g_path_get_basename (const gchar *file_name);
00159 gchar* g_path_get_dirname (const gchar *file_name);
00160
00161
00162
00163
00164
00165
00166 gchar* g_getenv (const gchar *variable);
00167
00168
00169
00170
00171
00172
00173 typedef void (*GVoidFunc) (void);
00174 #ifndef ATEXIT
00175 # define ATEXIT(proc) g_ATEXIT(proc)
00176 #else
00177 # define G_NATIVE_ATEXIT
00178 #endif
00179
00180
00181
00182
00183
00184 void g_atexit (GVoidFunc func);
00185
00186
00187 gchar* g_find_program_in_path (const gchar *program);
00188
00189
00190
00191 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
00192 gint nth_bit);
00193 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
00194 gint nth_bit);
00195 G_INLINE_FUNC guint g_bit_storage (guint number);
00196
00197
00198
00199
00200 typedef struct _GTrashStack GTrashStack;
00201 struct _GTrashStack
00202 {
00203 GTrashStack *next;
00204 };
00205
00206 G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
00207 gpointer data_p);
00208 G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
00209 G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
00210 G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
00211
00212
00213
00214 #if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
00215 G_INLINE_FUNC gint
00216 g_bit_nth_lsf (guint32 mask,
00217 gint nth_bit)
00218 {
00219 do
00220 {
00221 nth_bit++;
00222 if (mask & (1 << (guint) nth_bit))
00223 return nth_bit;
00224 }
00225 while (nth_bit < 32);
00226 return -1;
00227 }
00228 G_INLINE_FUNC gint
00229 g_bit_nth_msf (guint32 mask,
00230 gint nth_bit)
00231 {
00232 if (nth_bit < 0)
00233 nth_bit = 32;
00234 do
00235 {
00236 nth_bit--;
00237 if (mask & (1 << (guint) nth_bit))
00238 return nth_bit;
00239 }
00240 while (nth_bit > 0);
00241 return -1;
00242 }
00243 G_INLINE_FUNC guint
00244 g_bit_storage (guint number)
00245 {
00246 register guint n_bits = 0;
00247
00248 do
00249 {
00250 n_bits++;
00251 number >>= 1;
00252 }
00253 while (number);
00254 return n_bits;
00255 }
00256 G_INLINE_FUNC void
00257 g_trash_stack_push (GTrashStack **stack_p,
00258 gpointer data_p)
00259 {
00260 GTrashStack *data = (GTrashStack *) data_p;
00261
00262 data->next = *stack_p;
00263 *stack_p = data;
00264 }
00265 G_INLINE_FUNC gpointer
00266 g_trash_stack_pop (GTrashStack **stack_p)
00267 {
00268 GTrashStack *data;
00269
00270 data = *stack_p;
00271 if (data)
00272 {
00273 *stack_p = data->next;
00274
00275
00276
00277 data->next = NULL;
00278 }
00279
00280 return data;
00281 }
00282 G_INLINE_FUNC gpointer
00283 g_trash_stack_peek (GTrashStack **stack_p)
00284 {
00285 GTrashStack *data;
00286
00287 data = *stack_p;
00288
00289 return data;
00290 }
00291 G_INLINE_FUNC guint
00292 g_trash_stack_height (GTrashStack **stack_p)
00293 {
00294 GTrashStack *data;
00295 guint i = 0;
00296
00297 for (data = *stack_p; data; data = data->next)
00298 i++;
00299
00300 return i;
00301 }
00302 #endif
00303
00304
00305
00306
00307
00308 #ifdef G_OS_WIN32
00309 # ifdef GLIB_COMPILATION
00310 # define GLIB_VAR __declspec(dllexport)
00311 # else
00312 # define GLIB_VAR extern __declspec(dllimport)
00313 # endif
00314 #else
00315 # define GLIB_VAR extern
00316 #endif
00317
00318 GLIB_VAR const guint glib_major_version;
00319 GLIB_VAR const guint glib_minor_version;
00320 GLIB_VAR const guint glib_micro_version;
00321 GLIB_VAR const guint glib_interface_age;
00322 GLIB_VAR const guint glib_binary_age;
00323
00324 #define GLIB_CHECK_VERSION(major,minor,micro) \
00325 (GLIB_MAJOR_VERSION > (major) || \
00326 (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
00327 (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
00328 GLIB_MICRO_VERSION >= (micro)))
00329
00330 G_END_DECLS
00331
00332 #endif
00333
00334
00335