Return Type | Function name | Arguments |
---|---|---|
hzEcode | Filecopy | (const hzString&,const hzString&,) |
Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp
Function Logic:
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 ; }