Borged parts of sys/queue.h since non-BSDs don't have the header.

This commit is contained in:
Emil Mikulic 2003-06-28 04:13:19 +00:00
parent 9d6d7533fe
commit f56dcd2b76

View File

@ -31,7 +31,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/queue.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
@ -55,6 +54,63 @@
#define min(a,b) ( ((a)<(b)) ? (a) : (b) ) #define min(a,b) ( ((a)<(b)) ? (a) : (b) )
#endif #endif
/* ---------------------------------------------------------------------------
* LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.32.2.7
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Under a BSD license.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_FOREACH(var, head, field) \
for ((var) = LIST_FIRST((head)); \
(var); \
(var) = LIST_NEXT((var), field))
#define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
LIST_FIRST((head)) = (elm); \
(elm)->field.le_prev = &LIST_FIRST((head)); \
} while (0)
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_REMOVE(elm, field) do { \
if (LIST_NEXT((elm), field) != NULL) \
LIST_NEXT((elm), field)->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = LIST_NEXT((elm), field); \
} while (0)
/* ------------------------------------------------------------------------ */
LIST_HEAD(conn_list_head, connection) connlist = LIST_HEAD(conn_list_head, connection) connlist =
LIST_HEAD_INITIALIZER(conn_list_head); LIST_HEAD_INITIALIZER(conn_list_head);