2 Copyright (C) 2012-2021 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 Pwmd is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
23 #include "util-slist.h"
27 slist_length (struct slist_s
*list
)
32 for (cur
= list
; cur
; cur
= cur
->next
)
39 slist_nth_data (struct slist_s
*list
, unsigned n
)
44 for (i
= 0, cur
= list
; cur
; cur
= cur
->next
, i
++)
54 slist_append (struct slist_s
*list
, void *data
)
60 cur
= xcalloc (1, sizeof (struct slist_s
));
65 for (cur
= list
; cur
; cur
= cur
->next
)
71 cur
->next
= xcalloc (1, sizeof (struct slist_s
));
72 cur
->next
->data
= data
;
76 static struct slist_s
*
77 free_once (struct slist_s
*cur
)
79 struct slist_s
*next
= cur
? cur
->next
: NULL
;
86 slist_free (struct slist_s
*list
)
89 list
= free_once (list
);
93 slist_remove (struct slist_s
*list
, void *data
)
95 struct slist_s
*prev
, *cur
;
97 for (cur
= prev
= list
; cur
; prev
= cur
, cur
= cur
->next
)
99 if (cur
->data
== data
)
101 struct slist_s
*next
= free_once (cur
);