Return TypeFunction nameArguments
hzEcodeAssertDir(const char*,unsigned int,)

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

Function Logic:

0:START 1:!dirname||!dirname[0] 2:Return E_ARGUMENT 3:stat(dirname,&fs)!=-1 4:fs.st_mode&S_IFDIR 5:Return E_OK 6:Return hzerr(E_NOCREATE,Target dir [%s] exists as non-directory,dirname) 7:cpPath j i 8:*i; 9:*i&&*i!=(char)47; 10:* 11:stat(cpPath,&fs)==-1 12:mkdir(cpPath,(nPerms&0x01ff))==-1 13:strerror cpPath 14:Return E_OPENFAIL 15:fs.st_mode&S_IFDIR 16:cpPath 17:Return E_OPENFAIL 18:cpPath 19:Return E_OK

Function body:

hzEcode AssertDir (const char* dirname, unsigned int nPerms)
{
   _hzfunc("AssertDir") ;
   FSTAT       fs ;
   const char* i ;
   char*       j ;
   char*       cpPath ;
   if (!dirname || !dirname[0])
       return E_ARGUMENT ;
   if (stat(dirname, &fs) != -1)
   {
       if (fs.st_mode & S_IFDIR)
           return E_OK ;
       return hzerr(E_NOCREATE, "Target dir [%s] exists as non-directory", dirname) ;
   }
   cpPath = new char[strlen(dirname) + 1];
   j = cpPath ;
   i = dirname ;
   for (; *i ;)
   {
       for (*j++ = *i++ ; *i && *i != CHAR_FWSLASH ; *j++ = *i++) ;
       *j = 0;
       if (stat(cpPath, &fs) == -1)
       {
           if (mkdir(cpPath, (nPerms & 0x01ff))==-1)
           {
               hzerr(E_OPENFAIL, "Cannot make dir [%s] %s", cpPath, strerror(errno)) ;
               delete cpPath ;
               return E_OPENFAIL ;
           }
           continue ;
       }
       if (fs.st_mode & S_IFDIR)
           continue ;
       hzerr(E_OPENFAIL, "Directory entity [%s] exists as non-directory", cpPath) ;
       delete cpPath ;
       return E_OPENFAIL ;
   }
   delete cpPath ;
   return E_OK ;
}