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
00042 #ifndef _glib_missing_h_
00043 #define _glib_missing_h_
00044
00045 #include "common.h"
00046
00047 #ifdef USE_GLIB1
00048 typedef gboolean (*GEqualFunc)(gconstpointer a, gconstpointer b);
00049
00050 typedef struct GMemVTable {
00051 gpointer (*gmvt_malloc) (gsize n_bytes);
00052 gpointer (*gmvt_realloc) (gpointer mem, gsize n_bytes);
00053 void (*gmvt_free) (gpointer mem);
00054
00055 gpointer (*gmvt_calloc) (gsize n_blocks, gsize n_block_bytes);
00056 gpointer (*gmvt_try_malloc) (gsize n_bytes);
00057 gpointer (*gmvt_try_realloc) (gpointer mem, gsize n_bytes);
00058 } GMemVTable;
00059 #endif
00060
00061
00062
00063
00064
00065 gboolean gm_slist_is_looping(const GSList *slist);
00066 GSList *gm_slist_insert_after(GSList *list, GSList *lnk, gpointer data);
00067
00068 GList *gm_list_insert_after(GList *list, GList *lnk, gpointer data);
00069
00070 #ifdef USE_GLIB1
00071 GList *g_list_delete_link(GList *l, GList *lnk);
00072 GSList *g_slist_delete_link(GSList *sl, GSList *lnk);
00073 GString *g_string_append_len(GString *gs, const gchar *val, gssize len);
00074
00075 void g_hash_table_replace(GHashTable *ht, gpointer key, gpointer value);
00076
00077 void g_mem_set_vtable(GMemVTable *vtable);
00078 gboolean g_mem_is_system_malloc(void);
00079 #endif
00080
00081 gchar *gm_string_finalize(GString *gs);
00082
00083 size_t gm_vsnprintf(gchar *str, size_t n, gchar const *fmt, va_list args);
00084 size_t gm_snprintf(gchar *str, size_t n,
00085 gchar const *fmt, ...) G_GNUC_PRINTF (3, 4);
00086
00087 void gm_savemain(gint argc, gchar **argv, gchar **env);
00088 const gchar *gm_getproctitle(void);
00089 void gm_setproctitle(const gchar *title);
00090 gchar *gm_sanitize_filename(const gchar *filename,
00091 gboolean no_spaces, gboolean no_evil);
00092
00093 static inline void
00094 gm_hash_table_insert_const(GHashTable *ht,
00095 gconstpointer key, gconstpointer value)
00096 {
00097 g_hash_table_insert(ht, (gpointer) key, (gpointer) value);
00098 }
00099
00100 static inline void
00101 gm_hash_table_replace_const(GHashTable *ht,
00102 gconstpointer key, gconstpointer value)
00103 {
00104 g_hash_table_replace(ht, (gpointer) key, (gpointer) value);
00105 }
00106
00107 GSList *gm_hash_table_all_keys(GHashTable *ht);
00108 void gm_hash_table_foreach_key(GHashTable *ht, GFunc func, gpointer user_data);
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #define G_LIST_FOREACH(list, func) \
00121 G_STMT_START { \
00122 GList *l_ = (list); \
00123 while (NULL != l_) { \
00124 func(l_->data); \
00125 l_ = g_list_next(l_); \
00126 } \
00127 } G_STMT_END
00128
00129 #define G_LIST_FOREACH_WITH_DATA(list, func, user_data) \
00130 G_STMT_START { \
00131 GList *l_ = (list); \
00132 gpointer user_data_ = (user_data); \
00133 while (NULL != l_) { \
00134 func(l_->data, user_data_); \
00135 l_ = g_list_next(l_); \
00136 } \
00137 } G_STMT_END
00138
00139 #define G_LIST_FOREACH_SWAPPED(list, func, user_data) \
00140 G_STMT_START { \
00141 GList *l_ = (list); \
00142 gpointer user_data_ = (user_data); \
00143 while (NULL != l_) { \
00144 func(user_data_, l_->data); \
00145 l_ = g_list_next(l_); \
00146 } \
00147 } G_STMT_END
00148
00149
00150 #define G_SLIST_FOREACH(slist, func) \
00151 G_STMT_START { \
00152 GSList *sl_ = (slist); \
00153 while (NULL != sl_) { \
00154 func(sl_->data); \
00155 sl_ = g_slist_next(sl_); \
00156 } \
00157 } G_STMT_END
00158
00159
00160 #define G_SLIST_FOREACH_WITH_DATA(slist, func, user_data) \
00161 G_STMT_START { \
00162 GSList *sl_ = (slist); \
00163 gpointer user_data_ = (user_data); \
00164 while (NULL != sl_) { \
00165 func(sl_->data, user_data_); \
00166 sl_ = g_slist_next(sl_); \
00167 } \
00168 } G_STMT_END
00169
00170
00171
00172 #define G_SLIST_FOREACH_SWAPPED(slist, func, user_data) \
00173 G_STMT_START { \
00174 GSList *sl_ = (slist); \
00175 gpointer user_data_ = (user_data); \
00176 while (NULL != sl_) { \
00177 func(user_data_, sl_->data); \
00178 sl_ = g_slist_next(sl_); \
00179 } \
00180 } while(0)
00181
00182 #define GM_SLIST_FOREACH(slist, iter) \
00183 for ((iter) = (slist); NULL != (iter); (iter) = g_slist_next(iter))
00184
00185
00186 #endif