Advertisement
Guest User

list.h

a guest
Sep 19th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1.  #ifndef __LIST_H
  2.  #define __LIST_H
  3.  
  4. struct list_head {
  5.         struct list_head *next, *prev;
  6. };
  7. typedef struct list_head st_list_head;
  8.  
  9.  
  10. #define INIT_LIST_HEAD(ptr) do { \
  11.         (ptr)->next = (ptr); (ptr)->prev = (ptr); \
  12. } while (0)
  13.  
  14. /*
  15.  * __list_add: insert new between prev and next.
  16.  */
  17. static inline void __list_add(struct list_head *new,
  18.                               struct list_head *prev,
  19.                               struct list_head *next)
  20. {
  21.         next->prev = new;
  22.         new->next = next;
  23.         new->prev = prev;
  24.         prev->next = new;
  25. }
  26.  
  27. /**
  28.  * list_add: add a new entry to the end of the list.
  29.  */
  30. static inline void list_add1(struct list_head *new, struct list_head *head)
  31. {
  32.         __list_add(new, head->prev, head);
  33. }
  34.  
  35. /*
  36.  *__list_del: making the prev/next entries point to each other.
  37.  */
  38. static inline void __list_del(struct list_head *prev, struct list_head *next)
  39. {
  40.         next->prev = prev;
  41.         prev->next = next;
  42. }
  43.  
  44. /**
  45.  * list_del: deletes entry from list.
  46.  */
  47. static inline void list_del(struct list_head *entry)
  48. {
  49.         __list_del(entry->prev, entry->next);
  50.         entry->next = (void *) 0;
  51.         entry->prev = (void *) 0;
  52. }
  53.  
  54. /**
  55.  * list_empty: check is list is empty.
  56.  */
  57. static inline int list_empty(struct list_head *head)
  58. {
  59.         return head->next == head;
  60. }
  61.  
  62.  
  63. /**
  64.  * list_entry: retrieve the container struct.
  65.  */
  66. #define list_entry(ptr, type, member) \
  67.         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
  68.  
  69. /**
  70.  * list_for_each: traverse through the list.
  71.  */
  72. #define list_for_each(pos, head) \
  73.         for (pos = (head)->next; pos != (head); \
  74.                 pos = pos->next)
  75.  
  76. /**
  77.  * list_for_each_delete: traverse through the list with safe delete
  78.  */
  79. #define list_for_each_delete(pos, n, head) \
  80.         for (pos = (head)->next, n = pos->next; pos != (head); \
  81.                 pos = n, n = pos->next)
  82. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement