OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

642 lines
22 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../ulogd2/0003-add-internal-sys_queue.h.patch
  5. # Copyright (C) 2013 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. This patch extends ulogd2 to include a private copy of the <sys/queue.h>
  17. file which will get used if configure detects no <sys/queue.h> on the
  18. system.
  19. This case was detected when trying to build ulogd2 on a musl libc based
  20. environment, because musl doesn't provide <sys/queue.h>.
  21. according to a short discussion on #musl:
  22. dalias> sys/queue.h has nothing to do with libc. it's a linked list/queue
  23. implementation entirely in a header file
  24. --- ./configure.ac.orig 2013-01-08 10:28:45.009323522 +0100
  25. +++ ./configure.ac 2013-01-08 10:29:17.058021344 +0100
  26. @@ -26,7 +26,7 @@
  27. dnl Checks for header files.
  28. AC_HEADER_DIRENT
  29. AC_HEADER_STDC
  30. -AC_CHECK_HEADERS(fcntl.h unistd.h)
  31. +AC_CHECK_HEADERS(fcntl.h unistd.h sys/queue.h)
  32. dnl Checks for typedefs, structures, and compiler characteristics.
  33. AC_C_CONST
  34. --- ./config.h.in.orig 2013-01-08 10:30:01.003063255 +0100
  35. +++ ./config.h.in 2013-01-08 10:42:26.524304543 +0100
  36. @@ -57,6 +57,9 @@
  37. */
  38. #undef HAVE_SYS_NDIR_H
  39. +/* Define to 1 if you have the <sys/queue.h> header file. */
  40. +#undef HAVE_SYS_QUEUE_H
  41. +
  42. /* Define to 1 if you have the <sys/stat.h> header file. */
  43. #undef HAVE_SYS_STAT_H
  44. --- ./output/sqlite3/ulogd_output_SQLITE3.c.orig 2012-08-03 16:11:53.000000000 +0200
  45. +++ ./output/sqlite3/ulogd_output_SQLITE3.c 2013-01-08 11:46:54.573843636 +0100
  46. @@ -36,7 +36,11 @@
  47. #include <ulogd/ulogd.h>
  48. #include <ulogd/conffile.h>
  49. #include <sqlite3.h>
  50. +#ifdef HAVE_SYS_QUEUE_H
  51. #include <sys/queue.h>
  52. +#else
  53. +#include "sys/queue.h>
  54. +#endif
  55. #define CFG_BUFFER_DEFAULT 10
  56. --- /dev/null 2010-09-21 01:39:13.000000000 +0200
  57. +++ ./include/sys/queue.h 2013-01-08 11:48:52.924611951 +0100
  58. @@ -0,0 +1,574 @@
  59. +/*
  60. + * Copyright (c) 1991, 1993
  61. + * The Regents of the University of California. All rights reserved.
  62. + *
  63. + * Redistribution and use in source and binary forms, with or without
  64. + * modification, are permitted provided that the following conditions
  65. + * are met:
  66. + * 1. Redistributions of source code must retain the above copyright
  67. + * notice, this list of conditions and the following disclaimer.
  68. + * 2. Redistributions in binary form must reproduce the above copyright
  69. + * notice, this list of conditions and the following disclaimer in the
  70. + * documentation and/or other materials provided with the distribution.
  71. + * 3. Neither the name of the University nor the names of its contributors
  72. + * may be used to endorse or promote products derived from this software
  73. + * without specific prior written permission.
  74. + *
  75. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  76. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  79. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  80. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  81. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  82. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  85. + * SUCH DAMAGE.
  86. + *
  87. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  88. + */
  89. +
  90. +#ifndef _SYS_QUEUE_H_
  91. +#define _SYS_QUEUE_H_
  92. +
  93. +/*
  94. + * This file defines five types of data structures: singly-linked lists,
  95. + * lists, simple queues, tail queues, and circular queues.
  96. + *
  97. + * A singly-linked list is headed by a single forward pointer. The
  98. + * elements are singly linked for minimum space and pointer manipulation
  99. + * overhead at the expense of O(n) removal for arbitrary elements. New
  100. + * elements can be added to the list after an existing element or at the
  101. + * head of the list. Elements being removed from the head of the list
  102. + * should use the explicit macro for this purpose for optimum
  103. + * efficiency. A singly-linked list may only be traversed in the forward
  104. + * direction. Singly-linked lists are ideal for applications with large
  105. + * datasets and few or no removals or for implementing a LIFO queue.
  106. + *
  107. + * A list is headed by a single forward pointer (or an array of forward
  108. + * pointers for a hash table header). The elements are doubly linked
  109. + * so that an arbitrary element can be removed without a need to
  110. + * traverse the list. New elements can be added to the list before
  111. + * or after an existing element or at the head of the list. A list
  112. + * may only be traversed in the forward direction.
  113. + *
  114. + * A simple queue is headed by a pair of pointers, one the head of the
  115. + * list and the other to the tail of the list. The elements are singly
  116. + * linked to save space, so elements can only be removed from the
  117. + * head of the list. New elements can be added to the list after
  118. + * an existing element, at the head of the list, or at the end of the
  119. + * list. A simple queue may only be traversed in the forward direction.
  120. + *
  121. + * A tail queue is headed by a pair of pointers, one to the head of the
  122. + * list and the other to the tail of the list. The elements are doubly
  123. + * linked so that an arbitrary element can be removed without a need to
  124. + * traverse the list. New elements can be added to the list before or
  125. + * after an existing element, at the head of the list, or at the end of
  126. + * the list. A tail queue may be traversed in either direction.
  127. + *
  128. + * A circle queue is headed by a pair of pointers, one to the head of the
  129. + * list and the other to the tail of the list. The elements are doubly
  130. + * linked so that an arbitrary element can be removed without a need to
  131. + * traverse the list. New elements can be added to the list before or after
  132. + * an existing element, at the head of the list, or at the end of the list.
  133. + * A circle queue may be traversed in either direction, but has a more
  134. + * complex end of list detection.
  135. + *
  136. + * For details on the use of these macros, see the queue(3) manual page.
  137. + */
  138. +
  139. +/*
  140. + * List definitions.
  141. + */
  142. +#define LIST_HEAD(name, type) \
  143. +struct name { \
  144. + struct type *lh_first; /* first element */ \
  145. +}
  146. +
  147. +#define LIST_HEAD_INITIALIZER(head) \
  148. + { NULL }
  149. +
  150. +#define LIST_ENTRY(type) \
  151. +struct { \
  152. + struct type *le_next; /* next element */ \
  153. + struct type **le_prev; /* address of previous next element */ \
  154. +}
  155. +
  156. +/*
  157. + * List functions.
  158. + */
  159. +#define LIST_INIT(head) do { \
  160. + (head)->lh_first = NULL; \
  161. +} while (/*CONSTCOND*/0)
  162. +
  163. +#define LIST_INSERT_AFTER(listelm, elm, field) do { \
  164. + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
  165. + (listelm)->field.le_next->field.le_prev = \
  166. + &(elm)->field.le_next; \
  167. + (listelm)->field.le_next = (elm); \
  168. + (elm)->field.le_prev = &(listelm)->field.le_next; \
  169. +} while (/*CONSTCOND*/0)
  170. +
  171. +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
  172. + (elm)->field.le_prev = (listelm)->field.le_prev; \
  173. + (elm)->field.le_next = (listelm); \
  174. + *(listelm)->field.le_prev = (elm); \
  175. + (listelm)->field.le_prev = &(elm)->field.le_next; \
  176. +} while (/*CONSTCOND*/0)
  177. +
  178. +#define LIST_INSERT_HEAD(head, elm, field) do { \
  179. + if (((elm)->field.le_next = (head)->lh_first) != NULL) \
  180. + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
  181. + (head)->lh_first = (elm); \
  182. + (elm)->field.le_prev = &(head)->lh_first; \
  183. +} while (/*CONSTCOND*/0)
  184. +
  185. +#define LIST_REMOVE(elm, field) do { \
  186. + if ((elm)->field.le_next != NULL) \
  187. + (elm)->field.le_next->field.le_prev = \
  188. + (elm)->field.le_prev; \
  189. + *(elm)->field.le_prev = (elm)->field.le_next; \
  190. +} while (/*CONSTCOND*/0)
  191. +
  192. +#define LIST_FOREACH(var, head, field) \
  193. + for ((var) = ((head)->lh_first); \
  194. + (var); \
  195. + (var) = ((var)->field.le_next))
  196. +
  197. +/*
  198. + * List access methods.
  199. + */
  200. +#define LIST_EMPTY(head) ((head)->lh_first == NULL)
  201. +#define LIST_FIRST(head) ((head)->lh_first)
  202. +#define LIST_NEXT(elm, field) ((elm)->field.le_next)
  203. +
  204. +
  205. +/*
  206. + * Singly-linked List definitions.
  207. + */
  208. +#define SLIST_HEAD(name, type) \
  209. +struct name { \
  210. + struct type *slh_first; /* first element */ \
  211. +}
  212. +
  213. +#define SLIST_HEAD_INITIALIZER(head) \
  214. + { NULL }
  215. +
  216. +#define SLIST_ENTRY(type) \
  217. +struct { \
  218. + struct type *sle_next; /* next element */ \
  219. +}
  220. +
  221. +/*
  222. + * Singly-linked List functions.
  223. + */
  224. +#define SLIST_INIT(head) do { \
  225. + (head)->slh_first = NULL; \
  226. +} while (/*CONSTCOND*/0)
  227. +
  228. +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  229. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  230. + (slistelm)->field.sle_next = (elm); \
  231. +} while (/*CONSTCOND*/0)
  232. +
  233. +#define SLIST_INSERT_HEAD(head, elm, field) do { \
  234. + (elm)->field.sle_next = (head)->slh_first; \
  235. + (head)->slh_first = (elm); \
  236. +} while (/*CONSTCOND*/0)
  237. +
  238. +#define SLIST_REMOVE_HEAD(head, field) do { \
  239. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  240. +} while (/*CONSTCOND*/0)
  241. +
  242. +#define SLIST_REMOVE(head, elm, type, field) do { \
  243. + if ((head)->slh_first == (elm)) { \
  244. + SLIST_REMOVE_HEAD((head), field); \
  245. + } \
  246. + else { \
  247. + struct type *curelm = (head)->slh_first; \
  248. + while(curelm->field.sle_next != (elm)) \
  249. + curelm = curelm->field.sle_next; \
  250. + curelm->field.sle_next = \
  251. + curelm->field.sle_next->field.sle_next; \
  252. + } \
  253. +} while (/*CONSTCOND*/0)
  254. +
  255. +#define SLIST_FOREACH(var, head, field) \
  256. + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
  257. +
  258. +/*
  259. + * Singly-linked List access methods.
  260. + */
  261. +#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
  262. +#define SLIST_FIRST(head) ((head)->slh_first)
  263. +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  264. +
  265. +
  266. +/*
  267. + * Singly-linked Tail queue declarations.
  268. + */
  269. +#define STAILQ_HEAD(name, type) \
  270. +struct name { \
  271. + struct type *stqh_first; /* first element */ \
  272. + struct type **stqh_last; /* addr of last next element */ \
  273. +}
  274. +
  275. +#define STAILQ_HEAD_INITIALIZER(head) \
  276. + { NULL, &(head).stqh_first }
  277. +
  278. +#define STAILQ_ENTRY(type) \
  279. +struct { \
  280. + struct type *stqe_next; /* next element */ \
  281. +}
  282. +
  283. +/*
  284. + * Singly-linked Tail queue functions.
  285. + */
  286. +#define STAILQ_INIT(head) do { \
  287. + (head)->stqh_first = NULL; \
  288. + (head)->stqh_last = &(head)->stqh_first; \
  289. +} while (/*CONSTCOND*/0)
  290. +
  291. +#define STAILQ_INSERT_HEAD(head, elm, field) do { \
  292. + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
  293. + (head)->stqh_last = &(elm)->field.stqe_next; \
  294. + (head)->stqh_first = (elm); \
  295. +} while (/*CONSTCOND*/0)
  296. +
  297. +#define STAILQ_INSERT_TAIL(head, elm, field) do { \
  298. + (elm)->field.stqe_next = NULL; \
  299. + *(head)->stqh_last = (elm); \
  300. + (head)->stqh_last = &(elm)->field.stqe_next; \
  301. +} while (/*CONSTCOND*/0)
  302. +
  303. +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  304. + if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
  305. + (head)->stqh_last = &(elm)->field.stqe_next; \
  306. + (listelm)->field.stqe_next = (elm); \
  307. +} while (/*CONSTCOND*/0)
  308. +
  309. +#define STAILQ_REMOVE_HEAD(head, field) do { \
  310. + if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
  311. + (head)->stqh_last = &(head)->stqh_first; \
  312. +} while (/*CONSTCOND*/0)
  313. +
  314. +#define STAILQ_REMOVE(head, elm, type, field) do { \
  315. + if ((head)->stqh_first == (elm)) { \
  316. + STAILQ_REMOVE_HEAD((head), field); \
  317. + } else { \
  318. + struct type *curelm = (head)->stqh_first; \
  319. + while (curelm->field.stqe_next != (elm)) \
  320. + curelm = curelm->field.stqe_next; \
  321. + if ((curelm->field.stqe_next = \
  322. + curelm->field.stqe_next->field.stqe_next) == NULL) \
  323. + (head)->stqh_last = &(curelm)->field.stqe_next; \
  324. + } \
  325. +} while (/*CONSTCOND*/0)
  326. +
  327. +#define STAILQ_FOREACH(var, head, field) \
  328. + for ((var) = ((head)->stqh_first); \
  329. + (var); \
  330. + (var) = ((var)->field.stqe_next))
  331. +
  332. +#define STAILQ_CONCAT(head1, head2) do { \
  333. + if (!STAILQ_EMPTY((head2))) { \
  334. + *(head1)->stqh_last = (head2)->stqh_first; \
  335. + (head1)->stqh_last = (head2)->stqh_last; \
  336. + STAILQ_INIT((head2)); \
  337. + } \
  338. +} while (/*CONSTCOND*/0)
  339. +
  340. +/*
  341. + * Singly-linked Tail queue access methods.
  342. + */
  343. +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
  344. +#define STAILQ_FIRST(head) ((head)->stqh_first)
  345. +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
  346. +
  347. +
  348. +/*
  349. + * Simple queue definitions.
  350. + */
  351. +#define SIMPLEQ_HEAD(name, type) \
  352. +struct name { \
  353. + struct type *sqh_first; /* first element */ \
  354. + struct type **sqh_last; /* addr of last next element */ \
  355. +}
  356. +
  357. +#define SIMPLEQ_HEAD_INITIALIZER(head) \
  358. + { NULL, &(head).sqh_first }
  359. +
  360. +#define SIMPLEQ_ENTRY(type) \
  361. +struct { \
  362. + struct type *sqe_next; /* next element */ \
  363. +}
  364. +
  365. +/*
  366. + * Simple queue functions.
  367. + */
  368. +#define SIMPLEQ_INIT(head) do { \
  369. + (head)->sqh_first = NULL; \
  370. + (head)->sqh_last = &(head)->sqh_first; \
  371. +} while (/*CONSTCOND*/0)
  372. +
  373. +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  374. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  375. + (head)->sqh_last = &(elm)->field.sqe_next; \
  376. + (head)->sqh_first = (elm); \
  377. +} while (/*CONSTCOND*/0)
  378. +
  379. +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  380. + (elm)->field.sqe_next = NULL; \
  381. + *(head)->sqh_last = (elm); \
  382. + (head)->sqh_last = &(elm)->field.sqe_next; \
  383. +} while (/*CONSTCOND*/0)
  384. +
  385. +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  386. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  387. + (head)->sqh_last = &(elm)->field.sqe_next; \
  388. + (listelm)->field.sqe_next = (elm); \
  389. +} while (/*CONSTCOND*/0)
  390. +
  391. +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
  392. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  393. + (head)->sqh_last = &(head)->sqh_first; \
  394. +} while (/*CONSTCOND*/0)
  395. +
  396. +#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
  397. + if ((head)->sqh_first == (elm)) { \
  398. + SIMPLEQ_REMOVE_HEAD((head), field); \
  399. + } else { \
  400. + struct type *curelm = (head)->sqh_first; \
  401. + while (curelm->field.sqe_next != (elm)) \
  402. + curelm = curelm->field.sqe_next; \
  403. + if ((curelm->field.sqe_next = \
  404. + curelm->field.sqe_next->field.sqe_next) == NULL) \
  405. + (head)->sqh_last = &(curelm)->field.sqe_next; \
  406. + } \
  407. +} while (/*CONSTCOND*/0)
  408. +
  409. +#define SIMPLEQ_FOREACH(var, head, field) \
  410. + for ((var) = ((head)->sqh_first); \
  411. + (var); \
  412. + (var) = ((var)->field.sqe_next))
  413. +
  414. +/*
  415. + * Simple queue access methods.
  416. + */
  417. +#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
  418. +#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
  419. +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  420. +
  421. +
  422. +/*
  423. + * Tail queue definitions.
  424. + */
  425. +#define _TAILQ_HEAD(name, type, qual) \
  426. +struct name { \
  427. + qual type *tqh_first; /* first element */ \
  428. + qual type *qual *tqh_last; /* addr of last next element */ \
  429. +}
  430. +#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
  431. +
  432. +#define TAILQ_HEAD_INITIALIZER(head) \
  433. + { NULL, &(head).tqh_first }
  434. +
  435. +#define _TAILQ_ENTRY(type, qual) \
  436. +struct { \
  437. + qual type *tqe_next; /* next element */ \
  438. + qual type *qual *tqe_prev; /* address of previous next element */\
  439. +}
  440. +#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
  441. +
  442. +/*
  443. + * Tail queue functions.
  444. + */
  445. +#define TAILQ_INIT(head) do { \
  446. + (head)->tqh_first = NULL; \
  447. + (head)->tqh_last = &(head)->tqh_first; \
  448. +} while (/*CONSTCOND*/0)
  449. +
  450. +#define TAILQ_INSERT_HEAD(head, elm, field) do { \
  451. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  452. + (head)->tqh_first->field.tqe_prev = \
  453. + &(elm)->field.tqe_next; \
  454. + else \
  455. + (head)->tqh_last = &(elm)->field.tqe_next; \
  456. + (head)->tqh_first = (elm); \
  457. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  458. +} while (/*CONSTCOND*/0)
  459. +
  460. +#define TAILQ_INSERT_TAIL(head, elm, field) do { \
  461. + (elm)->field.tqe_next = NULL; \
  462. + (elm)->field.tqe_prev = (head)->tqh_last; \
  463. + *(head)->tqh_last = (elm); \
  464. + (head)->tqh_last = &(elm)->field.tqe_next; \
  465. +} while (/*CONSTCOND*/0)
  466. +
  467. +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  468. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  469. + (elm)->field.tqe_next->field.tqe_prev = \
  470. + &(elm)->field.tqe_next; \
  471. + else \
  472. + (head)->tqh_last = &(elm)->field.tqe_next; \
  473. + (listelm)->field.tqe_next = (elm); \
  474. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  475. +} while (/*CONSTCOND*/0)
  476. +
  477. +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  478. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  479. + (elm)->field.tqe_next = (listelm); \
  480. + *(listelm)->field.tqe_prev = (elm); \
  481. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  482. +} while (/*CONSTCOND*/0)
  483. +
  484. +#define TAILQ_REMOVE(head, elm, field) do { \
  485. + if (((elm)->field.tqe_next) != NULL) \
  486. + (elm)->field.tqe_next->field.tqe_prev = \
  487. + (elm)->field.tqe_prev; \
  488. + else \
  489. + (head)->tqh_last = (elm)->field.tqe_prev; \
  490. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  491. +} while (/*CONSTCOND*/0)
  492. +
  493. +#define TAILQ_FOREACH(var, head, field) \
  494. + for ((var) = ((head)->tqh_first); \
  495. + (var); \
  496. + (var) = ((var)->field.tqe_next))
  497. +
  498. +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  499. + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
  500. + (var); \
  501. + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
  502. +
  503. +#define TAILQ_CONCAT(head1, head2, field) do { \
  504. + if (!TAILQ_EMPTY(head2)) { \
  505. + *(head1)->tqh_last = (head2)->tqh_first; \
  506. + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
  507. + (head1)->tqh_last = (head2)->tqh_last; \
  508. + TAILQ_INIT((head2)); \
  509. + } \
  510. +} while (/*CONSTCOND*/0)
  511. +
  512. +/*
  513. + * Tail queue access methods.
  514. + */
  515. +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
  516. +#define TAILQ_FIRST(head) ((head)->tqh_first)
  517. +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  518. +
  519. +#define TAILQ_LAST(head, headname) \
  520. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  521. +#define TAILQ_PREV(elm, headname, field) \
  522. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  523. +
  524. +
  525. +/*
  526. + * Circular queue definitions.
  527. + */
  528. +#define CIRCLEQ_HEAD(name, type) \
  529. +struct name { \
  530. + struct type *cqh_first; /* first element */ \
  531. + struct type *cqh_last; /* last element */ \
  532. +}
  533. +
  534. +#define CIRCLEQ_HEAD_INITIALIZER(head) \
  535. + { (void *)&head, (void *)&head }
  536. +
  537. +#define CIRCLEQ_ENTRY(type) \
  538. +struct { \
  539. + struct type *cqe_next; /* next element */ \
  540. + struct type *cqe_prev; /* previous element */ \
  541. +}
  542. +
  543. +/*
  544. + * Circular queue functions.
  545. + */
  546. +#define CIRCLEQ_INIT(head) do { \
  547. + (head)->cqh_first = (void *)(head); \
  548. + (head)->cqh_last = (void *)(head); \
  549. +} while (/*CONSTCOND*/0)
  550. +
  551. +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  552. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  553. + (elm)->field.cqe_prev = (listelm); \
  554. + if ((listelm)->field.cqe_next == (void *)(head)) \
  555. + (head)->cqh_last = (elm); \
  556. + else \
  557. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  558. + (listelm)->field.cqe_next = (elm); \
  559. +} while (/*CONSTCOND*/0)
  560. +
  561. +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  562. + (elm)->field.cqe_next = (listelm); \
  563. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  564. + if ((listelm)->field.cqe_prev == (void *)(head)) \
  565. + (head)->cqh_first = (elm); \
  566. + else \
  567. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  568. + (listelm)->field.cqe_prev = (elm); \
  569. +} while (/*CONSTCOND*/0)
  570. +
  571. +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  572. + (elm)->field.cqe_next = (head)->cqh_first; \
  573. + (elm)->field.cqe_prev = (void *)(head); \
  574. + if ((head)->cqh_last == (void *)(head)) \
  575. + (head)->cqh_last = (elm); \
  576. + else \
  577. + (head)->cqh_first->field.cqe_prev = (elm); \
  578. + (head)->cqh_first = (elm); \
  579. +} while (/*CONSTCOND*/0)
  580. +
  581. +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  582. + (elm)->field.cqe_next = (void *)(head); \
  583. + (elm)->field.cqe_prev = (head)->cqh_last; \
  584. + if ((head)->cqh_first == (void *)(head)) \
  585. + (head)->cqh_first = (elm); \
  586. + else \
  587. + (head)->cqh_last->field.cqe_next = (elm); \
  588. + (head)->cqh_last = (elm); \
  589. +} while (/*CONSTCOND*/0)
  590. +
  591. +#define CIRCLEQ_REMOVE(head, elm, field) do { \
  592. + if ((elm)->field.cqe_next == (void *)(head)) \
  593. + (head)->cqh_last = (elm)->field.cqe_prev; \
  594. + else \
  595. + (elm)->field.cqe_next->field.cqe_prev = \
  596. + (elm)->field.cqe_prev; \
  597. + if ((elm)->field.cqe_prev == (void *)(head)) \
  598. + (head)->cqh_first = (elm)->field.cqe_next; \
  599. + else \
  600. + (elm)->field.cqe_prev->field.cqe_next = \
  601. + (elm)->field.cqe_next; \
  602. +} while (/*CONSTCOND*/0)
  603. +
  604. +#define CIRCLEQ_FOREACH(var, head, field) \
  605. + for ((var) = ((head)->cqh_first); \
  606. + (var) != (const void *)(head); \
  607. + (var) = ((var)->field.cqe_next))
  608. +
  609. +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  610. + for ((var) = ((head)->cqh_last); \
  611. + (var) != (const void *)(head); \
  612. + (var) = ((var)->field.cqe_prev))
  613. +
  614. +/*
  615. + * Circular queue access methods.
  616. + */
  617. +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
  618. +#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
  619. +#define CIRCLEQ_LAST(head) ((head)->cqh_last)
  620. +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  621. +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  622. +
  623. +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
  624. + (((elm)->field.cqe_next == (void *)(head)) \
  625. + ? ((head)->cqh_first) \
  626. + : (elm->field.cqe_next))
  627. +#define CIRCLEQ_LOOP_PREV(head, elm, field) \
  628. + (((elm)->field.cqe_prev == (void *)(head)) \
  629. + ? ((head)->cqh_last) \
  630. + : (elm->field.cqe_prev))
  631. +
  632. +#endif /* sys/queue.h */