LCOV - code coverage report
Current view: top level - src/utils - list.h (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 26 26 100.0 %
Date: 2014-03-02 Functions: 6 6 100.0 %
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Doubly-linked list
       3                 :            :  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
       4                 :            :  *
       5                 :            :  * This software may be distributed under the terms of the BSD license.
       6                 :            :  * See README for more details.
       7                 :            :  */
       8                 :            : 
       9                 :            : #ifndef LIST_H
      10                 :            : #define LIST_H
      11                 :            : 
      12                 :            : /**
      13                 :            :  * struct dl_list - Doubly-linked list
      14                 :            :  */
      15                 :            : struct dl_list {
      16                 :            :         struct dl_list *next;
      17                 :            :         struct dl_list *prev;
      18                 :            : };
      19                 :            : 
      20                 :       2421 : static inline void dl_list_init(struct dl_list *list)
      21                 :            : {
      22                 :       2421 :         list->next = list;
      23                 :       2421 :         list->prev = list;
      24                 :       2421 : }
      25                 :            : 
      26                 :     771980 : static inline void dl_list_add(struct dl_list *list, struct dl_list *item)
      27                 :            : {
      28                 :     771980 :         item->next = list->next;
      29                 :     771980 :         item->prev = list;
      30                 :     771980 :         list->next->prev = item;
      31                 :     771980 :         list->next = item;
      32                 :     771980 : }
      33                 :            : 
      34                 :       8478 : static inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
      35                 :            : {
      36                 :       8478 :         dl_list_add(list->prev, item);
      37                 :       8478 : }
      38                 :            : 
      39                 :     771962 : static inline void dl_list_del(struct dl_list *item)
      40                 :            : {
      41                 :     771962 :         item->next->prev = item->prev;
      42                 :     771962 :         item->prev->next = item->next;
      43                 :     771962 :         item->next = NULL;
      44                 :     771962 :         item->prev = NULL;
      45                 :     771962 : }
      46                 :            : 
      47                 :     956342 : static inline int dl_list_empty(struct dl_list *list)
      48                 :            : {
      49                 :     956342 :         return list->next == list;
      50                 :            : }
      51                 :            : 
      52                 :        198 : static inline unsigned int dl_list_len(struct dl_list *list)
      53                 :            : {
      54                 :            :         struct dl_list *item;
      55                 :        198 :         int count = 0;
      56         [ +  + ]:       1039 :         for (item = list->next; item != list; item = item->next)
      57                 :        841 :                 count++;
      58                 :        198 :         return count;
      59                 :            : }
      60                 :            : 
      61                 :            : #ifndef offsetof
      62                 :            : #define offsetof(type, member) ((long) &((type *) 0)->member)
      63                 :            : #endif
      64                 :            : 
      65                 :            : #define dl_list_entry(item, type, member) \
      66                 :            :         ((type *) ((char *) item - offsetof(type, member)))
      67                 :            : 
      68                 :            : #define dl_list_first(list, type, member) \
      69                 :            :         (dl_list_empty((list)) ? NULL : \
      70                 :            :          dl_list_entry((list)->next, type, member))
      71                 :            : 
      72                 :            : #define dl_list_last(list, type, member) \
      73                 :            :         (dl_list_empty((list)) ? NULL : \
      74                 :            :          dl_list_entry((list)->prev, type, member))
      75                 :            : 
      76                 :            : #define dl_list_for_each(item, list, type, member) \
      77                 :            :         for (item = dl_list_entry((list)->next, type, member); \
      78                 :            :              &item->member != (list); \
      79                 :            :              item = dl_list_entry(item->member.next, type, member))
      80                 :            : 
      81                 :            : #define dl_list_for_each_safe(item, n, list, type, member) \
      82                 :            :         for (item = dl_list_entry((list)->next, type, member), \
      83                 :            :                      n = dl_list_entry(item->member.next, type, member); \
      84                 :            :              &item->member != (list); \
      85                 :            :              item = n, n = dl_list_entry(n->member.next, type, member))
      86                 :            : 
      87                 :            : #define dl_list_for_each_reverse(item, list, type, member) \
      88                 :            :         for (item = dl_list_entry((list)->prev, type, member); \
      89                 :            :              &item->member != (list); \
      90                 :            :              item = dl_list_entry(item->member.prev, type, member))
      91                 :            : 
      92                 :            : #define DEFINE_DL_LIST(name) \
      93                 :            :         struct dl_list name = { &(name), &(name) }
      94                 :            : 
      95                 :            : #endif /* LIST_H */

Generated by: LCOV version 1.9