net-snmp 5.7
readdir.c
00001 /*
00002  * readdir() replacement for MSVC.
00003  */
00004 
00005 #define WIN32IO_IS_STDIO
00006 
00007 #include <net-snmp/net-snmp-config.h>
00008 #include <net-snmp/types.h>
00009 #include <net-snmp/library/system.h>
00010 #ifdef HAVE_SYS_STAT_H
00011 #include <sys/stat.h>
00012 #endif
00013 #include <tchar.h>
00014 #include <windows.h>
00015 
00016 
00017 /*
00018  * Readdir just returns the current string pointer and bumps the
00019  * * string pointer to the nDllExport entry.
00020  */
00021 struct direct  *
00022 readdir(DIR * dirp)
00023 {
00024     int             len;
00025     static int      dummy = 0;
00026 
00027     if (dirp->curr) {
00028         /*
00029          * first set up the structure to return 
00030          */
00031         len = strlen(dirp->curr);
00032         strcpy(dirp->dirstr.d_name, dirp->curr);
00033         dirp->dirstr.d_namlen = len;
00034 
00035         /*
00036          * Fake an inode 
00037          */
00038         dirp->dirstr.d_ino = dummy++;
00039 
00040         /*
00041          * Now set up for the nDllExport call to readdir 
00042          */
00043         dirp->curr += len + 1;
00044         if (dirp->curr >= (dirp->start + dirp->size)) {
00045             dirp->curr = NULL;
00046         }
00047 
00048         return &(dirp->dirstr);
00049     } else
00050         return NULL;
00051 }