list.h 810 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef __GBLIBC_LIST_H_
  2. #define __GBLIBC_LIST_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. struct list_node {
  7. struct list_node* prev;
  8. struct list_node* next;
  9. char data[];
  10. };
  11. typedef struct list_node list_node;
  12. typedef list_node list_head;
  13. #define NDDATA(node, type) (*((type*)((node).data)))
  14. #define NDPREV(node) ((node).prev)
  15. #define NDNEXT(node) ((node).next)
  16. #define NDISEND(node) (!((node).next))
  17. #define NEWNODE(type) ((struct list_node*)malloc(sizeof(list_node) + sizeof(type)))
  18. #define NDPTR(p_data) ((list_node*)((char*)p_data - sizeof(list_node)))
  19. void __node_insert(list_node* node, list_node* new_node);
  20. void __node_erase(list_node* node);
  21. #define NDINSERT(node, newnode) __node_insert(node, newnode)
  22. #define NDERASE(p_node) __node_erase(p_node)
  23. #ifdef __cplusplus
  24. }
  25. #endif
  26. #endif