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