xref: /illumos-gate/usr/src/cmd/fm/fminject/common/inj_list.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <inj_err.h>
28 #include <inj_list.h>
29 
30 #include <assert.h>
31 #include <unistd.h>
32 
33 void
inj_list_append(inj_list_t * mlp,void * new)34 inj_list_append(inj_list_t *mlp, void *new)
35 {
36 	inj_list_t *p = mlp->ml_prev;	/* p = tail list element */
37 	inj_list_t *q = new;		/* q = new list element */
38 
39 	mlp->ml_prev = q;
40 	q->ml_prev = p;
41 	q->ml_next = NULL;
42 
43 	if (p != NULL) {
44 		assert(p->ml_next == NULL);
45 		p->ml_next = q;
46 	} else {
47 		assert(mlp->ml_next == NULL);
48 		mlp->ml_next = q;
49 	}
50 }
51 
52 void
inj_list_prepend(inj_list_t * mlp,void * new)53 inj_list_prepend(inj_list_t *mlp, void *new)
54 {
55 	inj_list_t *p = new;		/* p = new list element */
56 	inj_list_t *q = mlp->ml_next;	/* q = head list element */
57 
58 	mlp->ml_next = p;
59 	p->ml_prev = NULL;
60 	p->ml_next = q;
61 
62 	if (q != NULL) {
63 		assert(q->ml_prev == NULL);
64 		q->ml_prev = p;
65 	} else {
66 		assert(mlp->ml_prev == NULL);
67 		mlp->ml_prev = p;
68 	}
69 }
70