summaryrefslogtreecommitdiffstats
path: root/common/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/list.c')
-rw-r--r--common/list.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/list.c b/common/list.c
index a887bcdd..579d9574 100644
--- a/common/list.c
+++ b/common/list.c
@@ -70,6 +70,36 @@ struct slist *slist_prepend(struct slist *list, void *data)
return entry;
}
+struct slist *slist_insert_before(struct slist *list, struct slist *sibling, void *data)
+{
+ struct slist *entry, *prev, *cur;
+
+ entry = malloc(sizeof(struct slist));
+ if (!entry)
+ return list;
+
+ entry->data = data;
+ entry->next = NULL;
+
+ if (!list)
+ return entry;
+
+ for (cur = list, prev = NULL; cur != NULL; prev = cur, cur = prev->next) {
+ if (cur == sibling)
+ break;
+ }
+
+ if (!prev) {
+ entry->next = list;
+ return entry;
+ }
+
+ entry->next = prev->next;
+ prev->next = entry;
+
+ return list;
+}
+
struct slist *slist_remove(struct slist *list, void *data)
{
struct slist *l, *next, *prev = NULL, *match = NULL;