SNMP Subagent Programmer's Guide

Dynamic Directory Program
2-52 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
/*****************************************************************************
* next_file The job of this
<-- 8
* function is to return the indices of the
* "next" row of this table.
****************************************************************************/
int
next_file(Void *ctxt,
Void **indices)
...
{
struct directory *dir = (struct directory *) ctxt;
struct file_entry *file;
/* Build the cache of names. */
build_files(dir);
<-- 9
/* If the first pointer is NULL, the library code
* wants the first row of the table. */
if (*indices == NULL)
<-- 10
{
file = dir->files; /* get first one */
}
else
{
DisplayString *name = (DisplayString *)indices[0];
for (file = dir->files; file; file = file->next)
{
if (comp_files(name, &file->file_name) < 0)
<-- 11
{
break;
}
}
}
if (file)
{
/* Overwrite the array of pointers that
* was passed in with pointers to the "next"
* set of indices. */
indices[0] = (Void *) &file->file_name;
<-- 12
return(0); /* success */
}
return(ENOENT);
<-- 13
}
Example 2-10. Dynamic Directory Main Program and Next and Locator
Functions (page 3 of 4)