From e11b4cced0f967a66ea81e3b6b92448e55d49624 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 18 May 2007 17:59:12 +0000 Subject: Add g_slist_nth, g_slist_nth_data, g_slist_last and g_slist_position functions to eglib. --- eglib/gmain.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'eglib/gmain.c') diff --git a/eglib/gmain.c b/eglib/gmain.c index d2f002f8..89794c05 100644 --- a/eglib/gmain.c +++ b/eglib/gmain.c @@ -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) -- cgit