"Fossies" - the Fresh Open Source Software Archive

Member "smbnetfs-0.6.3/src/list.h" (1 Mar 2019, 2414 Bytes) of package /linux/misc/smbnetfs-0.6.3.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "list.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.6.1_vs_0.6.2.

    1 #ifndef __LIST_H__
    2 #define __LIST_H__
    3 
    4 #include <stddef.h>
    5 
    6 typedef struct __LIST{
    7     struct __LIST   *next;
    8     struct __LIST   *prev;
    9 } LIST;
   10 
   11 #define list_entry(ptr, type, member)       \
   12     (type*)((char*)(ptr) - offsetof(type, member))
   13 
   14 #define STATIC_LIST_INITIALIZER(list)       { &(list), &(list) }
   15 
   16 static inline LIST* first_list_elem(LIST *list){
   17     return list->next;
   18 }
   19 
   20 static inline LIST* last_list_elem(LIST *list){
   21     return list->prev;
   22 }
   23 
   24 static inline void add_to_list(LIST *list, LIST *elem){
   25     /* Yes, i want SIGSEGV for debug */
   26     if ((elem->next != NULL) || (elem->prev != NULL)) __builtin_trap();
   27 
   28     elem->next = list->next;
   29     elem->prev = list;
   30     list->next->prev = elem;
   31     list->next = elem;
   32 }
   33 
   34 static inline void add_to_list_back(LIST *list, LIST *elem){
   35     /* Yes, i want SIGSEGV for debug */
   36     if ((elem->next != NULL) || (elem->prev != NULL)) __builtin_trap();
   37 
   38     elem->next = list;
   39     elem->prev = list->prev;
   40     list->prev->next = elem;
   41     list->prev = elem;
   42 }
   43 
   44 static inline void insert_to_list_after(LIST *list, LIST *elem, LIST *new_elem){
   45     (void)list;
   46 
   47     /* Yes, i want SIGSEGV for debug */
   48     if ((new_elem->next != NULL) || (new_elem->prev != NULL)) __builtin_trap();
   49 
   50     new_elem->next = elem->next;
   51     new_elem->prev = elem;
   52     elem->next->prev = new_elem;
   53     elem->next = new_elem;
   54 }
   55 
   56 static inline void insert_to_list_before(LIST *list, LIST *elem, LIST *new_elem){
   57     (void)list;
   58 
   59     /* Yes, i want SIGSEGV for debug */
   60     if ((new_elem->next != NULL) || (new_elem->prev != NULL)) __builtin_trap();
   61 
   62     new_elem->next = elem;
   63     new_elem->prev = elem->prev;
   64     elem->prev->next = new_elem;
   65     elem->prev = new_elem;
   66 }
   67 
   68 static inline void replace_in_list(LIST *list, LIST *elem, LIST *new_elem){
   69     (void)list;
   70     new_elem->next = elem->next;
   71     new_elem->prev = elem->prev;
   72     elem->next->prev = new_elem;
   73     elem->prev->next = new_elem;
   74     elem->next = elem->prev = NULL;
   75 }
   76 
   77 static inline void remove_from_list(LIST *list, LIST *elem){
   78     (void)list;
   79     elem->prev->next = elem->next;
   80     elem->next->prev = elem->prev;
   81     elem->next = elem->prev = NULL;
   82 }
   83 
   84 static inline int is_list_empty(LIST *list){
   85     return (list == list->next);
   86 }
   87 
   88 static inline int is_valid_list_elem(LIST *list, LIST *elem){
   89     return (elem != list);
   90 }
   91 
   92 static inline void init_list(LIST *list){
   93     list->next = list->prev = list;
   94 }
   95 
   96 #endif  /* __LIST_H__ */