copyfile() returns a byte count, with errno cleared, when the copy
fails after the first block. movefile() across file systems then
removes the source and leaves a truncated copy.
The copy loop adds the result of write() to the total without checking
it, takes a failed read() for end of file, and the result of close() on
the destination is dropped.
Return -1 with errno set on any of them, and retry short writes.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>