xref: /openbsd-src/usr.bin/make/lst.lib/lstRequeue.c (revision 31289fe882c406752e771f79f2b5359eab0f1c83)
1*31289fe8Sespie /*	$OpenBSD: lstRequeue.c,v 1.1 2008/01/12 13:05:57 espie Exp $	*/
2*31289fe8Sespie /*
3*31289fe8Sespie  * Copyright (c) 2008 Marc Espie.
4*31289fe8Sespie  *
5*31289fe8Sespie  * Redistribution and use in source and binary forms, with or without
6*31289fe8Sespie  * modification, are permitted provided that the following conditions
7*31289fe8Sespie  * are met:
8*31289fe8Sespie  * 1. Redistributions of source code must retain the above copyright
9*31289fe8Sespie  *    notice, this list of conditions and the following disclaimer.
10*31289fe8Sespie  * 2. Redistributions in binary form must reproduce the above copyright
11*31289fe8Sespie  *    notice, this list of conditions and the following disclaimer in the
12*31289fe8Sespie  *    documentation and/or other materials provided with the distribution.
13*31289fe8Sespie  *
14*31289fe8Sespie  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
15*31289fe8Sespie  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16*31289fe8Sespie  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17*31289fe8Sespie  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
18*31289fe8Sespie  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19*31289fe8Sespie  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20*31289fe8Sespie  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*31289fe8Sespie  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*31289fe8Sespie  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*31289fe8Sespie  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24*31289fe8Sespie  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*31289fe8Sespie  */
26*31289fe8Sespie #include	"lstInt.h"
27*31289fe8Sespie #include	<stdlib.h>
28*31289fe8Sespie 
29*31289fe8Sespie 
30*31289fe8Sespie /* Lst_Requeue(l, ln): takes node ln from the list and requeue it at front.
31*31289fe8Sespie  */
32*31289fe8Sespie void
Lst_Requeue(Lst l,LstNode ln)33*31289fe8Sespie Lst_Requeue(Lst l, LstNode ln)
34*31289fe8Sespie {
35*31289fe8Sespie 
36*31289fe8Sespie 	/* already at front */
37*31289fe8Sespie 	if (l->firstPtr == ln)
38*31289fe8Sespie 		return;
39*31289fe8Sespie 	/* unlink element */
40*31289fe8Sespie 	if (ln->nextPtr != NULL)
41*31289fe8Sespie 		ln->nextPtr->prevPtr = ln->prevPtr;
42*31289fe8Sespie 	if (ln->prevPtr != NULL)
43*31289fe8Sespie 		ln->prevPtr->nextPtr = ln->nextPtr;
44*31289fe8Sespie 
45*31289fe8Sespie 	if (l->lastPtr == ln)
46*31289fe8Sespie 		l->lastPtr = ln->prevPtr;
47*31289fe8Sespie 
48*31289fe8Sespie 	/* relink at front */
49*31289fe8Sespie 	ln->nextPtr = l->firstPtr;
50*31289fe8Sespie 	ln->prevPtr = NULL;
51*31289fe8Sespie 	l->firstPtr->prevPtr = ln;
52*31289fe8Sespie 	l->firstPtr = ln;
53*31289fe8Sespie }
54*31289fe8Sespie 
55