Blatts the named directory (if correct permissions). Uses recursion to delete any sub-directories

Return TypeFunction nameArguments
hzEcodeBlattDir(const char*,)

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

Function Logic:

0:START 1:unknown 2:Return E_ARGUMENT 3:pDir 4:unknown 5:Return E_OPENFAIL 6:unknown 7:unknown 8:teststr teststr teststr 9:unknown 10:items 11:Return E_CORRUPT 12:unknown 13:rc 14:unknown 15:sys_rc 16:unknown 17:rc 18:items 19:unknown 20:sys_rc 21:unknown 22:rc 23:Return rc

Function body:

hzEcode BlattDir (const char* dirname)
{
   //  Category: Directory
   //  
   //  Blatts the named directory (if correct permissions). Uses recursion to delete any sub-directories
   //  
   //  Arguments: 1) dirname The directory name (full path)
   //  
   //  Returns: E_ARGUMENT If the directory is not supplied
   //     E_OPENFAIL If the supplied directory could not be opened
   //     E_CORRUPT If any directory entry cannot be stated
   //     E_WRITEFAIL If the directory and any entry within it could not be unlinked
   //     E_OK  If the directory was successfully removed
   _hzfunc("BlattDir") ;
   FSTAT       fs ;            //  To obtain directory entry info
   dirent*     pDE ;           //  Directory entry
   DIR*        pDir ;          //  An open directory
   hzString    teststr ;       //  Full path of directory entry
   int32_t     sys_rc = 0; //  Return code from std calls
   hzEcode     rc = E_OK ;
   /*
   **  ** Move thru current directory and read files and sub directories
   **      */
   if (!dirname || !dirname[0])
       return E_ARGUMENT ;
   pDir = opendir(dirname) ;
   if (!pDir)
       return E_OPENFAIL ;
   for (; rc == E_OK && (pDE = readdir(pDir)) ;)
   {
       if (pDE->d_name[0]== ''.''&&(pDE->d_name[1]== 0|| (pDE->d_name[1]== ''.''&&pDE->d_name[2]== 0)))
           continue ;
       teststr = dirname ;
       teststr += "/" ;
       teststr += pDE->d_name ;
       //  Stat failure?
       if (stat(*teststr, &fs) == -1)
       {
           hzerr(E_CORRUPT, "Could not stat directory entry %s", *teststr) ;
           return E_CORRUPT ;
       }
       if (S_ISDIR(fs.st_mode))
       {
           rc = BlattDir(*teststr) ;
           continue ;
       }
       if (S_ISREG(fs.st_mode))
       {
           sys_rc = unlink(*teststr) ;
           if (sys_rc)
               rc = E_WRITEFAIL ;
           continue ;
       }
   }
   closedir(pDir) ;
   if (rc == E_OK)
   {
       sys_rc = rmdir(dirname) ;
       if (sys_rc)
           rc = E_WRITEFAIL ;
   }
   return rc ;
}