File: lstGoto.c

package info (click to toggle)
unixodbc 2.2.14p2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,628 kB
  • ctags: 12,533
  • sloc: ansic: 104,243; cpp: 38,571; sh: 15,958; makefile: 2,727; sql: 1
file content (43 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "lst.h"

/*! 
 * \brief   Returns the data stored at nIndex.
 * 
 *          This does a scan from first-to-last until nIndex or until EOL. This
 *          can be slow if there are many items in the list.
 *
 *          This does not return the item handle - it returns the user data stored
 *          in the item.
 *
 *          When done; the current item is either the item at nIndex or EOL.
 *
 * \param   hLst    Input. Viable list handle.
 * \param   nIndex  Input. 0-based index of the desired item.
 * 
 * \return  void*
 * \retval  NULL    Item at index could not be found - effectively data is NULL.
 * \retval  !NULL   Reference to the data stored at nIndex
 */
void *lstGoto( HLST hLst, long nIndex )
{
	long n = 0;

    if ( !hLst )
        return NULL;

	lstFirst( hLst );
	while ( n <= nIndex )
	{
        if ( lstEOL( hLst ) )
            break;
        if ( n == nIndex )
            return hLst->hCurrent->pData;
        n++;
		lstNext( hLst );
	}

    return NULL;
}