Index: uspace/lib/c/include/adt/list.h
===================================================================
--- uspace/lib/c/include/adt/list.h	(revision c67dbd622a32b92e827b239c60b0a0e72d711a01)
+++ uspace/lib/c/include/adt/list.h	(revision d08ba7fc117c3452bd836456d4e0d1fa6680849a)
@@ -67,7 +67,9 @@
 	((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
 
-#define list_foreach(list, iterator) \
-	for (link_t *iterator = (list).head.next; \
-	    iterator != &(list).head; iterator = iterator->next)
+#define list_foreach(list, member, itype, iterator) \
+	for (itype *iterator = NULL; iterator == NULL; iterator =(itype *)1) \
+	    for (link_t *_link = (list).head.next; \
+	    iterator = list_get_instance(_link, itype, member), \
+	    _link != &(list).head; _link = _link->next)
 
 /** Unlike list_foreach(), allows removing items while traversing a list.
@@ -238,5 +240,29 @@
 static inline link_t *list_last(list_t *list)
 {
-	return ((list->head.prev == &list->head) ? NULL : list->head.prev);
+	return (list->head.prev == &list->head) ? NULL : list->head.prev;
+}
+
+/** Get next item in list.
+ *
+ * @param link Current item link
+ * @param list List containing @a link
+ *
+ * @return Next item or NULL if @a link is the last item.
+ */
+static inline link_t *list_next(link_t *link, const list_t *list)
+{
+	return (link->next == &list->head) ? NULL : link->next;
+}
+
+/** Get previous item in list.
+ *
+ * @param link Current item link
+ * @param list List containing @a link
+ *
+ * @return Previous item or NULL if @a link is the first item.
+ */
+static inline link_t *list_prev(link_t *link, const list_t *list)
+{
+	return (link->prev == &list->head) ? NULL : link->prev;
 }
 
@@ -308,9 +334,11 @@
 	unsigned int cnt = 0;
 	
-	list_foreach(*list, link) {
+	link_t *link = list_first(list);
+	while (link != NULL) {
 		if (cnt == n)
 			return link;
 		
 		cnt++;
+		link = list_next(link, list);
 	}
 	
Index: uspace/lib/c/include/cfg.h
===================================================================
--- uspace/lib/c/include/cfg.h	(revision c67dbd622a32b92e827b239c60b0a0e72d711a01)
+++ uspace/lib/c/include/cfg.h	(revision d08ba7fc117c3452bd836456d4e0d1fa6680849a)
@@ -80,5 +80,5 @@
 
 #define cfg_file_foreach(file, cur) \
-	list_foreach((file)->sections, (cur))
+	list_foreach((file)->sections, link, const cfg_section_t, (cur))
 
 #define cfg_section_instance(cur) \
@@ -86,5 +86,5 @@
 
 #define cfg_section_foreach(section, cur) \
-	list_foreach((section)->entries, (cur))
+	list_foreach((section)->entries, link, const cfg_entry_t, (cur))
 
 #define cfg_entry_instance(cur) \
