1 | #include <config.h> |
2 | #include "lst.h" |
3 | |
4 | /*! |
5 | * \brief Returns the data stored at nIndex. |
6 | * |
7 | * This does a scan from first-to-last until nIndex or until EOL. This |
8 | * can be slow if there are many items in the list. |
9 | * |
10 | * This does not return the item handle - it returns the user data stored |
11 | * in the item. |
12 | * |
13 | * When done; the current item is either the item at nIndex or EOL. |
14 | * |
15 | * \param hLst Input. Viable list handle. |
16 | * \param nIndex Input. 0-based index of the desired item. |
17 | * |
18 | * \return void* |
19 | * \retval NULL Item at index could not be found - effectively data is NULL. |
20 | * \retval !NULL Reference to the data stored at nIndex |
21 | */ |
22 | void *lstGoto( HLST hLst, long nIndex ) |
23 | { |
24 | long n = 0; |
25 | |
26 | if ( !hLst ) |
27 | return NULL; |
28 | |
29 | lstFirst( hLst ); |
30 | while ( n <= nIndex ) |
31 | { |
32 | if ( lstEOL( hLst ) ) |
33 | break; |
34 | if ( n == nIndex ) |
35 | return hLst->hCurrent->pData; |
36 | n++; |
37 | lstNext( hLst ); |
38 | } |
39 | |
40 | return NULL; |
41 | } |
42 | |
43 | |
44 | |
45 | |