xref: /minix3/external/bsd/atf/dist/atf-c/detail/list.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*
2*11be35a1SLionel Sambuc  * Automated Testing Framework (atf)
3*11be35a1SLionel Sambuc  *
4*11be35a1SLionel Sambuc  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5*11be35a1SLionel Sambuc  * All rights reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
9*11be35a1SLionel Sambuc  * are met:
10*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*11be35a1SLionel Sambuc  *
16*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*11be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*11be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*11be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*11be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*11be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*11be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*11be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*11be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*11be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc  */
29*11be35a1SLionel Sambuc 
30*11be35a1SLionel Sambuc #include <stdlib.h>
31*11be35a1SLionel Sambuc #include <string.h>
32*11be35a1SLionel Sambuc 
33*11be35a1SLionel Sambuc #include "atf-c/error.h"
34*11be35a1SLionel Sambuc #include "atf-c/utils.h"
35*11be35a1SLionel Sambuc 
36*11be35a1SLionel Sambuc #include "list.h"
37*11be35a1SLionel Sambuc #include "sanity.h"
38*11be35a1SLionel Sambuc 
39*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
40*11be35a1SLionel Sambuc  * Auxiliary functions.
41*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
42*11be35a1SLionel Sambuc 
43*11be35a1SLionel Sambuc struct list_entry {
44*11be35a1SLionel Sambuc     struct list_entry *m_prev;
45*11be35a1SLionel Sambuc     struct list_entry *m_next;
46*11be35a1SLionel Sambuc     void *m_object;
47*11be35a1SLionel Sambuc     bool m_managed;
48*11be35a1SLionel Sambuc };
49*11be35a1SLionel Sambuc 
50*11be35a1SLionel Sambuc static
51*11be35a1SLionel Sambuc atf_list_citer_t
entry_to_citer(const atf_list_t * l,const struct list_entry * le)52*11be35a1SLionel Sambuc entry_to_citer(const atf_list_t *l, const struct list_entry *le)
53*11be35a1SLionel Sambuc {
54*11be35a1SLionel Sambuc     atf_list_citer_t iter;
55*11be35a1SLionel Sambuc     iter.m_list = l;
56*11be35a1SLionel Sambuc     iter.m_entry = le;
57*11be35a1SLionel Sambuc     return iter;
58*11be35a1SLionel Sambuc }
59*11be35a1SLionel Sambuc 
60*11be35a1SLionel Sambuc static
61*11be35a1SLionel Sambuc atf_list_iter_t
entry_to_iter(atf_list_t * l,struct list_entry * le)62*11be35a1SLionel Sambuc entry_to_iter(atf_list_t *l, struct list_entry *le)
63*11be35a1SLionel Sambuc {
64*11be35a1SLionel Sambuc     atf_list_iter_t iter;
65*11be35a1SLionel Sambuc     iter.m_list = l;
66*11be35a1SLionel Sambuc     iter.m_entry = le;
67*11be35a1SLionel Sambuc     return iter;
68*11be35a1SLionel Sambuc }
69*11be35a1SLionel Sambuc 
70*11be35a1SLionel Sambuc static
71*11be35a1SLionel Sambuc struct list_entry *
new_entry(void * object,bool managed)72*11be35a1SLionel Sambuc new_entry(void *object, bool managed)
73*11be35a1SLionel Sambuc {
74*11be35a1SLionel Sambuc     struct list_entry *le;
75*11be35a1SLionel Sambuc 
76*11be35a1SLionel Sambuc     le = (struct list_entry *)malloc(sizeof(*le));
77*11be35a1SLionel Sambuc     if (le != NULL) {
78*11be35a1SLionel Sambuc         le->m_prev = le->m_next = NULL;
79*11be35a1SLionel Sambuc         le->m_object = object;
80*11be35a1SLionel Sambuc         le->m_managed = managed;
81*11be35a1SLionel Sambuc     } else
82*11be35a1SLionel Sambuc         free(object);
83*11be35a1SLionel Sambuc 
84*11be35a1SLionel Sambuc     return le;
85*11be35a1SLionel Sambuc }
86*11be35a1SLionel Sambuc 
87*11be35a1SLionel Sambuc static
88*11be35a1SLionel Sambuc void
delete_entry(struct list_entry * le)89*11be35a1SLionel Sambuc delete_entry(struct list_entry *le)
90*11be35a1SLionel Sambuc {
91*11be35a1SLionel Sambuc     if (le->m_managed)
92*11be35a1SLionel Sambuc         free(le->m_object);
93*11be35a1SLionel Sambuc 
94*11be35a1SLionel Sambuc     free(le);
95*11be35a1SLionel Sambuc }
96*11be35a1SLionel Sambuc 
97*11be35a1SLionel Sambuc static
98*11be35a1SLionel Sambuc struct list_entry *
new_entry_and_link(void * object,bool managed,struct list_entry * prev,struct list_entry * next)99*11be35a1SLionel Sambuc new_entry_and_link(void *object, bool managed, struct list_entry *prev,
100*11be35a1SLionel Sambuc                    struct list_entry *next)
101*11be35a1SLionel Sambuc {
102*11be35a1SLionel Sambuc     struct list_entry *le;
103*11be35a1SLionel Sambuc 
104*11be35a1SLionel Sambuc     le = new_entry(object, managed);
105*11be35a1SLionel Sambuc     if (le != NULL) {
106*11be35a1SLionel Sambuc         le->m_prev = prev;
107*11be35a1SLionel Sambuc         le->m_next = next;
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc         prev->m_next = le;
110*11be35a1SLionel Sambuc         next->m_prev = le;
111*11be35a1SLionel Sambuc     }
112*11be35a1SLionel Sambuc 
113*11be35a1SLionel Sambuc     return le;
114*11be35a1SLionel Sambuc }
115*11be35a1SLionel Sambuc 
116*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
117*11be35a1SLionel Sambuc  * The "atf_list_citer" type.
118*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
119*11be35a1SLionel Sambuc 
120*11be35a1SLionel Sambuc /*
121*11be35a1SLionel Sambuc  * Getters.
122*11be35a1SLionel Sambuc  */
123*11be35a1SLionel Sambuc 
124*11be35a1SLionel Sambuc const void *
atf_list_citer_data(const atf_list_citer_t citer)125*11be35a1SLionel Sambuc atf_list_citer_data(const atf_list_citer_t citer)
126*11be35a1SLionel Sambuc {
127*11be35a1SLionel Sambuc     const struct list_entry *le = citer.m_entry;
128*11be35a1SLionel Sambuc     PRE(le != NULL);
129*11be35a1SLionel Sambuc     return le->m_object;
130*11be35a1SLionel Sambuc }
131*11be35a1SLionel Sambuc 
132*11be35a1SLionel Sambuc atf_list_citer_t
atf_list_citer_next(const atf_list_citer_t citer)133*11be35a1SLionel Sambuc atf_list_citer_next(const atf_list_citer_t citer)
134*11be35a1SLionel Sambuc {
135*11be35a1SLionel Sambuc     const struct list_entry *le = citer.m_entry;
136*11be35a1SLionel Sambuc     atf_list_citer_t newciter;
137*11be35a1SLionel Sambuc 
138*11be35a1SLionel Sambuc     PRE(le != NULL);
139*11be35a1SLionel Sambuc 
140*11be35a1SLionel Sambuc     newciter = citer;
141*11be35a1SLionel Sambuc     newciter.m_entry = le->m_next;
142*11be35a1SLionel Sambuc 
143*11be35a1SLionel Sambuc     return newciter;
144*11be35a1SLionel Sambuc }
145*11be35a1SLionel Sambuc 
146*11be35a1SLionel Sambuc bool
atf_equal_list_citer_list_citer(const atf_list_citer_t i1,const atf_list_citer_t i2)147*11be35a1SLionel Sambuc atf_equal_list_citer_list_citer(const atf_list_citer_t i1,
148*11be35a1SLionel Sambuc                                 const atf_list_citer_t i2)
149*11be35a1SLionel Sambuc {
150*11be35a1SLionel Sambuc     return i1.m_list == i2.m_list && i1.m_entry == i2.m_entry;
151*11be35a1SLionel Sambuc }
152*11be35a1SLionel Sambuc 
153*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
154*11be35a1SLionel Sambuc  * The "atf_list_iter" type.
155*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
156*11be35a1SLionel Sambuc 
157*11be35a1SLionel Sambuc /*
158*11be35a1SLionel Sambuc  * Getters.
159*11be35a1SLionel Sambuc  */
160*11be35a1SLionel Sambuc 
161*11be35a1SLionel Sambuc void *
atf_list_iter_data(const atf_list_iter_t iter)162*11be35a1SLionel Sambuc atf_list_iter_data(const atf_list_iter_t iter)
163*11be35a1SLionel Sambuc {
164*11be35a1SLionel Sambuc     const struct list_entry *le = iter.m_entry;
165*11be35a1SLionel Sambuc     PRE(le != NULL);
166*11be35a1SLionel Sambuc     return le->m_object;
167*11be35a1SLionel Sambuc }
168*11be35a1SLionel Sambuc 
169*11be35a1SLionel Sambuc atf_list_iter_t
atf_list_iter_next(const atf_list_iter_t iter)170*11be35a1SLionel Sambuc atf_list_iter_next(const atf_list_iter_t iter)
171*11be35a1SLionel Sambuc {
172*11be35a1SLionel Sambuc     const struct list_entry *le = iter.m_entry;
173*11be35a1SLionel Sambuc     atf_list_iter_t newiter;
174*11be35a1SLionel Sambuc 
175*11be35a1SLionel Sambuc     PRE(le != NULL);
176*11be35a1SLionel Sambuc 
177*11be35a1SLionel Sambuc     newiter = iter;
178*11be35a1SLionel Sambuc     newiter.m_entry = le->m_next;
179*11be35a1SLionel Sambuc 
180*11be35a1SLionel Sambuc     return newiter;
181*11be35a1SLionel Sambuc }
182*11be35a1SLionel Sambuc 
183*11be35a1SLionel Sambuc bool
atf_equal_list_iter_list_iter(const atf_list_iter_t i1,const atf_list_iter_t i2)184*11be35a1SLionel Sambuc atf_equal_list_iter_list_iter(const atf_list_iter_t i1,
185*11be35a1SLionel Sambuc                               const atf_list_iter_t i2)
186*11be35a1SLionel Sambuc {
187*11be35a1SLionel Sambuc     return i1.m_list == i2.m_list && i1.m_entry == i2.m_entry;
188*11be35a1SLionel Sambuc }
189*11be35a1SLionel Sambuc 
190*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
191*11be35a1SLionel Sambuc  * The "atf_list" type.
192*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
193*11be35a1SLionel Sambuc 
194*11be35a1SLionel Sambuc /*
195*11be35a1SLionel Sambuc  * Constructors and destructors.
196*11be35a1SLionel Sambuc  */
197*11be35a1SLionel Sambuc 
198*11be35a1SLionel Sambuc atf_error_t
atf_list_init(atf_list_t * l)199*11be35a1SLionel Sambuc atf_list_init(atf_list_t *l)
200*11be35a1SLionel Sambuc {
201*11be35a1SLionel Sambuc     struct list_entry *lebeg, *leend;
202*11be35a1SLionel Sambuc 
203*11be35a1SLionel Sambuc     lebeg = new_entry(NULL, false);
204*11be35a1SLionel Sambuc     if (lebeg == NULL) {
205*11be35a1SLionel Sambuc         return atf_no_memory_error();
206*11be35a1SLionel Sambuc     }
207*11be35a1SLionel Sambuc 
208*11be35a1SLionel Sambuc     leend = new_entry(NULL, false);
209*11be35a1SLionel Sambuc     if (leend == NULL) {
210*11be35a1SLionel Sambuc         free(lebeg);
211*11be35a1SLionel Sambuc         return atf_no_memory_error();
212*11be35a1SLionel Sambuc     }
213*11be35a1SLionel Sambuc 
214*11be35a1SLionel Sambuc     lebeg->m_next = leend;
215*11be35a1SLionel Sambuc     lebeg->m_prev = NULL;
216*11be35a1SLionel Sambuc 
217*11be35a1SLionel Sambuc     leend->m_next = NULL;
218*11be35a1SLionel Sambuc     leend->m_prev = lebeg;
219*11be35a1SLionel Sambuc 
220*11be35a1SLionel Sambuc     l->m_size = 0;
221*11be35a1SLionel Sambuc     l->m_begin = lebeg;
222*11be35a1SLionel Sambuc     l->m_end = leend;
223*11be35a1SLionel Sambuc 
224*11be35a1SLionel Sambuc     return atf_no_error();
225*11be35a1SLionel Sambuc }
226*11be35a1SLionel Sambuc 
227*11be35a1SLionel Sambuc void
atf_list_fini(atf_list_t * l)228*11be35a1SLionel Sambuc atf_list_fini(atf_list_t *l)
229*11be35a1SLionel Sambuc {
230*11be35a1SLionel Sambuc     struct list_entry *le;
231*11be35a1SLionel Sambuc     size_t freed;
232*11be35a1SLionel Sambuc 
233*11be35a1SLionel Sambuc     le = (struct list_entry *)l->m_begin;
234*11be35a1SLionel Sambuc     freed = 0;
235*11be35a1SLionel Sambuc     while (le != NULL) {
236*11be35a1SLionel Sambuc         struct list_entry *lenext;
237*11be35a1SLionel Sambuc 
238*11be35a1SLionel Sambuc         lenext = le->m_next;
239*11be35a1SLionel Sambuc         delete_entry(le);
240*11be35a1SLionel Sambuc         le = lenext;
241*11be35a1SLionel Sambuc 
242*11be35a1SLionel Sambuc         freed++;
243*11be35a1SLionel Sambuc     }
244*11be35a1SLionel Sambuc     INV(freed == l->m_size + 2);
245*11be35a1SLionel Sambuc }
246*11be35a1SLionel Sambuc 
247*11be35a1SLionel Sambuc /*
248*11be35a1SLionel Sambuc  * Getters.
249*11be35a1SLionel Sambuc  */
250*11be35a1SLionel Sambuc 
251*11be35a1SLionel Sambuc atf_list_iter_t
atf_list_begin(atf_list_t * l)252*11be35a1SLionel Sambuc atf_list_begin(atf_list_t *l)
253*11be35a1SLionel Sambuc {
254*11be35a1SLionel Sambuc     struct list_entry *le = l->m_begin;
255*11be35a1SLionel Sambuc     return entry_to_iter(l, le->m_next);
256*11be35a1SLionel Sambuc }
257*11be35a1SLionel Sambuc 
258*11be35a1SLionel Sambuc atf_list_citer_t
atf_list_begin_c(const atf_list_t * l)259*11be35a1SLionel Sambuc atf_list_begin_c(const atf_list_t *l)
260*11be35a1SLionel Sambuc {
261*11be35a1SLionel Sambuc     const struct list_entry *le = l->m_begin;
262*11be35a1SLionel Sambuc     return entry_to_citer(l, le->m_next);
263*11be35a1SLionel Sambuc }
264*11be35a1SLionel Sambuc 
265*11be35a1SLionel Sambuc atf_list_iter_t
atf_list_end(atf_list_t * l)266*11be35a1SLionel Sambuc atf_list_end(atf_list_t *l)
267*11be35a1SLionel Sambuc {
268*11be35a1SLionel Sambuc     return entry_to_iter(l, l->m_end);
269*11be35a1SLionel Sambuc }
270*11be35a1SLionel Sambuc 
271*11be35a1SLionel Sambuc atf_list_citer_t
atf_list_end_c(const atf_list_t * l)272*11be35a1SLionel Sambuc atf_list_end_c(const atf_list_t *l)
273*11be35a1SLionel Sambuc {
274*11be35a1SLionel Sambuc     return entry_to_citer(l, l->m_end);
275*11be35a1SLionel Sambuc }
276*11be35a1SLionel Sambuc 
277*11be35a1SLionel Sambuc void *
atf_list_index(atf_list_t * list,const size_t idx)278*11be35a1SLionel Sambuc atf_list_index(atf_list_t *list, const size_t idx)
279*11be35a1SLionel Sambuc {
280*11be35a1SLionel Sambuc     atf_list_iter_t iter;
281*11be35a1SLionel Sambuc 
282*11be35a1SLionel Sambuc     PRE(idx < atf_list_size(list));
283*11be35a1SLionel Sambuc 
284*11be35a1SLionel Sambuc     iter = atf_list_begin(list);
285*11be35a1SLionel Sambuc     {
286*11be35a1SLionel Sambuc         size_t pos = 0;
287*11be35a1SLionel Sambuc         while (pos < idx &&
288*11be35a1SLionel Sambuc                !atf_equal_list_iter_list_iter((iter), atf_list_end(list))) {
289*11be35a1SLionel Sambuc             iter = atf_list_iter_next(iter);
290*11be35a1SLionel Sambuc             pos++;
291*11be35a1SLionel Sambuc         }
292*11be35a1SLionel Sambuc     }
293*11be35a1SLionel Sambuc     return atf_list_iter_data(iter);
294*11be35a1SLionel Sambuc }
295*11be35a1SLionel Sambuc 
296*11be35a1SLionel Sambuc const void *
atf_list_index_c(const atf_list_t * list,const size_t idx)297*11be35a1SLionel Sambuc atf_list_index_c(const atf_list_t *list, const size_t idx)
298*11be35a1SLionel Sambuc {
299*11be35a1SLionel Sambuc     atf_list_citer_t iter;
300*11be35a1SLionel Sambuc 
301*11be35a1SLionel Sambuc     PRE(idx < atf_list_size(list));
302*11be35a1SLionel Sambuc 
303*11be35a1SLionel Sambuc     iter = atf_list_begin_c(list);
304*11be35a1SLionel Sambuc     {
305*11be35a1SLionel Sambuc         size_t pos = 0;
306*11be35a1SLionel Sambuc         while (pos < idx &&
307*11be35a1SLionel Sambuc                !atf_equal_list_citer_list_citer((iter),
308*11be35a1SLionel Sambuc                                                 atf_list_end_c(list))) {
309*11be35a1SLionel Sambuc             iter = atf_list_citer_next(iter);
310*11be35a1SLionel Sambuc             pos++;
311*11be35a1SLionel Sambuc         }
312*11be35a1SLionel Sambuc     }
313*11be35a1SLionel Sambuc     return atf_list_citer_data(iter);
314*11be35a1SLionel Sambuc }
315*11be35a1SLionel Sambuc 
316*11be35a1SLionel Sambuc size_t
atf_list_size(const atf_list_t * l)317*11be35a1SLionel Sambuc atf_list_size(const atf_list_t *l)
318*11be35a1SLionel Sambuc {
319*11be35a1SLionel Sambuc     return l->m_size;
320*11be35a1SLionel Sambuc }
321*11be35a1SLionel Sambuc 
322*11be35a1SLionel Sambuc char **
atf_list_to_charpp(const atf_list_t * l)323*11be35a1SLionel Sambuc atf_list_to_charpp(const atf_list_t *l)
324*11be35a1SLionel Sambuc {
325*11be35a1SLionel Sambuc     char **array;
326*11be35a1SLionel Sambuc     atf_list_citer_t iter;
327*11be35a1SLionel Sambuc     size_t i;
328*11be35a1SLionel Sambuc 
329*11be35a1SLionel Sambuc     array = malloc(sizeof(char *) * (atf_list_size(l) + 1));
330*11be35a1SLionel Sambuc     if (array == NULL)
331*11be35a1SLionel Sambuc         goto out;
332*11be35a1SLionel Sambuc 
333*11be35a1SLionel Sambuc     i = 0;
334*11be35a1SLionel Sambuc     atf_list_for_each_c(iter, l) {
335*11be35a1SLionel Sambuc         array[i] = strdup((const char *)atf_list_citer_data(iter));
336*11be35a1SLionel Sambuc         if (array[i] == NULL) {
337*11be35a1SLionel Sambuc             atf_utils_free_charpp(array);
338*11be35a1SLionel Sambuc             array = NULL;
339*11be35a1SLionel Sambuc             goto out;
340*11be35a1SLionel Sambuc         }
341*11be35a1SLionel Sambuc 
342*11be35a1SLionel Sambuc         i++;
343*11be35a1SLionel Sambuc     }
344*11be35a1SLionel Sambuc     array[i] = NULL;
345*11be35a1SLionel Sambuc 
346*11be35a1SLionel Sambuc out:
347*11be35a1SLionel Sambuc     return array;
348*11be35a1SLionel Sambuc }
349*11be35a1SLionel Sambuc 
350*11be35a1SLionel Sambuc /*
351*11be35a1SLionel Sambuc  * Modifiers.
352*11be35a1SLionel Sambuc  */
353*11be35a1SLionel Sambuc 
354*11be35a1SLionel Sambuc atf_error_t
atf_list_append(atf_list_t * l,void * data,bool managed)355*11be35a1SLionel Sambuc atf_list_append(atf_list_t *l, void *data, bool managed)
356*11be35a1SLionel Sambuc {
357*11be35a1SLionel Sambuc     struct list_entry *le, *next, *prev;
358*11be35a1SLionel Sambuc     atf_error_t err;
359*11be35a1SLionel Sambuc 
360*11be35a1SLionel Sambuc     next = (struct list_entry *)l->m_end;
361*11be35a1SLionel Sambuc     prev = next->m_prev;
362*11be35a1SLionel Sambuc     le = new_entry_and_link(data, managed, prev, next);
363*11be35a1SLionel Sambuc     if (le == NULL)
364*11be35a1SLionel Sambuc         err = atf_no_memory_error();
365*11be35a1SLionel Sambuc     else {
366*11be35a1SLionel Sambuc         l->m_size++;
367*11be35a1SLionel Sambuc         err = atf_no_error();
368*11be35a1SLionel Sambuc     }
369*11be35a1SLionel Sambuc 
370*11be35a1SLionel Sambuc     return err;
371*11be35a1SLionel Sambuc }
372*11be35a1SLionel Sambuc 
373*11be35a1SLionel Sambuc void
atf_list_append_list(atf_list_t * l,atf_list_t * src)374*11be35a1SLionel Sambuc atf_list_append_list(atf_list_t *l, atf_list_t *src)
375*11be35a1SLionel Sambuc {
376*11be35a1SLionel Sambuc     struct list_entry *e1, *e2, *ghost1, *ghost2;
377*11be35a1SLionel Sambuc 
378*11be35a1SLionel Sambuc     ghost1 = (struct list_entry *)l->m_end;
379*11be35a1SLionel Sambuc     ghost2 = (struct list_entry *)src->m_begin;
380*11be35a1SLionel Sambuc 
381*11be35a1SLionel Sambuc     e1 = ghost1->m_prev;
382*11be35a1SLionel Sambuc     e2 = ghost2->m_next;
383*11be35a1SLionel Sambuc 
384*11be35a1SLionel Sambuc     delete_entry(ghost1);
385*11be35a1SLionel Sambuc     delete_entry(ghost2);
386*11be35a1SLionel Sambuc 
387*11be35a1SLionel Sambuc     e1->m_next = e2;
388*11be35a1SLionel Sambuc     e2->m_prev = e1;
389*11be35a1SLionel Sambuc 
390*11be35a1SLionel Sambuc     l->m_end = src->m_end;
391*11be35a1SLionel Sambuc     l->m_size += src->m_size;
392*11be35a1SLionel Sambuc }
393