Return TypeFunction nameArguments
hzEcodeFilecopy(const hzString&,const hzString&,)

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

Function Logic:

0:START 1:!tgt 2:Return hzerr(E_ARGUMENT,No target filepath supplied) 3:OpenInputStrm rc 4:rc!=E_OK 5:Return rc 6:ofstream::open ofstream::fail 7:os.fail() 8:close 9:Return hzerr(E_WRITEFAIL,Could not open/create target file %s\n,*tgt) 10:rc==E_OK; 11:ifstream::read ifstream::gcount 12:!is.gcount() 13:ifstream::gcount ofstream::write ofstream::fail 14:os.fail() 15:Return hzerr(E_WRITEFAIL,Could not write %d bytes to target file %s\n,is.gcount(),*tgt) 16:close close 17:Return rc

Function body:

hzEcode Filecopy (const hzString& tgt, const hzString& src)
{
   _hzfunc("Filecopy") ;
   ifstream    is ;
   ofstream    os ;
   char        buf [1028];
   hzEcode     rc = E_OK ;
   if  (!tgt)
       return hzerr(E_ARGUMENT, "No target filepath supplied") ;
   rc = OpenInputStrm(is, src) ;
   if (rc != E_OK)
       return rc ;
   os.open(tgt) ;
   if (os.fail())
   {
       is.close() ;
       return hzerr(E_WRITEFAIL, "Could not open/create target file %s\n", *tgt) ;
   }
   for (; rc == E_OK ;)
   {
       is.read(buf, 1024);
       if (!is.gcount())
           break ;
       os.write(buf, is.gcount()) ;
       if (os.fail())
           return hzerr(E_WRITEFAIL, "Could not write %d bytes to target file %s\n", is.gcount(), *tgt) ;
   }
   is.close() ;
   os.close() ;
   threadLog("File %s copied to %s\n", *src, *tgt) ;
   return rc ;
}