SNMP Subagent Programmer's Guide
Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-43
Static Directory Program
/*****************************************************************************
* build_files Build the list of file names. <--
15
****************************************************************************/
void build_files(struct directory *dir)
{
struct dirent *dirent;
struct file_entry *file;
struct file_entry *file_list = NULL;
int len;
#define MAX_dirName 255 /* from GDMOC dynamls.h output */ <--
16
#define MAX_fileName 255
char searchsubvol [(MAX_dirName+1)];
short search_id;
short error;
short findnext_len;
if (dir->files)
{ return; }
/* ensure NULL termination of directory name. */
dir->dir_name.val[dir->dir_name.len] = '\0';
strcpy((char *) &searchsubvol, dir->dir_name.val); /* FINDSTART needs this */
strncat((char *) &searchsubvol, ".*", MAX_dirName);
findnext_len = strlen((char *) &searchsubvol);
error = FILENAME_FINDSTART_(&search_id, (char *)&searchsubvol,
(short) findnext_len, 2 /* this subvol only */);
while (!error) {
/* Build and fill in new entry. */
file = (struct file_entry *)safe_malloc(sizeof(*file));
file->file_name.val = (ubyte *) safe_malloc(MAX_fileName+1);
if (!(error = FILENAME_FINDNEXT_(search_id, (char*)file->file_name.val,
MAX_fileName, &findnext_len)))
{ /* Insert new entry in the list. */
file->file_name.len = findnext_len;
file_list = insert_new_file(file_list, file); <--
17
}
}
free(file)->file_name.val); /* get rid of storage allocated */
free(file); /* before FILENAME_FINDNEXT_ failed... */
error = FILENAME_FINDFINISH_(search_id);
dir->files = file_list;
}
...
Example 2-8. Static Directory Include File dirC (page 3 of 3)