Files
my-os-project2/ulib/linklist.h
2025-09-14 23:31:14 +02:00

46 lines
987 B
C

#ifndef ULIB_LINKLIST_H_
#define ULIB_LINKLIST_H_
#define LL_APPEND(head, new) \
do { \
if ((head) != NULL) { \
typeof((head)) __tmp; \
(new)->next = NULL; \
__tmp = (head); \
while (__tmp->next != NULL) { \
__tmp = __tmp->next; \
} \
__tmp->next = (new); \
} else { \
(new)->next = NULL; \
(head) = (new); \
} \
} while(0)
#define LL_REMOVE(head, ele) \
do { \
typeof((head)) __cur = (head); \
typeof((head)) __prev = NULL; \
while (__cur != (ele)) { \
__prev = __cur; \
__cur = __cur->next; \
} \
if (__prev != NULL) { \
__prev->next = __cur->next; \
} \
} while(0)
#define LL_FINDPROP(head, out, propname, propvalue) \
do { \
typeof((head)) __tmp = (head); \
while (__tmp) { \
if (__tmp->propname == (propvalue)) { \
(out) = __tmp; \
break; \
} \
__tmp = __tmp->next; \
} \
} while(0)
#endif // ULIB_LINKLIST_H_