Commit | Line | Data |
---|---|---|
dabf4152 AM |
1 | /* |
2 | Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU Lesser General Public License as published by | |
6 | the Free Software Foundation; either version 2.1 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public License | |
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
ee872606 RRS |
18 | #ifndef _LIBNFS_SLIST_H_ |
19 | #define _LIBNFS_SLIST_H_ | |
20 | ||
f1f22dbf | 21 | #define LIBNFS_LIST_ADD(list, item) \ |
dabf4152 AM |
22 | do { \ |
23 | (item)->next = (*list); \ | |
24 | (*list) = (item); \ | |
25 | } while (0); | |
26 | ||
f1f22dbf | 27 | #define LIBNFS_LIST_ADD_END(list, item) \ |
dabf4152 | 28 | if ((*list) == NULL) { \ |
f1f22dbf | 29 | LIBNFS_LIST_ADD((list), (item)); \ |
dabf4152 AM |
30 | } else { \ |
31 | void *head = (*list); \ | |
32 | while ((*list)->next) \ | |
33 | (*list) = (*list)->next; \ | |
34 | (*list)->next = (item); \ | |
35 | (item)->next = NULL; \ | |
36 | (*list) = head; \ | |
37 | } | |
38 | ||
f1f22dbf | 39 | #define LIBNFS_LIST_REMOVE(list, item) \ |
dabf4152 AM |
40 | if ((*list) == (item)) { \ |
41 | (*list) = (item)->next; \ | |
42 | } else { \ | |
43 | void *head = (*list); \ | |
44 | while ((*list)->next && (*list)->next != (item)) \ | |
45 | (*list) = (*list)->next; \ | |
46 | if ((*list)->next != NULL) { \ | |
47 | (*list)->next = (*list)->next->next; \ | |
48 | } \ | |
49 | (*list) = head; \ | |
50 | } | |
51 | ||
ee872606 | 52 | #endif /* !_LIBNFS_SLIST_H_ */ |