Add g_slist_nth, g_slist_nth_data, g_slist_last and g_slist_position functions to eglib.

This commit is contained in:
Luiz Augusto von Dentz 2007-05-18 17:59:12 +00:00
parent 5c3cff06eb
commit e11b4cced0
2 changed files with 42 additions and 0 deletions

View File

@ -1127,6 +1127,43 @@ void g_slist_free(GSList *list)
}
}
GSList *g_slist_nth(GSList *list, guint n)
{
while (n-- > 0 && list)
list = list->next;
return list;
}
gpointer g_slist_nth_data(GSList *list, guint n)
{
while (n-- > 0 && list)
list = list->next;
return list ? list->data : NULL;
}
gint g_slist_position(GSList *list, GSList *link)
{
gint i;
for (i = 0; list; list = list->next, i++) {
if (list == link)
return i;
}
return -1;
}
GSList* g_slist_last(GSList *list)
{
if (list)
while (list->next)
list = list->next;
return list;
}
/* Memory allocation functions */
gpointer g_malloc(gulong n_bytes)

View File

@ -192,6 +192,11 @@ int g_slist_length(GSList *list);
void g_slist_foreach(GSList *list, GFunc func, void *user_data);
void g_slist_free(GSList *list);
GSList *g_slist_nth(GSList *list, guint n);
gpointer g_slist_nth_data(GSList *list, guint n);
int g_slist_position(GSList *list, GSList *link);
GSList* g_slist_last(GSList *list);
/* End GSList declarations */
/* Memory allocation related */