X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=libs%2Fshttpd%2Fllist.h;fp=libs%2Fshttpd%2Fllist.h;h=04e79bba12fd1a390018fd5172d92bf1d1056272;hb=d8ccfe2b3944adf07d35534459cdda19d15217c8;hp=0000000000000000000000000000000000000000;hpb=21f835f30b4e092c847bf4569a00995774f7330e;p=fms.git diff --git a/libs/shttpd/llist.h b/libs/shttpd/llist.h new file mode 100644 index 0000000..04e79bb --- /dev/null +++ b/libs/shttpd/llist.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004-2005 Sergey Lyubka + * All rights reserved + * + * "THE BEER-WARE LICENSE" (Revision 42): + * Sergey Lyubka wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. + */ + +#ifndef LLIST_HEADER_INCLUDED +#define LLIST_HEADER_INCLUDED + +/* + * Linked list macros. + */ +struct llhead { + struct llhead *prev; + struct llhead *next; +}; + +#define LL_INIT(N) ((N)->next = (N)->prev = (N)) + +#define LL_HEAD(H) struct llhead H = { &H, &H } + +#define LL_ENTRY(P,T,N) ((T *)((char *)(P) - offsetof(T, N))) + +#define LL_ADD(H, N) \ + do { \ + ((H)->next)->prev = (N); \ + (N)->next = ((H)->next); \ + (N)->prev = (H); \ + (H)->next = (N); \ + } while (0) + +#define LL_TAIL(H, N) \ + do { \ + ((H)->prev)->next = (N); \ + (N)->prev = ((H)->prev); \ + (N)->next = (H); \ + (H)->prev = (N); \ + } while (0) + +#define LL_DEL(N) \ + do { \ + ((N)->next)->prev = ((N)->prev); \ + ((N)->prev)->next = ((N)->next); \ + LL_INIT(N); \ + } while (0) + +#define LL_EMPTY(N) ((N)->next == (N)) + +#define LL_FOREACH(H,N) for (N = (H)->next; N != (H); N = (N)->next) + +#define LL_FOREACH_SAFE(H,N,T) \ + for (N = (H)->next, T = (N)->next; N != (H); \ + N = (T), T = (N)->next) + +#endif /* LLIST_HEADER_INCLUDED */