Return TypeFunction nameArguments
hzEcodeReadDir(hzVect<hzDirent>&,const char*,const char*,)

Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp

Function Logic:

0:START 1:hzVect::Clear 2:cpPath&&cpPath[0] 3:GetAbsPath rc 4:rc!=E_OK 5:Return hzwarn(rc,Could not obtain absolute path for (%s),cpPath) 6:lstat(*thePath,&fs)<0 7:Return hzwarn(E_NOTFOUND,No such directory or file exists (%s),*thePath) 8:!S_ISDIR(fs.st_mode) 9:Return hzwarn(E_TYPE,Given path (%s) is not a directory,*thePath) 10:opendir pDir 11:GetCurrDir opendir pDir 12:!pDir 13:Return hzwarn(E_OPENFAIL,Directory (%s) could not be opened,*thePath) 14:pDE=readdir(pDir); 15:pDE->d_name[0]=='.'&&(pDE->d_name[1]==0||(pDE->d_name[1]=='.'&&pDE->d_name[2]==0)) 16:!FormCheckCstr(pDE->d_name,cpCriteria) 17:thePath 18:teststr teststr teststr 19:teststr 20:stat(*teststr,&fs)==-1 21:closedir 22:Return E_CORRUPT 23:filename hzDirent::InitStat hzVect::Add 24:closedir 25:Return E_OK

Function body:

hzEcode ReadDir (hzVect<hzDirent>& entries, const char* cpPath, const char* cpCriteria)
{
   _hzfunc("ReadDir(2)") ;
   FSTAT       fs ;
   dirent*     pDE ;
   DIR*        pDir ;
   hzDirent    meta ;
   hzString    thePath ;
   hzString    teststr ;
   hzString    filename ;
   hzEcode     rc ;
   entries.Clear() ;
   if (cpPath && cpPath[0])
   {
       rc = GetAbsPath(thePath, cpPath) ;
       if (rc != E_OK)
           return hzwarn(rc, "Could not obtain absolute path for (%s)", cpPath) ;
       if (lstat(*thePath, &fs) < 0)
           return hzwarn(E_NOTFOUND, "No such directory or file exists (%s)", *thePath) ;
       if (!S_ISDIR(fs.st_mode))
           return hzwarn(E_TYPE, "Given path (%s) is not a directory", *thePath) ;
       pDir = opendir(*thePath) ;
   }
   else
   {
       GetCurrDir(thePath) ;
       pDir = opendir(".") ;
   }
   if (!pDir)
       return hzwarn(E_OPENFAIL, "Directory (%s) could not be opened", *thePath) ;
   for (; pDE = readdir(pDir) ;)
   {
       if (pDE->d_name[0]== ''.''&&(pDE->d_name[1]== 0|| (pDE->d_name[1]== ''.''&&pDE->d_name[2]== 0)))
           continue ;
       if (!FormCheckCstr(pDE->d_name, cpCriteria))
           continue ;
       if (thePath)
       {
           teststr = thePath ;
           teststr += "/" ;
           teststr += pDE->d_name ;
       }
       else
           teststr = pDE->d_name ;
       if (stat(*teststr, &fs) == -1)
       {
           closedir(pDir) ;
           hzerr(E_CORRUPT, "Could not stat directory entry %s", *teststr) ;
           return E_CORRUPT ;
       }
       filename = pDE->d_name ;
       meta.InitStat(thePath, filename, fs) ;
       entries.Add(meta) ;
   }
   closedir(pDir) ;
   return E_OK ;
}