Uses the supplied input stream to open a file at the specified filepath. The main reason for this function is to standarize error condition reporting as all file open operations have essentially the same set of issues namely:- 1) The file either is not there 2) The pathname names a directory or other file system object, instead of a file 3) The file is empty (an error when intending to read) 4) The file cannot be read (program does not have access permissions

Return TypeFunction nameArguments
hzEcodeOpenInputStrm(ifstream&,const char*,)

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

Function Logic:

0:START 1:unknown 2:Return hzerr(E_ARGUMENT,No input filename specified) 3:unknown 4:Return hzerr(E_NOTFOUND,Filename %s does not exist,filepath) 5:unknown 6:Return hzerr(E_TYPE,Filename %s is not a file,filepath) 7:unknown 8:Return hzerr(E_NODATA,Filename %s is empty,filepath) 9:unknown 10:items 11:items 12:unknown 13:Return hzerr(E_OPENFAIL,Filename %s could not be opened,filepath) 14:Return E_OK

Function body:

hzEcode OpenInputStrm (ifstream& input)const char* filepath, 
{
   //  Category: Directory
   //  
   //  Uses the supplied input stream to open a file at the specified filepath. The main reason for this function is to standarize error condition reporting as
   //  all file open operations have essentially the same set of issues namely:-
   //  
   //   1) The file either is not there
   //   2) The pathname names a directory or other file system object, instead of a file
   //   3) The file is empty (an error when intending to read)
   //   4) The file cannot be read (program does not have access permissions
   //  
   //  Arguments: 1) input  Reference to an input stream which this function will open
   //     2) filepath Full pathname of file to open
   //     3) callfn  This function's caller. If this is zero, this function refrains from logging error and just returns them.
   //  
   //  Returns: E_ARGUMENT If the filepath is NULL
   //     E_NOTFOUND If the filepath specified does not exist as a directory entry of any kind
   //     E_TYPE  If the filepath names a directory entry that is not a file
   //     E_NODATA If the filepath is a file but empty
   //     E_OPENFAIL If the file specified could not be opened for reading
   //     E_OK  If the input stream was opened OK
   _hzfunc(__func__) ;
   FSTAT   fs ;        //  File status
   //  Check filepath is supplied
   if (!filepath || !filepath[0])
       return hzerr(E_ARGUMENT, "No input filename specified") ;
   //  Check if filepath names a file
   if (lstat(filepath, &fs) < 0)
       return hzerr(E_NOTFOUND, "Filename %s does not exist", filepath) ;
   //  Check filepath actually is a file
   if (!S_ISREG(fs.st_mode))
       return hzerr(E_TYPE, "Filename %s is not a file", filepath) ;
   //  Check file has content
   if (!fs.st_size)
       return hzerr(E_NODATA, "Filename %s is empty", filepath) ;
   //  Check supplied stream is not already open
   if (input.is_open())
       hzwarn(E_DUPLICATE, "Filename %s is already open", filepath) ;
   else
   {
       input.open(filepath) ;
       if (input.fail())
           return hzerr(E_OPENFAIL, "Filename %s could not be opened", filepath) ;
   }
   return E_OK ;
}