1 /* 2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Adam de Boor. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21 #ifndef lint 22 static char sccsid[] = "@(#)lstDestroy.c 5.2 (Berkeley) 03/11/90"; 23 #endif /* not lint */ 24 25 /*- 26 * LstDestroy.c -- 27 * Nuke a list and all its resources 28 */ 29 30 #include "lstInt.h" 31 32 /*- 33 *----------------------------------------------------------------------- 34 * Lst_Destroy -- 35 * Destroy a list and free all its resources. If the freeProc is 36 * given, it is called with the datum from each node in turn before 37 * the node is freed. 38 * 39 * Results: 40 * None. 41 * 42 * Side Effects: 43 * The given list is freed in its entirety. 44 * 45 *----------------------------------------------------------------------- 46 */ 47 void 48 Lst_Destroy (l, freeProc) 49 Lst l; 50 register void (*freeProc)(); 51 { 52 register ListNode ln; 53 register ListNode tln = NilListNode; 54 register List list = (List)l; 55 56 if (l == NILLST || ! l) { 57 /* 58 * Note the check for l == (Lst)0 to catch uninitialized static Lst's. 59 * Gross, but useful. 60 */ 61 return; 62 } 63 64 if (freeProc) { 65 for (ln = list->firstPtr; 66 ln != NilListNode && tln != list->firstPtr; 67 ln = tln) { 68 tln = ln->nextPtr; 69 (*freeProc) (ln->datum); 70 free ((Address)ln); 71 } 72 } else { 73 for (ln = list->firstPtr; 74 ln != NilListNode && tln != list->firstPtr; 75 ln = tln) { 76 tln = ln->nextPtr; 77 free ((Address)ln); 78 } 79 } 80 81 free ((Address)l); 82 } 83