Translate the supplied null terminate string, assumed to be an path relative to the current directory, into an absolute path. Places the result into the supplied string recepticle. Note that if the relative path is not supplied the output value will be the name of the current working directory. Note also that this function DOES NOT TEST if the resulting path exists or that it can be accessed.

Return TypeFunction nameArguments
hzEcodeGetAbsPath(hzString&,const char*,)

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

Function Logic:

0:START 1:unknown 2:abs 3:Return E_OK 4:unknown 5:abs abs rel abs 6:Return E_OK 7:items cpDir 8:unknown 9:unknown 10:Return hzwarn(E_NOTFOUND,The current working directory has access issues) 11:unknown 12:Return hzwarn(E_NOTFOUND,The current working directory has been unlinked) 13:Return hzwarn(E_NOTFOUND,Unspecified error) 14:unknown 15:abs items 16:Return E_OK 17:unknown 18:unknown 19:unknown 20:j items 21:unknown 22:unknown 23:items 24:Return E_BADVALUE 25:unknown 26:unknown 27:* 28:abs abs abs items 29:Return E_OK

Function body:

hzEcode GetAbsPath (hzString& abs)const char* rel, 
{
   //  Category: Directory
   //  
   //  Translate the supplied null terminate string, assumed to be an path relative to the current directory, into an absolute path. Places the result into the
   //  supplied string recepticle.
   //  
   //  Note that if the relative path is not supplied the output value will be the name of the current working directory.
   //  
   //  Note also that this function DOES NOT TEST if the resulting path exists or that it can be accessed.
   //  
   //  Arguments: 1) Dir  The hzString reference to populate
   //  
   //  Returns: E_NOTFOUND If the current directory has access issues or has been unlinked
   //     E_OK  If the operation was successful
   _hzfunc("GetCurrDir") ;
   char*   cpDir ;     //  Buffer for current working directory
   //  If the supplied relative path is actually absolute, just set absolte = relative
   if (rel[0]== CHAR_FWSLASH)
       { abs = rel ; return E_OK ; }
   //  Look for the home directory sequence
   if (rel[0]== CHAR_TILDA && rel[1]== CHAR_FWSLASH)
   {
       abs = getenv("HOME") ;
       abs += "/" ;
       abs += (rel + 2);
       return E_OK ;
   }
   //  Clear string
   abs.Clear() ;
   //  Get current working dir
   cpDir = get_current_dir_name() ;
   if (!cpDir)
   {
       if (errno == EACCES)    return hzwarn(E_NOTFOUND, "The current working directory has access issues") ;
       if (errno == ENOENT)    return hzwarn(E_NOTFOUND, "The current working directory has been unlinked") ;
       return hzwarn(E_NOTFOUND, "Unspecified error") ;
   }
   //  If no relative path supplied, use the current directory
   if (!rel || !rel[0])
   {
       abs = cpDir ;
       free(cpDir) ;
       return E_OK ;
   }
   char*       i ;         //  Path iterator
   char*       j ;         //  Placeholder
   uint32_t    lev ;       //  Directory level
   uint32_t    oset ;      //  Offset into path
   uint32_t    step ;      //  Number of backward steps (../)
   if (rel[0]== CHAR_PERIOD && rel[1]== CHAR_PERIOD && rel[2]== CHAR_FWSLASH)
   {
       for (lev = 0,i = cpDir ; *i ; i++)
       {
           if (*i == CHAR_FWSLASH)
               { j = i ; lev++ ; }
       }
       //  Count the sequences of ../
       for (step = 1,oset = 3; rel[oset] == CHAR_PERIOD && rel[oset+1]== CHAR_PERIOD && rel[oset+2]== CHAR_FWSLASH ; step++, oset += 3);
       if (step > lev)
           { free(cpDir) ; return E_BADVALUE ; }
       for (; step ; step--)
       {
           for (j-- ; i != cpDir && *j != CHAR_FWSLASH ; j--) ;
       }
       *j = 0;
   }
   abs = cpDir ;
   abs += "/" ;
   abs += rel ;
   free(cpDir) ;
   return E_OK ;
}