12fe8fb19SBen Gras /*
22fe8fb19SBen Gras * Copyright (c) 1993 John Brezak
32fe8fb19SBen Gras * All rights reserved.
42fe8fb19SBen Gras *
52fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
62fe8fb19SBen Gras * modification, are permitted provided that the following conditions
72fe8fb19SBen Gras * are met:
82fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
92fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer.
102fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
112fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the
122fe8fb19SBen Gras * documentation and/or other materials provided with the distribution.
132fe8fb19SBen Gras * 3. The name of the author may be used to endorse or promote products
142fe8fb19SBen Gras * derived from this software without specific prior written permission.
152fe8fb19SBen Gras *
162fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
172fe8fb19SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
182fe8fb19SBen Gras * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
192fe8fb19SBen Gras * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
202fe8fb19SBen Gras * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
212fe8fb19SBen Gras * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
222fe8fb19SBen Gras * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
242fe8fb19SBen Gras * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
252fe8fb19SBen Gras * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
262fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE.
272fe8fb19SBen Gras */
282fe8fb19SBen Gras
292fe8fb19SBen Gras #include <sys/cdefs.h>
302fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
31*f14fb602SLionel Sambuc __RCSID("$NetBSD: insque.c,v 1.3 2012/06/25 22:32:45 abs Exp $");
322fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
332fe8fb19SBen Gras
342fe8fb19SBen Gras #include <assert.h>
352fe8fb19SBen Gras #include <search.h>
362fe8fb19SBen Gras
372fe8fb19SBen Gras struct qelem {
382fe8fb19SBen Gras struct qelem *q_forw;
392fe8fb19SBen Gras struct qelem *q_back;
402fe8fb19SBen Gras };
412fe8fb19SBen Gras
422fe8fb19SBen Gras void
insque(void * entry,void * pred)43*f14fb602SLionel Sambuc insque(void *entry, void *pred)
442fe8fb19SBen Gras {
452fe8fb19SBen Gras struct qelem *e = (struct qelem *) entry;
462fe8fb19SBen Gras struct qelem *p = (struct qelem *) pred;
472fe8fb19SBen Gras
482fe8fb19SBen Gras _DIAGASSERT(e != 0);
492fe8fb19SBen Gras
502fe8fb19SBen Gras e->q_back = p;
512fe8fb19SBen Gras if (p) {
522fe8fb19SBen Gras e->q_forw = p->q_forw;
532fe8fb19SBen Gras if (p->q_forw)
542fe8fb19SBen Gras p->q_forw->q_back = e;
552fe8fb19SBen Gras p->q_forw = e;
562fe8fb19SBen Gras } else
572fe8fb19SBen Gras e->q_forw = 0;
582fe8fb19SBen Gras }
59