1*2e2caf59SThomas Veerman /* $NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $ */
2*2e2caf59SThomas Veerman
3*2e2caf59SThomas Veerman /*
4*2e2caf59SThomas Veerman * Copyright (c) 1988, 1989, 1990, 1993
5*2e2caf59SThomas Veerman * The Regents of the University of California. All rights reserved.
6*2e2caf59SThomas Veerman *
7*2e2caf59SThomas Veerman * This code is derived from software contributed to Berkeley by
8*2e2caf59SThomas Veerman * Adam de Boor.
9*2e2caf59SThomas Veerman *
10*2e2caf59SThomas Veerman * Redistribution and use in source and binary forms, with or without
11*2e2caf59SThomas Veerman * modification, are permitted provided that the following conditions
12*2e2caf59SThomas Veerman * are met:
13*2e2caf59SThomas Veerman * 1. Redistributions of source code must retain the above copyright
14*2e2caf59SThomas Veerman * notice, this list of conditions and the following disclaimer.
15*2e2caf59SThomas Veerman * 2. Redistributions in binary form must reproduce the above copyright
16*2e2caf59SThomas Veerman * notice, this list of conditions and the following disclaimer in the
17*2e2caf59SThomas Veerman * documentation and/or other materials provided with the distribution.
18*2e2caf59SThomas Veerman * 3. Neither the name of the University nor the names of its contributors
19*2e2caf59SThomas Veerman * may be used to endorse or promote products derived from this software
20*2e2caf59SThomas Veerman * without specific prior written permission.
21*2e2caf59SThomas Veerman *
22*2e2caf59SThomas Veerman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*2e2caf59SThomas Veerman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*2e2caf59SThomas Veerman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*2e2caf59SThomas Veerman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*2e2caf59SThomas Veerman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*2e2caf59SThomas Veerman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*2e2caf59SThomas Veerman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*2e2caf59SThomas Veerman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*2e2caf59SThomas Veerman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*2e2caf59SThomas Veerman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*2e2caf59SThomas Veerman * SUCH DAMAGE.
33*2e2caf59SThomas Veerman */
34*2e2caf59SThomas Veerman
35*2e2caf59SThomas Veerman #ifndef MAKE_NATIVE
36*2e2caf59SThomas Veerman static char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $";
37*2e2caf59SThomas Veerman #else
38*2e2caf59SThomas Veerman #include <sys/cdefs.h>
39*2e2caf59SThomas Veerman #ifndef lint
40*2e2caf59SThomas Veerman #if 0
41*2e2caf59SThomas Veerman static char sccsid[] = "@(#)lstIsAtEnd.c 8.1 (Berkeley) 6/6/93";
42*2e2caf59SThomas Veerman #else
43*2e2caf59SThomas Veerman __RCSID("$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $");
44*2e2caf59SThomas Veerman #endif
45*2e2caf59SThomas Veerman #endif /* not lint */
46*2e2caf59SThomas Veerman #endif
47*2e2caf59SThomas Veerman
48*2e2caf59SThomas Veerman /*-
49*2e2caf59SThomas Veerman * LstIsAtEnd.c --
50*2e2caf59SThomas Veerman * Tell if the current node is at the end of the list.
51*2e2caf59SThomas Veerman * The sequential functions access the list in a slightly different way.
52*2e2caf59SThomas Veerman * CurPtr points to their idea of the current node in the list and they
53*2e2caf59SThomas Veerman * access the list based on it. Because the list is circular, Lst_Next
54*2e2caf59SThomas Veerman * and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
55*2e2caf59SThomas Veerman * used to determine when to stop.
56*2e2caf59SThomas Veerman */
57*2e2caf59SThomas Veerman
58*2e2caf59SThomas Veerman #include "lstInt.h"
59*2e2caf59SThomas Veerman
60*2e2caf59SThomas Veerman /*-
61*2e2caf59SThomas Veerman *-----------------------------------------------------------------------
62*2e2caf59SThomas Veerman * Lst_IsAtEnd --
63*2e2caf59SThomas Veerman * Return true if have reached the end of the given list.
64*2e2caf59SThomas Veerman *
65*2e2caf59SThomas Veerman * Results:
66*2e2caf59SThomas Veerman * TRUE if at the end of the list (this includes the list not being
67*2e2caf59SThomas Veerman * open or being invalid) or FALSE if not. We return TRUE if the list
68*2e2caf59SThomas Veerman * is invalid or unopend so as to cause the caller to exit its loop
69*2e2caf59SThomas Veerman * asap, the assumption being that the loop is of the form
70*2e2caf59SThomas Veerman * while (!Lst_IsAtEnd (l)) {
71*2e2caf59SThomas Veerman * ...
72*2e2caf59SThomas Veerman * }
73*2e2caf59SThomas Veerman *
74*2e2caf59SThomas Veerman * Side Effects:
75*2e2caf59SThomas Veerman * None.
76*2e2caf59SThomas Veerman *
77*2e2caf59SThomas Veerman *-----------------------------------------------------------------------
78*2e2caf59SThomas Veerman */
79*2e2caf59SThomas Veerman Boolean
Lst_IsAtEnd(Lst l)80*2e2caf59SThomas Veerman Lst_IsAtEnd(Lst l)
81*2e2caf59SThomas Veerman {
82*2e2caf59SThomas Veerman List list = l;
83*2e2caf59SThomas Veerman
84*2e2caf59SThomas Veerman return (!LstValid (l) || !list->isOpen ||
85*2e2caf59SThomas Veerman (list->atEnd == Head) || (list->atEnd == Tail));
86*2e2caf59SThomas Veerman }
87*2e2caf59SThomas Veerman
88