X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=libsysfs%2Fdlist.c;h=b440d65bed0f0f1fb7b8be5fa69999c6ba8a0692;hb=da767d0739c86a04a0c0326cebff6c08ffe1228c;hp=6dfcf726baed68e8aa595416a321718e6e3da43c;hpb=fe3fe3b29ffbc7d0ce7dca6a371da31d8b3ff7f8;p=elogind.git diff --git a/libsysfs/dlist.c b/libsysfs/dlist.c index 6dfcf726b..b440d65be 100644 --- a/libsysfs/dlist.c +++ b/libsysfs/dlist.c @@ -27,6 +27,7 @@ * delete function. Otherwise dlist will just use free. */ +#include #include "dlist.h" /* @@ -73,14 +74,14 @@ inline void *_dlist_mark_move(Dlist *list,int direction) { if(direction) { - if( list->marker->next!=NULL) + if( list->marker && list->marker->next!=NULL) list->marker=list->marker->next; else return(NULL); } else { - if( list->marker->prev!=NULL) + if( list->marker && list->marker->prev!=NULL) list->marker=list->marker->prev; else return(NULL); @@ -259,6 +260,16 @@ void dlist_unshift(Dlist *list,void *data) dlist_insert(list,data,0); } +void dlist_unshift_sorted(Dlist *list, void *data, + int (*sorter)(void *new, void *old)) +{ + if (list->count == 0) + dlist_unshift(list, data); + else { + list->marker=list->head->next; + dlist_insert_sorted(list, data, sorter); + } +} /* * Remove end node from list.