1*b14f942aSguenther /* $OpenBSD: insque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $ */
2cd087ff3Smillert
3cd087ff3Smillert /*
4cd087ff3Smillert * Copyright (c) 1993 John Brezak
5cd087ff3Smillert * All rights reserved.
6cd087ff3Smillert *
7cd087ff3Smillert * Redistribution and use in source and binary forms, with or without
8cd087ff3Smillert * modification, are permitted provided that the following conditions
9cd087ff3Smillert * are met:
10cd087ff3Smillert * 1. Redistributions of source code must retain the above copyright
11cd087ff3Smillert * notice, this list of conditions and the following disclaimer.
12cd087ff3Smillert * 2. Redistributions in binary form must reproduce the above copyright
13cd087ff3Smillert * notice, this list of conditions and the following disclaimer in the
14cd087ff3Smillert * documentation and/or other materials provided with the distribution.
15cd087ff3Smillert * 3. The name of the author may be used to endorse or promote products
16cd087ff3Smillert * derived from this software without specific prior written permission.
17cd087ff3Smillert *
18cd087ff3Smillert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
19cd087ff3Smillert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20cd087ff3Smillert * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21cd087ff3Smillert * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22cd087ff3Smillert * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23cd087ff3Smillert * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24cd087ff3Smillert * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25cd087ff3Smillert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26cd087ff3Smillert * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27cd087ff3Smillert * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28cd087ff3Smillert * POSSIBILITY OF SUCH DAMAGE.
29cd087ff3Smillert */
30cd087ff3Smillert
31*b14f942aSguenther #include <stdlib.h>
32cd087ff3Smillert #include <search.h>
33cd087ff3Smillert
34cd087ff3Smillert struct qelem {
35cd087ff3Smillert struct qelem *q_forw;
36cd087ff3Smillert struct qelem *q_back;
37cd087ff3Smillert };
38cd087ff3Smillert
39cd087ff3Smillert void
insque(void * entry,void * pred)40cd087ff3Smillert insque(void *entry, void *pred)
41cd087ff3Smillert {
42*b14f942aSguenther struct qelem *e = entry;
43*b14f942aSguenther struct qelem *p = pred;
44cd087ff3Smillert
45*b14f942aSguenther if (p == NULL)
46*b14f942aSguenther e->q_forw = e->q_back = NULL;
47*b14f942aSguenther else {
48cd087ff3Smillert e->q_forw = p->q_forw;
49cd087ff3Smillert e->q_back = p;
50*b14f942aSguenther if (p->q_forw != NULL)
51cd087ff3Smillert p->q_forw->q_back = e;
52cd087ff3Smillert p->q_forw = e;
53cd087ff3Smillert }
54*b14f942aSguenther }
55