Return Type | Function name | Arguments |
---|---|---|
hzEcode | AssertDir | (const char*,unsigned int,) |
Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp
Function Logic:
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 ; }