summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-18 17:59:12 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-18 17:59:12 +0000
commite11b4cced0f967a66ea81e3b6b92448e55d49624 (patch)
treea324e374701e6fb515d8261294ac5ea540776c8e
parent5c3cff06eb6cfd03f5133a7d087c55413875e400 (diff)
Add g_slist_nth, g_slist_nth_data, g_slist_last and g_slist_position functions to eglib.
-rw-r--r--eglib/gmain.c37
-rw-r--r--eglib/gmain.h5
2 files changed, 42 insertions, 0 deletions
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)
diff --git a/eglib/gmain.h b/eglib/gmain.h
index ce9bdce5..c75f25d2 100644
--- a/eglib/gmain.h
+++ b/eglib/gmain.h
@@ -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 */