lstIsAtEnd.c revision 236769
1251607Sdim/*	$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $	*/
2251607Sdim
3251607Sdim/*
4251607Sdim * Copyright (c) 1988, 1989, 1990, 1993
5251607Sdim *	The Regents of the University of California.  All rights reserved.
6251607Sdim *
7251607Sdim * This code is derived from software contributed to Berkeley by
8251607Sdim * Adam de Boor.
9251607Sdim *
10251607Sdim * Redistribution and use in source and binary forms, with or without
11251607Sdim * modification, are permitted provided that the following conditions
12251607Sdim * are met:
13251607Sdim * 1. Redistributions of source code must retain the above copyright
14251607Sdim *    notice, this list of conditions and the following disclaimer.
15251607Sdim * 2. Redistributions in binary form must reproduce the above copyright
16251607Sdim *    notice, this list of conditions and the following disclaimer in the
17251607Sdim *    documentation and/or other materials provided with the distribution.
18251607Sdim * 3. Neither the name of the University nor the names of its contributors
19263508Sdim *    may be used to endorse or promote products derived from this software
20263508Sdim *    without specific prior written permission.
21251607Sdim *
22263508Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23251607Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24251607Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25263508Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26251607Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27263508Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28251607Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29263508Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30251607Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31263508Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32263508Sdim * SUCH DAMAGE.
33251607Sdim */
34251607Sdim
35251607Sdim#ifndef MAKE_NATIVE
36251607Sdimstatic char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $";
37251607Sdim#else
38251607Sdim#include <sys/cdefs.h>
39251607Sdim#ifndef lint
40251607Sdim#if 0
41251607Sdimstatic char sccsid[] = "@(#)lstIsAtEnd.c	8.1 (Berkeley) 6/6/93";
42251607Sdim#else
43251607Sdim__RCSID("$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $");
44251607Sdim#endif
45251607Sdim#endif /* not lint */
46251607Sdim#endif
47251607Sdim
48251607Sdim/*-
49251607Sdim * LstIsAtEnd.c --
50251607Sdim *	Tell if the current node is at the end of the list.
51251607Sdim *	The sequential functions access the list in a slightly different way.
52251607Sdim *	CurPtr points to their idea of the current node in the list and they
53251607Sdim *	access the list based on it. Because the list is circular, Lst_Next
54251607Sdim *	and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
55251607Sdim *	used to determine when to stop.
56251607Sdim */
57251607Sdim
58251607Sdim#include	"lstInt.h"
59251607Sdim
60251607Sdim/*-
61263508Sdim *-----------------------------------------------------------------------
62263508Sdim * Lst_IsAtEnd --
63251607Sdim *	Return true if have reached the end of the given list.
64251607Sdim *
65251607Sdim * Results:
66251607Sdim *	TRUE if at the end of the list (this includes the list not being
67251607Sdim *	open or being invalid) or FALSE if not. We return TRUE if the list
68251607Sdim *	is invalid or unopend so as to cause the caller to exit its loop
69251607Sdim *	asap, the assumption being that the loop is of the form
70251607Sdim *	    while (!Lst_IsAtEnd (l)) {
71251607Sdim *	    	  ...
72251607Sdim *	    }
73251607Sdim *
74251607Sdim * Side Effects:
75251607Sdim *	None.
76251607Sdim *
77251607Sdim *-----------------------------------------------------------------------
78251607Sdim */
79263508SdimBoolean
80251607SdimLst_IsAtEnd(Lst l)
81263508Sdim{
82263508Sdim    List list = l;
83263508Sdim
84263508Sdim    return (!LstValid (l) || !list->isOpen ||
85263508Sdim	    (list->atEnd == Head) || (list->atEnd == Tail));
86251607Sdim}
87251607Sdim
88263508Sdim