8762 syslogd: variable 'prev' set but not used
[unleashed.git] / usr / src / cmd / syslogd / list.c
blobeb239c4f1f29f905ddbbdff0e4eea96b87d9a2b8
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <pthread.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <assert.h>
30 #include <poll.h>
31 #include <stdio.h>
32 #include "llt.h"
34 void
35 ll_init(llh_t *head)
37 head->back = &head->front;
38 head->front = NULL;
41 void
42 ll_enqueue(llh_t *head, ll_t *data)
44 data->n = NULL;
45 *head->back = data;
46 head->back = &data->n;
50 * apply the function func to every element of the ll in sequence. Can
51 * be used to free up the element, so "n" is computed before func is
52 * called on it.
54 void
55 ll_mapf(llh_t *head, void (*func)(void *))
57 ll_t *t = head->front;
58 ll_t *n;
60 while (t) {
61 n = t->n;
62 func(t);
63 t = n;
67 ll_t *
68 ll_peek(llh_t *head)
70 return (head->front);
73 ll_t *
74 ll_dequeue(llh_t *head)
76 ll_t *ptr;
77 ptr = head->front;
78 if (ptr && ((head->front = ptr->n) == NULL))
79 head->back = &head->front;
80 return (ptr);
83 ll_t *
84 ll_traverse(llh_t *ptr, int (*func)(void *, void *), void *user)
86 ll_t *t;
87 ll_t **prev = &ptr->front;
89 t = ptr->front;
90 while (t) {
91 switch (func(t, user)) {
92 case 1:
93 return (NULL);
94 case 0:
95 prev = &(t->n);
96 t = t->n;
97 break;
98 case -1:
99 if ((*prev = t->n) == NULL)
100 ptr->back = prev;
101 return (t);
104 return (NULL);
107 /* Make sure the list isn't corrupt and returns number of list items */
109 ll_check(llh_t *head)
111 int i = 0;
112 ll_t *ptr = head->front;
113 #ifndef NDEBUG
114 ll_t **prev = &head->front;
115 #endif
117 while (ptr) {
118 i++;
119 #ifndef NDEBUG
120 prev = &ptr->n;
121 #endif
122 ptr = ptr->n;
124 assert(head->back == prev);
125 return (i);