*BSD News Article 12683


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!wupost!csus.edu!netcom.com!alm
From: alm@netcom.com (Andrew Moore)
Subject: Re: libc missing *insque remque*
Message-ID: <1993Mar16.225705.27368@netcom.com>
Organization: Netcom Online Communications Services (408-241-9760 login: guest)
References: <BRI.93Mar16031241@pegasus.mit.edu> <C3zMJx.C1H@unx.sas.com>
Date: Tue, 16 Mar 1993 22:57:05 GMT
Lines: 72

In article <C3zMJx.C1H@unx.sas.com> sastdr@torpid.unx.sas.com (Thomas David Rivers) writes:
>In article <BRI.93Mar16031241@pegasus.mit.edu> bri@athena.mit.edu (Brian D. Carlstrom) writes:
>>i'm trying to build zephyr for 386bsd and its all done except
>>i need to link zhm and zwgc. unfortunately i need insque and remque
>>which arent in my lib that i build from the srcdist. where is the best
>>place to get the missing routines. i tried to get them from another libc
>>but the werent there either.
>>
>>-bri
>>--
>>
>>-bri
>
>
>Since these were small, I thought I'd simply post them here...
>
>I took this from the Berkely compatibility routines in the MIT X11R5
>distribution... They used to be for providing BSD compatibility on SYSV, but
>now, I guess they will work for BSD as well...
>
>Note: They do *not* do an queue locking....

[ code deleted ]

The posted code is not compatible with SunOS's version, which do not check
for NULLs.  Each call below memory faults under SunOS:

f()
{
struct qelem h, i, j;

insque(&h, 0);		/* wrong! because !0 */
i.q_forw = 0;
insque(&h, &i);		/* wrong! because !i.q_forw */
h.q_back = 0;
i.q_forw = &h;
insque(&h, &i);		/* wrong! because !i.q_forw->q_back */
i.q_back = 0;
h.q_forw = 0;
h.q_back = &i;
remque(&h);		/* wrong! because !h.q_forw */
remque(&i);		/* wrong! because !i.q_back */
}


The following would seem to be Sun libc's implementation:
-Andrew Moore <alm@netcom.com>


/* queue.c: This file contains routines for inserting and removing an
   element from an existing doubly linked list. */

#define relink(pred, succ) \
{ \
	succ->q_back = pred; \
	pred->q_forw = succ; \
}

/* insque: insert elem after pred; pred->q_forw is not NULL */
insque(elem, pred)
	struct qelem *elem, *pred;
{
	relink(elem, pred->q_forw);
	relink(pred, elem);
}

/* remque: remove elem; elem->q_forw and elem->q_back are not NULL */
remque(elem)
	struct qelem *elem;
{
	relink(elem->q_back, elem->q_forw);
}