|
Packit Service |
87a54e |
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2017 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#ifndef __C_LIST_UTIL_H__
|
|
Packit |
5756e2 |
#define __C_LIST_UTIL_H__
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "c-list/src/c-list.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void c_list_relink(CList *lst);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef int (*CListSortCmp)(const CList *a, const CList *b, const void *user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
CList *c_list_sort_headless(CList *lst, CListSortCmp cmp, const void *user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void c_list_sort(CList *head, CListSortCmp cmp, const void *user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/* c_list_length_is:
|
|
Packit |
5756e2 |
* @list: the #CList list head
|
|
Packit |
5756e2 |
* @check_len: the length to compare
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: basically the same as (c_list_length (@list) == @check_len),
|
|
Packit |
5756e2 |
* but does not require to iterate the entire list first. There is only
|
|
Packit |
5756e2 |
* one real use: to find out whether there is exactly one element in the
|
|
Packit |
5756e2 |
* list, by passing @check_len as 1.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
c_list_length_is(const CList *list, unsigned long check_len)
|
|
Packit Service |
a1bd4f |
{
|
|
Packit Service |
a1bd4f |
unsigned long n = 0;
|
|
Packit Service |
a1bd4f |
const CList * iter;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
c_list_for_each (iter, list) {
|
|
Packit Service |
a1bd4f |
++n;
|
|
Packit Service |
a1bd4f |
if (n > check_len)
|
|
Packit Service |
a1bd4f |
return 0;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return n == check_len;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define c_list_for_each_prev(_iter, _list) \
|
|
Packit Service |
a1bd4f |
for (_iter = (_list)->prev; (_iter) != (_list); _iter = (_iter)->prev)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define c_list_for_each_prev_safe(_iter, _safe, _list) \
|
|
Packit Service |
a1bd4f |
for (_iter = (_list)->prev, _safe = (_iter)->prev; (_iter) != (_list); \
|
|
Packit Service |
a1bd4f |
_iter = (_safe), _safe = (_safe)->prev)
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define c_list_for_each_entry_prev(_iter, _list, _m) \
|
|
Packit Service |
a1bd4f |
for (_iter = c_list_entry((_list)->prev, __typeof__(*_iter), _m); &(_iter)->_m != (_list); \
|
|
Packit Service |
a1bd4f |
_iter = c_list_entry((_iter)->_m.prev, __typeof__(*_iter), _m))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#endif /* __C_LIST_UTIL_H__ */
|