1 | #include <config.h> |
2 | #include "lst.h" |
3 | |
4 | /********************* |
5 | * lstClose |
6 | * |
7 | * Call for Cursor or root list. |
8 | *********************/ |
9 | int lstClose( HLST hLst ) |
10 | { |
11 | HLSTITEM hItem; |
12 | |
13 | if ( !hLst ) |
14 | return LST_ERROR; |
15 | |
16 | hLst->nRefs--; |
17 | |
18 | /********************* |
19 | * We will not really remove the list if we have |
20 | * refs to it... we will just decrement ref. |
21 | * We will be deleted when the last ref is being removed. |
22 | *********************/ |
23 | if ( hLst->nRefs > 0 ) |
24 | return LST_SUCCESS; |
25 | |
26 | /************************ |
27 | * DELETE ITEMS (and their refs) |
28 | * - do not use standard nav funcs because they will skip items where bDelete |
29 | ************************/ |
30 | hItem = hLst->hFirst; |
31 | while ( hItem ) |
32 | { |
33 | _lstFreeItem( hItem ); |
34 | hItem = hLst->hFirst; |
35 | } |
36 | |
37 | /************************ |
38 | * RECURSE AS REQUIRED. RECURSION WILL STOP AS SOON AS WE GET TO A LIST WHICH |
39 | * DOES NOT NEED TO BE DELETED YET (refs >= 0). |
40 | ************************/ |
41 | if ( hLst->hLstBase ) /* we are a cursor */ |
42 | lstClose( hLst->hLstBase ); /* dec ref count and close if < 0 */ |
43 | |
44 | /************************ |
45 | * FREE LIST HANDLE |
46 | ************************/ |
47 | free( hLst ); |
48 | |
49 | return LST_SUCCESS; |
50 | } |
51 | |
52 | |
53 | |
54 | |