Skip to content

Commit

Permalink
simpleq.h: import unmodified file from BSD coreutils
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
andy5995 committed Jan 24, 2023
1 parent 68313b3 commit dd578e4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/bsd-coreutils/compat/include/simpleq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Darwin comes with an outdated version of sys/queue.h
* however since Darwin is BSD based we can fix this by
* using a fake queue, and redefinging a lot of the structures
*/

#undef SIMPLEQ_HEAD
#undef SIMPLEQ_ENTRY
#undef SIMPLEQ_FOREACH
#undef SIMPLEQ_INSERT_TAIL
#undef SIMPLEQ_FIRST
#undef SIMPLEQ_END
#undef SIMPLEQ_NEXT

#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST (head) == SIMPLEQ_END (head))
#define SIMPLEQ_END(head) NULL
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)

#define SIMPLEQ_HEAD(name, type) \
struct name \
{ \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}

#define SIMPLEQ_ENTRY(type) \
struct \
{ \
struct type *sqe_next; /* next element */ \
}

#define SIMPLEQ_INSERT_TAIL(head, elm, field) \
do \
{ \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} \
while (0)

#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ \
NULL, &(head).sqh_first \
}

#define SIMPLEQ_FOREACH(var, head, field) \
for ((var) = SIMPLEQ_FIRST (head); (var) != SIMPLEQ_END (head); \
(var) = SIMPLEQ_NEXT (var, field))

0 comments on commit dd578e4

Please sign in to comment.