1 /*-
2  * lstLength.c --
3  *	Find the length of a lst
4  *
5  * Copyright (c) 1988 by the Regents of the University of California
6  * Copyright (c) 1988 by Adam de Boor
7  *
8  * Permission to use, copy, modify, and distribute this
9  * software and its documentation for any purpose and without
10  * fee is hereby granted, provided that the above copyright
11  * notice appears in all copies.  The University of California nor
12  * Adam de Boor makes any representations about the suitability of this
13  * software for any purpose.  It is provided "as is" without
14  * express or implied warranty.
15  *
16  *
17  */
18 #ifndef lint
19 static char *rcsid =
20 "$Id: lstLength.c,v 1.2 88/11/17 20:53:27 adam Exp $ SPRITE (Berkeley)";
21 #endif lint
22 
23 #include    "lstInt.h"
24 
25 int
26 Lst_Length(l)
27     Lst	    l;	  /* List whose length is desired */
28 {
29     register ListNode 	node;
30     register List 	list = (List)l;
31     register int  	len;
32 
33     if (!LstValid(l)) {
34 	return -1;
35     }
36 
37     for (len = 0, node = list->firstPtr;
38 	 node != NilListNode;
39 	 len++, node = node->nextPtr) {
40 	if (node == list->firstPtr && len != 0) {
41 	    break;
42 	}
43     }
44     return len;
45 }
46